/* Partout Fleet Management — web UI
   Tokens per ui-guidelines §7. Light default. Density: operator tool. */

:root {
  --brand: #2563eb;
  --brand-subtle: #eff6ff;
  --surface: #ffffff;
  --surface-app: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  --healthy: #059669;
  --healthy-subtle: #d1fae5;
  --warning: #d97706;
  --warning-subtle: #fef3c7;
  --critical: #dc2626;
  --critical-subtle: #fee2e2;
  --info: #2563eb;
  --info-subtle: #dbeafe;
  --neutral: #64748b;
  --neutral-subtle: #f1f5f9;
  --radius-card: 12px;
  --radius-ctrl: 8px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --sidebar-w: 270px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--surface-app);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }

/* ---------- layout shell ---------- */
#app { height: 100%; }
.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.brand { padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand .word { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand .sub { font-size: 11.5px; color: var(--text-faint); }
.brand .port {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  background: var(--neutral-subtle); color: var(--text-muted);
  padding: 2px 7px; border-radius: 20px;
}

.nav { padding: 6px 10px; flex: 1; }
.nav-section { font-size: 10.5px; letter-spacing: 0.08em; color: var(--text-faint);
  text-transform: uppercase; padding: 12px 8px 4px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-ctrl);
  color: var(--text-muted); cursor: pointer; font-size: 13.5px;
  position: relative; user-select: none;
}
.nav-item:hover { background: var(--neutral-subtle); }
.nav-item.active { background: var(--brand-subtle); color: var(--brand); font-weight: 600; }
.nav-item.disabled { opacity: 0.55; cursor: not-allowed; }
.nav-item .chip-ms {
  margin-left: auto; font-size: 10px; font-family: var(--mono);
  background: var(--neutral-subtle); color: var(--text-faint);
  padding: 1px 6px; border-radius: 10px; white-space: nowrap;
}
.nav-item .icon { width: 17px; text-align: center; opacity: 0.9; }
.nav-scope {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 26px; border-radius: var(--radius-ctrl);
  color: var(--text-faint); cursor: pointer; font-size: 12.5px;
}
.nav-scope:hover { background: var(--neutral-subtle); color: var(--text-muted); }
.nav-scope.active { color: var(--brand); font-weight: 600; }

.usercard {
  border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 600; font-size: 12px;
}
.usercard .who { line-height: 1.2; }
.usercard .uname { font-size: 13px; font-weight: 600; }
.usercard .urole { font-size: 11px; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 52px; min-height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
}
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: 13px; }
.crumbs .cur { color: var(--text); font-weight: 600; }
.crumbs .sep { opacity: 0.5; }
.ctx-badge {
  font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600;
  background: var(--neutral-subtle); color: var(--text-muted);
}
.topbar .spacer { flex: 1; }
.sse-dot { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--healthy); }
.dot.warn { background: var(--warning); }
.dot.down { background: var(--critical); }

.body { flex: 1; overflow-y: auto; padding: 22px; }

/* ---------- generic components ---------- */
h1.page { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-sub { color: var(--text-muted); margin: 0 0 18px; font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 14px; margin: 0 0 4px; }
.card .cap { color: var(--text-faint); font-size: 12px; margin: 0 0 12px; }
.card .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card .head .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 14px 16px;
}
.stat .lbl { font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.stat .num { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.stat.ok .num { color: var(--healthy); }
.stat.warn .num { color: var(--warning); }
.stat.bad .num { color: var(--critical); }
.stat.info .num { color: var(--info); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface);
}
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--brand-subtle); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  white-space: nowrap;
}
.badge.ok { background: var(--healthy-subtle); color: var(--healthy); }
.badge.warn { background: var(--warning-subtle); color: var(--warning); }
.badge.bad { background: var(--critical-subtle); color: var(--critical); }
.badge.info { background: var(--info-subtle); color: var(--info); }
.badge.neutral { background: var(--neutral-subtle); color: var(--neutral); }
.badge.outline-bad { background: transparent; color: var(--critical); border: 1px solid var(--critical); }
.badge.outline-warn { background: transparent; color: var(--warning); border: 1px solid var(--warning); }

