/* Palette after morpho.org: blue-tinted neutrals, Morpho blue, soft gradient hero. */
:root {
  --bg: #f4f7ff; --surface: #ffffff; --surface-2: #edf3fe; --surface-3: #dee8fc;
  --border: #dee8fc; --border-strong: #d0ddf7;
  --text: #15181a; --text-2: #464f60; --muted: #727f99;
  --accent: #2b76ff; --accent-hover: #3c80ff; --accent-ink: #ffffff; --accent-soft: #5792ff14;
  --ok: #04675b; --ok-bg: #d9efed; --warn: #774205; --warn-bg: #ffe9cf; --bad: #ab103f; --bad-bg: #ffdadf;
  --chart: #2b76ff; --grid: #e6eefd;
  --hero-1: #86b1ff; --hero-2: #2b76ff; --hero-ink: #ffffff;
  --shadow: 0 1px 2px rgba(18, 18, 18, .04), 0 8px 24px -12px rgba(43, 118, 255, .12);
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px;
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --surface: #1a1d21; --surface-2: #22262c; --surface-3: #2c313a;
    --border: #ffffff14; --border-strong: #ffffff29;
    --text: #ffffff; --text-2: #d0ddf7; --muted: #95a1b8;
    --accent: #5792ff; --accent-hover: #79a8ff; --accent-ink: #ffffff; --accent-soft: #5792ff29;
    --ok: #72c6bc; --ok-bg: #04675b33; --warn: #fcc27f; --warn-bg: #ba824229; --bad: #ff7792; --bad-bg: #d5446929;
    --chart: #79a8ff; --grid: #ffffff0f;
    --hero-1: #3c80ff; --hero-2: #003185; --hero-ink: #ffffff;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --surface: #1a1d21; --surface-2: #22262c; --surface-3: #2c313a;
  --border: #ffffff14; --border-strong: #ffffff29;
  --text: #ffffff; --text-2: #d0ddf7; --muted: #95a1b8;
  --accent: #5792ff; --accent-hover: #79a8ff; --accent-ink: #ffffff; --accent-soft: #5792ff29;
  --ok: #72c6bc; --ok-bg: #04675b33; --warn: #fcc27f; --warn-bg: #ba824229; --bad: #ff7792; --bad-bg: #d5446929;
  --chart: #79a8ff; --grid: #ffffff0f;
  --hero-1: #3c80ff; --hero-2: #003185; --hero-ink: #ffffff;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 16px; margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h3 { margin: 0; font-size: 18px; font-weight: 500; letter-spacing: -0.01em; }
h4, .label {
  font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
h4 { margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0; }
.error { color: var(--bad); min-height: 1em; margin: 8px 0 0; }
.ok-text { color: var(--ok); }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  height: 36px; padding: 0 16px; border-radius: 999px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  font: 500 13px/1 var(--font); white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.icon { padding: 0 12px; }
.btn.small { height: 30px; padding: 0 12px; font-size: 12px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.link:hover { color: var(--text); }
input, select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--radius-s); height: 36px; padding: 0 12px; min-width: 0; transition: border-color .15s, background .15s;
}
input::placeholder { color: var(--muted); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* login */
.login { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); overflow: hidden; }
#login-fx { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.login-card {
  position: relative; width: 100%; max-width: 380px; border-radius: var(--radius-l); overflow: hidden;
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--border-strong);
  box-shadow: 0 30px 80px -30px rgba(43, 118, 255, .45), 0 0 0 1px rgba(255, 255, 255, .04) inset;
  animation: card-in .9s cubic-bezier(.16, 1, .3, 1) both;
}
.login-card .brand {
  justify-content: center; padding: 38px 28px; font-size: 18px; color: var(--hero-ink);
  background: linear-gradient(120deg, var(--hero-1), var(--hero-2), #79a8ff, var(--hero-1));
  background-size: 300% 300%; animation: hero-shift 12s ease-in-out infinite;
  position: relative; overflow: hidden;
}
.login-card .brand::after { /* light sweep across the header */
  content: ""; position: absolute; inset: -50% auto -50% -60%; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .35), transparent);
  transform: skewX(-20deg); animation: sweep 5.5s ease-in-out 1.2s infinite;
}
.login-card .brand .logo { background: rgba(255, 255, 255, .22); color: #fff; animation: logo-pulse 4s ease-in-out infinite; }
.login-body { display: grid; gap: 14px; padding: 22px 28px 22px; }
.login-body > * { animation: rise .7s cubic-bezier(.16, 1, .3, 1) both; }
.login-body > :nth-child(1) { animation-delay: .25s; }
.login-body > :nth-child(2) { animation-delay: .32s; }
.login-body > :nth-child(3) { animation-delay: .39s; }
.login-body > :nth-child(4), .login-body > :nth-child(5) { animation-delay: .46s; }
.login-body p { margin: 0; }
.login-card .btn { height: 44px; position: relative; overflow: hidden; }
.login-card .btn.primary::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-120%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .28), transparent); transition: transform .7s ease;
}
.login-card .btn.primary:hover::after { transform: translateX(120%); }
.login-card input { height: 44px; }
.login-card input:focus { box-shadow: 0 0 0 4px var(--accent-soft); }
.login-foot { text-align: center; }
.login-card.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97) both; }

