/*
  Closure design tokens, phone shell, and shared components.
  Values come from ui-prototypes/DESIGN.md. Change the doc first, then this file.

  Pages that use this file keep <meta name="theme-color" content="#f3efe8">.
  A meta tag cannot read a CSS variable, so that value must match --canvas.

  This file holds only what more than one screen uses: utilities, the header,
  the scroll area, buttons, inset groups, and the overlay stack. A feature's
  own layout stays on its page:
  - Case list: org filter, title row, walnut bands, case rows, stacked views.
  - Case: tabs, case head and faces, brief, timeline, dock and composer,
    mentions, summary article, and sheet form controls (.field, .switch,
    .choices, .ghost).
  Two names stay page-local on purpose: .field is a labeled input on the case,
  and .who is a speaker name in a conversation block. Read-only rows are
  .inset__row and the profile header is .sheet__identity.
*/

:root {
  /* Foundation */
  --canvas: #f3efe8;
  --surface: #fffcf9;
  --field: #ffffff;
  --light-oat: #f7f3ec;
  --band: #322c28;
  --you: #322c28;
  --logo: #3d2416;
  --line: #e4dcd0;
  --line-strong: #d3c9ba;
  --pressed-strong: #e9e2d8;
  --disabled: #cfc6ba;
  --bezel: #221f1c;

  /* Text */
  --ink: #1c1916;
  --muted: #6b645c;
  --faint: #736b62;

  /* Action and state */
  --accent: #14574a;
  --accent-tint: #e7f3ef;
  --urgent: #8c3424;
  --working: #c4841a;
  --working-ink: #6e4a12;
  --working-tint: #f8efd8;
  --done: #0e7a45;
  --discussion-ink: #5c564c;
  --discussion-tint: #ece6dd;
  --discussion-head: #f1ece5;

  /* Data ramp, low to best */
  --ramp-low: #f8efd8;
  --ramp-mid: #e7f0d8;
  --ramp-high: #d5eddf;
  --ramp-best: #b7e0c8;

  /* People. The app assigns slots per screen; never use them for interface meaning. */
  --person-1: #3d5a66;
  --person-2: #243e68;
  --person-3: #5c3d6e;
  --person-4: #743857;
  --person-5: #3a3d75;
  --person-6: #4a515c;

  /* Type */
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;

  /* Depth */
  --shadow: 0 1px 2px rgba(28, 25, 22, 0.05);

  /* Corners */
  --radius-tag: 6px;
  --radius-icon-tile: 8px;
  --radius-row: 10px;
  --radius-field: 12px;
  --radius-button: 14px;
  --radius-panel: 16px;
  --radius-card: 18px;
  --radius-sheet: 20px;
  --radius-pill: 999px;

  /* Spacing */
  --gutter: 16px;
  --card-inset: 14px;
  --section-gap: 18px;
  --touch-min: 44px;
  --button-height: 48px;

  /* Safe areas */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* Reset */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
p { margin: 0; }
button, a, input, textarea, select { font: inherit; color: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Phone frame */

.stage { min-height: 100%; }
.stage-note { display: none; }

.phone {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
  position: relative;
  overflow: hidden;
}

/* Utilities */

.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;
}
.icon { width: 22px; height: 22px; display: block; }
.icon--sm { width: 16px; height: 16px; }

/* Header: back control, centered logo, your avatar. A second row may sit inside it. */

header.top {
  flex: none;
  padding: max(6px, var(--safe-t)) var(--gutter) 0;
  background: color-mix(in srgb, var(--canvas) 94%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  min-height: var(--touch-min);
}
.nav-leading { justify-self: start; min-width: 0; }
.nav-trailing { justify-self: end; }
.nav-logo { line-height: 0; }
.nav-logo img { height: 32px; width: auto; display: block; }
.nav-you {
  width: 36px;
  height: 36px;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 50%;
}
.nav-av {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 680;
  background: var(--logo);
  box-shadow: 0 0 0 2px var(--canvas), 0 0 0 3.5px var(--logo);
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: -4px;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 6px 8px 6px 0;
  font-size: 16px;
  font-weight: 560;
}
.back[hidden] { display: none !important; }

/* Page title, the same on every screen */

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 680;
}

/* Content area. Only this region scrolls; it stops while a sheet is open. */

.scroll {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
}
.scroll--page { padding-bottom: max(28px, var(--safe-b)); }
.scroll--dock { padding-bottom: 8px; }
.phone.sheet-open .scroll { overflow: hidden; }

/* Actions. A secondary sits above the primary when both appear. */

.button {
  width: 100%;
  min-height: var(--button-height);
  border: 0;
  border-radius: var(--radius-button);
  font-size: 16px;
  font-weight: 700;
}
.button + .button { margin-top: 8px; }
.button--primary { background: var(--accent); color: var(--light-oat); }
.button--primary:disabled { background: var(--disabled); color: white; }
.button--secondary { background: var(--canvas); color: var(--ink); }
.button--secondary:active { background: var(--pressed-strong); }
.admin-link {
  display: block;
  width: 100%;
  margin: 14px 0 2px;
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.admin-link[hidden] { display: none !important; }

/* Inset groups: read-only label and value rows. Cream on the page, oat inside a sheet. */

.inset {
  background: var(--surface);
  border-radius: var(--radius-panel);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.inset--sheet {
  margin: 0 0 16px;
  background: var(--canvas);
  box-shadow: none;
}
.inset__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 12px var(--card-inset);
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.inset__row:first-child { border-top: 0; }
.inset__row > span:first-child { color: var(--muted); }
.inset__row > b { font-weight: 650; text-align: right; }

/* Overlays: scrim, bottom sheet, and toast, all inside the phone frame */

.scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 40%, transparent);
  z-index: 20;
}
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  background: var(--surface);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 8px var(--gutter) max(18px, var(--safe-b));
  transform: translateY(105%);
  transition: transform 0.28s ease;
  max-height: 88%;
  overflow: auto;
}
.phone.sheet-open .sheet { transform: translateY(0); }
.sheet__grab {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  margin: 4px auto 12px;
}
.sheet__title {
  margin: 0 0 6px;
  font-size: 20px;
  letter-spacing: -0.02em;
  font-weight: 680;
}
.sheet__hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}
.sheet__identity {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0 0 16px;
}
.sheet__identity .sheet__title { margin: 0; }
.sheet__email {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.3;
}
.toast {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  top: max(12px, var(--safe-t));
  z-index: 30;
  background: var(--ink);
  color: var(--light-oat);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.scrim[hidden], .sheet[hidden], .toast[hidden] { display: none !important; }

/* Motion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Review frame for wide screens. A presentation frame, not a desktop layout. */

@media (min-width: 840px) {
  body { background: var(--disabled); }
  .stage {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px 24px 28px;
  }
  .phone {
    width: 390px;
    height: min(844px, calc(100dvh - 96px));
    border-radius: 32px;
    box-shadow: 0 0 0 10px var(--bezel), 0 28px 70px rgba(34, 31, 28, 0.28);
  }
  .stage-note {
    display: block;
    max-width: 390px;
    margin: 0;
    text-align: center;
    color: var(--ink);
    font-size: 13px;
    line-height: 1.4;
  }
}
