/* TelePlus admin panel — same palette as the TelePlus apps (Ui.java): night = graphite, day = light.
   Theme: data-theme="dark" | "light" on <html>; no attribute = follow the system. */
:root {
  --bg: #121317; --bg2: #15161b; --surface: #1a1c22; --card: #1e2027; --card-hi: #2a2d36;
  --line: #30333c; --line-soft: #26282f; --text: #e6e7eb; --muted: #9aa0aa; --dim: #747a86;
  --nav: #16171c; --input: #15161b; --logo-bg: #23262e;
  --brand1: #a195ec; --brand2: #ec8da8;                /* accents for text/rings at night (softer) */
  --grad: linear-gradient(135deg, #5f52b8 0%, #a34b6c 100%);   /* fills under white text at night */
  --sel: rgba(161, 149, 236, 0.14);
  --ok: #3ccf8e; --slow: #f0b43c; --down: #f0607e; --frozen: #5aa9f0; --drm: #a7abb8; --new: #8a8fa3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f4fb; --bg2: #ede8fb; --surface: #ffffff; --card: #ffffff; --card-hi: #efeafb;
    --line: #d9d2f0; --line-soft: #ebe6f7; --text: #17142a; --muted: #6b6884; --dim: #8b88a3;
    --nav: #ffffff; --input: #ffffff; --logo-bg: #1c1830;
    --brand1: #7c5cff; --brand2: #ff4f8b;
    --grad: linear-gradient(135deg, #7c5cff 0%, #ff4f8b 100%);
    --sel: rgba(124, 92, 255, 0.10);
    --ok: #1f9d64; --slow: #c98a00; --down: #e2405f; --frozen: #2e8fd6; --drm: #8b8fa0; --new: #8a8fa3;
    --shadow: 0 1px 3px rgba(23, 20, 42, 0.08);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f4fb; --bg2: #ede8fb; --surface: #ffffff; --card: #ffffff; --card-hi: #efeafb;
  --line: #d9d2f0; --line-soft: #ebe6f7; --text: #17142a; --muted: #6b6884; --dim: #8b88a3;
  --nav: #ffffff; --input: #ffffff; --logo-bg: #1c1830;
  --brand1: #7c5cff; --brand2: #ff4f8b;
  --grad: linear-gradient(135deg, #7c5cff 0%, #ff4f8b 100%);
  --sel: rgba(124, 92, 255, 0.10);
  --ok: #1f9d64; --slow: #c98a00; --down: #e2405f; --frozen: #2e8fd6; --drm: #8b8fa0; --new: #8a8fa3;
  --shadow: 0 1px 3px rgba(23, 20, 42, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand1); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand1); outline-offset: 2px; border-radius: 8px; }
h1 { font-size: 21px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); }
code, .mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12px; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 18px 12px; display: flex; flex-direction: column; gap: 2px;
  background: var(--nav); border-right: 1px solid var(--line-soft); }
.logo { display: flex; align-items: center; gap: 10px; padding: 2px 10px 18px; font-weight: 700; font-size: 16px; }
.logo i { width: 32px; height: 32px; border-radius: 9px; background: var(--grad); display: grid; place-items: center;
  font-style: normal; font-size: 14px; color: #fff; }
.logo small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 9px; color: var(--muted);
  font-weight: 500; text-decoration: none; }
