/* PXEForge web UI — Netbox-style minimal layout, fully offline.
 *
 * Theme tokens live on `:root` (dark default) and `:root[data-theme=light]`.
 * Both palettes share variable *names*, so component CSS uses
 * `var(--bg)` regardless and the toggle in the topbar just flips the
 * data-attribute. No JS-side recolouring, no React re-renders, no FOUC
 * (the inline script in index.html paints the right theme before main
 * CSS lands). */

:root {
  /* Dark palette (default). */
  --bg:           #0b1018;
  --bg-panel:    #121826;
  --bg-panel-2:  #1a2334;
  --bg-elev:     #223047;
  --fg:           #e4e8ef;
  --fg-dim:      #8a94a7;
  --fg-dimmer:   #5a6379;
  --accent:       #00d4b4;   /* Netbox-ish teal */
  --accent-dim:  #07a38c;
  --warn:         #ffb347;
  --err:          #ef6e6e;
  --ok:           #4ade80;
  --border:       #223047;
  --border-soft: #172033;
  --terminal-bg: #06090e;
  --shadow-card: 0 1px 0 rgba(255,255,255,0.02), 0 8px 24px rgba(0,0,0,0.25);
  --radius:      6px;
  --radius-lg:  10px;
  --sidebar-w:  240px;
  --topbar-h:   56px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

:root[data-theme="light"] {
  /* Light palette — high-contrast neutral, accent unchanged for brand
     consistency. Designed against Netbox Labs's reference screenshot:
     near-white surfaces, soft grey dividers, dark text. */
  --bg:           #f6f8fb;
  --bg-panel:    #ffffff;
  --bg-panel-2:  #f0f3f8;
  --bg-elev:     #e6ebf2;
  --fg:           #1c2330;
  --fg-dim:      #5a6377;
  --fg-dimmer:   #95a0b3;
  --accent:       #00b89c;
  --accent-dim:  #008b73;
  --warn:         #b67016;
  --err:          #c63a3a;
  --ok:           #1f9b54;
  --border:       #d8dde6;
  --border-soft: #e7eaf0;
  --terminal-bg: #0d1219; /* terminal stays dark even in light mode */
  --shadow-card: 0 1px 0 rgba(0,0,0,0.02), 0 6px 18px rgba(20,28,52,0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--sans); font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--fg);
  transition: background 0.16s ease, color 0.16s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd { font-family: var(--mono); font-size: 12.5px;
  background: var(--bg-panel-2); padding: 1px 5px; border-radius: 3px; }

/* ── Shell ─────────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
}
.sidebar {
  grid-area: sidebar;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar .brand img { width: 40px; height: auto; }
.sidebar .brand strong { font-size: 16px; letter-spacing: 0.4px; }
.sidebar .brand .sub { color: var(--fg-dim); font-size: 11px; }
.sidebar nav { padding: 10px 0; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; color: var(--fg); font-size: 13.5px;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.sidebar nav a:hover { background: var(--bg-panel-2); text-decoration: none; }
.sidebar nav a.active {
  background: var(--bg-panel-2);
  border-left-color: var(--accent);
  color: var(--accent);
}
.sidebar nav a .count {
  margin-left: auto;
  background: var(--bg-elev); color: var(--fg-dim);
  padding: 1px 7px; font-size: 11px; border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.sidebar nav a.active .count { background: var(--accent); color: #002923; }
.sidebar .footer {
  padding: 10px 18px; border-top: 1px solid var(--border);
  color: var(--fg-dimmer); font-size: 11px;
}
.sidebar .footer code { background: transparent; color: var(--fg-dim); padding: 0; }

/* ── Top bar ───────────────────────────────────────────────────────── */

.topbar {
  grid-area: topbar;
  display: flex; align-items: center;
  padding: 0 20px; gap: 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  margin: 0; font-size: 15px; font-weight: 600;
  color: var(--fg); letter-spacing: 0.2px;
}
.topbar .spacer { flex: 1; }
.topbar .chip {
  background: var(--bg-panel-2); border: 1px solid var(--border);
  color: var(--fg-dim); font-size: 12px;
  padding: 4px 10px; border-radius: 12px;
  white-space: nowrap;
}
.topbar .chip strong { color: var(--fg); font-weight: 600; }

/* Theme toggle button. Two glyphs stacked; CSS swaps which is visible
   based on the active theme. Keeps the layout stable when toggling. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 32px;
  background: transparent; color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { background: var(--bg-panel-2); border-color: var(--accent); }
.theme-toggle .t-sun  { display: none; }
.theme-toggle .t-moon { display: inline; }
:root[data-theme="light"] .theme-toggle .t-sun  { display: inline; }
:root[data-theme="light"] .theme-toggle .t-moon { display: none; }

/* ── Main content ─────────────────────────────────────────────────── */

.main {
  grid-area: main;
  overflow: auto;
  padding: 22px 26px 40px;
}
.grid { display: grid; gap: 20px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1024px) {
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ── Cards / panels ───────────────────────────────────────────────── */

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.card > header {
  padding: 12px 16px;
  background: var(--bg-panel-2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card > header h2 { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--fg); }
.card > header .sub { color: var(--fg-dim); font-size: 12px; margin-left: auto; }
.card .body { padding: 16px; }

.stat { padding: 16px; }
.stat .label { color: var(--fg-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.8px; }
.stat .value { font-size: 28px; font-weight: 600; line-height: 1.1; margin-top: 4px; color: var(--fg); }
.stat .trend { font-size: 12px; color: var(--fg-dim); margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 16px; border-bottom: 1px solid var(--border-soft); }
th {
  color: var(--fg-dim); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 1px;
  background: var(--bg-panel-2);
}
tr:hover td { background: var(--bg-panel-2); }
td.mono { font-family: var(--mono); font-size: 12.5px; }
td.num  { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Tags / pills ─────────────────────────────────────────────────── */

.tag {
  display: inline-block;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
  background: var(--bg-elev); color: var(--fg-dim);
}
.tag.ok   { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
.tag.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.tag.err  { background: color-mix(in srgb, var(--err) 22%, transparent); color: var(--err); }
.tag.accent { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.tag.arch { text-transform: uppercase; }

/* ── Forms ────────────────────────────────────────────────────────── */

button, .btn {
  background: var(--accent); color: #002923;
  border: 0; border-radius: var(--radius);
  padding: 7px 14px; font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}
button:hover, .btn:hover { background: var(--accent-dim); color: #fff; }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); }
button.ghost:hover { background: var(--bg-panel-2); color: var(--fg); }
button.danger { background: transparent; color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); }
button.danger:hover { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); }

label.field {
  display: grid; gap: 4px; margin-bottom: 14px;
}
label.field .name { color: var(--fg-dim); font-size: 12px; }
label.field .hint { color: var(--fg-dimmer); font-size: 11px; }
label.field input[type="text"],
label.field input[type="number"],
label.field select,
label.field textarea {
  width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; font: inherit;
}
label.field input:focus, label.field select:focus, label.field textarea:focus {
  outline: none; border-color: var(--accent);
}
label.check {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 10px; margin-bottom: 6px;
  border: 1px solid var(--border-soft); border-radius: var(--radius);
}
label.check input { accent-color: var(--accent); }

/* ── Drop zone ────────────────────────────────────────────────────── */

.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px; text-align: center;
  color: var(--fg-dim); cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.drop.hover, .drop:hover {
  border-color: var(--accent); color: var(--fg);
  background: var(--bg-panel-2);
}
.drop strong { color: var(--accent); }

/* Plain progress bar (used for ISO uploads). */
.progress { height: 6px; background: var(--bg-panel-2); border-radius: 3px; overflow: hidden; margin-top: 12px; display: none; }
.progress.active { display: block; }
.progress .bar { height: 100%; width: 0%; background: var(--accent); transition: width .25s; }

/* ── Forge progress widget ─────────────────────────────────────────
   Anvil-with-sparks animation paired with a horizontal progress bar.
   Used on the Forge Gate tab to give a sense of the "in-flight"
   imaging count without having to read a number. */
.forge-progress {
  display: flex; align-items: center; gap: 16px;
  padding: 16px;
}
.forge-progress .anvil {
  width: 64px; height: 64px; flex: none;
  background: url("/assets/anvil-forge.svg") no-repeat center / contain;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--warn) 40%, transparent));
}
.forge-progress .info { flex: 1; min-width: 0; }
.forge-progress .info .label {
  font-size: 12.5px; color: var(--fg-dim); margin-bottom: 6px;
}
.forge-progress .bar-track {
  height: 8px; background: var(--bg-elev); border-radius: 4px;
  overflow: hidden; position: relative;
}
.forge-progress .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warn), var(--accent));
  width: 0%;
  transition: width 0.4s ease;
  position: relative;
}
.forge-progress .bar-fill::after {
  /* Subtle moving sheen so the bar feels alive even at 0% movement. */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,0.18) 50%,
    rgba(255,255,255,0) 100%);
  animation: forge-sheen 1.6s linear infinite;
}
@keyframes forge-sheen {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
.forge-progress.idle .anvil { filter: none; opacity: 0.45; }
.forge-progress.idle .bar-fill::after { animation: none; }

/* ── Page-load anvil ──────────────────────────────────────────────── */
.loader {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 40px 20px;
  color: var(--fg-dim);
}
.loader .anvil {
  width: 110px; height: 110px;
  background: url("/assets/anvil-forge.svg") no-repeat center / contain;
}

/* ── Top bar readiness chip ──────────────────────────────────────── */
.chip.ready    { background: color-mix(in srgb, var(--ok) 18%, transparent);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip.notready { background: color-mix(in srgb, var(--err) 18%, transparent);  color: var(--err);  border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.chip.warming  { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }

/* ── Dashboard stat strip ────────────────────────────────────────── */
.statstrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 1100px) { .statstrip { grid-template-columns: repeat(2, 1fr); } }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px;
      padding: 4px 0; font-size: 13px; }
.kv .k { color: var(--fg-dim); }
.kv .v { font-family: var(--mono); color: var(--fg); word-break: break-all; }
.kv .v.warn { color: var(--warn); }
.kv .v.err  { color: var(--err); }
.kv .v.ok   { color: var(--ok); }

/* ── Image rows: amber tint on un-bootable images ────────────────── */
tr.unbootable td { background: color-mix(in srgb, var(--warn) 7%, transparent) !important; }
tr.unbootable td:first-child { border-left: 3px solid var(--warn); }
.row-warn { color: var(--warn); font-size: 11.5px; margin-top: 2px; }

/* ── Table source badge ──────────────────────────────────────────── */
.src-badge { font-family: var(--mono); font-size: 11px; padding: 1px 6px;
             border-radius: 4px; background: var(--bg-elev); color: var(--fg-dim); }
.src-badge.nfs { background: color-mix(in srgb, #7cd3ff 18%, var(--bg-elev));
                 color: color-mix(in srgb, #7cd3ff 90%, var(--fg)); }

/* ── NFS rows ────────────────────────────────────────────────────── */
.nfs-row { display: grid; grid-template-columns: 32px 1fr auto auto auto; align-items: center;
           gap: 14px; padding: 10px 14px; background: var(--bg-panel-2);
           border-left: 3px solid var(--accent); border-radius: var(--radius); }
.nfs-row.down { border-left-color: var(--err); }
.nfs-row .id  { font-family: var(--mono); font-size: 12.5px; color: var(--fg); }
.nfs-row .meta { color: var(--fg-dim); font-size: 12px; }
.nfs-row .err  { color: var(--err); font-size: 11.5px; word-break: break-all; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok   { background: var(--ok); }
.dot.err  { background: var(--err); }
.dot.warn { background: var(--warn); }

/* Inline form rows. */
.form-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; }
@media (max-width: 900px) { .form-row { grid-template-columns: 1fr; } }

/* ── Gate queue "horse race" visual ──────────────────────────────── */
.gate-track {
  display: grid; gap: 6px;
  padding: 10px 0;
}
.gate-row {
  display: grid; grid-template-columns: 32px 1fr auto auto; align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--bg-panel-2); border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}
.gate-row.assigned { border-left-color: var(--ok); }
.gate-row .pos { font-family: var(--mono); font-size: 15px; color: var(--accent); font-weight: 600; }
.gate-row.assigned .pos { color: var(--ok); }
.gate-row .mac { font-family: var(--mono); font-size: 13px; }
.gate-row .meta { color: var(--fg-dim); font-size: 12px; }

.empty { color: var(--fg-dim); padding: 30px; text-align: center; }
.msg { color: var(--fg-dim); font-size: 12.5px; margin-top: 8px; }
.msg.err { color: var(--err); }
.msg.ok  { color: var(--ok); }

/* ── Terminal pane ──────────────────────────────────────────────── */
.terminal {
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--terminal-bg);
  overflow: hidden;
  height: calc(100vh - var(--topbar-h) - 90px);
  min-height: 480px;
  box-shadow: var(--shadow-card);
}
.terminal .pane {
  flex: 1; overflow: auto;
  padding: 10px 14px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  color: #cfd6e2;
  white-space: pre-wrap; word-break: break-word;
}
.terminal .pane .lvl-error { color: var(--err); }
.terminal .pane .lvl-warn  { color: var(--warn); }
.terminal .pane .lvl-info  { color: #cfd6e2; }
.terminal .pane .lvl-debug { color: #8b94a8; }
.terminal .pane .lvl-trace { color: #5a6379; }
.terminal .pane .ts        { color: #5a6379; }
.terminal .pane .tg        { color: #7cd3ff; }
.terminal .pane .echo      { color: var(--accent); }
.terminal .input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: #0a0e15;
  border-top: 1px solid #1d2330;
}
.terminal .input-row .prompt { color: var(--accent); font-family: var(--mono); }
.terminal .input-row input {
  flex: 1; background: transparent; border: 0; color: #e4e8ef;
  font: inherit; font-family: var(--mono); font-size: 13px;
  outline: none; padding: 4px 0;
}
.terminal .toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 14px;
  background: #0a0e15;
  border-bottom: 1px solid #1d2330;
  font-size: 12px; color: #8a94a7;
}
.terminal .toolbar .right { margin-left: auto; display: flex; gap: 6px; }
.terminal .toolbar button {
  padding: 3px 9px; font-size: 11px;
  background: transparent; color: #8a94a7; border: 1px solid #1d2330;
  font-weight: 500;
}
.terminal .toolbar button:hover { color: #e4e8ef; background: #1d2330; }

/* ── About card ─────────────────────────────────────────────────── */
.about-hero { padding: 20px 24px; }
.about-hero h2 { font-size: 22px; margin: 0 0 8px; color: var(--fg); }
.about-hero .lead { color: var(--fg-dim); font-size: 14px; max-width: 60ch; }
.about-hero .who { margin-top: 18px; font-size: 13px; }
.about-hero .who span { color: var(--fg-dim); }
.about-hero .who strong { color: var(--accent); }
