/* KSC Fleet — internal operator PWA.
   Dark theme matched to the client portal; accent #0ea5e9.
   Warning/error tokens per web-app/CLAUDE.md (#fdcb6e / #e17055). Mobile-first. */

:root {
  --bg: #0d0d0d;
  --bg-secondary: #1a1a1a;   /* cards */
  --surface: #262626;        /* inputs, raised */
  --surface-2: #202020;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --accent-glow: rgba(14,165,233,0.14);
  --text-primary: #e8e8e8;
  --text-secondary: #999999;
  --text-muted: #666666;
  --border: #2a2a2a;
  --border-focus: #0ea5e9;
  --success: #22c55e;
  --warning: #fdcb6e;
  --error: #e17055;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.65);
  --t: 0.15s ease;
  --appbar-h: 56px;
  --maxw: 760px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
img { display: block; max-width: 100%; }

/* ── App bar ─────────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: calc(var(--appbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  padding-right: 12px;
  background: rgba(13,13,13,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar-back {
  background: none; border: none; color: var(--text-primary);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 6px 8px;
  border-radius: var(--radius);
}
.appbar-back:hover { background: var(--surface); }
.appbar-brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.appbar-logo { height: 26px; width: 26px; }
.appbar-title {
  font-size: 1.05rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.appbar-actions { display: flex; gap: 2px; }
.iconbtn {
  background: none; border: none; color: var(--text-secondary);
  font-size: 1.2rem; line-height: 1; cursor: pointer;
  width: 38px; height: 38px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:hover { background: var(--surface); color: var(--text-primary); }
.iconbtn.spin { animation: spin 0.8s linear infinite; }

/* ── Layout ──────────────────────────────────────────── */
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}
.section { margin-bottom: 22px; }
.section-title {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.muted { color: var(--text-secondary); }
.dim { color: var(--text-muted); }
.tiny { font-size: 0.75rem; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.card.attention { border-color: rgba(225,112,85,0.5); }
.card-link { cursor: pointer; transition: border-color var(--t), transform var(--t); }
.card-link:active { transform: scale(0.995); }
.card-link:hover { border-color: var(--accent); }

/* ── Site cards ──────────────────────────────────────── */
.site-card { display: flex; flex-direction: column; gap: 12px; }
.site-head { display: flex; align-items: center; gap: 12px; }
.site-logo {
  width: 44px; height: 44px; border-radius: var(--radius);
  object-fit: contain; background: var(--surface); padding: 4px; flex: none;
}
.site-logo-fallback {
  width: 44px; height: 44px; border-radius: var(--radius); flex: none;
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 700; font-size: 1.1rem;
}
.site-name { font-weight: 600; font-size: 1rem; }
.site-client { font-size: 0.8rem; color: var(--text-secondary); }
.site-stats { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Stat chips ──────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 0.78rem;
  color: var(--text-secondary); white-space: nowrap;
}
.chip b { color: var(--text-primary); font-weight: 600; }
.chip.ok { color: var(--success); border-color: rgba(34,197,94,0.3); }
.chip.warn { color: var(--warning); border-color: rgba(253,203,110,0.35); }
.chip.err { color: var(--error); border-color: rgba(225,112,85,0.4); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-muted); }
.dot.ok { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.6); }
.dot.warn { background: var(--warning); }
.dot.err { background: var(--error); box-shadow: 0 0 6px rgba(225,112,85,0.6); }
.dot.sleep { background: var(--accent); }

.badge {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 2px 7px; border-radius: 999px;
}
.badge.err { background: rgba(225,112,85,0.16); color: var(--error); }
.badge.warn { background: rgba(253,203,110,0.16); color: var(--warning); }
.badge.ok { background: rgba(34,197,94,0.16); color: var(--success); }
.badge.info { background: var(--accent-glow); color: var(--accent); }
.badge.neutral { background: var(--surface); color: var(--text-secondary); }

