/* Savanna — the one hand-written stylesheet (WS-15 §4.6/§4.8, docs/BRAND.md).
   Written ONLY against tokens: colours, fonts, radius and shadow come from the theme file
   (theme-site.css | theme-spec.css) loaded before this one; the spacing scale is defined here.
   Mobile first: bottom tab bar under 768 px, left rail from 768 px. Tap targets >= 44 px. */

:root {
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --topbar-h: 3.5rem;
  --tabbar-h: 3.75rem;
  --rail-w: 15rem;
  --page-max: 72rem;
  --tap: 2.75rem;
}

/* --- reset ------------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; display: inline-block; vertical-align: middle; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.2; font-weight: 600; }
p { margin: 0 0 var(--space-3); }
.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--color-muted); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* --- layout ------------------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding: 0 var(--space-4);
  background: var(--gradient-brand);
  color: var(--color-primary-ink);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: inherit; min-height: var(--tap); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--color-surface); padding: 2px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.brand-sub { font-size: 0.625rem; letter-spacing: 0.2em; text-transform: uppercase; opacity: 0.8; }

.who { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.who-text { display: none; flex-direction: column; line-height: 1.15; min-width: 0; }
.who-name { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 0.75rem; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 2rem; height: 2rem; border-radius: 50%; border: 2px solid var(--color-primary-ink); }
.logout { margin: 0; }

/* view-as: sticky under the top bar, warn background, tokens only */
.acting-banner {
  position: sticky;
  top: var(--topbar-h);
  z-index: 19;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-warn);
  color: var(--color-ink);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
}
.acting-text { min-width: 0; }
.acting-stop { margin: 0; flex: 0 0 auto; }
.acting-stop .btn { background: var(--color-surface); }

/* top-bar mode toggle (sun / moon cycles system → light → dark) */
.mode-toggle { margin: 0; }
.btn-icon-only { min-width: var(--tap); padding-left: var(--space-2); padding-right: var(--space-2); }

/* screen help (WS-19 package 56): the ⓘ and its popover, anchored under the top bar */
.help { position: relative; }
.help-button[aria-expanded="true"] { background: var(--color-surface); color: var(--color-ink); opacity: 1; }
.help-popover {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 30;
  width: 20rem;
  max-width: calc(100vw - 2 * var(--space-4));
  max-height: calc(100vh - var(--topbar-h) - 2 * var(--space-4));
  overflow: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
}
.help-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.help-title { font-family: var(--font-display); font-size: 1rem; }
.help-body h2 { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-muted); margin: var(--space-3) 0 var(--space-1); }
.help-body h2:first-child { margin-top: 0; }
.help-body p, .help-body ul { margin: 0 0 var(--space-2); }
.help-body ul { padding-left: 1.1rem; }
.help-body li { margin-bottom: var(--space-1); }
.help-body a { color: var(--color-accent); }
.help-foot { display: flex; gap: var(--space-2); margin-top: var(--space-3); }

/* /preferences */
.prefs { display: grid; gap: var(--space-4); }
.prefs-form { display: grid; gap: var(--space-4); }
.prefs-group { border: 0; padding: 0; margin: 0; display: grid; gap: var(--space-2); }
.prefs-group legend { font-weight: 600; margin-bottom: var(--space-2); }
.prefs-choice { display: flex; align-items: center; gap: var(--space-3); min-height: var(--tap); cursor: pointer; }
.prefs-choice input { width: 1.25rem; height: 1.25rem; accent-color: var(--color-primary); }
.prefs-note { margin: 0; font-size: 0.875rem; }
.prefs-actions { display: flex; justify-content: flex-end; }
.prefs-connections { display: grid; gap: var(--space-3); }
.prefs-connections > h2 { margin: 0; }

/* /theme-preview: per-pane light / dark switch and the two "use" forms (the pane layout
   itself is desk.css) */
.theme-pane-head { flex-wrap: wrap; }
.theme-pane-mode { display: inline-flex; gap: var(--space-1); }
.theme-pane-mode .btn { background: var(--color-surface); color: var(--color-ink); opacity: 0.85; }
.theme-pane-mode .btn[aria-pressed="true"] { opacity: 1; box-shadow: inset 0 0 0 2px var(--color-primary); }
.theme-pane-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.theme-pane-actions form { margin: 0; }

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--tabbar-h) + var(--space-5) + env(safe-area-inset-bottom));
}
body.no-nav .page { padding-bottom: var(--space-5); }

