/* Admin panel — Nocturne design system.
   Tokens below are lifted verbatim from the Nocturne project's styles.css: ground #161826,
   surface #232532, blurple accent #9184d9, Inter at weight 500, the 0.7-density spacing scale,
   8px radii, elevation as a hairline edge + ambient darkness. Take every colour, size, radius
   and shadow from these variables — don't hard-code a hex or a px the tokens already carry.

   Nocturne signatures to preserve when editing:
   - freestanding rules and table row-lines FADE to transparent over 48px at each end;
   - buttons are OUTLINED (1px accent border on transparent), never filled;
   - the accent appears as a line, a mark or a glow — never as a flood;
   - headings stay at weight 500 (hierarchy is size and space, not boldness);
   - no pure black or white — every value comes from a ramp. */
:root {
  color-scheme: dark;

  --color-bg: #161826;
  --color-surface: #232532;
  --color-text: #e9e9ed;
  --color-accent: #9184d9;
  --color-divider: color-mix(in srgb, #e9e9ed 16%, transparent);

  --color-neutral-100: #f3f5fe;
  --color-neutral-200: #e4e7f5;
  --color-neutral-300: #cfd3e5;
  --color-neutral-600: #75798c;
  --color-neutral-700: #595d6c;
  --color-neutral-800: #3f424d;
  --color-neutral-900: #292b31;

  --color-accent-100: #f5f4ff;
  --color-accent-200: #e7e5fe;
  --color-accent-300: #d2cefd;
  --color-accent-400: #b5abfc;
  --color-accent-800: #423a6a;
  --color-accent-900: #2b2741;

  /* Semantic pair — the ONE documented extension to Nocturne's mono palette. The system has no
     danger/positive role, but an admin panel must not signal a failed action by wording alone.
     Both sit at the accent's lightness and chroma discipline (OKLCH L≈0.66, low chroma) so they
     read as part of the system rather than stock red/green. Used only for status text, never as
     a fill. */
  --color-danger: #d98f95;
  --color-positive: #8fc7a9;

  --font-heading: "Inter", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: 2.8px;
  --space-2: 5.6px;
  --space-3: 8.4px;
  --space-4: 11.2px;
  --space-6: 16.8px;
  --space-8: 22.4px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;

  --shadow-sm: 0 0 0 1px #3f424d;
  --shadow-md: 0 0 0 1px #595d6c, 0 6px 18px rgba(0,0,0,0.55);
  --shadow-lg: 0 0 0 1px #9397ab, 0 16px 40px rgba(0,0,0,0.65);

  /* Legacy aliases — app.js carries a few inline var() references. Keep these mapped. */
  --bg: var(--color-bg);
  --card: var(--color-surface);
  --line: var(--color-divider);
  --fg: var(--color-text);
  --muted: color-mix(in srgb, var(--color-text) 55%, transparent);
  --accent: var(--color-accent);
  --up: var(--color-positive);
  --danger: var(--color-danger);
}

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

body {
  margin: 0; background: var(--color-bg); color: var(--color-text);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55; font-weight: 400;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading); font-weight: 500;
  line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 var(--space-2);
}
h1 { font-size: 18px; }                 /* the header brand mark */
h2 { font-size: 32px; margin-bottom: var(--space-3); }   /* page titles: Servers, Backups */
.card h2 { font-size: 20px; }           /* in-card titles sit a step down */
h3 { font-size: 16px; margin: var(--space-6) 0 var(--space-3); }

a { color: var(--color-accent); text-underline-offset: 3px; }
a:hover { color: var(--color-accent-300); }
.muted { color: color-mix(in srgb, var(--color-text) 55%, transparent); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--color-accent) 30%, transparent); }

/* Nocturne's .nav: no bottom border, brand pushes the rest right */
header {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-6) var(--space-8);
}
header h1 { margin: 0; margin-right: auto; }
header > div { display: flex; align-items: center; gap: var(--space-3); }

/* Centred, and wide enough for the server cards to sit side by side. (Nocturne's own
   direction is left-aligned/asymmetric; centring here is a deliberate house override —
   headings stay flush-left inside the container so the character survives.) */
main { max-width: 1180px; margin: 0 auto; padding: 0 var(--space-8) var(--space-8); }
header { max-width: 1180px; margin: 0 auto; }

