/* Ferrum SLM Studio — dark theme, rust-orange accent. Vanilla CSS, no frameworks. */
:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #273449;
  --line: #334155;
  --fg: #e2e8f0;
  --muted: #94a3b8;
  --accent: #ea580c;
  --accent2: #fb923c;
  --accent-strong: #c2410c;       /* white text on it: 5.2:1 (the plain accent gives 3.6:1) */
  --accent-strong-hover: #9a3412;
  --field-line: #8195b0;          /* form-field borders: at least 3:1 against the page */
  --focus: #fde047;               /* the focus ring */
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #f87171;
  --term-bg: #0b1120;
  --term-stderr: #fca5a5;
  --term-log: #7dd3fc;
  --banner-bg: #422006;
  --banner-fg: #fde68a;
  --badge-fg: #04210f;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23e2e8f0' d='M3 4.5L6 8l3-3.5z'/%3E%3C/svg%3E");
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f7;
  --bg2: #ffffff;
  --bg3: #e4eaf2;
  --line: #cbd5e1;
  --fg: #162a45;
  --muted: #475569;
  --accent: #c2410c;
  --accent2: #ea580c;
  --accent-strong: #9a3412;
  --accent-strong-hover: #7c2d12;
  --field-line: #64748b;
  --focus: #1e40af;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --term-bg: #f8fafc;
  --term-stderr: #b91c1c;
  --term-log: #1e40af;
  --banner-bg: #fef3c7;
  --banner-fg: #78350f;
  --badge-fg: #ffffff;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23162a45' d='M3 4.5L6 8l3-3.5z'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Top bar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand b { color: var(--accent2); }
.mini-stats { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--muted); }
.mini b { color: var(--fg); }
.conn { color: var(--err); font-size: 16px; }
.conn.ok { color: var(--ok); }

/* Tabs */
#tabs { display: flex; gap: 2px; padding: 0 10px; background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  padding: 10px 14px; cursor: pointer; font-size: 13px;
}
.tab:hover { color: var(--fg); }
.tab:focus-visible { outline-offset: -3px; }
.tab.active { color: var(--accent2); border-bottom-color: var(--accent); }

/* Content */
#content { flex: 1; overflow: auto; padding: 16px 20px; }
.panel { display: none; max-width: 980px; }
.panel.active { display: block; }
h2 { margin: 0 0 6px; font-size: 18px; }
h3 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hint { color: var(--muted); margin: 0 0 14px; }
.muted { color: var(--muted); }
code { font-family: var(--mono); background: var(--bg3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.banner { background: var(--banner-bg); border: 1px solid var(--warn); color: var(--banner-fg); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }
.hidden { display: none !important; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); margin: 6px 0; }
label.narrow { max-width: 150px; }
input[type=text], input[type=number], textarea, select {
  background: var(--bg2); color: var(--fg); border: 1px solid var(--field-line);
  border-radius: 6px; padding: 8px 10px; font: inherit;
  color-scheme: inherit;
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-color: var(--bg2);
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px 12px;
}
select option, select optgroup {
  background: var(--bg2);
  color: var(--fg);
}
::placeholder { color: var(--muted); opacity: 1; }

/* Keyboard focus: one high-contrast ring everywhere (never removed). */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 1px; border-color: var(--focus); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; width: 100%; }
.row { display: flex; gap: 10px; align-items: flex-end; margin: 8px 0; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 10px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; padding: 8px 14px 14px; }
legend { color: var(--muted); padding: 0 6px; }