.chip {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  background: var(--neutral-subtle); color: var(--text-muted);
  padding: 1px 7px; border-radius: 5px; margin: 1px 3px 1px 0;
}
.chip.brand { background: var(--brand-subtle); color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius-ctrl);
  padding: 7px 13px; font-size: 13px; cursor: pointer; font-family: var(--sans);
}
.btn:hover { background: var(--neutral-subtle); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--critical); border-color: #fecaca; }
.btn.danger:hover { background: var(--critical-subtle); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--neutral-subtle); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input, select, textarea {
  font-family: var(--sans); font-size: 13px; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-ctrl);
  padding: 7px 10px; background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-subtle); }
input.mono, textarea.mono { font-family: var(--mono); font-size: 12.5px; }
label.fld { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
label.fld > span { display: block; margin-bottom: 5px; color: var(--text-faint); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
label.fld input, label.fld select, label.fld textarea { width: 100%; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-faint);
}
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: 0.5; }

.err-box {
  background: var(--critical-subtle); border: 1px solid #fecaca; color: #7f1d1d;
  border-radius: var(--radius-ctrl); padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
}
.info-box {
  background: var(--info-subtle); border: 1px solid #bfdbfe; color: #1e40af;
  border-radius: var(--radius-ctrl); padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
}
.warn-box {
  background: var(--warning-subtle); border: 1px solid #fde68a; color: #92400e;
  border-radius: var(--radius-ctrl); padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
}

/* not-available placeholder (ui-guidelines §4) */
.notavail {
  border: 1px dashed var(--border); border-radius: var(--radius-card);
  padding: 34px; text-align: center; color: var(--text-muted);
  background: var(--surface);
}
.notavail .tag {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  background: var(--neutral-subtle); color: var(--text-muted);
  padding: 3px 10px; border-radius: 20px; margin-bottom: 10px;
}
.notavail h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.notavail p { margin: 0 auto; max-width: 460px; font-size: 13px; }

/* terminal / stream console */
.console {
  background: #0f172a; color: #e2e8f0; border-radius: var(--radius-card);
  padding: 14px 16px; font-family: var(--mono); font-size: 12.5px;
  max-height: 420px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.console .hd { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: #94a3b8; font-size: 12px; }
.console .lights { display: flex; gap: 6px; }
.console .lights i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.console .lights i:nth-child(1) { background: #ef4444; }
.console .lights i:nth-child(2) { background: #f59e0b; }
.console .lights i:nth-child(3) { background: #22c55e; }
.console .line-err { color: #fca5a5; }
.console .line-tag { color: #60a5fa; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  padding: 9px 14px; font-size: 13px; color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; user-select: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tab.disabled { opacity: 0.5; cursor: not-allowed; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; }
.kv .mono { font-size: 12px; }

/* login */
.login-wrap { height: 100vh; display: grid; place-items: center; background: var(--surface-app); }
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 30px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card .sub { color: var(--text-faint); font-size: 13px; margin: 0 0 20px; }

.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--brand-subtle);
  border-top-color: var(--brand); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spin { animation: none; }
}

/* Live PTY terminal (xterm.js host). */
.term-host { height: 480px; background: #0f172a; border-radius: var(--radius-ctrl); padding: 6px; overflow: hidden; }
.term-host .xterm, .term-host .xterm-viewport, .term-host .xterm-screen { font-family: var(--mono); }

/* Global toast notifications (top-right, auto-dismiss). */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--neutral);
  border-radius: var(--radius-ctrl);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  padding: 10px 12px; font-size: 13px; color: var(--text);
  animation: toast-in 0.18s ease-out;
}
.toast.ok { border-left-color: var(--healthy); }
.toast.err { border-left-color: var(--critical); }
.toast.info { border-left-color: var(--info); }
.toast-msg { flex: 1; word-break: break-word; }
.toast-x {
  border: 0; background: transparent; color: var(--text-faint);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.toast-x:hover { color: var(--text); }
@keyframes toast-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* Users page controls. */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .fld { min-width: 140px; }
.inline-sel {
  font-size: 12px; padding: 3px 6px; border: 1px solid var(--border);
  border-radius: var(--radius-ctrl); background: var(--surface); color: var(--text);
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* External-data status chip (Updates toolbar). */
.ext-status { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.ext-status.ext-err { color: var(--critical); }
.ext-status.ext-stale { color: var(--warning); }