@keyframes card-in { from { opacity: 0; transform: translateY(24px) scale(.97); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes hero-shift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes sweep { 0% { left: -60%; } 45%, 100% { left: 130%; } }
@keyframes logo-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .0); } 50% { box-shadow: 0 0 0 6px rgba(255, 255, 255, .14); } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(3px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) {
  .login-card, .login-body > *, .login-card .brand, .login-card .brand::after, .login-card .brand .logo { animation: none !important; }
}

/* top bar */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; letter-spacing: -0.01em; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(160deg, var(--hero-1), var(--hero-2)); color: #fff; font-family: Georgia, serif; font-size: 17px;
}
.tag {
  font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; padding: 12px 32px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#updated { font-family: var(--mono); font-size: 11px; margin-right: 4px; }

/* layout */
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 32px 48px; display: grid; gap: 20px; }
.wrap > *, .grid2 > * { min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.banner {
  padding: 12px 16px; border-radius: var(--radius-m); background: var(--warn-bg); color: var(--warn); font-size: 13px;
}

/* hero */
.hero {
  display: grid; grid-template-columns: 1.1fr 1.6fr; gap: 24px; align-items: end;
  padding: 32px; border-radius: var(--radius-l); color: var(--hero-ink);
  background:
    radial-gradient(700px 300px at 85% -20%, rgba(255, 255, 255, .35), transparent 60%),
    linear-gradient(160deg, var(--hero-1), var(--hero-2));
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hero .label { color: rgba(255, 255, 255, .78); }
.hero-value { font-size: 52px; line-height: 1.05; font-weight: 500; letter-spacing: -0.035em; margin: 10px 0 8px; }
.hero-sub { font-family: var(--mono); font-size: 12px; color: rgba(255, 255, 255, .85); }
.hero-side { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.hero-stat {
  padding: 16px; border-radius: var(--radius-m);
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); backdrop-filter: blur(6px);
}
.hero-stat .v { font-size: 20px; font-weight: 500; letter-spacing: -0.02em; margin-top: 6px; }
.hero-stat .s { font-size: 11px; color: rgba(255, 255, 255, .78); margin-top: 2px; font-family: var(--mono); }

/* stat tiles */
.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card .label { display: flex; align-items: center; gap: 6px; }
.card .v { font-size: 28px; font-weight: 500; letter-spacing: -0.03em; margin-top: 8px; line-height: 1.1; }
.card .s { color: var(--muted); font-size: 12px; margin-top: 4px; min-height: 18px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* panels */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l);
  padding: 20px 20px 12px; box-shadow: var(--shadow); min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tools input[type=search] { width: 240px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); }
.seg button {
  background: transparent; color: var(--muted); border: 0; height: 28px; padding: 0 14px; border-radius: 999px;
  cursor: pointer; font: 500 12px/1 var(--mono);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.chart { height: 240px; position: relative; margin-bottom: 8px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart svg text { font-family: var(--mono); }
.chart .empty { position: absolute; inset: 0; display: grid; place-items: center; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-s); padding: 8px 12px; font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); white-space: nowrap;
}

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 12px; white-space: nowrap; }
th {
  font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; user-select: none; border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--text); }
th.sorted { color: var(--text); }
.nt { text-transform: none; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
#devices tbody tr { cursor: pointer; transition: background .12s; }
#devices tbody tr:hover td { background: var(--surface-2); }
#devices tbody tr:hover td:first-child { border-radius: var(--radius-s) 0 0 var(--radius-s); }
#devices tbody tr:hover td:last-child { border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.dev-name { font-weight: 500; }
td .muted.small { font-family: var(--mono); font-size: 11px; }
.empty { text-align: center; color: var(--muted); padding: 28px; margin: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.active { color: var(--ok); background: var(--ok-bg); }
.pill.idle { color: var(--warn); background: var(--warn-bg); }
.pill.offline, .pill.stopped { color: var(--bad); background: var(--bad-bg); }
.pill.queued, .pill.joining { color: var(--accent); background: var(--accent-soft); }

.bar { width: 120px; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 10px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--hero-1), var(--accent)); }
.bar.full > i { background: var(--muted); opacity: .5; }