.nav a:hover { background: var(--sel); color: var(--text); }
.nav a.on { color: var(--text); background: var(--sel); box-shadow: inset 3px 0 0 var(--brand1); }
.nav .ic { width: 18px; text-align: center; opacity: 0.85; }
.nav .badge { margin-left: auto; }
.nav .sep { height: 1px; background: var(--line-soft); margin: 8px 10px; }
.side .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--dim); border-top: 1px solid var(--line-soft); display: grid; gap: 8px; }
.side .foot .who { color: var(--muted); }
.acct { display: flex; align-items: center; gap: 8px; }
.acct-me { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; color: var(--text); text-decoration: none; padding: 4px; border-radius: 9px; }
.acct-me:hover { background: var(--sel); text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.acct-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.acct-txt b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-txt small { color: var(--dim); font-size: 11.5px; }
.btn.logout { color: var(--down); border-color: color-mix(in srgb, var(--down) 35%, transparent); background: transparent; }
.btn.logout:hover { background: color-mix(in srgb, var(--down) 10%, transparent); }
.theme-sw { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.theme-sw button { background: none; border: 0; color: var(--muted); padding: 5px 9px; font: 500 12px var(--font); cursor: pointer; }
.theme-sw button.on { background: var(--sel); color: var(--text); }
.main { padding: 22px 28px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .sp { flex: 1; }
.crumbs { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.menu-btn { display: none; }
.btn.back { padding: 7px 12px; }

/* ---------- cards */
.card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2 .sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.grid { display: grid; gap: 16px; align-items: stretch; }
.grid > .card, .grid > .card + .card { margin-top: 0; min-width: 0; display: flex; flex-direction: column; }
.grid > a.card { text-decoration: none; color: inherit; }
.grid > a.card:hover { border-color: var(--line); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; min-height: 96px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .v { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.kpi .s { color: var(--dim); font-size: 12px; margin-top: auto; }
.kpi.bad .v { color: var(--down); }
.kpi.good .v { color: var(--ok); }
a.kpi { text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--line); }

/* ---------- buttons, inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 7px 12px; border-radius: 9px; font: 500 13px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--card-hi); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.pri { background: var(--grad); border-color: transparent; color: #fff; }
.btn.pri:hover { filter: brightness(1.07); }
.btn.danger { color: var(--down); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 4px 0; width: 30px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btns.nowrap { flex-wrap: nowrap; }
input, select, textarea { font: 13px var(--font); color: var(--text); background: var(--input); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 10px; min-width: 0; }
select option { background: var(--surface); color: var(--text); }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input[type=checkbox] { accent-color: var(--brand1); width: 16px; height: 16px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand1); outline: none; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.form { display: grid; gap: 12px; }
.form.cols { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.filters select { max-width: 240px; }
.hint { color: var(--dim); font-size: 12px; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--dim); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--card); z-index: 1; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--sel); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nw { white-space: nowrap; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--dim); font-size: 12px; margin-top: 1px; }
.url { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; color: var(--dim); }
.logo-img { width: 40px; height: 26px; object-fit: contain; border-radius: 5px; background: var(--logo-bg); vertical-align: middle; padding: 2px; }
.logo-ph { width: 40px; height: 26px; border-radius: 5px; background: var(--logo-bg); display: inline-block; vertical-align: middle; }

/* ---------- badges, meters */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
  background: var(--card-hi); color: var(--muted); white-space: nowrap; }
.st::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.st-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.st-slow { color: var(--slow); background: color-mix(in srgb, var(--slow) 14%, transparent); }
.st-down { color: var(--down); background: color-mix(in srgb, var(--down) 13%, transparent); }
.st-frozen { color: var(--frozen); background: color-mix(in srgb, var(--frozen) 13%, transparent); }
.st-drm { color: var(--drm); }
.st-new { color: var(--new); }
.lv-high { color: #fff; background: var(--down); }
.lv-warn { color: var(--slow); background: color-mix(in srgb, var(--slow) 14%, transparent); }
.lv-info { color: var(--brand1); background: var(--sel); }
.badge.brand { background: var(--grad); color: #fff; }
.chip-sec { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--card-hi); color: var(--muted); margin: 1px 4px 1px 0; white-space: nowrap; }
.hist { display: inline-flex; gap: 2px; vertical-align: middle; }
.hist i { width: 5px; height: 14px; border-radius: 2px; background: var(--new); }
.hist i.ok { background: var(--ok); } .hist i.slow { background: var(--slow); } .hist i.down { background: var(--down); }
.hist i.frozen { background: var(--frozen); } .hist i.drm { background: var(--drm); }
.meter { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.meter .bar { width: 64px; height: 6px; border-radius: 99px; background: var(--card-hi); overflow: hidden; }
.meter .bar i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.meter.mid .bar i { background: var(--slow); } .meter.low .bar i { background: var(--down); }

/* ---------- chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bars div { flex: 1; border-radius: 3px 3px 0 0; background: var(--brand1); min-height: 2px; opacity: 0.85; }
.bars div.lo { background: var(--down); }
.bars-x { display: flex; justify-content: space-between; color: var(--dim); font-size: 11px; margin-top: 4px; }

/* ---------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 9px 14px; font: 500 13px var(--font); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--brand1); }

/* ---------- modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; width: min(640px, 100%);
  max-height: calc(100vh - 32px); overflow: auto; padding: 20px 22px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4); }
.modal.wide { width: min(980px, 100%); }
.modal .mh { display: flex; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal .mh h2 { margin: 0; flex: 1; }
.modal .mf { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
video { width: 100%; max-height: 60vh; background: #000; border-radius: 10px; }
pre.log { background: var(--bg2); border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; max-height: 50vh; overflow: auto;
  white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--text); margin: 0; }

/* ---------- misc */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-left: 3px solid var(--brand1); padding: 10px 14px;
  border-radius: 10px; max-width: 380px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); animation: tin .2s ease-out; }
.toast.err { border-left-color: var(--down); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.empty { color: var(--dim); text-align: center; padding: 28px 10px; }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: color-mix(in srgb, var(--slow) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--slow) 40%, transparent); color: var(--text); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.bad { background: color-mix(in srgb, var(--down) 10%, transparent); border-color: color-mix(in srgb, var(--down) 40%, transparent); }
.banner.good { background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sp { flex: 1; }
.muted { color: var(--muted); } .dim { color: var(--dim); }
.ok-t { color: var(--ok); } .bad-t { color: var(--down); } .warn-t { color: var(--slow); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 7px 0; border-bottom: 1px solid var(--line-soft); display: flex; gap: 10px; align-items: baseline; }
.list-plain li:last-child { border: 0; }
.list-plain .t { color: var(--dim); font-size: 12px; white-space: nowrap; min-width: 92px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 12px; color: var(--muted); user-select: none; }
.chip.on { background: var(--grad); color: #fff; border-color: transparent; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }

/* ---------- settings rows: label left, value right, same column for every row */
.set-row { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.card > .set-row:last-child { border-bottom: 0; }
.set-name { font-weight: 600; font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.set-hint { color: var(--dim); font-size: 12px; margin-top: 2px; }
.set-in { display: grid; grid-template-columns: minmax(0, 1fr) 76px; align-items: center; gap: 8px; }
.set-in > input, .set-in > select { width: 100%; }
.set-in > label.chk { justify-self: end; }
.set-in > input[type=number] { text-align: right; }
.set-unit { color: var(--dim); font-size: 12px; }
.set-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.set-head .set-name { color: var(--muted); font-weight: 500; font-size: 12px; margin-bottom: 3px; }
.save-bar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; align-items: center; margin-top: 16px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.12); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .logo { justify-content: center; padding-bottom: 22px; font-size: 20px; }
.login .btn { width: 100%; padding: 10px; }
.err-t { color: var(--down); font-size: 13px; min-height: 18px; }

@media (max-width: 1250px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.4); }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv { grid-template-columns: 1fr; }
  .set-row { grid-template-columns: 1fr; }
  .set-in { grid-template-columns: minmax(0, 1fr) 76px; }
  .set-head { grid-template-columns: 1fr 1fr; }
}
