/* Base design system — all colors/shape come from skin cssVars with sane fallbacks. */
:root {
  --bg: #0b1220; --bg2: #0e1729; --panel: #111a2e; --panel2: #16223a;
  --accent: #22d3ee; --accent2: #818cf8; --accent-ink: #04212a;
  --text: #e2e8f0; --muted: #7c8db0; --border: #1e2c47;
  --ok: #34d399; --warn: #fbbf24; --danger: #f87171;
  --radius: 10px; --font: 'Segoe UI', 'Noto Sans TC', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 32px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-box h1 { margin: 12px 0 4px; font-size: 22px; letter-spacing: .06em; }
.login-form { display: grid; gap: 12px; margin-top: 24px; text-align: left; }

/* ---------- Shell ---------- */
.shell { display: flex; height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg2); border-right: 1px solid var(--border); padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 10px; }
.brand-logo { width: 30px; height: 30px; object-fit: contain; }
.brand-text { font-weight: 700; letter-spacing: .05em; font-size: 16px; color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  padding: 9px 12px; border-radius: calc(var(--radius) / 2); color: var(--text); opacity: .85;
}
.nav-item:hover { background: var(--panel2); opacity: 1; }
.nav-item.active { background: var(--panel2); color: var(--accent); opacity: 1; font-weight: 600; }
.shell-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  border-bottom: 1px solid var(--border); background: var(--bg2);
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar-device { width: 220px; }
.ws-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); display: inline-block; }
.ws-dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.page { flex: 1; overflow-y: auto; padding: 20px; display: grid; gap: 16px; align-content: start; }

/* ---------- Cards / widgets ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
  background: var(--panel2);
}
.card-head-actions { display: flex; gap: 8px; font-weight: 400; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

/* ---------- Stats / meters ---------- */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .v { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .k { color: var(--muted); font-size: 12px; }
.meter { height: 8px; border-radius: 99px; background: var(--panel2); overflow: hidden; border: 1px solid var(--border); }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.meter.warn > i { background: var(--warn); }
.meter.danger > i { background: var(--danger); }
.meter.ok > i { background: var(--ok); }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tbl tr:hover td { background: var(--panel2); }
.tbl td.empty { text-align: center; color: var(--muted); padding: 24px; }
.tbl .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Controls ---------- */
.btn {
  font: inherit; padding: 7px 14px; border-radius: calc(var(--radius) / 2); cursor: pointer;
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.field {
  font: inherit; padding: 8px 12px; border-radius: calc(var(--radius) / 2);
  background: var(--panel2); color: var(--text); border: 1px solid var(--border); outline: none;
}
.field:focus { border-color: var(--accent); }
select.field { cursor: pointer; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 160px; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }

/* ---------- Badges / misc ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; border: 1px solid var(--border); background: var(--panel2); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.danger { color: var(--danger); border-color: var(--danger); }
.badge.accent { color: var(--accent); border-color: var(--accent); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.off { background: var(--muted); }

/* ---------- Lists / streams ---------- */
.stream { display: flex; flex-direction: column; gap: 6px; max-height: 380px; overflow-y: auto; }
.stream-item { display: flex; gap: 10px; padding: 7px 10px; background: var(--panel2); border-radius: calc(var(--radius) / 2); align-items: baseline; }
.stream-item time { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.stream-item .tag { flex: 0 0 auto; }

/* ---------- Map (pure SVG) ---------- */
.mapbox { width: 100%; height: 340px; background: var(--panel2); border-radius: calc(var(--radius) / 2); overflow: hidden; }
.mapbox svg { width: 100%; height: 100%; display: block; }
.mapbox .grid-line { stroke: var(--border); stroke-width: 1; }
.mapbox .track { fill: none; stroke: var(--accent); stroke-width: 2; }
.mapbox .pt { fill: var(--accent2); }
.mapbox .pt.latest { fill: var(--ok); r: 6; }
.mapbox .geo { fill: rgba(34,211,238,.08); stroke: var(--accent); stroke-dasharray: 4 3; }

/* ---------- Screen / camera viewports ---------- */
.viewport {
  position: relative; background: #000; border-radius: calc(var(--radius) / 2);
  display: grid; place-items: center; min-height: 320px; overflow: hidden;
}
.viewport img { max-width: 100%; max-height: 70vh; display: block; cursor: crosshair; }
.viewport .placeholder { color: var(--muted); padding: 60px; }

/* ---------- Media grid ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-cell { background: var(--panel2); border: 1px solid var(--border); border-radius: calc(var(--radius) / 2); overflow: hidden; }
.media-cell .thumb { width: 100%; height: 120px; object-fit: cover; display: block; background: #000; cursor: pointer; }
.media-cell .meta { padding: 8px 10px; display: flex; justify-content: space-between; gap: 6px; align-items: center; font-size: 12px; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-width: min(900px, 94vw); max-height: 90vh; overflow: auto; }
.modal img, .modal video { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--panel); border: 1px solid var(--ok); color: var(--text);
  padding: 10px 16px; border-radius: calc(var(--radius) / 2); box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toast-in .25s ease;
}
.toast.danger { border-color: var(--danger); }
.toast.warn { border-color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .4s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.spinner { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- Skin switcher ---------- */
.skin-card { display: flex; flex-direction: column; gap: 8px; }
.skin-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.swatches { display: flex; gap: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border); }

/* ---------- Breadcrumb ---------- */
.crumbs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.crumbs a { cursor: pointer; }
.crumbs span.sep { color: var(--muted); }

/* ---------- SMS threads ---------- */
.sms-list { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.thread-item { padding: 10px 12px; border-radius: calc(var(--radius) / 2); cursor: pointer; background: var(--panel2); margin-bottom: 6px; }
.thread-item.active { outline: 1px solid var(--accent); }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: var(--radius); background: var(--panel2); margin-bottom: 8px; }
.bubble.out { margin-left: auto; background: var(--accent); color: var(--accent-ink); }
.bubble .t { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sms-list { grid-template-columns: 1fr; }
}