/* dialogs */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; margin: 0; }
.kv dt { color: var(--muted); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding-top: 2px; }
.kv dd { margin: 0; word-break: break-all; }
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius-l); padding: 0; background: var(--surface); color: var(--text);
  width: min(580px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(0, 0, 0, .24);
}
.dialog.wide { width: min(800px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(18, 18, 18, .55); backdrop-filter: blur(4px); }
.dialog-body { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 24px; flex-wrap: wrap; }
.dialog-foot > div { display: flex; gap: 8px; }
.rows { display: grid; gap: 8px; margin-bottom: 10px; }
.row { display: grid; grid-template-columns: 2fr 1fr 1fr 2fr auto; gap: 8px; }
.row.cold { grid-template-columns: 2.2fr 1fr auto; }
.pw-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field span { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.cmd { display: flex; gap: 10px; align-items: center; background: var(--surface-2); border-radius: var(--radius-m); padding: 10px 10px 10px 14px; }
.cmd code { flex: 1; word-break: break-all; white-space: pre-wrap; color: var(--text-2); }
.foot { text-align: center; font-family: var(--mono); font-size: 11px; }

@media (max-width: 1000px) {
  .hero { grid-template-columns: 1fr; align-items: start; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .wrap { padding: 16px 16px 40px; gap: 14px; }
  .hero { padding: 22px; }
  .hero-value { font-size: 40px; }
  .hero-side { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .v { font-size: 22px; }
  .cards .card:last-child:nth-child(odd) { grid-column: span 2; }
  .hero-stat { padding: 12px 14px; }
  .hero-stat .v { font-size: 18px; margin-top: 2px; }
  .tools, .tools input[type=search] { width: 100%; }
  .tools select { flex: 1; }
  #updated { width: 100%; }
  .pw-row, .row, .row.cold { grid-template-columns: 1fr; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
}

/* ---------- dashboard motion ---------- */
.app-bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
#dash-fx { width: 100%; height: 100%; display: block; opacity: .9; }
/* let the live map show faintly through the panels */
.panel, .card { background: color-mix(in srgb, var(--surface) 88%, transparent); }
.topbar { background: color-mix(in srgb, var(--bg) 72%, transparent); }

/* staggered entrance on first load */
#app.intro .topbar { animation: rise .6s cubic-bezier(.16, 1, .3, 1) both; }
#app.intro .wrap > * { animation: rise .8s cubic-bezier(.16, 1, .3, 1) both; }
#app.intro .wrap > :nth-child(2) { animation-delay: .05s; }
#app.intro .wrap > :nth-child(3) { animation-delay: .12s; }
#app.intro .wrap > :nth-child(4) { animation-delay: .19s; }
#app.intro .wrap > :nth-child(5) { animation-delay: .26s; }
#app.intro .wrap > :nth-child(n+6) { animation-delay: .33s; }

/* hero shine */
.hero::after {
  content: ""; position: absolute; top: -50%; bottom: -50%; left: -40%; width: 30%; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .18), transparent);
  transform: skewX(-20deg); animation: hero-sweep 9s ease-in-out 2s infinite;
}
.hero > * { position: relative; z-index: 1; }
@keyframes hero-sweep { 0% { left: -40%; } 30%, 100% { left: 130%; } }

/* live status dots */
.pill.active::before, .pill.queued::before, .pill.joining::before { animation: ping 2s cubic-bezier(0, 0, .2, 1) infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 currentColor; } 70%, 100% { box-shadow: 0 0 0 5px transparent; } }

/* chart draw-in */
.chart-line.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.6s cubic-bezier(.65, 0, .35, 1) .3s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* gentle hover lift */
.card, .hero-stat { transition: transform .25s ease, box-shadow .25s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(18, 18, 18, .04), 0 14px 30px -14px rgba(43, 118, 255, .28); }

@media (prefers-reduced-motion: reduce) {
  .hero::after, .pill::before, #app.intro .topbar, #app.intro .wrap > * { animation: none !important; }
  .chart-line.draw { animation: none; stroke-dasharray: none; stroke-dashoffset: 0; }
  .card:hover { transform: none; }
}

.speed { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.speed .down { color: var(--accent); }
.speed .up { color: var(--ok); }

/* info tooltips + typical comparison */
.info {
  display: inline-grid; place-items: center; width: 15px; height: 15px; margin-left: 6px; padding: 0; vertical-align: 1px;
  border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
  font: italic 600 10px/1 Georgia, serif; text-transform: none; letter-spacing: 0; cursor: help;
}
.info:hover, .info:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
.tip {
  position: fixed; z-index: 100; max-width: 280px; padding: 10px 12px; border-radius: var(--radius-s);
  background: var(--text); color: var(--bg); font: 400 12px/1.5 var(--font); letter-spacing: 0; text-transform: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); pointer-events: none;
}
.perf { font-size: 11px; margin-top: 2px; white-space: nowrap; }
.ratio { font-family: var(--mono); font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: 99px; }
.ratio.ok { color: var(--ok); background: var(--ok-bg); }
.ratio.warn { color: var(--warn); background: var(--warn-bg); }
.ratio.bad { color: var(--bad); background: var(--bad-bg); }
.hero .info { display: none; }

.speed-btn {
  display: inline-grid; place-items: center; width: 22px; height: 22px; margin-left: 8px; padding: 0; vertical-align: middle;
  border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
  font-size: 13px; line-height: 1; cursor: pointer; transition: color .15s, border-color .15s;
}
.speed-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.speed-btn:disabled { cursor: default; }
.speed-btn.spin { color: var(--accent); border-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.speed-btn.locked { opacity: .35; filter: grayscale(1); cursor: not-allowed; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
