/* Fleet dashboard: one stylesheet for every page.
   Dark by default; light when <html data-theme="light"> (set by ui.js, remembered).
   Identity: every server has a colour tag (--hue, from NODES in services.js). */

:root {
    --bg: #0e1420;
    --surface: #151d2b;
    --surface-2: #1b2535;
    --line: #26324a;
    --line-strong: #364563;
    --text: #e6ebf2;
    --dim: #97a5b9;
    --up: #3dd68c;
    --down: #ff6b6b;
    --paused: #c4a5ff;
    --warn: #f2b544;
    --accent: #f2b544;          /* selection + focus: panel-indicator amber */
    --on-accent: #1a1406;
    --link: #8fb4ff;
    --tag-text: #0e1420;
    --shadow: 0 1px 0 rgba(0, 0, 0, .25);
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --label: Bahnschrift, "DIN Alternate", "DIN 2014", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f4f6f9;
    --line: #d3dae4;
    --line-strong: #b5c0cf;
    --text: #172033;
    --dim: #4a5568;
    --up: #047857;
    --down: #c62828;
    --paused: #6d3fd1;
    --warn: #9a5b00;
    --accent: #b86e00;
    --on-accent: #ffffff;
    --link: #1d4ed8;
    --shadow: 0 1px 2px rgba(23, 32, 51, .06);
    color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); min-height: 100vh; }