/* Server cards as widgets across the width; align-items:start so an open terminal in one
   card doesn't stretch its neighbour. */
.srv-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: var(--space-3); align-items: start; margin-bottom: var(--space-3);
}
.srv-grid > .card { margin: 0; }
@media (max-width: 980px) { .srv-grid { grid-template-columns: 1fr; } }

/* Freestanding rules fade at both ends — the system's signature */
hr, .hr {
  height: 1px; border: 0; margin: var(--space-6) 0;
  background: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent);
}

.card {
  background: var(--color-surface); border: 0; border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); padding: var(--space-6); margin: 0 0 var(--space-3);
}

label {
  display: block; font-size: 12px; margin: var(--space-4) 0 5px;
  color: color-mix(in srgb, var(--color-text) 70%, transparent);
}
input, select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; font: inherit; font-size: 14px;
  color: var(--color-text); caret-color: var(--color-accent);
  background: var(--color-bg);
  border: 1px solid var(--color-divider); border-radius: var(--radius-md);
}
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--color-text) 45%, transparent); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--color-accent); outline-offset: 0; }
input::placeholder { color: color-mix(in srgb, var(--color-text) 32%, transparent); }
select {
  appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 15px, calc(100% - 9px) 15px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

/* Buttons are outlined, never filled — primary carries the accent as a border */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-heading); font-weight: 500; font-size: 14px; line-height: 1.2;
  color: var(--color-accent); cursor: pointer;
  background: transparent; border: 1px solid var(--color-accent);
  padding: var(--space-2) calc(var(--space-3) * 1.2); border-radius: var(--radius-md);
}
button:hover { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
button:active { background: color-mix(in srgb, var(--color-accent) 22%, transparent); }
button.secondary { color: var(--color-text); border-color: var(--color-divider); }
button.secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
button.secondary:active { background: color-mix(in srgb, var(--color-text) 14%, transparent); }
button.danger { color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 70%, transparent); }
button.danger:hover { background: color-mix(in srgb, var(--color-danger) 12%, transparent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button svg { display: block; }

.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.err { color: var(--color-danger); font-size: 13px; margin-top: var(--space-2); min-height: 1.1em; }
.ok { color: var(--color-positive); font-size: 13px; margin-top: var(--space-2); }

/* Tables: row-level rules so the end-fade spans the row, not each cell */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: var(--space-3) var(--space-2); border-bottom: 1px solid transparent; vertical-align: top; }
th {
  font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 60%, transparent);
  padding: var(--space-2);
}
thead tr {
  background: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent) no-repeat bottom / 100% 1px;
}
tbody tr {
  background: linear-gradient(to right,
    transparent, color-mix(in srgb, var(--color-text) 8%, transparent) 48px,
    color-mix(in srgb, var(--color-text) 8%, transparent) calc(100% - 48px), transparent) no-repeat bottom / 100% 1px;
}

/* Badges are Nocturne tags. Mono palette: rank reads through tonal weight, not hue —
   owner is the accent tint, admin an accent outline, moderator neutral, trusted the quietest. */
.badge {
  display: inline-flex; align-items: center; font-size: 11px; letter-spacing: 0.02em;
  padding: 3px 10px; border-radius: calc(var(--radius-md) * 0.75);
  background: var(--color-neutral-800); color: var(--color-neutral-100);
  margin: 0 var(--space-1) var(--space-1) 0;
}
.badge.trusted   { background: var(--color-neutral-900); color: color-mix(in srgb, var(--color-text) 60%, transparent); }
.badge.moderator { background: var(--color-neutral-800); color: var(--color-neutral-100); }
.badge.admin     { background: transparent; border: 1px solid var(--color-accent); color: var(--color-accent); }
.badge.owner     { background: var(--color-accent-800); color: var(--color-accent-100); }
/* live container state */
.badge.state { background: var(--color-neutral-900); color: color-mix(in srgb, var(--color-text) 60%, transparent); }
.badge.state.up { background: var(--color-accent-900); color: var(--color-accent-200); }
.badge.state.down { background: var(--color-neutral-800); color: var(--color-neutral-200); }

code {
  background: var(--color-bg); padding: 3px 6px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); font-family: var(--font-mono); font-size: 11.5px; word-break: break-all;
}
/* near-white from the ramp, not #fff — still scans */
.qr { width: 180px; height: 180px; border-radius: var(--radius-md); background: var(--color-neutral-100); padding: 6px; }
.grid { display: grid; grid-template-columns: 1fr 150px; gap: var(--space-3) var(--space-4); align-items: center; margin-bottom: var(--space-2); }

