/* OLT Manager — "Lightpath" design system
   Night-shift NOC console: deep duct navy, splice-cyan light, status colours that
   map to real fiber faults (power fail = violet, LoS = amber-orange). */

:root, :root[data-theme="dark"] {
  --bg: #0F1A2B;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(25,194,224,.10), transparent 60%);
  --surface: #15233A;
  --surface-2: #1B2C47;
  --surface-3: #22365A;
  --line: #26385A;
  --line-soft: #1E2F4C;
  --text: #E8EEF8;
  --text-2: #B7C5DB;
  --muted: #8193B0;
  --accent: #19C2E0;
  --accent-2: #5B8CFF;
  --accent-ink: #04222B;
  --accent-soft: rgba(25,194,224,.14);
  --good: #34D399; --good-soft: rgba(52,211,153,.14);
  --bad: #F8717A;  --bad-soft: rgba(248,113,122,.14);
  --warn: #FBBF24; --warn-soft: rgba(251,191,36,.14);
  --power: #A78BFA; --power-soft: rgba(167,139,250,.16);
  --los: #FB923C;  --los-soft: rgba(251,146,60,.16);
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(3,10,22,.35);
  --radius-lg: 14px; --radius: 10px; --radius-sm: 7px;
  --sidebar: 236px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #EEF2F8;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(10,143,176,.08), transparent 60%);
  --surface: #FFFFFF;
  --surface-2: #F5F8FC;
  --surface-3: #EAF0F8;
  --line: #DCE3EE;
  --line-soft: #E8EDF5;
  --text: #13233B;
  --text-2: #33476A;
  --muted: #5D6F8C;
  --accent: #0A8FB0;
  --accent-2: #3563E9;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(10,143,176,.10);
  --good: #059669; --good-soft: rgba(5,150,105,.10);
  --bad: #DC2640;  --bad-soft: rgba(220,38,64,.09);
  --warn: #B7791F; --warn-soft: rgba(183,121,31,.12);
  --power: #7C3AED; --power-soft: rgba(124,58,237,.10);
  --los: #C2410C;  --los-soft: rgba(194,65,12,.10);
  --shadow: 0 1px 2px rgba(19,35,59,.06), 0 6px 18px rgba(19,35,59,.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); background-image: var(--bg-glow); background-attachment: fixed;
  color: var(--text); font: 14px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { flex: none; }
.brand b { font-size: 16px; font-weight: 600; letter-spacing: -.01em; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11.5px; }
.search { position: relative; margin: 0 2px 14px; }
.search input { width: 100%; padding: 8px 10px 8px 32px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font: inherit; font-size: 13px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.nav-group { margin: 6px 0 10px; }
.nav-group > span { display: block; color: var(--muted); font-size: 11.5px; font-weight: 500; padding: 6px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; font-size: 13.5px; position: relative; }
.nav a svg { color: var(--muted); flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--text); }
.nav a.on svg { color: var(--accent); }
.nav a.on::before { content: ""; position: absolute; left: -14px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav .count { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 20px; background: var(--bad); color: #fff; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3);
  color: var(--text); font-weight: 600; font-size: 12px; flex: none; }
.side-foot .who { min-width: 0; flex: 1; line-height: 1.2; }
.side-foot .who b { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.side-foot .who small { color: var(--muted); font-size: 11.5px; }
.icon-btn { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.main { min-width: 0; padding: 22px 28px 40px; max-width: 1480px; width: 100%; }
.mobilebar { display: none; }
footer { color: var(--muted); font-size: 12px; padding: 26px 0 0; }

/* ---------- page head ---------- */
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin: 2px 0 18px; }
h1 { font-size: 23px; font-weight: 600; letter-spacing: -.015em; margin: 0; line-height: 1.2; }
h1 .muted { font-weight: 400; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.005em; }
h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 13px; }
.head .row { align-items: center; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px;
  margin-bottom: 16px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > .head:first-child { margin-top: 0; }
.card .head { margin-bottom: 12px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid > .card, .grid > div > .card { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .three { grid-template-columns: 1fr; } }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } }

/* ---------- KPI strip ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { position: relative; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 14px 16px 13px; color: var(--text); box-shadow: var(--shadow); overflow: hidden; }
.stat:hover { text-decoration: none; border-color: var(--surface-3); }
.stat b { display: block; font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat i { position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--line); }
.stat.good i { background: var(--good); } .stat.bad i { background: var(--bad); } .stat.warn i { background: var(--warn); }
.stat.accent i { background: var(--accent); } .stat.power i { background: var(--power); }
.stat .split { display: flex; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.stat .split em { font-style: normal; display: inline-flex; align-items: center; gap: 5px; }

/* ---------- PON patch panel (dashboard hero) ---------- */
.ponpanel { display: grid; gap: 10px; }
.slotrow { display: grid; grid-template-columns: 74px 1fr; gap: 10px; align-items: center; }
.slotrow > span { color: var(--muted); font-size: 12px; }
.slotrow > span b { color: var(--text-2); display: block; font-weight: 500; font-size: 13px; }
.ports { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 1100px) { .ports { grid-template-columns: repeat(8, minmax(0, 1fr)); } }
.port { position: relative; display: block; border-radius: 8px; padding: 7px 6px 6px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text); min-height: 54px; overflow: hidden; }
.port:hover { text-decoration: none; border-color: var(--accent); }
.port .pn { font-size: 11px; color: var(--muted); display: block; }
.port .pc { font-size: 15px; font-weight: 600; display: block; line-height: 1.25; }
.port .po { font-size: 11px; color: var(--bad); }
.port .fill { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--good); }
.port.h-warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.port.h-bad { border-color: color-mix(in srgb, var(--bad) 70%, var(--line)); background: var(--bad-soft); }
.port.h-bad .fill { background: var(--bad); }
.port.h-warn .fill { background: var(--warn); }
.port.empty { opacity: .45; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
th a { color: var(--muted); }
tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover td, table.list tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.scroll table th:first-child { border-top-left-radius: var(--radius-lg); }
.card table th { background: transparent; position: static; padding-top: 4px; }
table.compact td { padding: 7px 8px; }
table.compact td:first-child { padding-left: 0; }
.kv th { width: 132px; background: transparent; position: static; color: var(--muted); font-weight: 400; padding-left: 0; }
.kv td { word-break: break-word; padding-right: 0; }
.kv tr td, .kv tr th { border-bottom: 1px dashed var(--line-soft); }

/* ---------- small things ---------- */
.mono, code { font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.small { font-size: 12px; } .muted { color: var(--muted); } .nowrap { white-space: nowrap; }
.big { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.err { color: var(--bad); } .good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.power { background: var(--power-soft); color: var(--power); }
.pill.los { background: var(--los-soft); color: var(--los); }
.pill.plain::before { display: none; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--muted); vertical-align: 1px; }
.dot.alert { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.info { background: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 11px; text-align: center; }
.bar { background: var(--surface-3); height: 6px; border-radius: 4px; min-width: 70px; overflow: hidden; }
.bar i { display: block; height: 6px; border-radius: 4px; background: var(--bad); }

/* signal meter: -8 dBm (full) ... -30 dBm (empty) */
.sig { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.sig .m { width: 46px; height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.sig .m i { display: block; height: 100%; border-radius: 4px; background: var(--good); }
.sig.weak .m i { background: var(--warn); } .sig.crit .m i { background: var(--bad); }
.sig.weak b { color: var(--warn); } .sig.crit b { color: var(--bad); }
.sig b { font-weight: 500; font-family: "IBM Plex Mono", monospace; font-size: 12.5px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-weight: 500; font-size: 13px; line-height: 1.3; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); background: transparent; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.warn { color: var(--warn); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions form { display: inline; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input, select, textarea { font: inherit; font-size: 13.5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); }
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input { min-width: 230px; }
.filters input.short { min-width: 0; width: 130px; }
.form label { display: block; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.form label input, .form label select { display: block; width: 100%; margin-top: 5px; color: var(--text); font-weight: 400; }
.form label.check { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.form label.check input { display: inline; width: auto; margin: 0; }
.form .cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.form h2 { margin-top: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 12px; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.actions-grid form { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px; display: flex; flex-direction: column; gap: 8px; }
.actions-grid form h3 { margin: 0 0 2px; }
.actions-grid input, .actions-grid select { width: 100%; }
.actions-grid p { margin: 0; }

.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px; background: var(--good-soft); color: var(--good);
  border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); font-weight: 500; }
.flash.err { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 16px 0; color: var(--muted); }
.empty { text-align: center; padding: 34px; color: var(--muted); }
pre { background: var(--surface-2); border: 1px solid var(--line); padding: 12px; border-radius: var(--radius); overflow: auto;
  font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--text-2); }
pre.cli { max-height: 440px; }
details > summary { cursor: pointer; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--muted); }
details[open] > summary::before { content: "▾ "; }
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }

/* ---------- ONU hero ---------- */
.onu-hero { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .onu-hero { grid-template-columns: 1fr; } }
.gauge { display: flex; align-items: center; gap: 16px; }
.gauge svg { flex: none; }
.gauge .gv { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.gauge .gl { color: var(--muted); font-size: 12.5px; }
.cause { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; padding-bottom: 22px; }
.login .card { padding: 24px; }
.login label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.login input { width: 100%; margin-top: 6px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }

/* ---------- responsive shell ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(5,12,24,.55); }
  .mobilebar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--line); }
  .main { padding: 16px 16px 30px; }
  .filters input { min-width: 0; flex: 1; }
  .stat b { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 600px) {
  .slotrow { grid-template-columns: 1fr; gap: 6px; }
  .slotrow > span b { display: inline; margin-right: 6px; }
  .ports { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
  .port { min-height: 42px; padding: 4px 4px 5px; border-radius: 6px; }
  .port .po { display: none; }
  .port .pc { font-size: 13px; }
  .port.h-bad .pc { color: var(--bad); }
  .stats { grid-template-columns: 1fr 1fr; }
  .head > .row, .head > form { width: 100%; }
}

/* extra VLAN rows (authorize) */
.xvlans { display: grid; gap: 8px; margin-bottom: 10px; }
.xrow { display: grid; grid-template-columns: 110px 90px 1fr 1fr auto; gap: 10px; align-items: end;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.xrow .xhint { grid-column: 1 / -1; }
@media (max-width: 720px) { .xrow { grid-template-columns: 1fr 1fr; } }

/* batch action bar */
.batchbar { position: sticky; top: 8px; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 12px; margin: 0 0 12px; border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--surface-2); box-shadow: var(--shadow); }
.batchbar[hidden] { display: none; }
.batchbar select, .batchbar input { width: auto; min-width: 0; }
.batchbar .bf { display: inline-flex; gap: 6px; }

/* PON graphs grid */
.pon-graphs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.pon-graphs .pg { margin: 0; padding: 12px; color: inherit; text-decoration: none; display: block; }
.pon-graphs .pg:hover, .pon-graphs .pg.on { border-color: var(--accent); }
.msg { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.msg:last-child { border-bottom: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px; }
.installer { max-width: 560px; margin: 0 auto; }
.installer input, .installer select { font-size: 16px; }

.unsaved { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 14px; margin-bottom: 14px; border-radius: var(--radius); border: 1px solid var(--warn);
  background: var(--warn-soft); color: var(--text); font-size: 14px; }
.diff .add { color: var(--good); } .diff .del { color: var(--bad); } .diff .hunk { color: var(--accent); }
.odb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.odb-port { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2);
  display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.odb-port.used { border-color: var(--good); } .odb-port.bad { border-color: var(--bad); }
.odb-port.free { opacity: .7; }
