/* KibblePilot SPA styles (D-013 — hand-written, no build). Mobile-first; breakpoint
   ~768px (bottom tab bar on phone → side nav on desktop, NFR-19). Touch targets
   ≥44px. Color is never the only signal (icons + text). Light/dark via color-scheme. */

:root {
  /* Slate + indigo (G5 review) — neutral slate surfaces, one indigo accent. */
  --accent: #4f6bed;
  --accent-dk: #3f57d6;
  --header: #20262e; /* slate header bar */
  --header-text: #eef1f5;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6675;
  --border: #dce1e8;
  --ok: #2d8a4f;
  --busy: #c98a18;
  --warn: #c0392b;
  --warn-bg: #fdecea;
  --lockout-bg: #fff4e5;
  --lockout-border: #e9a23b;
  --radius: 12px;
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --header: #161c24;
    --bg: #161b22;
    --surface: #1d2530;
    --text: #e7edf3;
    --muted: #9aa7b6;
    --border: #2c3645;
    --accent: #6b83f0;
    --accent-dk: #5972e6;
    --warn-bg: #3a221f;
    --lockout-bg: #3a2c13;
  }
}

* { box-sizing: border-box; }
/* The HTML `hidden` attribute must always win — otherwise a component rule like
   `.banner { display: flex }` overrides the UA `[hidden]{display:none}` and elements
   toggled via `.hidden` (lockout/offline banners, account menu) never actually hide. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
h1, h2 { margin: 0 0 0.5rem; }
.page-title { font-size: 1.4rem; margin: 0.25rem 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.big { font-size: 1.6rem; font-weight: 600; margin: 0.25rem 0; }
.spacer { flex: 1; }
.boot, .loading { padding: 2rem; text-align: center; color: var(--muted); }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff;
  padding: 0.5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

/* --- buttons --- */
.btn {
  min-height: var(--tap); padding: 0 1rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 10px;
  font-size: 1rem; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 0.4rem;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dk); }