button {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 14px; cursor: pointer; font: inherit; white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-strong-hover); border-color: var(--accent-strong-hover); }
button.ghost { background: transparent; }
button.linkbtn { background: none; border: none; padding: 0; color: var(--accent2); text-decoration: underline; font-size: 12px; }
button.linkbtn:hover { color: var(--fg); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.err { color: var(--err); font-size: 12.5px; min-height: 16px; display: block; margin: 2px 0 6px; }
.errmore { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 8px; }
.errmore .hint-line { color: var(--muted); font-size: 12.5px; }
.spinner {
  display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid var(--muted); border-top-color: var(--accent2); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stats { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.stats b { color: var(--accent2); }

/* Train */
.progress { flex: 1; height: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; min-width: 180px; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .15s; }
#trChart { width: 100%; height: 140px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.result { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; min-height: 8px; }

/* Output */
.output {
  background: var(--term-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap; min-height: 120px; margin-top: 8px;
}
.serverlog {
  background: var(--term-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  font-family: var(--mono); font-size: 12.5px; min-height: 80px; max-height: 260px; overflow: auto;
}
.serverlog .line { white-space: pre-wrap; word-break: break-word; }
.output:empty::before { content: attr(placeholder); color: var(--muted); }

/* Tables */
table.data { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
table.data th, table.data td { border: 1px solid var(--line); padding: 7px 9px; text-align: right; }
table.data th { background: var(--bg2); color: var(--muted); text-align: right; }
table.data td:first-child, table.data th:first-child { text-align: left; }
.verdict-good { color: var(--ok); font-weight: 600; }
.verdict-weak { color: var(--warn); font-weight: 600; }

/* Info cards */
.infocards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 10px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.card .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.card .v { font-family: var(--mono); font-size: 14px; margin-top: 2px; word-break: break-all; }

/* System */
.sysgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.gauge { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.gauge .big { font-size: 32px; font-weight: 700; color: var(--accent2); font-family: var(--mono); }
.meter { height: 10px; background: var(--bg3); border-radius: 6px; overflow: hidden; margin: 8px 0 4px; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.core { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
.core .cbar { height: 6px; background: var(--bg3); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.core .cbar > div { height: 100%; background: var(--accent); }

/* Terminal */
#terminal { display: flex; flex-direction: column; height: 230px; border-top: 1px solid var(--line); background: var(--term-bg); color: var(--fg); }
.term-head { display: flex; justify-content: space-between; align-items: center; padding: 5px 12px; background: var(--bg2); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.term-out { flex: 1; overflow: auto; padding: 8px 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; }
.term-out .line { white-space: pre-wrap; word-break: break-word; }
.term-out .stderr { color: var(--term-stderr); }
.term-out .log { color: var(--term-log); }
.term-out .cmd { color: var(--accent2); }
.term-out .sys { color: var(--muted); }
.term-input { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--line); }
.prompt { color: var(--ok); font-family: var(--mono); font-size: 12.5px; white-space: nowrap; max-width: 50%; overflow: hidden; text-overflow: ellipsis; }
#termCmd { flex: 1; background: transparent; border: none; color: var(--fg); font-family: var(--mono); font-size: 12.5px; }
.term-out:focus-visible { outline-offset: -3px; }

/* Toasts */
#toasts { position: fixed; bottom: 250px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--bg3); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; max-width: 360px; box-shadow: 0 4px 20px rgba(0,0,0,.4); animation: slidein .2s; }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
/* The kind is also a symbol, not only a colour. */
.toast.err::before { content: "✕ "; font-weight: 700; color: var(--err); }
.toast.ok::before { content: "✓ "; font-weight: 700; color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* Dataset catalog (HuggingFace / Kaggle) */
.catalog { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.catalog-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 8px;
}
.catalog-item button { white-space: nowrap; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 0.78em; background: var(--accent); color: var(--badge-fg);
  text-transform: uppercase; letter-spacing: 0.03em;
}

/* Capability dialogs */
dialog.capdlg {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg2);
  color: var(--fg);
  max-width: 640px;
  padding: 18px 20px;
}
dialog.capdlg::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.capdlg h2 { margin-top: 0; }
dialog.capdlg .dlg-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin: 16px 0 0; padding: 0;
}
dialog.capdlg .capfoot { color: var(--muted); font-size: 11px; margin-top: 12px; }

/* Tooltips (tooltip.js): one shared bubble, positioned with CSSOM (no inline style attribute). */
.tip {
  position: fixed; z-index: 1000; left: 0; top: 0;
  width: min(440px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow: auto;
  padding: 10px 12px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  font-size: 12.5px; line-height: 1.45; pointer-events: none; text-transform: none; letter-spacing: normal;
}
.tip-title { font-weight: 600; color: var(--accent2); margin-bottom: 4px; font-size: 13px; }
.tip-sec { margin: 4px 0 0; }
.tip-sec b { color: var(--muted); font-weight: 600; }
.tip-warn { color: var(--warn); }
.tip-bad { color: var(--err); }
.tip-ok { color: var(--ok); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* "Your hardware" line in the top bar */
.hwline { flex: 1; min-width: 0; margin: 0 14px; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Beginner / Expert mode & collapsible log dock */
.mode-switch { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.mode-switch select { padding: 3px 26px 3px 8px; font-size: 12px; }
body[data-mode="beginner"] .adv-only { display: none !important; }
#terminal.collapsed { height: auto; }
#terminal.collapsed .term-out { display: none; }

/* Motion: no sliding toasts or animated bars for people who ask for less. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