a { color: var(--link); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.num { font-family: var(--label); font-variant-numeric: tabular-nums; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.skip-nav {
    position: absolute; left: 8px; top: -80px; z-index: 50; padding: 8px 12px;
    background: var(--surface); border: 2px solid var(--accent); border-radius: 6px; color: var(--text);
}
.skip-nav:focus { top: 8px; }
svg.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Server tag (the identity device) ────────────────────────────── */
.tag {
    display: inline-flex; align-items: center; justify-content: center; min-width: 2.4em; height: 1.7em;
    padding: 0 .4em; border-radius: 4px; background: var(--hue, var(--dim)); color: var(--tag-text);
    font: 700 13px/1 var(--label); letter-spacing: .02em; white-space: nowrap;
}

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 20; background: var(--surface);
    border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.topbar .wrap { display: flex; align-items: center; gap: 12px 24px; min-height: 60px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); margin-right: auto; }
.brand-mark { display: grid; gap: 3px; width: 26px; }
.brand-mark i { display: block; height: 5px; border-radius: 2px; }
.brand-mark i:nth-child(1) { background: #8fa8ff; }
.brand-mark i:nth-child(2) { background: #4fd1c5; width: 70%; }
.brand-mark i:nth-child(3) { background: #f6a94a; width: 85%; }
.brand-name { font: 700 19px/1.1 var(--label); letter-spacing: .01em; }
.brand-sub { display: block; font: 400 12px/1.2 var(--sans); color: var(--dim); }

.tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs a {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px;
    color: var(--dim); text-decoration: none; font-weight: 600;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }

.tools { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; }
.tools a.ext { display: inline-flex; align-items: center; gap: 5px; color: var(--dim); text-decoration: none; font-size: 14px; height: 36px; }
.tools a.ext:hover { color: var(--text); }
.tools a.ext svg { width: 13px; height: 13px; }
.theme-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; cursor: pointer;
    background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; font-size: 14px; font-weight: 600;
}
.theme-btn:hover { border-color: var(--accent); }
.clock { font: 600 14px var(--label); color: var(--dim); min-width: 4.8em; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Page head: totals ───────────────────────────────────────────── */
.pagehead { padding-top: 22px; padding-bottom: 14px; }
.totals { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 0; }
.totals li { display: flex; align-items: baseline; gap: 6px; padding: 0 22px; border-left: 1px solid var(--line); color: var(--dim); }
.totals li:first-child { padding-left: 0; border-left: 0; }
.totals b { font: 700 30px/1 var(--label); color: var(--text); font-variant-numeric: tabular-nums; }
.totals .tot {
    display: flex; align-items: baseline; gap: 6px; background: none; border: 0; padding: 2px 0; margin: 0;
    font: inherit; color: inherit; text-decoration: none; cursor: pointer; border-bottom: 2px solid transparent;
}
.totals .tot:hover { color: var(--text); border-bottom-color: var(--line-strong); }
.totals .t-up b { color: var(--up); }
.totals .t-down.bad b { color: var(--down); }
.totals .t-paused b { color: var(--paused); }
.updated { margin-top: 8px; font-size: 13px; color: var(--dim); }

/* ── Filter panel ────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); }
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.filters > * { min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.search { position: relative; flex: 1 1 260px; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--dim); }
.search input {
    width: 100%; height: 40px; padding: 0 34px 0 38px; background: var(--bg);
    border: 1px solid var(--line-strong); border-radius: 8px;
}
.search input::placeholder { color: var(--dim); }
.search input::-webkit-search-cancel-button { cursor: pointer; }

.seg { display: inline-flex; align-items: center; gap: 8px; border: 0; min-width: 0; }
.seg legend, .fieldname { font-size: 13px; color: var(--dim); float: left; margin-right: 2px; }
.seg-opts { display: inline-flex; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; padding: 3px; gap: 2px; }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.seg span {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border-radius: 6px;
    font-size: 14px; color: var(--dim); white-space: nowrap;
}
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.count { font: 600 12px var(--label); font-variant-numeric: tabular-nums; opacity: .8; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; min-height: 40px; }
.switch input {
    appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px; margin: 0; cursor: pointer;
    background: var(--line-strong); position: relative; flex: none; transition: background .15s;
}
.switch input::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
    background: var(--surface); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

.servers-bar { display: flex; flex-wrap: wrap; width: 100%; min-width: 0; gap: 6px; align-items: center; }
.srv { position: relative; flex: none; }
.srv input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.srv > span {
    display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px 0 4px; border-radius: 8px;
    border: 1px solid var(--line-strong); background: var(--bg); font-size: 13.5px; white-space: nowrap; color: var(--dim);
}
.srv > span.all { padding-left: 10px; }
.srv:hover > span { color: var(--text); }
.srv input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--text); font-weight: 600; }
.srv input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.srv .tag { height: 24px; font-size: 12px; }

.result-line { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; font-size: 13.5px; color: var(--dim); margin-top: 12px; min-height: 22px; }
.linkbtn { background: none; border: 0; color: var(--link); cursor: pointer; text-decoration: underline; font-size: 13.5px; padding: 2px 0; }

/* ── Server sections (projects page) ─────────────────────────────── */
main { padding-top: 22px; padding-bottom: 36px; }
.node, .box { scroll-margin-top: 130px; }
.node { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 0 18px; margin-bottom: 30px; }
.spine { background: var(--hue); border-radius: 8px; opacity: .95; }
.spine .tag {
    position: sticky; top: 72px; width: 100%; height: auto; padding: 10px 0; background: transparent;
    font-size: 17px; flex-direction: column; gap: 2px;
}
.node-head {
    display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
    padding: 4px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.node-title { flex: 1 1 280px; min-width: 0; }
.node-title h2 { font: 700 21px/1.2 var(--label); letter-spacing: .005em; }
.node-title h2 a { color: inherit; text-decoration: none; }
.node-title h2 a:hover { text-decoration: underline; }
.node-spec { font-size: 13.5px; color: var(--dim); }
.node-count { font-size: 13.5px; color: var(--dim); }
.node-count b { color: var(--text); font: 700 15px var(--label); }

.meters { display: flex; gap: 14px; align-items: center; min-height: 30px; }
.meter { display: grid; grid-template-columns: auto auto; gap: 2px 8px; align-items: baseline; font-size: 12px; color: var(--dim); min-width: 64px; }
.meter b { font: 700 14px var(--label); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.meter .bar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--up); border-radius: 2px; }
.meter.warn .bar i { background: var(--warn); }
.meter.warn b { color: var(--warn); }
.meter.danger .bar i { background: var(--down); }
.meter.danger b { color: var(--down); }
.node-down { font: 700 13px var(--label); color: var(--down); }

.group { margin-bottom: 18px; }
.group h3 { font-size: 14px; font-weight: 600; color: var(--dim); margin-bottom: 8px; }
.group h3 .count { margin-left: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; }

/* ── Project card ────────────────────────────────────────────────── */
.card {
    position: relative; display: flex; flex-direction: column; gap: 6px; min-height: 136px; padding: 12px 14px 11px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
    text-decoration: none; min-width: 0; box-shadow: var(--shadow);
}
a.card:hover { border-color: var(--hue, var(--line-strong)); }
.card-top { display: flex; gap: 10px; align-items: flex-start; }
.led {
    width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none;
    background: var(--line-strong);
}
.card.online .led { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 22%, transparent); }
.card.offline .led { background: var(--down); border-radius: 2px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 25%, transparent); }
.card.maintenance .led { background: var(--paused); }
.card-name { flex: 1; min-width: 0; }
.card-name h4 { font-size: 15.5px; line-height: 1.3; font-weight: 650; overflow-wrap: break-word; }
.card-name .addr { font-size: 13px; color: var(--dim); overflow-wrap: anywhere; }
.kind {
    flex: none; font-size: 11.5px; line-height: 1; padding: 4px 7px; border-radius: 4px; white-space: nowrap;
    color: var(--dim); border: 1px solid var(--line-strong);
}
.kind.own { color: var(--link); border-color: color-mix(in srgb, var(--link) 55%, transparent); }
.desc {
    font-size: 13.5px; color: var(--dim); flex: 1; display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden; padding-left: 20px;
}
.card-foot {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 0 0 20px;
    border-top: 1px dashed var(--line); font-size: 13px; min-height: 31px;
}
.state { font-weight: 600; color: var(--dim); }
.card.online .state { color: var(--up); }
.card.offline .state { color: var(--down); }
.card.maintenance .state { color: var(--paused); }
.metric { color: var(--dim); font: 600 13px var(--label); font-variant-numeric: tabular-nums; }
.chk {
    display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 7px; border-radius: 4px;
    border: 1px solid var(--line-strong); color: var(--dim);
}
.chk::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chk.up { color: var(--up); border-color: color-mix(in srgb, var(--up) 45%, transparent); }
.chk.down { color: var(--down); border-color: var(--down); font-weight: 700; }
.foot-tag { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.foot-tag .tag { height: 20px; font-size: 11px; min-width: 2.2em; }

.card.inactive { background: transparent; border-style: dashed; box-shadow: none; }
.card.inactive h4 { color: var(--dim); text-decoration: line-through; text-decoration-thickness: 1px; }
.card.inactive .led { background: transparent; border: 2px solid var(--dim); }
.card.paused .led { border-color: var(--paused); }
.card.paused .state { color: var(--paused); }
.life { font-size: 11.5px; line-height: 1; padding: 4px 7px; border-radius: 4px; background: color-mix(in srgb, var(--paused) 18%, transparent); color: var(--paused); font-weight: 700; flex: none; }

.empty { text-align: center; padding: 56px 16px; color: var(--dim); }
.empty p { font-size: 16px; color: var(--text); margin-bottom: 4px; }
.empty button {
    margin-top: 14px; height: 40px; padding: 0 16px; background: var(--surface); border: 1px solid var(--line-strong);
    border-radius: 8px; cursor: pointer; font-weight: 600;
}
.alert {
    display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 8px; margin-bottom: 16px;
    border: 1px solid var(--down); color: var(--down); background: color-mix(in srgb, var(--down) 10%, transparent);
}

/* ── Servers page ────────────────────────────────────────────────── */
.fleet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.box {
    display: grid; grid-template-columns: 8px minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
}
.box::before { content: ""; background: var(--hue); }
.box-body { padding: 14px 16px 12px; display: grid; gap: 12px; }
.box-head { display: flex; gap: 10px; align-items: center; }
.box-head .tag { height: 32px; font-size: 15px; min-width: 2.8em; }
.box-head h2 { font: 700 19px/1.15 var(--label); }
.box-head .node-spec { font-size: 13px; }
.box-state { margin-left: auto; text-align: right; font-size: 13px; color: var(--dim); white-space: nowrap; }
.box-state b { display: block; font: 700 14px var(--label); color: var(--up); }
.box.down .box-state b { color: var(--down); }
.box.down { border-color: var(--down); }
.vitals { display: grid; gap: 9px; }
.vrow { display: grid; grid-template-columns: 52px minmax(0, 1fr) 46px; gap: 10px; align-items: center; font-size: 13px; }
.vrow .lbl { color: var(--dim); }
.vrow .pct { font: 700 15px var(--label); text-align: right; font-variant-numeric: tabular-nums; }
.vrow .track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.vrow .track i { display: block; height: 100%; background: var(--up); border-radius: 4px; }
.vrow.warn .track i { background: var(--warn); } .vrow.warn .pct { color: var(--warn); }
.vrow.danger .track i { background: var(--down); } .vrow.danger .pct { color: var(--down); }
.vrow .sub { grid-column: 2 / -1; margin-top: -6px; font-size: 12px; color: var(--dim); }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--dim); }
.facts b { color: var(--text); font: 700 14px var(--label); font-variant-numeric: tabular-nums; }
.facts .warn b { color: var(--warn); } .facts .danger b { color: var(--down); }
.spark { position: relative; height: 54px; border-top: 1px dashed var(--line); padding-top: 8px; }
.spark svg { width: 100%; height: 38px; display: block; }
.spark .area { fill: color-mix(in srgb, var(--hue) 22%, transparent); stroke: none; }
.spark .line { fill: none; stroke: var(--hue); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.spark-cap { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--dim); }
.box-foot { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.plist { border-top: 1px dashed var(--line); padding-top: 8px; font-size: 13px; }
.plist summary { cursor: pointer; color: var(--text); font-weight: 600; padding: 4px 0; list-style-position: inside; }
.plist summary .node-spec { font-weight: 400; }
.plist ul { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 14px; margin: 6px 0 4px; }
.plist li { display: flex; align-items: center; gap: 7px; min-width: 0; }
.plist li a { color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist li a:hover { color: var(--link); text-decoration: underline; }
.plist .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.plist .dot.up { background: var(--up); }
.plist .dot.down { background: var(--down); border-radius: 1px; }
.plist .dot.paused { background: var(--paused); }
.plist .tools { color: var(--dim); font-size: 12.5px; margin-top: 4px; }
.box.static .box-state b { color: var(--dim); }
.tooltip {
    position: fixed; z-index: 40; pointer-events: none; padding: 5px 9px; border-radius: 6px; font-size: 12.5px;
    background: var(--text); color: var(--bg); font-weight: 600;
}

.foot { padding-bottom: 36px; color: var(--dim); font-size: 13px; }

@media (max-width: 720px) {
    .wrap { padding: 0 14px; }
    .topbar .wrap { gap: 8px 12px; }
    .brand-sub, .clock, .tools a.ext span { display: none; }
    .tabs { order: 3; width: 100%; }
    .tabs a { flex: 1; justify-content: center; }
    .theme-btn .lbl { display: none; }
    .totals li, .totals li:first-child { padding: 0 16px 0 0; border-left: 0; }
    .totals b { font-size: 24px; }
    .seg { width: 100%; flex-wrap: wrap; }
    .seg legend { float: none; width: 100%; }
    .seg-opts { width: 100%; }
    .seg label { flex: 1; }
    .seg span { width: 100%; justify-content: center; padding: 0 6px; }
    .node { grid-template-columns: 34px minmax(0, 1fr); gap: 0 12px; }
    .spine .tag { font-size: 13px; top: 112px; }
    .grid { grid-template-columns: 1fr; }
    .servers-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
    .fleet-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.plain { border: 0; min-width: 0; }
