:root {
  --bg: #07090d;
  --panel: #0e1218;
  --panel-2: #131922;
  --line: #1d2531;
  --line-2: #2a3442;
  --text: #e8ecf2;
  --muted: #8a95a6;
  --dim: #5b6575;
  --orange: #ff6a2b;
  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, .12);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, .12);
  --warn: #fbbf24;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(255, 106, 43, .08), transparent 60%),
    linear-gradient(var(--bg), var(--bg));
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .35;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.6), transparent 70%);
}
a { color: inherit; }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

.page {
  position: relative; max-width: 1100px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.logo { width: 52px; height: 52px; border-radius: 50%; background: #fff; object-fit: contain; flex: none; box-shadow: 0 0 0 2px var(--line-2); }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; line-height: 1.1; }
.brand h1 em { font-style: normal; color: var(--orange); }
.meta { color: var(--muted); font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.pill[data-state="up"] { background: var(--ok-bg); border-color: rgba(52,211,153,.35); color: var(--ok); }
.pill[data-state="up"] i { background: var(--ok); box-shadow: 0 0 0 0 rgba(52,211,153,.6); animation: pulse 2.4s infinite; }
.pill[data-state="down"] { background: var(--bad-bg); border-color: rgba(248,113,113,.35); color: var(--bad); }
.pill[data-state="down"] i { background: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.55); } 70% { box-shadow: 0 0 0 8px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }

/* ---------- system strip ---------- */
.system { margin-bottom: 22px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.stat, .drive, .nowplaying { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.stat { padding: 12px 14px; }
.sl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.sv { font-size: 22px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.ss { font-size: 11px; color: var(--dim); margin-bottom: 8px; }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--orange); transition: width .6s ease; }
.bar.warn i { background: var(--warn); }
.bar.crit i { background: var(--bad); }
.bar.ghost i { width: 0; }
.drives { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.drive { padding: 11px 14px; }
.dl { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; white-space: nowrap; overflow: hidden; }
.dl b { color: var(--text); font-weight: 700; }
.dl span { margin-left: auto; color: var(--text); font-size: 12px; }
.dsub { font-size: 11px; color: var(--dim); margin-top: 6px; }

/* ---------- Plex now playing ---------- */
.nowplaying { padding: 12px 14px; margin-bottom: 22px; }
.np-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.np-head b { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.np-head span { margin-left: auto; font-size: 12px; color: var(--orange); }
.np { padding: 8px 0; border-top: 1px solid var(--line); }
.np:first-of-type { border-top: 0; }
.np-t b { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-t span { display: block; font-size: 12px; color: var(--muted); margin: 2px 0 7px; }
.np-bar { height: 3px; }
.np-empty { font-size: 13px; color: var(--dim); }

/* ---------- server cards ---------- */
.group { margin-bottom: 22px; }
.group h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; }
.group h2 span { font-family: var(--mono); font-weight: 500; color: var(--dim); }
.group h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.card {
  --accent: #888;
  position: relative; display: flex; align-items: center; gap: 14px; padding: 14px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  transition: border-color .15s, background .15s, transform .15s;
  animation: rise .35s ease both;
}
.card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); opacity: .9; }
.card:hover { border-color: var(--line-2); background: var(--panel-2); }
.card:active { transform: scale(.985); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ic { width: 46px; height: 46px; border-radius: 12px; flex: none; display: grid; place-items: center; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); }
.ic svg { width: 24px; height: 24px; }
.body { flex: 1; min-width: 0; }
.name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { display: flex; gap: 2px; height: 10px; margin-top: 8px; align-items: flex-end; }
.spark i { width: 4px; height: 100%; border-radius: 1px; background: var(--ok); opacity: .55; }
.spark i.bad { background: var(--bad); opacity: .9; }
.state { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.badge b { font-weight: 600; }
.ms { font-size: 11px; color: var(--dim); }
.card[data-state="up"] .badge { background: var(--ok-bg); color: var(--ok); }
.card[data-state="up"] .badge i { background: var(--ok); }
.card[data-state="down"] { border-color: rgba(248,113,113,.35); }
.card[data-state="down"] .badge { background: var(--bad-bg); color: var(--bad); }
.card[data-state="down"] .badge i { background: var(--bad); }
.card[data-state="down"] .ms { color: var(--bad); }

/* ---------- uptime + history ---------- */
.upt { font-size: 11px; color: var(--dim); }
.hist { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--dim); display: grid; place-items: center; padding: 0; cursor: pointer; opacity: 0; transition: opacity .15s; }
.hist svg { width: 16px; height: 16px; }
.card:hover .hist, .card:focus-within .hist { opacity: 1; }
.hist:hover { color: var(--text); border-color: var(--line-2); background: var(--panel-2); }
@media (hover: none) { .hist { opacity: 1; } }
.card .state { margin-right: 26px; }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .sheet { align-items: center; } }
.sheet-card { width: min(720px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 18px 18px 0 0; padding: 16px 16px max(20px, env(safe-area-inset-bottom)); animation: rise .2s ease both; }
@media (min-width: 700px) { .sheet-card { border-radius: 18px; } }
body.sheet-open { overflow: hidden; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.sheet-head h2 { margin: 0; font-size: 18px; flex: 1; min-width: 120px; }
.sheet-head h2::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 8px; }
.ranges { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.ranges button { font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); background: transparent; border: 0; border-radius: 7px; padding: 5px 10px; cursor: pointer; }
.ranges button.on { background: var(--panel-2); color: var(--text); }
@media (max-width: 560px) {
  .sheet-head .ranges { order: 3; flex-basis: 100%; }
  .sheet-head .ranges button { flex: 1; }
}
.sheet .x { font: inherit; font-size: 22px; line-height: 1; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--muted); cursor: pointer; }
.hgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.ht { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ht span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.ht b { display: block; font-size: 18px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.chart { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 10px 6px; margin-bottom: 16px; }
.chart svg { width: 100%; height: 150px; display: block; }
.chart.empty { color: var(--dim); font-size: 13px; padding: 30px; text-align: center; }
.axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--dim); margin-top: 4px; }
.sheet h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 8px; }
.sheet h3 span { color: var(--dim); font-weight: 500; margin-left: 6px; }
.inc { list-style: none; margin: 0 0 12px; padding: 0; }
.inc li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); }
.inc li:first-child { border-top: 0; }
.inc i { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-top: 6px; flex: none; }
.inc b { display: block; font-size: 14px; }
.inc span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.hnote { color: var(--dim); font-size: 12px; margin: 8px 0 0; }
@media (max-width: 520px) { .hgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- restart buttons (admin) ---------- */
.rst { position: absolute; top: 8px; right: 40px; width: 28px; height: 28px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--dim); display: none; place-items: center; padding: 0; cursor: pointer; opacity: 0; transition: opacity .15s; }
.rst svg { width: 16px; height: 16px; }
.card[data-can-restart="1"] .rst { display: grid; }
.card[data-can-restart="1"] .state { margin-right: 58px; }
.card:hover .rst, .card:focus-within .rst { opacity: 1; }
.rst:hover { color: var(--text); border-color: var(--line-2); background: var(--panel-2); }
.rst:disabled { cursor: default; }
@media (hover: none) { .rst { opacity: 1; } }
.card[data-restarting="1"] .badge { background: rgba(251,191,36,.12); color: #FBBF24; }
.card[data-restarting="1"] .badge i { background: #FBBF24; animation: rst-pulse 1s ease-in-out infinite alternate; }
.card[data-restarting="1"] .rst { opacity: 1; color: #FBBF24; }
.card[data-restarting="1"] .rst svg { animation: rst-spin 1s linear infinite; }
@keyframes rst-spin { to { transform: rotate(360deg); } }
@keyframes rst-pulse { from { opacity: .35; } to { opacity: 1; } }
.ask-card { max-width: 440px; }
.ask-card h2 { margin: 0 0 8px; font-size: 18px; }
.ask-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.ask-card #askMsg { color: var(--bad); font-size: 12px; min-height: 1em; }
.ask-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.btn { font: inherit; font-size: 14px; font-weight: 600; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent-c, #FF6A2B); border-color: transparent; color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- people (guest manager) ---------- */
.people { margin: 8px 0 22px; }
.ppl-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.ppl-head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.ppl-head span { margin-left: auto; font-size: 12px; color: var(--dim); }
.ppl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .ppl-grid { grid-template-columns: minmax(0, 1fr); } }
.pp { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.pp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.pp-head b { font-size: 15px; }
.pp-head b::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-right: 8px; vertical-align: 1px; }
.pp-head span { font-size: 11px; color: var(--dim); }
.pp-head a { margin-left: auto; font-size: 12px; color: var(--muted); text-decoration: none; border: 1px solid var(--line-2); border-radius: 8px; padding: 3px 9px; white-space: nowrap; }
.pp-head a:hover { color: var(--text); background: var(--panel-2); }
.pp h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--dim); margin: 10px 0 2px; font-weight: 600; }
.pp-list { list-style: none; margin: 0; padding: 0; }
.pp-list li { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.pp-list li:first-child { border-top: 0; }
.pp-list li > div { flex: 1; min-width: 0; }
.pp-list b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-list span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.pp-list time { font-size: 11px; color: var(--dim); white-space: nowrap; padding-top: 2px; }
.pp-now .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-top: 5px; flex: none; }
.pp-now .np-bar { margin-top: 6px; }
.pp-empty { font-size: 13px; color: var(--dim); padding: 8px 0 2px; }
.pp-empty.bad { color: var(--bad); }
.pp-empty a { color: var(--orange); }
.pp-note { font-size: 11px; color: var(--dim); margin: 8px 0 0; }

/* ---------- footer ---------- */
.foot { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; }
.foot a { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--muted); padding: 7px 11px; border: 1px solid var(--line-2); border-radius: 10px; }
.foot a:hover { color: var(--text); border-color: var(--dim); }
.foot svg { width: 15px; height: 15px; }
.foot .mono { margin-left: auto; }

