/* Base layer: reset, element defaults, the per-screen content-width system,
   and the app shell (top bar / nav dropdown / back-bar / section tabs).

   No screen-specific styles here — legacy screens keep theirs in style.css
   until each is rebuilt (IMPLEMENTATION_PLAN.md Phase 3); rebuilt screens use
   components.css + screens.css. No inline styles anywhere in new markup:
   one-offs become utility classes at the bottom of this file. */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: var(--font-xl);
  font-weight: 600;
}

h2 {
  font-size: var(--font-lg);
  font-weight: 600;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 var(--space-5);
  font-size: var(--font-sm);
}

label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 500;
  margin-bottom: 0.375rem;
}

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: var(--font-md);
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: var(--space-4);
}

input[type="date"] {
  padding: 0.5rem 0.75rem;
  font-size: var(--font-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

/* Keyboard-only focus ring for everything else (buttons, links, tabs…).
   :focus-visible skips mouse/touch focus, so this never flashes on click;
   text inputs keep their own always-on :focus ring above. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  padding: 0.625rem 1rem;
  font-size: var(--font-md);
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: background 0.15s;
}

button:hover:not(:disabled) { background: var(--accent-hover); }
button:not(:disabled):active { filter: brightness(0.95); }
/* Disabled fades whatever variant it is instead of swapping to a solid grey. */
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
button.secondary:hover:not(:disabled) {
  background: var(--bg);
  color: var(--accent-hover);
}

/* Pressed feedback for transparent button-likes, where a brightness filter
   over nothing is invisible. */
.navlink:active,
.tab:active,
.menu-item:active,
button.cardrow:active { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-accent);
}

/* Buttons default to intrinsic width; these opt into the exceptions. */
.btn-block { width: 100%; }

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: var(--font-xs);
}

.btn-danger-text { color: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
}

.error {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  white-space: pre-line;
  margin-bottom: var(--space-4);
}

.toggle {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  text-align: center;
  font-size: var(--font-sm);
  color: var(--muted);
  justify-content: center;
}

.toggle a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.toggle a:hover { text-decoration: underline; }

.empty {
  color: var(--muted);
  font-size: var(--font-sm);
  padding: var(--space-4) 0;
  text-align: center;
}

.hidden { display: none !important; }

/* ---- Content width system ------------------------------------------------
   Every screen declares one of three widths; the router applies the class to
   <main> when the screen shows. Default (pre-JS) is narrow, matching the
   auth/loading cards. */

main {
  max-width: var(--w-narrow);
  margin: 5vh auto;
  padding: 0 var(--space-4);
}

main.w-narrow { max-width: var(--w-narrow); }
main.w-standard { max-width: var(--w-standard); }
main.w-wide { max-width: var(--w-wide); }
main.w-full { max-width: none; }

body.app main { margin: var(--space-5) auto; }

/* Full-width screens (rota builder) own the whole viewport: the grey page
   background goes white so the screen reads as one surface, not a card, and
   the main/section chain becomes a flex column filling the viewport so the
   builder's panel dividers (rb-body) can run to the bottom edge. Vertical
   margins go too — the day-tabs header divider attaches under the app chrome.
   Horizontal padding stays; the rb-* shell rows bleed past it with negative
   margins so non-shell children (banners, loading states) keep their gutter. */
body.screen-full { background: var(--surface); }

body.screen-full .content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