/* ── Camera cards ────────────────────────────────────── */
.cam-card { display: flex; flex-direction: column; gap: 10px; }
.cam-head { display: flex; align-items: flex-start; gap: 10px; }
.cam-name { font-weight: 600; }
.cam-id { font-size: 0.72rem; color: var(--text-muted); }
.kv-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
  font-size: 0.8rem;
}
.kv { display: flex; flex-direction: column; gap: 1px; }
.kv .k { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
.kv .v { color: var(--text-primary); }

/* ── Battery gauge ───────────────────────────────────── */
.battery { display: inline-flex; align-items: center; gap: 6px; }
.battery-bar { width: 40px; height: 12px; border: 1px solid var(--border); border-radius: 3px; position: relative; overflow: hidden; background: var(--surface); }
.battery-bar > span { position: absolute; inset: 1px; width: 0; border-radius: 2px; background: var(--success); transition: width var(--t); }
.battery-bar.warn > span { background: var(--warning); }
.battery-bar.err > span { background: var(--error); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-size: 0.875rem; font-weight: 600;
  padding: 10px 14px; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: background var(--t), border-color var(--t), opacity var(--t);
  white-space: nowrap; user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #04222e; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); border-color: var(--accent); }
.btn-danger { background: transparent; color: var(--error); border-color: rgba(225,112,85,0.4); }
.btn-danger:hover:not(:disabled) { background: rgba(225,112,85,0.12); }
.btn-sm { padding: 7px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 0.9375rem; font-family: inherit;
  color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  outline: none; transition: border-color var(--t), box-shadow var(--t);
  color-scheme: dark;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow);
}
.field-hint { font-size: 0.72rem; color: var(--text-muted); }
.inline-fields { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-fields .form-group { flex: 1; min-width: 120px; }

/* ── Login ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 36px 30px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 20px;
}
.login-logo { display: flex; justify-content: center; }
.login-logo img { height: 56px; }
.login-card h1 { font-size: 1.2rem; font-weight: 600; text-align: center; }
.login-card .sub { font-size: 0.85rem; color: var(--text-secondary); text-align: center; margin-top: -10px; }

/* ── Messages ────────────────────────────────────────── */
.error-msg { color: var(--error); font-size: 0.85rem; }
.empty-state {
  text-align: center; color: var(--text-secondary); padding: 48px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius); font-size: 0.85rem;
  border: 1px solid var(--border); background: var(--surface-2);
}
.banner.warn { border-color: rgba(253,203,110,0.35); background: rgba(253,203,110,0.08); }
.banner.err { border-color: rgba(225,112,85,0.4); background: rgba(225,112,85,0.08); }
.banner.info { border-color: rgba(14,165,233,0.35); background: var(--accent-glow); }

/* ── Spinner ─────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts / activity ───────────────────────────────── */
.toasts {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.toast {
  pointer-events: auto; width: 100%; max-width: var(--maxw);
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; gap: 8px;
  animation: toast-in 0.18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.toast-head { display: flex; align-items: center; gap: 10px; }
.toast-title { font-size: 0.85rem; font-weight: 600; flex: 1; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.toast.ok { border-color: rgba(34,197,94,0.4); }
.toast.err { border-color: rgba(225,112,85,0.45); }
.toast-result { font-size: 0.78rem; display: flex; flex-direction: column; gap: 3px; }
.toast-result .cap { display: flex; align-items: center; gap: 6px; }

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,0.66);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  width: 100%; max-width: var(--maxw); max-height: 92vh; overflow-y: auto;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-lg);
  animation: sheet-in 0.2s ease;
}
@keyframes sheet-in { from { transform: translateY(20px); opacity: 0.6; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.frame {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  background: #000; min-height: 240px;
}
iframe.frame { height: 70vh; }
img.frame { object-fit: contain; }

/* ── Tabs / pills ────────────────────────────────────── */
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 0.8rem;
  color: var(--text-secondary); cursor: pointer;
}
.pill.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }

/* ── Wizard ──────────────────────────────────────────── */
.steps { display: flex; gap: 6px; margin-bottom: 18px; }
.step-dot { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.step-dot.done { background: var(--accent); }
.step-dot.active { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.step-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 14px; }
.cam-builder { border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }

/* ── Recent commands list ────────────────────────────── */
.cmd-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border); font-size: 0.8rem;
}
.cmd-row:last-child { border-bottom: none; }
.cmd-name { font-weight: 500; }

/* ── Divider ─────────────────────────────────────────── */
hr.sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Desktop niceties ────────────────────────────────── */
@media (min-width: 640px) {
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}
[hidden] { display: none !important; }
