/* ============================================================
   Fit Notebook — app.css
   Layout shells: public pages, user app (sidebar + bottom nav),
   admin (environment strip, compact density), auth card, landing,
   /design style guide (DESIGN_SYSTEM §4).
   ============================================================ */

/* ---------- Public layout ---------- */
.public-shell { min-height: 100vh; display: flex; flex-direction: column; }
.site-header {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: var(--z-nav);
}
.site-header-inner {
  max-width: var(--content-max); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); padding: var(--space-3) var(--space-5);
  min-height: 60px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-display); font-weight: 800; font-size: var(--fs-lg);
  color: var(--text-primary); text-decoration: none; letter-spacing: -0.02em;
}
.wordmark .icon { color: var(--brand); width: 24px; height: 24px; }
.wordmark .wm-note { color: var(--brand); }
.site-main { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-10); }
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: var(--fs-xs);
  padding: var(--space-5);
  text-align: center;
}

/* ---------- Landing ---------- */
.hero { padding: var(--space-9) 0 var(--space-8); max-width: 640px; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--brand-strong);
  background: var(--brand-soft); border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3); margin-bottom: var(--space-4);
}
.hero h1 { font-size: var(--fs-display); font-weight: 800; letter-spacing: -0.03em; }
.hero .lede { font-size: var(--fs-lg); color: var(--text-secondary); max-width: 46ch; }
.hero-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-6); }
.feature-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: var(--space-8);
}
.feature-card .icon { width: 26px; height: 26px; color: var(--brand); margin-bottom: var(--space-3); }
.feature-card h3 { font-size: var(--fs-base); margin-bottom: var(--space-1); }
.feature-card p { font-size: var(--fs-sm); color: var(--text-secondary); margin: 0; }
.feature-card .badge { margin-bottom: var(--space-3); }

/* ---------- Landing: dashboard preview illustration (Checkpoint 11) ----------
   Built entirely from existing components (progress-ring, chart-stat) with
   sample numbers; aria-hidden in the view since it conveys nothing beyond
   what the surrounding copy already says. */
.hero-visual {
  max-width: 480px;
  margin: 0 0 var(--space-9);
}
.hero-visual-head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: var(--space-3); margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.hero-visual-dots { display: inline-flex; gap: var(--space-1); }
.hero-visual-dots i {
  width: 8px; height: 8px; border-radius: var(--radius-full);
  background: var(--border-strong); display: inline-block;
}
.hero-visual-ring { display: flex; align-items: center; gap: var(--space-4); }

/* ---------- Landing: how it works / domain features / trust ---------- */
.how-it-works, .feature-domains { padding: var(--space-8) 0; max-width: var(--content-max); }
.how-it-works h2, .feature-domains h2 { margin-bottom: var(--space-6); }
.trust-card { margin: var(--space-2) 0 var(--space-9); }
.trust-card-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); }
.trust-card-head .icon { color: var(--brand); }
.trust-card-head h2 { margin: 0; }

/* ---------- User app layout ---------- */
.app-shell { min-height: 100vh; }
.app-header {
  background: var(--nav-bg); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: var(--z-nav);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-2) var(--space-4);
  min-height: 56px;
}
.app-header .page-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-base); margin: 0; }
.app-main { padding: var(--space-5) var(--space-4) calc(var(--bottomnav-h) + var(--space-8)); max-width: var(--content-max); margin: 0 auto; width: 100%; }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--nav-bg); border-top: 1px solid var(--border);
  display: flex; z-index: var(--z-nav);
  padding-bottom: env(safe-area-inset-bottom);
  min-height: var(--bottomnav-h);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--bottomnav-h);
  color: var(--nav-text); text-decoration: none;
  font-size: 11px; font-weight: 600;
}
.bottom-nav a[aria-current="page"] { color: var(--nav-active-text); }
.bottom-nav a[aria-current="page"] .icon { color: var(--nav-active-text); }
.bottom-nav .nav-log {
  margin-top: -18px;
}
.bottom-nav .nav-log .log-fab {
  width: 52px; height: 52px; border-radius: var(--radius-full);
  background: var(--brand); color: var(--on-brand);
  display: grid; place-items: center;
  box-shadow: var(--shadow-2);
}
.bottom-nav .nav-log .icon { color: var(--on-brand); width: 26px; height: 26px; }

/* Sidebar (desktop) */
.sidebar { display: none; }
@media (min-width: 1024px) {
  .app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar {
    display: flex; flex-direction: column; gap: var(--space-2);
    background: var(--nav-bg); border-right: 1px solid var(--border);
    padding: var(--space-5) var(--space-3);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .bottom-nav { display: none; }
  .app-main { padding-bottom: var(--space-9); }
  .app-header { position: static; }
}
.sidebar .wordmark { padding: 0 var(--space-3) var(--space-4); }
.nav-group-label {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  padding: var(--space-4) var(--space-3) var(--space-1);
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--touch-target);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--nav-text); text-decoration: none;
  font-size: var(--fs-sm); font-weight: 600;
}
.nav-item:hover { background: var(--bg-inset); color: var(--text-primary); }
.nav-item[aria-current="page"] { background: var(--nav-active-bg); color: var(--nav-active-text); }

