/* Server Manager UI. One stylesheet, no build step. Colours are custom
   properties; dark mode follows the system unless the user chose a theme. */

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --border: #e2dfd8;
  --border-strong: #cbc7bd;
  --text: #1d1c1a;
  --text-2: #55524c;
  --muted: #6f6b63;
  --accent: #0b6b72;
  --accent-hover: #095860;
  --accent-soft: #e2f1f1;
  --on-accent: #ffffff;
  --ok: #17713f;
  --ok-soft: #e1f3e8;
  --warn: #8f5200;
  --warn-soft: #fbefd5;
  --crit: #b62a25;
  --crit-soft: #fbe6e4;
  --info: #2457b8;
  --info-soft: #e4ecfb;
  --neutral-soft: #eceae4;
  --sidebar: #1b2423;
  --sidebar-text: #c9d1cf;
  --sidebar-muted: #8b9795;
  --sidebar-active: #2b3837;
  --shadow: 0 1px 2px rgb(20 20 15 / 6%), 0 4px 16px rgb(20 20 15 / 5%);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111413;
    --surface: #1a1e1d;
    --surface-2: #202524;
    --border: #2d3332;
    --border-strong: #434b49;
    --text: #e9e7e2;
    --text-2: #bdbab3;
    --muted: #9b9890;
    --accent: #58c4ca;
    --accent-hover: #7bd4d9;
    --accent-soft: #173537;
    --on-accent: #06292c;
    --ok: #5ccb93;
    --ok-soft: #153325;
    --warn: #e6ac4d;
    --warn-soft: #3a2c10;
    --crit: #f27d76;
    --crit-soft: #401b19;
    --info: #86aef7;
    --info-soft: #1a2947;
    --neutral-soft: #2a2f2e;
    --sidebar: #0c0f0e;
    --sidebar-active: #1f2726;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111413;
  --surface: #1a1e1d;
  --surface-2: #202524;
  --border: #2d3332;
  --border-strong: #434b49;
  --text: #e9e7e2;
  --text-2: #bdbab3;
  --muted: #9b9890;
  --accent: #58c4ca;
  --accent-hover: #7bd4d9;
  --accent-soft: #173537;
  --on-accent: #06292c;
  --ok: #5ccb93;
  --ok-soft: #153325;
  --warn: #e6ac4d;
  --warn-soft: #3a2c10;
  --crit: #f27d76;
  --crit-soft: #401b19;
  --info: #86aef7;
  --info-soft: #1a2947;
  --neutral-soft: #2a2f2e;
  --sidebar: #0c0f0e;
  --sidebar-active: #1f2726;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--neutral-soft); padding: 1px 5px; border-radius: 4px; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }

/* --- Shell ------------------------------------------------------------ */

.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 14px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; color: #fff; font-weight: 700; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #58c4ca, #0b6b72); display: grid; place-items: center; color: #06292c; font-size: 12px; font-weight: 800; }
.nav-label { padding: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--sidebar-muted); }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--sidebar-text); }
.nav-link:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 #58c4ca; }
.nav-link .count { margin-left: auto; font-size: 11px; background: #b62a25; color: #fff; border-radius: 10px; padding: 0 6px; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--sidebar-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.btn.nav-toggle { display: none; }
.content { padding: 20px 24px 48px; max-width: 1480px; width: 100%; }

.page-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 16px; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 30; transform: translateX(-100%); transition: transform 0.18s ease; }
  .nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgb(0 0 0 / 45%); }
  .btn.nav-toggle { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .content { padding: 14px 12px 40px; }
  .hide-sm { display: none !important; }
  .show-sm { display: block !important; }
  .topbar .who span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* --- Buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 550; line-height: 1.2;
  padding: 7px 12px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--crit); border-color: var(--crit); }
.btn-danger:hover { background: var(--crit-soft); border-color: var(--crit); }
.btn-danger-solid { background: var(--crit); border-color: var(--crit); color: var(--surface); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--neutral-soft); border-color: transparent; }
.inline-form { display: inline; }