/* server card: name/status row above the action buttons */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-6); }

/* terminal-style log + console viewer — sits on the darker ground as an inset */
.terminal { display: none; margin-top: var(--space-6); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); }
.terminal.open { display: block; }
.terminal-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); background: var(--color-surface);
  background-image: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent);
  background-repeat: no-repeat; background-position: bottom; background-size: 100% 1px;
}
/* the three dots stay one quiet neutral — no traffic-light hues in a mono system */
.terminal-bar .dots { display: inline-flex; gap: var(--space-1); }
.terminal-bar .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--color-neutral-700); }
.terminal-bar .t-title {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 50%, transparent);
}
.terminal-body {
  margin: 0; max-height: 360px; overflow: auto; padding: var(--space-3);
  background: var(--color-bg); color: color-mix(in srgb, var(--color-text) 72%, transparent);
  font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
}

.invite-note { margin-top: var(--space-4); }
.invite-out { margin-top: var(--space-6); line-height: 1.6; }
.invite-out code { display: inline-block; margin-top: var(--space-2); }

/* icon buttons (logs / whitelist / console / copy) — outlined like every other button */
.head-right { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.icon-btn {
  width: 36px; height: 36px; padding: 0;
  color: var(--color-text); border-color: var(--color-divider);
}
.icon-btn:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.icon-btn.active { color: var(--color-accent); border-color: var(--color-accent); }
.icon-btn svg { display: block; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 14px; height: 14px; }
.icon-btn.danger { color: var(--color-text); }
.icon-btn.danger:hover { color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 70%, transparent); background: color-mix(in srgb, var(--color-danger) 10%, transparent); }

/* interactive console input row */
.console-input {
  display: flex; gap: var(--space-2); padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  background-image: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent);
  background-repeat: no-repeat; background-position: top; background-size: 100% 1px;
}
.console-input input { flex: 1; font-family: var(--font-mono); font-size: 12px; min-height: 32px; }
.console-input button { flex: 0 0 auto; }

.linkrow { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.linkrow code { flex: 1; margin-top: 0; }

.actionmsg { color: color-mix(in srgb, var(--color-text) 55%, transparent); font-size: 12.5px; align-self: center; }
.secret { user-select: all; letter-spacing: 1px; font-family: var(--font-mono); }
.uactions { white-space: nowrap; text-align: right; }
.uactions .icon-btn { margin-left: var(--space-1); }
.subrow td { background: var(--color-bg); }
.utable th, .utable td { vertical-align: middle; }
.ta-r { text-align: right; }

/* cascading role picker popout */
.role-menu {
  position: absolute; z-index: 200; background: var(--color-surface);
  border-radius: var(--radius-lg); padding: var(--space-1); min-width: 250px;
  box-shadow: var(--shadow-lg);
}
.rm-item {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
}
.rm-item:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.rm-cur { font-size: 11px; }
.rm-sub {
  display: none; position: absolute; left: 100%; top: -1px; margin-left: 3px;
  background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-1);
  min-width: 150px; box-shadow: var(--shadow-lg);
}
.rm-item:hover > .rm-sub { display: block; }
.rm-opt { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; white-space: nowrap; }
.rm-opt:hover { background: color-mix(in srgb, var(--color-accent) 18%, transparent); color: var(--color-accent-100); }
.rm-opt.sel { color: var(--color-accent); }

/* whitelist editor */
.wlbox { display: none; margin-top: var(--space-6); border-radius: var(--radius-md); padding: var(--space-4); background: var(--color-bg); box-shadow: var(--shadow-sm); }
.wlbox.open { display: block; }
.wl-head { font-family: var(--font-heading); font-weight: 500; font-size: 14px; margin-bottom: var(--space-4); }
.wl-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); min-height: 1.5rem; }
.wl-chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  background: var(--color-neutral-800); color: var(--color-neutral-100);
  border-radius: calc(var(--radius-md) * 0.75); padding: 3px 4px 3px 10px; font-size: 11.5px;
}
.wl-chip button { background: none; border: 0; color: color-mix(in srgb, var(--color-text) 55%, transparent); padding: 0 var(--space-1); font-size: 15px; line-height: 1; min-height: 0; }
.wl-chip button:hover { background: none; color: var(--color-danger); }
.wl-add { display: flex; gap: var(--space-2); }
.wl-add input { flex: 1; }