/* ---------- Admin layout ---------- */
.admin-strip {
  background: var(--brand); color: var(--on-brand);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center; padding: var(--space-1);
}

/* ---------- Auth layout ---------- */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center;
  padding: var(--space-5);
  background: linear-gradient(160deg, var(--brand-soft), var(--bg-page) 55%);
}
.auth-card { width: min(100%, 420px); }
.auth-card .wordmark { justify-content: center; display: flex; margin-bottom: var(--space-5); }
.auth-footer { text-align: center; color: var(--text-muted); font-size: var(--fs-xs); margin-top: var(--space-5); }

/* ---------- Error pages ---------- */
.error-page { text-align: center; padding: var(--space-11) var(--space-5); }
.error-code {
  font-family: var(--font-display); font-weight: 800;
  font-size: var(--fs-display); color: var(--brand);
  letter-spacing: -0.03em;
}
.error-page p { color: var(--text-secondary); max-width: 44ch; margin: 0 auto var(--space-6); }

/* ---------- Style guide (/design) ---------- */
.sg-section { margin-bottom: var(--space-9); }
.sg-section > h2 {
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--brand-soft);
  margin-bottom: var(--space-5);
}
.sg-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); }
.sg-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.sg-tokens { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.sg-token {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-xs); font-family: var(--font-display);
}
.sg-token .swatch { width: 28px; height: 28px; border-radius: var(--radius-md); flex: none; }
.sg-note { font-size: var(--fs-sm); color: var(--text-muted); }
.chart-demo { height: 260px; position: relative; }

/* ---------- Auth pages (Checkpoint 1B) ---------------------------------- */
.auth-links {
  margin-top: var(--space-5);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.auth-card .alert { margin-bottom: var(--space-4); }
.auth-card form + .auth-links { margin-top: var(--space-4); }
.hero-signin { margin-top: var(--space-4); font-size: var(--fs-sm); color: var(--text-secondary); }

/* Password reveal toggle, injected by app.js (no inline handlers under CSP). */
.field-with-reveal { position: relative; }
.field-with-reveal .input { padding-right: var(--space-9); }
.reveal-btn {
  position: absolute;
  right: var(--space-1);
  bottom: var(--space-1);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.reveal-btn:hover { color: var(--text-primary); }
.reveal-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.password-meter { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--text-muted); }
.password-meter[data-level="ok"] { color: var(--success); }

/* ===========================================================================
   Checkpoint 11B — dashboard layout grid and collapsible desktop sidebar
   ======================================================================== */

/* ---------- Dashboard page header ---------- */
.dash-header {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: var(--space-4);
  padding-bottom: var(--space-5); margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
}
.dash-header-titles { min-width: 0; }
.dash-greeting {
  margin: 0; font-family: var(--font-display); font-size: var(--fs-xl);
  line-height: var(--lh-heading);
  /* A long display name wraps rather than pushing the actions off-screen. */
  overflow-wrap: anywhere;
}
.dash-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-2); color: var(--text-secondary); font-size: var(--fs-sm);
}
.dash-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  background: var(--brand-soft); color: var(--brand-strong);
  font-size: var(--fs-xs); font-weight: 700;
}
.dash-chip .icon { width: 13px; height: 13px; }
.dash-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- The Today grid: 12 columns on desktop, deliberately uneven ---- */
.today-grid { display: grid; gap: var(--space-5); grid-template-columns: 1fr; }
.today-grid > .col-anchor,
.today-grid > .col-side { min-width: 0; }
.col-side { display: flex; flex-direction: column; gap: var(--space-5); }
@media (min-width: 768px) {
  .today-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .today-grid > .col-anchor { grid-column: 1 / -1; }
  .col-side {
    grid-column: 1 / -1;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
}
@media (min-width: 1200px) {
  .today-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .today-grid > .col-anchor { grid-column: span 7; }
  .col-side { grid-column: span 5; display: flex; flex-direction: column; }
}
/* A plain equal-width row for secondary content below the anchor area. */
.sub-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

/* ---------- Collapsible desktop sidebar ----------
   The collapsed flag lives on <html> so public/assets/js/sidebar-boot.js can
   apply the stored preference before the sidebar is parsed, avoiding a visible
   width jump. With JavaScript off the class is never set, so the sidebar stays
   expanded and completely usable — the no-JS fallback is the default state. */
:root { --sidebar-w-collapsed: 76px; }

.sidebar-head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-1) var(--space-3);
}
.sidebar-head .wordmark { padding: 0; flex: 1 1 auto; min-width: 0; }
.sidebar-toggle {
  flex: 0 0 auto; display: none; /* desktop-only control */
  align-items: center; justify-content: center;
  width: var(--touch-target); height: var(--touch-target);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-secondary); cursor: pointer;
}
.sidebar-toggle:hover { background: var(--bg-inset); color: var(--text-primary); }
.nav-group { display: flex; flex-direction: column; }
.nav-item { position: relative; }
.nav-item .icon { flex: 0 0 auto; }