.btn-warn { background: var(--busy); color: #fff; border-color: var(--busy); }
.btn-danger { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 0.6rem; font-size: 0.85rem; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0 0.25rem; text-decoration: underline; font-size: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- header --- */
.app-header {
  display: flex; align-items: center; gap: 0.75rem;
  /* Safe-area insets (I-7): status-bar-style=black-translucent + viewport-fit=cover means
     the PWA content fills behind the iOS status bar, so the sticky header must pad past it
     (top inset) and past the notch/rounded corners in landscape (left/right insets). */
  padding: 0.5rem 1rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  padding-left: calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
  background: var(--header); color: var(--header-text); position: sticky; top: 0; z-index: 20;
}
.app-header .brand { font-weight: 700; font-size: 1.1rem; }
.online { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.online .dot { background: #6ee7a8; } /* green = online status (conventional), not brand */
.issue-badge {
  position: relative; background: rgba(255,255,255,0.15); border: none; color: #fff;
  min-height: 40px; padding: 0 0.7rem; border-radius: 20px; cursor: pointer; font-size: 1rem;
}
.issue-badge.has-issues { background: var(--busy); }
.issue-badge .count { font-weight: 700; margin-left: 0.25rem; }
.acct { position: relative; }
.acct-btn { background: rgba(255,255,255,0.15); border: none; color: #fff; min-height: 40px; padding: 0 0.7rem; border-radius: 8px; cursor: pointer; }
.acct-menu { position: absolute; right: 0; top: 110%; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; min-width: 160px; box-shadow: 0 6px 24px rgba(0,0,0,0.18); overflow: hidden; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 0.7rem 1rem; min-height: var(--tap); cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--bg); }

/* --- layout: body + nav --- */
.app-body { display: flex; min-height: calc(100vh - 56px); }
.side-nav { display: none; }
.app-main { flex: 1; padding: 1rem; padding-bottom: 5rem; max-width: 900px; margin: 0 auto; width: 100%; }
.app-main:focus { outline: none; }

.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--surface);
  border-top: 1px solid var(--border); z-index: 20;
  /* Safe-area insets (I-7): clear the iOS home indicator (bottom) and the landscape notch (sides). */
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.tab-link {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tap); padding: 0.4rem 0; text-decoration: none; color: var(--muted);
  font-size: 0.7rem;
}
.tab-link.active { color: var(--accent); }
.tab-link .nav-icon { font-size: 1.2rem; }

@media (min-width: 768px) {
  .tab-bar { display: none; }
  .side-nav { display: flex; flex-direction: column; gap: 0.25rem; width: 210px; padding: 1rem 0.5rem; border-right: 1px solid var(--border); }
  .nav-link { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; border-radius: 8px; text-decoration: none; color: var(--text); min-height: var(--tap); }
  .nav-link:hover { background: var(--bg); }
  .nav-link.active { background: var(--accent); color: #fff; }
  .app-main { padding: 1.5rem; padding-bottom: 1.5rem; }
}

/* --- cards + grid --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card-title { font-size: 1.05rem; }
.dash-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .dash-grid { grid-template-columns: 1fr 1fr; } }
.dash-grid .card { margin-bottom: 0; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }

/* --- status / chips / dots --- */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot-ok { background: var(--ok); }
.dot-busy { background: var(--busy); }
.dot-warn { background: var(--warn); }
.status-line { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; margin: 0.3rem 0; }
.health-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem; border-radius: 16px; background: var(--bg); font-size: 0.8rem; border: 1px solid var(--border); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.8rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* --- stepper --- */
.stepper { display: inline-flex; align-items: center; gap: 0.5rem; }
.stepper-btn { width: var(--tap); height: var(--tap); border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: 1.4rem; cursor: pointer; }
.stepper-btn:disabled { opacity: 0.4; }
.stepper-value { min-width: 3ch; text-align: center; font-size: 1.3rem; font-weight: 600; }

/* --- forms --- */
label { display: block; }
.cfg-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0; flex-wrap: wrap; }
.cfg-row.inline { justify-content: flex-start; }
input, select { font: inherit; padding: 0.5rem 0.6rem; min-height: var(--tap); border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
input[type="checkbox"] { min-height: auto; width: 22px; height: 22px; }
label.inline { display: inline-flex; align-items: center; gap: 0.5rem; }
.form-error { color: var(--warn); min-height: 1.2em; }
.caution { background: var(--warn-bg); padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.85rem; }

/* --- login --- */
.login-wrap, .login-host { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.4rem; }
.login-form .brand { text-align: center; color: var(--accent); }
.login-form input { width: 100%; }

/* --- banners --- */
.banner { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 0.8rem; flex-wrap: wrap; }
.banner-error { background: var(--warn-bg); color: var(--warn); }
.banner-lockout { background: var(--lockout-bg); border: 1px solid var(--lockout-border); }
.banner-lockout.sticky { border-radius: 0; margin: 0; justify-content: space-between; }
.banner .link { color: inherit; }

/* --- tables --- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.data-table th { color: var(--muted); font-weight: 600; }
.ev-row { cursor: pointer; }
.ev-row:hover { background: var(--bg); }
.ev-detail pre { margin: 0; padding: 0.5rem; background: var(--bg); border-radius: 6px; overflow-x: auto; font-size: 0.8rem; }
.tag { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 12px; background: var(--bg); font-size: 0.78rem; border: 1px solid var(--border); }
.sev-error, .sev-critical { color: var(--warn); border-color: var(--warn); }
.outcome-cleared { color: var(--ok); border-color: var(--ok); }
.outcome-not_cleared { color: var(--warn); border-color: var(--warn); }
.pager { display: flex; align-items: center; gap: 0.75rem; justify-content: center; margin-top: 0.8rem; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.8rem; align-items: center; }
.chip-label { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 0.2rem 0.6rem; }

/* --- schedules --- */
.tabs { display: flex; gap: 0.25rem; overflow-x: auto; margin-bottom: 0.8rem; }
.tab { min-height: var(--tap); padding: 0 0.8rem; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; cursor: pointer; color: var(--text); }
.tab-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.sched-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.sched-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 0.5rem; flex-wrap: wrap; }
.sched-row.disabled { opacity: 0.6; }
.sched-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.toggle { min-height: 36px; padding: 0 0.7rem; border-radius: 16px; border: 1px solid var(--border); cursor: pointer; background: var(--bg); }
.toggle.on { background: var(--ok); color: #fff; border-color: var(--ok); }
.sched-editor { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.8rem; border: 1px dashed var(--accent); border-radius: 8px; margin-bottom: 0.5rem; }
.empty { color: var(--muted); padding: 1rem; text-align: center; }

/* --- issues --- */
.issues-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.7rem; }
.issue { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.7rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 0.5rem; }
.issue-body { flex: 1; }
.issue .dot { margin-top: 0.4rem; }

/* --- clog history --- */
.clog-summary { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1.2rem; text-align: center; min-width: 90px; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-ok .stat-value { color: var(--ok); }
.stat-bad .stat-value { color: var(--warn); }

/* --- calibration --- */
.profile-list, .session-list { list-style: none; margin: 0 0 0.8rem; padding: 0; }
.profile-list li, .session-list li { display: flex; align-items: center; gap: 0.6rem; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.profile-list li.active { font-weight: 600; }
.calib-grid { display: grid; gap: 0.7rem; }
.calib-grid label { display: flex; flex-direction: column; gap: 0.3rem; }

/* --- feed result --- */
.feed-result { margin-top: 0.8rem; min-height: 2rem; }
.outcome { padding: 0.6rem; border-radius: 8px; background: var(--bg); }
.outcome-completed strong { color: var(--ok); }
.outcome-aborted strong, .outcome-failed strong { color: var(--warn); }

/* --- dialog / overlay --- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.dialog { background: var(--surface); border-radius: var(--radius); padding: 1.2rem; max-width: 420px; width: 100%; }
.dialog-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; }

/* --- toasts --- */
.toast-host { position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 60; pointer-events: none; width: max-content; max-width: 90vw; }
@media (min-width: 768px) { .toast-host { bottom: 1.5rem; } }
.toast { background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--warn); color: #fff; }
.toast-success { background: var(--ok); color: #fff; }