/* --- Cards, grids, stats ---------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .grid, .grid + .card, .grid + .grid, .stack > * + * { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.card-head h2 { flex: 1; }
.card-body { padding: 14px; }
.card-foot { padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.grid > .card { margin-top: 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid-main { grid-template-columns: minmax(0, 1fr); } }

.stat { padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat .detail { font-size: 12px; color: var(--text-2); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }

.bar { appearance: none; -webkit-appearance: none; width: 100%; height: 8px; border: 0; border-radius: 4px; background: var(--neutral-soft); overflow: hidden; display: block; margin: 8px 0 4px; }
.bar::-webkit-progress-bar { background: var(--neutral-soft); }
.bar::-webkit-progress-value { background: var(--accent); border-radius: 4px; }
.bar::-moz-progress-bar { background: var(--accent); border-radius: 4px; }
.bar-warn::-webkit-progress-value { background: var(--warn); }
.bar-warn::-moz-progress-bar { background: var(--warn); }
.bar-crit::-webkit-progress-value { background: var(--crit); }
.bar-crit::-moz-progress-bar { background: var(--crit); }

/* --- Badges ----------------------------------------------------------- */

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 6px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap; background: var(--neutral-soft); color: var(--text-2); }
.badge .icon { width: 12px; height: 12px; stroke-width: 2.4; vertical-align: 0; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-crit { background: var(--crit-soft); color: var(--crit); }
.badge-info { background: var(--info-soft); color: var(--info); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; border: 1px solid var(--border); font-size: 12px; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }

/* --- Tables ----------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
th a { color: inherit; display: inline-flex; align-items: center; gap: 3px; }
th[aria-sort] a { color: var(--text); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.show-sm { display: none !important; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.cell-main { font-weight: 600; color: var(--text); }
.msg { max-width: 520px; overflow-wrap: anywhere; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 2px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--border); }

/* --- Definition lists -------------------------------------------------- */

.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* --- Tabs --------------------------------------------------------------- */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 550; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Forms -------------------------------------------------------------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
label, .label { font-weight: 600; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); }
.error { font-size: 12px; color: var(--crit); font-weight: 600; }
.req { color: var(--crit); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="url"], input[type="search"], input[type="time"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 9px; width: 100%; min-height: 34px;
}
textarea { resize: vertical; min-height: 84px; font-family: var(--mono); font-size: 13px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
[aria-invalid="true"] { border-color: var(--crit) !important; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; }
.check input { margin-top: 2px; }
.check .hint { display: block; font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 650; font-size: 13px; padding: 0; margin-bottom: 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.section + .section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.filters .field { flex: 1 1 140px; max-width: 240px; }
.filters label { font-size: 12px; color: var(--muted); font-weight: 500; }

.note { border-left: 3px solid var(--info); background: var(--info-soft); padding: 8px 12px; border-radius: 0 6px 6px 0; color: var(--text); }
.note-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.note-crit { border-left-color: var(--crit); background: var(--crit-soft); }

/* --- Flash / toast ------------------------------------------------------ */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border-strong); border-left: 4px solid var(--info); border-radius: 6px; padding: 10px 12px; box-shadow: var(--shadow); }
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--crit); }
.toast p { margin: 0; flex: 1; }
.toast strong { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* --- Dialog ------------------------------------------------------------- */

dialog { border: 1px solid var(--border-strong); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(10 12 12 / 55%); }
.dialog-head { padding: 14px 16px 0; }
.dialog-body { padding: 10px 16px 4px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px 14px; }

/* --- Logs --------------------------------------------------------------- */

.log { margin: 0; padding: 12px 14px; background: #101413; color: #d6dbd9; font: 12.5px/1.55 var(--mono); max-height: 62vh; min-height: 120px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 0 0 var(--radius) var(--radius); tab-size: 4; }
.log-short { max-height: 320px; }
.pre { margin: 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; font: 12.5px/1.5 var(--mono); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; }

.credentials { border: 2px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 14px; }
.credentials h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.credentials .kv { margin-top: 10px; }
.credentials dd { font-family: var(--mono); font-size: 13px; user-select: all; }

.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.9s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* --- Charts ------------------------------------------------------------- */

.chart { margin: 0; padding: 12px 14px 8px; }
.chart figcaption { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; margin-bottom: 4px; }
.chart-title { font-size: 12px; color: var(--muted); font-weight: 600; }
.chart-last { font-size: 18px; font-weight: 680; letter-spacing: -0.01em; }
.chart-range { font-size: 12px; color: var(--muted); margin-left: auto; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-area { fill: var(--accent); opacity: 0.12; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-label { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart-cursor { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-nodata { color: var(--muted); padding: 22px 0; text-align: center; margin: 0; }

/* --- Login --------------------------------------------------------------- */

.bare { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.bare-card { width: min(380px, 100%); }
.bare-card .card-body { padding: 24px; }
.bare-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: 18px; }
.bare .field + .field { margin-top: 12px; }
.bare .btn { width: 100%; margin-top: 16px; padding: 9px 12px; }
.otp { font-family: var(--mono); font-size: 20px !important; letter-spacing: 0.3em; text-align: center; }

.qr { width: 184px; height: 184px; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); }
.qr svg { display: block; width: 100%; height: 100%; }
.qr rect { fill: #000; }
.enrol { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.enrol > div { flex: 1 1 240px; min-width: 0; }

.error-page { text-align: center; padding: 48px 16px; }
.error-page .code { font-size: 56px; font-weight: 750; letter-spacing: -0.03em; color: var(--border-strong); line-height: 1; }
.error-page p { max-width: 520px; margin: 8px auto 18px; color: var(--text-2); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: baseline; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }

a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; border-color: var(--border-strong); }
.card-head .badge { flex: none; }
h1 .badge, h1 .mono { vertical-align: 2px; margin-left: 4px; }
h1 .mono { font-size: 15px; font-weight: 500; color: var(--text-2); }
.toast .btn { padding: 2px 4px; }
.form-grid { max-width: 900px; }
/* Keep the legend inside the fieldset box so the section rule does not run through it. */
legend { float: left; width: 100%; }
legend + * { clear: both; }
.stack + .card, .card + .stack, .stack + .stack { margin-top: 16px; }