@media (max-width: 640px) {
  .brand h1 { font-size: 18px; }
  .logo { width: 44px; height: 44px; }
  .pill { padding: 6px 10px; font-size: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat:nth-child(3) { grid-column: span 2; }
  .stats .stat:nth-child(3) .bar { display: none; }
  .cards { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .top { flex-wrap: wrap; row-gap: 10px; } .brand { flex: 1 1 calc(100% - 72px); } .pill { order: 3; margin-left: 58px; } }

/* ---------- admin editor ---------- */
.admin { max-width: 980px; margin: 0 auto; padding: 24px 16px 120px; position: relative; }
.admin h1 { font-size: 22px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 6px; }
.admin h1 em { font-style: normal; color: var(--orange); }
.admin .lead { color: var(--muted); font-size: 14px; margin: 0 0 22px; line-height: 1.5; }
.admin .lead a { color: var(--orange); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 18px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 12px; }
.panel .hint { font-size: 12px; color: var(--dim); margin: 8px 0 0; line-height: 1.5; }
.panel .hint.bad { color: var(--bad); }
.conn { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.conn h3 { font-size: 15px; margin: 0 0 8px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label.f span { display: block; margin-bottom: 5px; }
input, select { font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 10px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--orange); }
input.invalid { border-color: var(--bad); }
input[type=color] { padding: 3px; height: 40px; cursor: pointer; }
.srv { padding: 12px 0; border-top: 1px solid var(--line); }
.srv:first-child { border-top: 0; padding-top: 0; }
.srv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.srv-head .f-name { flex: 1; font-weight: 600; }
.srv .prev { width: 38px; height: 38px; flex: none; border-radius: 10px; display: grid; place-items: center; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.srv .prev svg { width: 20px; height: 20px; }
.srv-fields { display: grid; grid-template-columns: 2fr 1fr 1fr 64px; gap: 8px; }
.srv-fields .f-note { grid-column: 1 / -1; }
.srv-fields .check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); grid-column: 1 / -1; }
.srv-fields .check input { width: auto; }
.srv-head button.icon { height: 38px; }
button { font: inherit; font-size: 14px; font-weight: 600; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 14px; cursor: pointer; }
button:hover { border-color: var(--dim); }
button.primary { background: var(--orange); border-color: var(--orange); color: #160700; }
button.icon { padding: 0; width: 34px; color: var(--muted); }
button.icon:hover { color: var(--bad); }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)); background: rgba(7,9,13,.92); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
.savebar .dirty { margin-right: auto; font-size: 13px; color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--panel-2);
  border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--bad); color: var(--bad); }
@media (max-width: 760px) {
  .srv-fields { grid-template-columns: 1fr 1fr; }
  .srv-fields .f-url { grid-column: 1 / -1; }
}
