:root {
  --bg: #101216;
  --panel: #181b21;
  --panel-2: #20242c;
  --border: #2a2f39;
  --text: #e4e6eb;
  --muted: #8b919c;
  --accent: #52b54b;
  --accent-2: #3d8f37;
  --warn: #e0a030;
  --danger: #e05252;
  --blue: #4a90e2;
  --purple: #a070e0;
  --radius: 10px;
  --sidebar: 220px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* layout */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: var(--panel); border-right: 1px solid var(--border);
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20;
  transition: transform .2s;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 18px 18px 14px; }
.brand img { width: 28px; height: 28px; }
.brand.big { font-size: 24px; padding: 0 0 6px; justify-content: center; }
.brand.big img { width: 36px; height: 36px; }
.sidebar nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.sidebar nav a:hover { background: var(--panel-2); }
.sidebar nav a.active { background: var(--accent-2); color: #fff; }
.sidebar .ico { width: 18px; text-align: center; opacity: .85; }
.pill { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.server-info { margin-top: auto; padding: 14px 18px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.main { margin-left: var(--sidebar); flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; }
#menuBtn { display: none; }
.view { padding: 20px 24px 48px; max-width: 1600px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 40px #000a; }
  .main { margin-left: 0; }
  #menuBtn { display: inline-flex; }
  .view { padding: 16px 16px 40px; }
  .topbar { padding: 10px 16px; }
  #whoami { display: none; }
}

/* controls */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; padding: 4px 8px; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font: inherit; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.toolbar label { min-width: 140px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); color: var(--muted); border: 0; padding: 7px 12px; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-2); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
}
.login-card p { margin: 0; text-align: center; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); margin-bottom: 16px; }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 16px; }
@media (max-width: 500px) { .grid.two, .grid.three { grid-template-columns: 1fr; } }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 200px; }

/* top lists */
.toplist { display: flex; flex-direction: column; gap: 8px; }
.toprow { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toprow .rank { width: 18px; color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.toprow .thumb { width: 32px; height: 48px; border-radius: 4px; object-fit: cover; background: var(--panel-2); flex: none; }
.toprow .thumb.sq { height: 32px; }
.toprow .txt { flex: 1; min-width: 0; }
.toprow .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toprow .meta { color: var(--muted); font-size: 12px; }
.toprow .num { font-weight: 600; flex: none; }
.bar { height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }

/* now playing */
.now-summary { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 16px; color: var(--muted); }
.now-summary b { color: var(--text); }
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card-top { display: flex; gap: 14px; padding: 14px; }
.poster { width: 100px; height: 150px; border-radius: 6px; object-fit: cover; background: var(--panel-2); flex: none; }
.poster.sq { height: 100px; }
.card-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.card-title { font-size: 16px; font-weight: 600; line-height: 1.25; }
.card-sub { color: var(--muted); }
.card-user { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; display: inline-grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--muted); }
.avatar.big { width: 64px; height: 64px; font-size: 24px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; padding: 0 14px 12px; font-size: 13px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.progress { height: 6px; background: var(--panel-2); position: relative; }
.progress span { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.progress span.buf { background: #ffffff22; }
.progress-txt { display: flex; justify-content: space-between; padding: 6px 14px 10px; font-size: 12px; color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.DirectPlay { background: #52b54b33; color: #7fd178; }
.badge.DirectStream { background: #4a90e233; color: #7fb3f0; }
.badge.Transcode { background: #e0a03033; color: #f0c060; }
.badge.paused { background: #ffffff1a; color: var(--muted); }
.badge.plex { background: #e5a00d33; color: #f0b840; }
.badge.danger { background: #e0525233; color: #f08080; }
.badge.admin { background: #a070e033; color: #c0a0f0; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: var(--panel); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td .t-title { display: flex; align-items: center; gap: 10px; min-width: 220px; }
td .t-title img { width: 28px; height: 42px; object-fit: cover; border-radius: 3px; background: var(--panel-2); flex: none; }
tr.clickable { cursor: pointer; }
tr.expand td { background: var(--bg); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

/* library */
.poster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px; }
.poster-grid figure { margin: 0; min-width: 0; }
.poster-grid img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 6px; background: var(--panel-2); display: block; }
.poster-grid.sq img { aspect-ratio: 1; }
.poster-grid figcaption { font-size: 12px; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poster-grid figcaption .muted { display: block; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; margin: 10px 0 14px; padding: 12px; background: var(--bg); border-radius: 8px; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0; }
.help { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.status-line { font-size: 13px; color: var(--muted); margin-top: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: 0 6px 24px #0008;
}
.toast.err { border-color: var(--danger); }
.user-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.user-head h2 { font-size: 22px; margin: 0; }
.seg button { white-space: nowrap; }
@media (max-width: 500px) { .seg button { padding: 7px 9px; font-size: 13px; } }
.toolbar .now-summary { margin-bottom: 0; }
.small-txt { font-size: 12px; white-space: nowrap; }
.toolbar:has(#nowSummary) { align-items: center; }
/* Server metrics */
.sys-head { margin: 28px 0 12px; gap: 12px; align-items: baseline; }
.sys-head h2 { margin: 0; }
.sys-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.sys-grid .wide { grid-column: 1 / -1; }
.sys-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.sys-title h3 { margin: 0; }
.sys-title .big { font-size: 22px; }
.big.warn, .sys-meta .warn { color: var(--warn); }
.big.bad, .sys-meta .bad { color: var(--danger); }
.spark { width: 100%; height: 50px; display: block; background: var(--panel-2); border-radius: 6px; margin-bottom: 10px; }
.sys-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); margin: 8px 0; }
.meter { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; flex: 1; }
.meter span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.meter.warn span { background: var(--warn); }
.meter.bad span { background: var(--danger); }
.meter.stack { display: flex; height: 10px; margin: 4px 0 8px; }
.meter.stack .used { background: #a070e0; }
.meter.stack .cache { background: #a070e055; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 16px; margin-bottom: 6px; }
.core { display: flex; align-items: center; gap: 8px; font-size: 12px; white-space: nowrap; }
.core .meter { min-width: 24px; }
.core-id { width: 26px; color: var(--muted); font-variant-numeric: tabular-nums; }
.core-v { width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.core-f { width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.eng { margin: 8px 0; }
.eng-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.eng-top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.used { background: #a070e0; }
.dot.cache { background: #a070e055; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.net-now { font-size: 15px; font-weight: 600; white-space: nowrap; }
.net-now .rx { color: #4a90e2; }
.net-now .tx { color: var(--accent); }
table.mini { width: 100%; border-collapse: collapse; font-size: 12px; }
table.mini th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px 4px 0; }
table.mini td { padding: 4px 6px 4px 0; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.storage { display: grid; gap: 10px 24px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.st .eng-top { font-size: 12px; }
@media (max-width: 500px) { .sys-grid { grid-template-columns: 1fr; } }
.note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.sys-title { flex-wrap: wrap; } .sys-title .small-txt { white-space: normal; }