body.screen-full main {
  /* margin: 0 all round — not just margin-block. body.app main sets
     `margin: … auto`, and auto inline margins on a flex item disable
     cross-axis stretch, shrink-wrapping main to the canvas's intrinsic width
     and unbounding the timeline's internal scroll. */
  margin: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

body.screen-full main > section {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ---- App shell: top bar + back-bar + section tabs -------------------------
   The top bar and back-bar only appear once signed in (body.app). On the
   auth / org-setup / loading screens the layout falls back to the original
   single centered card. */

#topbar { display: none; }

body.app .layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Persistent horizontal top bar. The redesign moved nav off the left edge so
   the wide rota-builder canvas gets the ~220px the old sidebar cost it. Brand
   left, primary nav beside it, Setup + account flush right. */
body.app #topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
}

.topbar-brand {
  font-size: var(--font-lg);
  font-weight: 600;
  padding: 0 var(--space-2);
}

/* Wraps both nav groups. On desktop it's a flex row that eats the free space
   so the secondary nav + account sit flush right; on compact it detaches into
   a dropdown panel (see the media query below). */
.topbar-menu {
  display: flex;
  align-items: center;
  flex: 1;
  gap: var(--space-2);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

/* The lone ⚙ Setup item: pushed to the right end, grouped with the account
   button and away from the three primary destinations. */
.topbar-nav--secondary {
  margin-left: auto;
}

.navlink {
  background: transparent;
  color: var(--text);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.navlink:hover { background: var(--bg); }
.navlink.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.navlink--setup {
  font-size: var(--font-sm);
  color: var(--muted);
}
.navlink--setup-icon {
  font-size: var(--font-lg);
  line-height: 1;
}
/* Desktop: gear glyph only. The label reappears inside the compact nav
   dropdown, where every navlink is a full-width labelled row. */
.navlink--setup-label { display: none; }

.nav-badge {
  display: inline-block;
  margin-left: 0.375rem;
  padding: 0 0.4rem;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--font-xs);
  font-weight: 600;
  line-height: 1.4;
  vertical-align: middle;
}

/* Account button at the right end of the bar: just the avatar circle. Opens
   the account menu, where the org name and actions live. */
.topbar-account {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.topbar-account:hover { background: transparent; }

.topbar-account-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xs);
  font-weight: 700;
}

/* Back/breadcrumb bar — shown only on drill-down screens. Static so it scrolls
   with content beneath the sticky top bar rather than fighting it for top:0. */
#back-bar {
  position: static;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.bb-back {
  flex: 0 0 auto;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.6rem 0.25rem;
  font-size: var(--font-lg);
  line-height: 1;
}
.bb-back:hover { background: var(--bg); }
.bb-trail { font-size: var(--font-sm); color: var(--muted); }
.bb-parent { color: var(--accent); font-weight: 500; }

/* Section sub-tabs (e.g. Staff: People | Availability). Rendered by the
   router into #section-tabs, the first child of <main>, so they track the
   screen's content width. */
#section-tabs { margin-bottom: var(--space-3); }

/* Hamburger: hidden on desktop (nav is inline in the bar); shown on compact,
   where it toggles the nav dropdown. */
#nav-toggle {
  display: none;
  flex: 0 0 auto;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--font-lg);
  line-height: 1;
  padding: 0.2rem 0.6rem;
}
#nav-toggle:hover { background: var(--bg); }

/* Backdrop behind the compact nav dropdown; tap to dismiss. */
#nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-nav-overlay);
  background: var(--backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
body.nav-open #nav-overlay { opacity: 1; pointer-events: auto; }

@media (max-width: 720px) {
  body.app #topbar {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }

  #nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Both nav groups detach from the bar into a panel anchored beneath it
     (top bar is position:sticky, so it's the containing block). The panel
     stacks above the overlay because #topbar owns a higher stacking context. */
  .topbar-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.125rem;
    padding: var(--space-2);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  body.nav-open .topbar-menu { display: flex; }

  .topbar-nav {
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-nav--secondary {
    margin-left: 0;
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
  }

  .navlink {
    width: 100%;
    text-align: left;
  }

  /* In the dropdown every navlink is a full-width labelled row, so the gear
     gets its "Setup" label back. */
  .navlink--setup-label {
    display: inline;
    margin-left: 0.5rem;
  }

  /* The detached nav panel no longer reserves the account's slot, so pin it
     to the right end of the bar. */
  .topbar-account {
    margin-left: auto;
  }

  #nav-overlay { display: block; }

  /* Touch discipline: shell controls meet the 44px floor on compact. */
  .navlink,
  #nav-toggle,
  .bb-back,
  .topbar-account {
    min-height: var(--touch-target);
  }
  #nav-toggle,
  .bb-back {
    min-width: var(--touch-target);
  }
}

/* ---- Utilities -----------------------------------------------------------
   Shared one-offs that would otherwise become inline styles. */

.u-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8em;
}

/* In the document for assistive tech and the back-bar breadcrumb (which reads
   an element's text), but rendered nowhere. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Honour the OS-level reduce-motion setting. Durations go to ~0 rather than
   `none` so animationend/transitionend still fire if code ever listens. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
