:root {
  color-scheme: dark;
  --bg: #080d19;
  --bg-deep: #050914;
  --panel: rgba(18, 26, 45, 0.82);
  --panel-solid: #121a2d;
  --panel-soft: #0e1628;
  --line: rgba(151, 166, 196, 0.16);
  --line-strong: rgba(151, 166, 196, 0.28);
  --text: #f1f4fb;
  --muted: #8e9ab2;
  --quiet: #66728a;
  --violet: #7375ff;
  --violet-soft: rgba(115, 117, 255, 0.14);
  --mint: #24d6b0;
  --red: #ff6d76;
  --amber: #e6b84a;
  --radius: 18px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(85, 86, 205, 0.2), transparent 34rem),
    radial-gradient(circle at 90% 28%, rgba(25, 147, 131, 0.08), transparent 28rem),
    linear-gradient(180deg, var(--bg-deep), var(--bg));
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
#app:focus { outline: none; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 78px;
  padding: max(14px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) 14px max(28px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 12, 23, 0.8);
  backdrop-filter: blur(24px) saturate(150%);
}

.brand { display: inline-flex; align-items: center; gap: 12px; width: max-content; }
.brand strong { display: block; font-size: 15px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: var(--quiet); font-size: 9px; letter-spacing: .17em; text-transform: uppercase; }
.brand-mark { position: relative; display: flex; align-items: end; gap: 3px; width: 31px; height: 31px; padding: 7px; border: 1px solid rgba(115,117,255,.42); border-radius: 10px; background: linear-gradient(145deg, rgba(115,117,255,.2), rgba(36,214,176,.08)); }
.brand-mark i { display: block; width: 3px; border-radius: 3px; background: linear-gradient(180deg, var(--mint), var(--violet)); }
.brand-mark i:nth-child(1) { height: 7px; }
.brand-mark i:nth-child(2) { height: 14px; }
.brand-mark i:nth-child(3) { height: 10px; }

