/* ==========================================================================
   Totem Control — cyber layer (loaded last)
   Dark obsidian + glass + neon accents on top of the existing components.
   Tokens -> backdrop -> surfaces -> topbar -> tabs -> metrics -> fleet
   cards -> dock -> focus/motion -> phone. Light theme keeps its own palette;
   only the structure below applies to it.
   ========================================================================== */

:root {
  --cy-card: rgba(15, 19, 34, .8);
  --cy-card-solid: #0f1322;
  --cy-border: rgba(255, 255, 255, .1);
  --cy-hi: inset 0 1px 0 0 rgba(255, 255, 255, .08);
  --cy-pill-border: rgba(51, 65, 85, .5);
  --cy-track: rgba(0, 0, 0, .4);
  --cy-mint: #34d399;
  --cy-mint-glow: 0 0 8px rgba(52, 211, 153, .35);
  --cy-grad: linear-gradient(90deg, #2563eb, #06b6d4);
  --cy-bar: linear-gradient(90deg, #06b6d4, #2563eb);
  --cy-label: #94a3b8;
  --cy-muted: #64748b;
  --cy-strong: #f1f5f9;
  --cy-dock: rgba(11, 14, 23, .85);
}
:root:not([data-theme="light"]) {
  color-scheme: dark;
  --bg: #08090f;
  --solid: #0f1322;
  --glass: var(--cy-card);
  --glass-border: var(--cy-border);
  --tile: rgba(255, 255, 255, .03);
  --tile-border: rgba(255, 255, 255, .07);
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, .12);
  --ok-line: rgba(52, 211, 153, .35);
  --track: #1e293b;
  --shadow: 0 18px 40px -20px rgba(0, 0, 0, .8);
}
:root[data-theme="light"] {
  --cy-card: rgba(255, 255, 255, .78);
  --cy-card-solid: #fff;
  --cy-border: rgba(15, 23, 42, .1);
  --cy-hi: inset 0 1px 0 0 rgba(255, 255, 255, .9);
  --cy-pill-border: rgba(148, 163, 184, .45);
  --cy-track: rgba(15, 23, 42, .06);
  --cy-mint: #059669;
  --cy-mint-glow: none;
  --cy-label: #64748b;
  --cy-muted: #64748b;
  --cy-strong: #0f172a;
  --cy-dock: rgba(255, 255, 255, .85);
}

/* ---- backdrop: obsidian + soft radial glows behind the header and content ---- */
:root:not([data-theme="light"]) .aurora { background: #08090f; }
:root:not([data-theme="light"]) .aurora::before,
:root:not([data-theme="light"]) .aurora::after { display: none; }
:root:not([data-theme="light"]) .aurora {
  background:
    radial-gradient(60rem 28rem at 12% -6%, rgba(37, 99, 235, .16), transparent 62%),
    radial-gradient(48rem 26rem at 92% 4%, rgba(6, 182, 212, .11), transparent 60%),
    radial-gradient(56rem 30rem at 50% 108%, rgba(52, 211, 153, .07), transparent 62%),
    #08090f;
}

/* ---- glass surfaces ---- */
.panel, .stat, .roll, .card, .bcard {
  background: var(--cy-card);
  border: 1px solid var(--cy-border);
  border-radius: 16px;
  box-shadow: var(--cy-hi), var(--shadow);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
}
.panel { border-radius: 18px; }
.tile, .kpi {
  background: rgba(255, 255, 255, .025);
  border: 1px solid var(--cy-border);
  border-radius: 14px;
  box-shadow: var(--cy-hi);
  min-width: 0;
}
:root[data-theme="light"] .tile, :root[data-theme="light"] .kpi { background: rgba(255, 255, 255, .6); }
.panel__head h2, .panel-title { text-wrap: balance; color: var(--cy-strong); }

/* ---- top bar ---- */
:root:not([data-theme="light"]) .topbar { background: rgba(8, 9, 15, .72); border-bottom: 1px solid rgba(255, 255, 255, .06); }
.brand__text strong {
  font-weight: 800;
  letter-spacing: -.015em;
  background: linear-gradient(90deg, #22d3ee 0%, #a5f3fc 45%, #ffffff 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
:root[data-theme="light"] .brand__text strong { background-image: linear-gradient(90deg, #0891b2, #0f172a); }
.brand__text small { color: var(--cy-muted); }

/* live-status dot */
.conn { gap: 7px; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--cy-label); }
.conn__dot { width: 8px; height: 8px; }
.conn__dot--up { background: #34d399; box-shadow: 0 0 8px #34d399; animation: cyLive 2s ease-in-out infinite; }
.conn__dot--down { background: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, .7); }
@keyframes cyLive { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.82); } }

/* quick-stat pills */
.players {
  background: rgba(15, 19, 34, .6);
  border: 1px solid var(--cy-pill-border);
  border-radius: 999px;
  box-shadow: var(--cy-hi);
  font-size: 12.5px;
  color: var(--cy-label);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
:root[data-theme="light"] .players { background: rgba(255, 255, 255, .7); }
.players svg { width: 14px; height: 14px; color: #22d3ee; }
.players__n { font-family: var(--font-mono); font-weight: 700; color: var(--cy-strong); font-variant-numeric: tabular-nums; }
.players--ok { border-color: rgba(52, 211, 153, .35); }
.players--ok svg, .players--ok .players__n { color: var(--cy-mint); }

/* utility cluster: one right-aligned group */
.topbar__tools {
  gap: 4px;
  padding: 3px;
  border-radius: 14px;
  background: var(--cy-track);
  border: 1px solid rgba(255, 255, 255, .05);
}
.topbar__tools .conn { padding: 0 10px 0 8px; }
.topbar__tools .icon-btn { background: transparent; border-color: transparent; box-shadow: none; color: var(--cy-label); }
.topbar__tools .icon-btn:hover { background: rgba(255, 255, 255, .07); color: var(--cy-strong); }
:root[data-theme="light"] .topbar__tools .icon-btn:hover { background: rgba(15, 23, 42, .06); }

/* ---- section tabs (main + sub) ---- */
.tabs, .subtabs {
  background: var(--cy-track);
  border: 1px solid rgba(255, 255, 255, .05);
  border-radius: 12px;
  padding: 4px;
  box-shadow: none;
}
.subtabs { display: inline-flex; max-width: 100%; gap: 2px; }
.tab, .subtab {
  color: var(--cy-label);
  font-weight: 500;
  border-radius: 9px;
  transition: color .2s ease, background-color .2s ease, box-shadow .2s ease;
}
.subtab { border: 0; background: transparent; padding: 7px 14px; }
.tab:hover, .subtab:hover { color: #e2e8f0; }
:root[data-theme="light"] .tab:hover, :root[data-theme="light"] .subtab:hover { color: #0f172a; }
.tab.is-active, .subtab.is-active { color: #fff; font-weight: 600; }
.tabs__ind {
  border-radius: 9px;
  background: var(--cy-grad);
  box-shadow: 0 0 12px rgba(59, 130, 246, .4);
}
.subtab.is-active { background: var(--cy-grad); box-shadow: 0 0 12px rgba(59, 130, 246, .4); }

/* ---- metric cards: stat strip, tiles, kpis ---- */
.stat__label, .tile__label, .kpi span, .roll__head, .bcard__nums span, .stat-row span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--cy-label);
}
.stat__value, .tile__value, .kpi b, .roll__shards, .stat-row b {
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--cy-strong);
}
.stat__value, .tile__value { font-size: 24px; line-height: 1.15; }
.stat__sub, .eco-sub, .kpi small, .tile__sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--cy-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pos, .stat__value .pos, .tile__value .pos, .kpi b .pos, .bcard__nums b.pos, .stat__value--usd, .tile--usd .tile__value {
  color: var(--cy-mint);
  text-shadow: var(--cy-mint-glow);
}
.neg { color: #f87171; }

/* stat strip: label row with the icon on the right, number under it */
.stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "body icon";
  align-items: start;
  gap: 8px;
  padding: 14px 16px;
}
.stat__icon { grid-area: icon; width: 28px; height: 28px; border-radius: 8px; }
.stat__icon svg { width: 15px; height: 15px; }
.stat__body { grid-area: body; gap: 6px; min-width: 0; }

/* micro-icons inside tile headers */
.tile { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; }
.tile__label { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tile__ic { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0; color: #22d3ee; background: rgba(34, 211, 238, .1); }
.tile__ic svg { width: 13px; height: 13px; }

/* ---- fleet: bot cards ---- */
.cardgrid { gap: 14px; }
.bcard {
  padding: 16px;
  gap: 14px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.bcard:hover, .bcard:focus-visible { border-color: rgba(34, 211, 238, .4); box-shadow: var(--cy-hi), 0 0 0 1px rgba(34, 211, 238, .15), var(--shadow); }
.bcard__av { position: relative; display: inline-flex; flex-shrink: 0; }
.bcard__dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #64748b; border: 2px solid var(--cy-card-solid);
}
.bcard__dot.is-on { background: #34d399; box-shadow: 0 0 8px #34d399; }
.bcard__id b { color: var(--cy-strong); }
.bcard__id span { color: var(--cy-muted); }
.bcard .badge { flex-shrink: 0; border-radius: 999px; font-size: 11px; font-weight: 600; padding: 3px 9px; }
.bcard__nums {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--cy-track);
  border: 1px solid rgba(255, 255, 255, .04);
}
.bcard__nums div { gap: 4px; min-width: 0; }
.bcard__nums span { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard__nums b { font-family: var(--font-mono); font-size: 15px; font-weight: 700; color: var(--cy-strong); overflow: hidden; text-overflow: ellipsis; }
.bcard__eta { font-size: 12px; color: var(--cy-muted); font-variant-numeric: tabular-nums; }
.bcard__bar, .minibar { height: 6px; border-radius: 999px; background: #1e293b; }
:root[data-theme="light"] .bcard__bar, :root[data-theme="light"] .minibar { background: #e2e8f0; }
.bcard__bar i, .minibar i { border-radius: 999px; background: var(--cy-bar); box-shadow: 0 0 6px #38bdf8; transition: width .5s ease; }
.bcard__actions { padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .06); gap: 10px; }
.bcard__p24 { font-size: 12px; color: var(--cy-muted); font-weight: 500; margin-right: auto; white-space: nowrap; }
.bcard__p24 b { font-family: var(--font-mono); font-weight: 700; margin-left: 4px; }
.bcard__actions .ping { font-size: 12px; font-family: var(--font-mono); }

/* ---- buttons ---- */
.btn--primary { background: var(--cy-grad); color: #fff; border-color: transparent; box-shadow: 0 0 12px rgba(59, 130, 246, .35); }
.btn--primary:hover { box-shadow: 0 0 18px rgba(59, 130, 246, .55); }

/* ---- focus + motion (Web Interface Guidelines) ---- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid #22d3ee;
  outline-offset: 2px;
}
.bcard:focus-visible { outline: 2px solid #22d3ee; outline-offset: 2px; }
:root:not([data-theme="light"]) select { background-color: #0f1322; color: #f1f5f9; }
@media (prefers-reduced-motion: reduce) {
  .conn__dot--up, .badge--online::before { animation: none; }
  .bcard, .bcard__bar i, .bottomnav a, .bottomnav a::after, .tabs__ind { transition: none; }
}

/* ---- phone ---- */
@media (max-width: 720px) {
  .app { padding: 0 16px 24px; }
  .topbar__tools { padding: 2px; }
  .topbar__tools .icon-btn { width: 38px; height: 38px; }

  /* 2-column metric grids with 12/16 padding */
  .statstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat__value, .tile__value { font-size: 20px; }
  .stat__sub, .eco-sub { font-size: 11.5px; }
  .tiles, .eco-kpis, .projgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile__label { font-size: 10.5px; }
  .subtabs { display: flex; overflow-x: auto; }

  /* fleet: cards only on phones */
  #fleetLayout { display: none; }
  .cardgrid { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
  .bcard { padding: 14px; }

  /* floating dock */
  .bottomnav {
    left: 16px; right: 16px; bottom: calc(16px + var(--safe-b));
    z-index: 50;
    padding: 8px 12px;
    gap: 4px;
    border-radius: 16px;
    background: var(--cy-dock);
    border: 1px solid var(--cy-border);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, .7), var(--cy-hi);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    backdrop-filter: blur(24px) saturate(160%);
  }
  .bottomnav a {
    position: relative;
    border-radius: 12px;
    padding: 7px 4px 9px;
    font-size: 11px;
    font-weight: 500;
    color: var(--cy-muted);
    transition: color .25s ease, background-color .25s ease;
  }
  .bottomnav a::after {
    content: '';
    position: absolute; left: 50%; bottom: 2px;
    width: 18px; height: 3px; margin-left: -9px;
    border-radius: 999px;
    background: var(--cy-grad);
    box-shadow: 0 0 8px rgba(34, 211, 238, .7);
    opacity: 0; transform: scaleX(.3);
    transition: opacity .25s ease, transform .3s cubic-bezier(.3, .95, .3, 1);
  }
  .bottomnav a.is-active { color: #e2e8f0; background: rgba(59, 130, 246, .12); }
  :root[data-theme="light"] .bottomnav a.is-active { color: #0f172a; }
  .bottomnav a.is-active svg { color: #22d3ee; filter: drop-shadow(0 0 6px rgba(34, 211, 238, .5)); }
  .bottomnav a.is-active::after { opacity: 1; transform: scaleX(1); }
  .moresheet { bottom: calc(96px + var(--safe-b)); background: var(--cy-dock); border-color: var(--cy-border); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); }
  body { padding-bottom: calc(100px + var(--safe-b)); }
}