/* --- nav: bottom tab bar (phone) --------------------------------------------------------- */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--gradient-brand);
  color: var(--color-primary-ink);
  box-shadow: var(--shadow);
}
.nav-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap);
  padding: var(--space-1) var(--space-2);
  color: inherit;
  opacity: 0.78;
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.nav-item::-webkit-details-marker { display: none; }
.nav-item:hover { text-decoration: none; opacity: 1; }
.nav-item[aria-current="page"] { opacity: 1; }
.nav-item[aria-current="page"] .nav-icon { color: var(--color-primary); }
.nav-icon { width: 1.5rem; height: 1.5rem; }
.nav-more { flex: 1 1 0; display: flex; flex-direction: column; position: relative; }
.nav-more > summary { height: 100%; }
.nav-menu {
  position: absolute;
  right: var(--space-2);
  bottom: calc(100% + var(--space-2));
  min-width: 11rem;
  padding: var(--space-2);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
}
.nav-menu .nav-item { flex-direction: row; justify-content: flex-start; gap: var(--space-3); font-size: 0.9375rem; opacity: 1; border-radius: calc(var(--radius) / 2); }
.nav-menu .nav-item:hover { background: var(--color-accent-soft); }
.nav-menu .nav-item[aria-current="page"] { color: var(--color-accent); }

/* --- components -------------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--color-surface-2);
  color: var(--color-ink);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--color-primary); color: var(--color-primary-ink); }
.btn-ghost { background: transparent; color: inherit; border-color: currentColor; opacity: 0.9; }
.btn-sm { min-height: 2.25rem; padding: var(--space-1) var(--space-3); font-size: 0.875rem; }
.btn-block { width: 100%; }
.btn-icon { width: 1.25rem; height: 1.25rem; }
.chip {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5rem;
  background: var(--color-surface-2);
  color: var(--color-ink);
}
.chip-work, .chip-ok { background: var(--color-primary); color: var(--color-primary-ink); }
.chip-ask, .chip-warn { background: var(--color-warn); color: var(--color-ink); }
.chip-fail { background: var(--color-fail); color: var(--color-primary-ink); }
.chip-skip, .chip-unknown { background: var(--color-border); color: var(--color-muted); }

/* welcome (home until the desk pages land) */
.welcome { max-width: 40rem; margin: var(--space-4) auto; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); margin-top: var(--space-4); }
.tile {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 600;
}
.tile:hover { text-decoration: none; filter: brightness(0.97); }
.tile-icon { width: 1.25rem; height: 1.25rem; }

/* login / denied */
.login { display: flex; align-items: center; justify-content: center; min-height: calc(100dvh - var(--topbar-h) - var(--space-6)); }
.login-card { width: 100%; max-width: 22rem; text-align: center; padding: var(--space-6) var(--space-5); }
.login-mark { width: 4.5rem; height: 4.5rem; border-radius: 50%; margin-bottom: var(--space-3); }
.login-title { font-size: 2rem; margin-bottom: var(--space-1); }
.login-sub { color: var(--color-muted); letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.6875rem; margin-bottom: var(--space-5); }
.login-note { font-size: 0.8125rem; margin: var(--space-4) 0 0; }
.denied-reason { margin: var(--space-3) 0 var(--space-5); }

/* toasts */
.toasts {
  position: fixed;
  left: var(--space-3);
  right: var(--space-3);
  bottom: calc(var(--tabbar-h) + var(--space-3) + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
body.no-nav .toasts { bottom: var(--space-3); }
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border-left: 4px solid var(--color-primary);
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 160ms ease-out;
}
.toast-error { border-left-color: var(--color-fail); }
.toast-warn { border-left-color: var(--color-warn); }
.toast-ok { border-left-color: var(--color-ok); }
.toast-close { border: 0; background: transparent; color: var(--color-muted); min-width: var(--tap); min-height: var(--tap); cursor: pointer; font-size: 1.25rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- desktop: left rail ------------------------------------------------------------------ */

@media (min-width: 768px) {
  .who-text { display: flex; }
  .nav {
    top: var(--topbar-h);
    right: auto;
    bottom: 0;
    width: var(--rail-w);
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--space-1);
    padding: var(--space-3);
    background: var(--color-surface);
    color: var(--color-ink);
    border-right: 1px solid var(--color-border);
    box-shadow: none;
  }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: calc(var(--radius) / 1.5);
    font-size: 0.9375rem;
    opacity: 1;
  }
  .nav-item:hover { background: var(--color-accent-soft); }
  .nav-item[aria-current="page"] { background: var(--color-accent-soft); color: var(--color-accent); }
  .nav-more { flex: 0 0 auto; }
  .nav-more > summary { height: auto; }
  .nav-menu { position: static; min-width: 0; padding: 0 0 0 var(--space-3); border: 0; box-shadow: none; background: transparent; }
  .nav-more[open] > summary { color: var(--color-accent); }
  body.has-nav .page { margin-left: var(--rail-w); padding: var(--space-5) var(--space-6); max-width: calc(var(--page-max) + var(--rail-w)); }
  .toasts { left: auto; right: var(--space-5); bottom: var(--space-5); width: 24rem; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

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