.main-nav { display: flex; align-items: center; gap: 5px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
.main-nav a { min-width: 74px; padding: 9px 16px; text-align: center; color: var(--muted); font-size: 13px; border-radius: 9px; transition: .2s ease; }
.main-nav a:hover { color: var(--text); }
.main-nav a.active { color: white; background: var(--panel-solid); box-shadow: 0 5px 16px rgba(0,0,0,.18); }

.button { border: 0; border-radius: 11px; padding: 10px 15px; cursor: pointer; transition: transform .16s ease, border-color .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: wait; transform: none; }
.button-quiet { border: 1px solid var(--line); background: rgba(255,255,255,.035); color: var(--muted); }
.button-quiet:hover { border-color: var(--line-strong); color: var(--text); }
.button-primary { background: linear-gradient(135deg, #7375ff, #5c61dd); color: white; box-shadow: 0 10px 30px rgba(76,80,210,.24); }
.button-secondary { border: 1px solid rgba(36,214,176,.28); color: var(--mint); background: rgba(36,214,176,.08); }
.button-danger { border: 1px solid rgba(255,109,118,.25); color: #ff949b; background: rgba(255,109,118,.06); }
.button-small { padding: 7px 10px; font-size: 12px; border-radius: 8px; }
.notify-button { justify-self: end; display: inline-flex; gap: 9px; align-items: center; font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--quiet); box-shadow: 0 0 0 3px rgba(102,114,138,.12); }
.notify-button.is-on .status-dot { background: var(--mint); box-shadow: 0 0 0 3px rgba(36,214,176,.12), 0 0 10px rgba(36,214,176,.4); }

.page { width: min(1440px, calc(100% - 56px)); margin: 0 auto; padding: 68px 0 84px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 34px; }
.page-heading h1 { margin: 4px 0 10px; font-size: clamp(30px, 4vw, 52px); font-weight: 590; letter-spacing: -.04em; }
.eyebrow, .section-kicker, .card-label { margin: 0; color: var(--violet); font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.lede { max-width: 660px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.freshness { display: flex; align-items: center; gap: 9px; padding-bottom: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.pulse { position: relative; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); }
.pulse::after { content: ""; position: absolute; inset: -4px; border: 1px solid rgba(36,214,176,.28); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { transform: scale(.8); opacity: .4; } 50% { transform: scale(1.35); opacity: 1; } }

.control-deck { display: flex; align-items: end; gap: 18px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(15,23,40,.7); box-shadow: var(--shadow); }
.control-group { display: grid; gap: 8px; }
.control-group > label, .compare-selects label > span { color: var(--quiet); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.control-window { flex: 1; }
.segment { display: flex; gap: 4px; }
.segment button { min-width: 58px; padding: 10px 14px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; }
.segment button:hover { color: white; background: rgba(255,255,255,.04); }
.segment button.active { color: white; background: var(--violet-soft); box-shadow: inset 0 0 0 1px rgba(115,117,255,.22); }
.select, .input { min-height: 38px; padding: 0 34px 0 12px; color: var(--text); border: 1px solid var(--line); border-radius: 9px; background: #0c1425; outline: none; }
.input { padding-right: 12px; color-scheme: dark; }
.select:focus, .input:focus { border-color: rgba(115,117,255,.62); box-shadow: 0 0 0 3px rgba(115,117,255,.1); }
.date-controls { display: flex; gap: 12px; }
.date-controls[hidden] { display: none; }

.view-tabs { display: flex; gap: 24px; margin: 36px 0 28px; border-bottom: 1px solid var(--line); }
.view-tabs button { position: relative; padding: 0 4px 14px; color: var(--muted); border: 0; background: transparent; cursor: pointer; font-weight: 600; }
.view-tabs button.active { color: white; }
.view-tabs button.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--violet), var(--mint)); }

.filter-row, .compare-controls, .section-heading { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.filter-row h2, .compare-controls h2, .section-heading h2 { margin: 5px 0 0; font-size: 20px; letter-spacing: -.02em; }
.count-pill { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; border-radius: 10px; color: var(--text); background: rgba(115,117,255,.2); font-size: 10px; }
.asset-picker { position: absolute; top: calc(100% + 10px); right: 0; z-index: 20; width: min(390px, 90vw); padding: 10px; border: 1px solid var(--line-strong); border-radius: 14px; background: #111a2e; box-shadow: 0 22px 70px rgba(0,0,0,.48); }
.asset-option { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border-radius: 9px; cursor: pointer; }
.asset-option:hover { background: rgba(255,255,255,.04); }
.asset-option > span { display: flex; align-items: center; gap: 10px; }
.asset-option small { color: var(--quiet); }
.asset-option input { accent-color: var(--violet); }
.asset-color { width: 8px; height: 8px; border-radius: 3px; }
.asset-chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 34px; margin: 16px 0 22px; }
.asset-chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.025); font-size: 11px; }
.asset-chip button { padding: 0; color: var(--quiet); border: 0; background: none; cursor: pointer; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, rgba(18,26,45,.9), rgba(12,19,34,.82)); box-shadow: 0 16px 55px rgba(0,0,0,.16); }
.chart-card-large { padding: 24px; }
.chart-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.chart-card h3 { margin: 5px 0 0; font-size: 17px; }
.latest-value { text-align: right; }
.latest-value strong { display: block; font-size: 20px; font-weight: 570; font-variant-numeric: tabular-nums; }
.latest-value small { color: var(--quiet); }
.chart { min-height: 250px; margin-top: 14px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-empty, .empty-state { min-height: 210px; display: grid; place-items: center; color: var(--quiet); text-align: center; font-size: 13px; border: 1px dashed var(--line); border-radius: 12px; }
.empty-state { min-height: 110px; }
.chart-tooltip { position: fixed; z-index: 100; pointer-events: none; padding: 8px 10px; color: white; border: 1px solid var(--line-strong); border-radius: 8px; background: rgba(7,12,23,.94); box-shadow: 0 8px 30px rgba(0,0,0,.3); font-size: 11px; transform: translate(10px,-100%); }

.compare-controls { align-items: end; margin-bottom: 22px; }
.compare-selects { display: flex; align-items: end; gap: 10px; }
.compare-selects label { display: grid; gap: 7px; }
.compare-selects .select { min-width: 180px; }
.swap-button { width: 38px; height: 38px; padding: 0; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.03); cursor: pointer; }
.compare-stack { display: grid; gap: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 2px; }
.formula { color: var(--quiet); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }

.task-heading { align-items: center; }
.task-section { margin-top: 18px; padding: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(15,23,40,.72); }
.section-heading { margin-bottom: 20px; }
.subtle { color: var(--quiet); font-size: 11px; }
.badge { padding: 6px 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; }
.badge.success { color: var(--mint); border-color: rgba(36,214,176,.22); background: rgba(36,214,176,.07); }
.badge.partial { color: var(--amber); border-color: rgba(230,184,74,.22); background: rgba(230,184,74,.07); }
.badge.failed { color: var(--red); border-color: rgba(255,109,118,.22); background: rgba(255,109,118,.07); }
.batch-summary { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 12px; }
.batch-assets { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-top: 20px; }
.batch-asset { padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: rgba(6,11,21,.35); }
.batch-asset-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.batch-asset-head strong { display: block; font-size: 13px; }
.batch-asset-head small { color: var(--quiet); }
.attempt-list { display: grid; gap: 8px; }
.attempt { position: relative; display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.attempt-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--quiet); }
.attempt.success .attempt-dot { background: var(--mint); }
.attempt.failure .attempt-dot { background: var(--red); }
.attempt.skipped .attempt-dot { background: var(--amber); }
.attempt em { max-width: 150px; color: var(--quiet); font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: 10px 12px; color: var(--quiet); border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; letter-spacing: .1em; font-weight: 500; }
.data-table td { padding: 14px 12px; color: var(--muted); border-bottom: 1px solid rgba(151,166,196,.09); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.error-text { color: #ff9aa1; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.setting-card { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: rgba(6,11,21,.3); }
.setting-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-card-head h3 { margin: 0; font-size: 14px; }
.setting-card p { margin: 5px 0 16px; color: var(--quiet); font-size: 11px; }
.setting-form { display: flex; align-items: end; gap: 10px; }
.setting-form .control-group { flex: 1; }
.toggle { position: relative; width: 38px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; border-radius: 12px; background: #283147; cursor: pointer; transition: .2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #8390a7; transition: .2s; }
.toggle input:checked + span { background: rgba(36,214,176,.28); }
.toggle input:checked + span::after { transform: translateX(16px); background: var(--mint); }
.channel-order-section { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.channel-order-section h3 { margin: 0; font-size: 14px; }
.channel-order-section > p { margin: 6px 0 16px; color: var(--quiet); font-size: 11px; }
.channel-orders { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.channel-order { padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.channel-order strong { display: block; margin-bottom: 10px; font-size: 12px; }
.channel-token { display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 7px; padding: 7px 8px; margin-top: 6px; border-radius: 8px; background: rgba(255,255,255,.035); color: var(--muted); font-size: 11px; }
.channel-token b { color: var(--quiet); font-weight: 500; }
.order-actions { display: flex; gap: 3px; }
.order-actions button { width: 24px; height: 24px; padding: 0; color: var(--quiet); border: 0; border-radius: 6px; background: rgba(255,255,255,.04); cursor: pointer; }
.order-actions button:disabled { opacity: .2; }

.install-note { margin-bottom: 14px; padding: 12px 14px; color: var(--amber); border: 1px solid rgba(230,184,74,.18); border-radius: 10px; background: rgba(230,184,74,.06); font-size: 12px; line-height: 1.6; }
.device-list { display: grid; gap: 10px; }
.device-card { display: grid; grid-template-columns: auto minmax(0,1fr) minmax(160px,240px) auto; align-items: center; gap: 14px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.device-icon { display: grid; place-items: center; width: 38px; height: 38px; color: var(--mint); border-radius: 11px; background: rgba(36,214,176,.08); }
.device-meta strong { display: block; font-size: 12px; }
.device-meta small { display: block; margin-top: 4px; color: var(--quiet); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-note { width: 100%; }
.device-actions { display: flex; gap: 7px; }

.footer { width: min(1440px, calc(100% - 56px)); margin: 0 auto; padding: 22px 0 max(22px, env(safe-area-inset-bottom)); display: flex; justify-content: space-between; color: var(--quiet); border-top: 1px solid var(--line); font-size: 10px; letter-spacing: .04em; }
.toast-region { position: fixed; z-index: 200; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 15px; color: var(--text); border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(17,26,46,.96); box-shadow: 0 16px 50px rgba(0,0,0,.35); font-size: 12px; animation: toast-in .2s ease; }
.toast.error { border-color: rgba(255,109,118,.32); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.loading-block { min-height: 220px; border-radius: 14px; background: linear-gradient(100deg, rgba(255,255,255,.025) 25%, rgba(255,255,255,.05) 38%, rgba(255,255,255,.025) 52%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }

@media (max-width: 1020px) {
  .control-deck { flex-wrap: wrap; }
  .control-window { flex-basis: 100%; }
  .batch-assets, .channel-orders { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .device-card { grid-template-columns: auto 1fr auto; }
  .device-note { grid-column: 2 / -1; grid-row: 2; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 70px; grid-template-columns: 1fr auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); background: rgba(7,12,23,.96); backdrop-filter: none; }
  .brand small { display: none; }
  .main-nav { position: fixed; z-index: 40; left: 16px; right: 16px; bottom: max(12px, env(safe-area-inset-bottom)); justify-content: center; background: rgba(13,20,36,.94); box-shadow: 0 14px 50px rgba(0,0,0,.4); backdrop-filter: blur(20px); }
  .main-nav a { flex: 1; }
  .notify-button { padding: 9px 10px; }
  .notify-button #notify-label { display: none; }
  .page { width: calc(100% - 28px); padding: 42px 0 100px; }
  .page-heading { display: block; }
  .page-heading h1 { font-size: 34px; }
  .freshness { margin-top: 18px; }
  .task-heading .button { width: 100%; margin-top: 20px; }
  .control-deck { padding: 14px; align-items: stretch; }
  .segment { overflow-x: auto; padding-bottom: 2px; }
  .segment button { min-width: 55px; }
  .date-controls { width: 100%; display: grid; grid-template-columns: 1fr; }
  .date-controls[hidden] { display: none; }
  .date-controls .control-group { min-width: 0; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card { padding: 16px; }
  .filter-row, .compare-controls { align-items: flex-start; }
  .compare-controls { display: block; }
  .compare-selects { margin-top: 16px; }
  .compare-selects label { min-width: 0; flex: 1; }
  .compare-selects .select { width: 100%; min-width: 0; }
  .formula { display: none; }
  .task-section { padding: 18px 14px; }
  .batch-assets, .settings-grid, .channel-orders { grid-template-columns: 1fr; }
  .data-table { min-width: 650px; }
  .device-heading { align-items: flex-start; }
  .device-heading .button { max-width: 150px; }
  .device-card { grid-template-columns: auto 1fr; }
  .device-actions { grid-column: 1 / -1; }
  .device-actions .button { flex: 1; }
  .device-note { grid-column: 1 / -1; grid-row: auto; }
  .footer { width: calc(100% - 28px); padding-bottom: 94px; }
}

@media (max-width: 460px) {
  .page-heading h1 { font-size: 30px; }
  .control-window { min-width: 0; }
  .filter-row { flex-wrap: wrap; }
  .asset-picker { left: 0; right: auto; }
  .compare-selects { gap: 6px; }
  .compare-selects .select { padding-left: 8px; font-size: 11px; }
  .chart-card-head { gap: 8px; }
  .latest-value strong { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
