/* Base Reset, Typography & Layout Shell */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-body-size);
  line-height: var(--t-body-line);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-body-size);
  line-height: var(--t-body-line);
  overflow-x: hidden;
}

h1, h2, h3, p, ul, ol, dl, dd {
  margin-top: 0;
}

h1 {
  font-size: var(--t-page-size);
  line-height: var(--t-page-line);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

h1.lead-title {
  font-size: var(--t-lead-size);
  line-height: var(--t-lead-line);
}

h2 {
  font-size: var(--t-title-size);
  line-height: var(--t-title-line);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

h3 {
  font-size: var(--t-body-size);
  line-height: var(--t-body-line);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

p {
  margin-bottom: var(--sp-4);
  max-width: 70ch;
}

a {
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--navy-press);
}

:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.meta-text {
  font-size: var(--t-meta-size);
  line-height: var(--t-meta-line);
  color: var(--ink-2);
}

.muted-text {
  font-size: var(--t-meta-size);
  line-height: var(--t-meta-line);
  color: var(--ink-3);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.side-rail {
  width: var(--w-rail);
  flex-shrink: 0;
  border-right: 1px solid var(--rule);
  padding: var(--sp-6) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  background: var(--page);
}

.brand-title {
  font-size: var(--t-body-size);
  line-height: var(--t-body-line);
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  padding: var(--sp-1) var(--sp-2);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.rail-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border-left: 2px solid transparent;
  color: var(--ink-2);
  text-decoration: none;
  font-size: var(--t-body-size);
  line-height: var(--t-body-line);
  font-weight: 400;
  border-radius: var(--r-ctl);
  transition: background-color var(--t-ctl) ease, color var(--t-ctl) ease;
}

.rail-link:hover {
  background: var(--wash);
  color: var(--ink);
}

.rail-link.active {
  border-left-color: var(--navy);
  color: var(--ink);
  font-weight: 600;
  background: var(--navy-wash);
}

.rail-count {
  font-size: var(--t-meta-size);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.rail-footer {
  margin-top: auto;
  border-top: 1px solid var(--rule);
  padding-top: var(--sp-3);
}

.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--rule);
  min-height: 64px;
}

.top-bar-brand {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.account-menu-wrap {
  position: relative;
  margin-left: auto;
}

/* The Report button sits in the top bar just left of the account name. Together they push to
   the right end; when Report is not there the account name keeps its own auto margin above. */
.top-bar > #reportFab {
  margin-left: auto;
  flex: 0 0 auto;
}

.top-bar > #reportFab + .account-menu-wrap {
  margin-left: 0;
}

.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--sp-1));
  min-width: 200px;
  background: var(--page);
  border: 1px solid var(--rule);
  border-radius: var(--r-box);
  box-shadow: var(--shadow-sheet);
  padding: var(--sp-2);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.main-content {
  width: 100%;
  max-width: var(--w-list);
  padding: var(--sp-6) var(--sp-6) var(--sp-16);
}

.main-content.narrow {
  max-width: var(--w-form);
}

.auth-center-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.auth-box {
  width: 100%;
  max-width: 400px;
  text-align: left;
}

/* Onboarding Step Header */
.step-header {
  border-bottom: 1px solid var(--rule);
  background: var(--page);
}

.step-header-inner {
  max-width: var(--w-form);
  padding: var(--sp-4) var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.step-progress-track {
  width: 100%;
  height: 3px;
  background: var(--wash);
}

.step-progress-fill {
  height: 100%;
  background: var(--navy);
}

.step-progress-fill.p25 { width: 25%; }
.step-progress-fill.p50 { width: 50%; }
.step-progress-fill.p75 { width: 75%; }
.step-progress-fill.p100 { width: 100%; }

/* Two-column detail pattern */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--sp-8);
  align-items: start;
}

.detail-grid-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-8);
  align-items: start;
}

/* Phone bottom bar */
.bottom-bar {
  display: none;
}

@media (max-width: 899px) {
  .side-rail {
    display: none;
  }

  .top-bar {
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-2);
  }

  /* The brand, Report and the account name share a narrow bar: each gives way instead of
     wrapping or pushing the others off the edge. */
  .top-bar-brand,
  .top-bar #reportFab {
    flex-shrink: 0;
  }

  .account-menu-wrap {
    min-width: 0;
  }

  .account-menu-wrap > button {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-content {
    padding: var(--sp-4) var(--sp-4) var(--sp-16);
  }

  .step-header-inner {
    padding: var(--sp-3) var(--sp-4);
  }

  .detail-grid,
  .detail-grid-equal {
    grid-template-columns: 1fr;
    gap: var(--sp-6);
  }

  .bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--page);
    border-top: 1px solid var(--rule);
    z-index: 30;
  }

  .bottom-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-1);
    min-height: 48px;
    text-decoration: none;
    color: var(--ink-2);
    font-size: var(--t-meta-size);
    border-top: 2px solid transparent;
  }

  .bottom-link.active {
    color: var(--navy);
    font-weight: 600;
    border-top-color: var(--navy);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0ms !important;
  }
}