@media (min-width: 1024px) {
  .sidebar-toggle { display: inline-flex; }
  html.sb-collapsed .app-shell { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  html.sb-collapsed .sidebar { padding-left: var(--space-2); padding-right: var(--space-2); }
  html.sb-collapsed .sidebar-head { flex-direction: column; padding-bottom: var(--space-2); }
  /* Only the mark survives collapse; the wordmark text is the span. */
  html.sb-collapsed .sidebar .wordmark span { display: none; }
  html.sb-collapsed .sidebar .wordmark { justify-content: center; flex: 0 0 auto; }
  /* Clipped, NOT display:none — the label must stay in the accessibility tree
     so each collapsed icon keeps its accessible name. */
  html.sb-collapsed .nav-label {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  html.sb-collapsed .nav-group-label {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  /* A rule replaces each group heading so the groups stay visually separated. */
  html.sb-collapsed .nav-group + .nav-group {
    border-top: 1px solid var(--border);
    margin-top: var(--space-2); padding-top: var(--space-2);
  }
  html.sb-collapsed .nav-item { justify-content: center; padding: 0; }
  /* Hover/focus tooltip, since the label is clipped while collapsed. */
  html.sb-collapsed .nav-item::after {
    content: attr(data-tip);
    position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%);
    padding: 4px var(--space-2); border-radius: var(--radius-sm);
    background: var(--bg-surface-raised); color: var(--text-primary);
    border: 1px solid var(--border); box-shadow: 0 6px 18px var(--shadow-color);
    font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
    opacity: 0; pointer-events: none; z-index: var(--z-dropdown);
    transition: opacity var(--dur-fast) var(--ease);
  }
  html.sb-collapsed .nav-item:hover::after,
  html.sb-collapsed .nav-item:focus-visible::after { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html.sb-collapsed .nav-item::after { transition: none; }
}

/* ===========================================================================
   Checkpoint 11C — mobile navigation drawer
   Reuses the SAME <aside class="sidebar"> markup the desktop uses, so the 28
   destinations and their active states exist in exactly one place.
   Opens two ways: `html.nav-open` (app.js, focus-trapped) or `.sidebar:target`
   (pure CSS, which is what makes it work with JavaScript disabled).
   ======================================================================== */

/* Desktop-only controls, hidden by default and revealed per breakpoint. */
.nav-toggle, .nav-close { display: none; }
.nav-scrim { display: none; }

@media (max-width: 1023.98px) {
  /* The hamburger. 44x44 minimum, sits left of the page title. */
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    width: var(--touch-target); height: var(--touch-target);
    margin-right: calc(var(--space-1) * -1);
    border-radius: var(--radius-md);
    color: var(--nav-text); text-decoration: none;
  }
  .nav-toggle:hover { background: var(--bg-inset); color: var(--text-primary); }

  /* The drawer. Off-canvas and NOT focusable until opened — visibility:hidden
     keeps its 28 links out of the tab order while closed, which a transform
     alone would not do. */
  .sidebar {
    display: flex; flex-direction: column; gap: var(--space-2);
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(86vw, 300px);
    padding: var(--space-4) var(--space-3);
    background: var(--nav-bg); border-right: 1px solid var(--border);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    z-index: var(--z-dialog);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--dur-base) var(--ease), visibility var(--dur-base) var(--ease);
  }
  .sidebar:target,
  html.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 0 0 40px var(--shadow-color);
  }

  /* Close control inside the drawer head. */
  .nav-close {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    width: var(--touch-target); height: var(--touch-target);
    margin-left: auto;
    border-radius: var(--radius-md);
    color: var(--nav-text); text-decoration: none;
  }
  .nav-close:hover { background: var(--bg-inset); color: var(--text-primary); }

  /* Scrim. Only interactive while the drawer is open. */
  .nav-scrim {
    position: fixed; inset: 0;
    background: var(--overlay);
    z-index: calc(var(--z-dialog) - 1);
    opacity: 0; pointer-events: none;
    transition: opacity var(--dur-base) var(--ease);
  }
  .sidebar:target ~ .nav-scrim,
  html.nav-open .nav-scrim {
    display: block; opacity: 1; pointer-events: auto;
  }

  /* The desktop collapse control has no meaning in a drawer. */
  .sidebar-toggle { display: none !important; }
  /* Nothing is ever collapsed on a phone, even if the stored preference says so. */
  html.sb-collapsed .sidebar .wordmark span { display: inline; }
  html.sb-collapsed .nav-label,
  html.sb-collapsed .nav-group-label {
    position: static; width: auto; height: auto;
    overflow: visible; clip-path: none; white-space: normal;
  }
  html.sb-collapsed .nav-item { justify-content: flex-start; padding: 0 var(--space-3); }
  html.sb-collapsed .nav-item::after { content: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-scrim { transition: none; }
}