/* ── backups ───────────────────────────────────────────────────────────────
   Activity status on top (one task at a time), the default schedule with its
   Save, then one collapsible per game with the on/off switch on the header. */
.bk-topstatus {
  display: flex; align-items: center; gap: var(--space-4);
  font-size: 13.5px; margin-bottom: var(--space-6);
  padding: var(--space-4) var(--space-6); border-radius: var(--radius-md);
  background: var(--color-surface); box-shadow: var(--shadow-sm);
}
/* a short solid accent mark carries live state — the accent as a mark, not a flood */
.bk-topstatus::before {
  content: ""; width: 2px; height: 26px; border-radius: 1px; flex: none;
  background: var(--color-neutral-700);
}
.bk-topstatus.active::before { background: var(--color-accent); box-shadow: 0 0 8px var(--color-accent); }
.bk-sec { margin-bottom: var(--space-4); }
.bk-sec-title {
  font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 60%, transparent); margin-bottom: var(--space-3);
}
.bk-defsched {
  padding-bottom: var(--space-6);
  background: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent) no-repeat bottom / 100% 1px;
}
.bk-accs { display: flex; flex-direction: column; gap: var(--space-2); }
.bk-acc { border-radius: var(--radius-md); background: var(--color-bg); box-shadow: var(--shadow-sm); overflow: hidden; }
.bk-acc-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-6); cursor: pointer; user-select: none;
  font-family: var(--font-heading); font-weight: 500; font-size: 15px;
}
.bk-acc-head:hover { background: color-mix(in srgb, var(--color-text) 4%, transparent); }
.bk-caret { color: color-mix(in srgb, var(--color-text) 45%, transparent); font-size: 12px; transition: transform .15s; }
.bk-caret.open { transform: rotate(90deg); }
.bk-headhint { font-family: var(--font-body); font-weight: 400; font-size: 11px; margin-left: auto; color: color-mix(in srgb, var(--color-text) 45%, transparent); }
.bk-acc-body {
  display: none; padding: var(--space-4) var(--space-6) var(--space-6);
  background: linear-gradient(to right,
    transparent, var(--color-divider) 48px,
    var(--color-divider) calc(100% - 48px), transparent) no-repeat top / 100% 1px;
}
.bk-acc-body.open { display: block; }
.bk-acc-body select, .bk-acc-body input[type=time] { min-height: 32px; padding: 4px 8px; font-size: 12.5px; }
.bk-acc-body select { padding-right: 24px; background-position: calc(100% - 13px) 14px, calc(100% - 8px) 14px; }
.bk-acc-body [data-fsnap] { max-width: 22rem; }
.bk-acc-body button { padding: var(--space-1) var(--space-3); font-size: 12.5px; }
.bk-custom { display: inline-flex; align-items: center; gap: var(--space-2); }
.bk-fmsg { font-size: 12.5px; margin-top: var(--space-2); }
.bk-fmsg a { color: var(--color-accent); }
.bk-row-fetch { margin-top: var(--space-3); }
.bk-next { font-size: 11.5px; margin-top: var(--space-2); color: color-mix(in srgb, var(--color-text) 45%, transparent); }

/* toggle switch (scheduled backups on/off) — Nocturne ships no switch, so this is built from
   the .radio checked treatment: accent border, accent knob, accent-900 track. */
.switch { position: relative; display: inline-block; width: 34px; height: 19px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px;
  border: 1.5px solid var(--color-divider); background: transparent; transition: .15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 11px; width: 11px; left: 2px; top: 2px;
  border-radius: 50%; background: var(--color-neutral-600); transition: .15s;
}
.switch input:checked + .slider { border-color: var(--color-accent); background: var(--color-accent-900); }
.switch input:checked + .slider::before { transform: translateX(15px); background: var(--color-accent); }
.switch input:focus-visible + .slider { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: 0.45; }

@media (max-width: 620px) {
  header, main { padding-inline: var(--space-6); }
  h2 { font-size: 25px; }
  .bk-acc-head, .bk-acc-body, .bk-topstatus { padding-inline: var(--space-4); }
}
