/* ==========================================================================
   SF Care Schedule — design system
   Aesthetic: warm editorial almanac. Paper ground, letterpress hairlines,
   old-style serif for time, mono for numbers. The pastel coverage fills are
   inherited from the Google Doc and are load-bearing: Linda already reads
   them, so they are preserved rather than redesigned.
   ========================================================================== */

/* --- Type -----------------------------------------------------------------
   Fraunces   display, month names. Old-style, soft, human.
   Atkinson   UI and cell text. Designed by the Braille Institute for
              low-vision legibility, which is the actual requirement in a
              dense date grid read on a phone.
   JetBrains  day numbers, times, airport and flight codes. Tabular figures,
              and a departure-board register that fits the content.
   ------------------------------------------------------------------------ */

:root {
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Paper and ink */
  --paper: #faf7f0;
  --paper-raised: #fffdf8;
  --paper-sunk: #f2ede2;
  --ink: #221e1a;
  --ink-soft: #5b5349;
  --ink-faint: #918776;
  --rule: #ddd4c4;
  --rule-strong: #c4b8a2;

  /* Coverage fills — inherited verbatim from the doc. Do not retune. */
  --mark-fill: #fce5cd;
  --mark-accent: #c96a15;
  --linda-fill: #d9d2e9;
  --linda-accent: #6b3fa0;
  --ruhi-fill: #d0e0e3;
  --ruhi-accent: #37697a;
  --vahid-accent: #8b7fa8;

  /* States */
  --past-fill: #efefef;
  --pending: #b3261e;
  --temporary: #4a7c3f;
  --uncovered: #b3261e;

  /* Geometry */
  --hair: 1px;
  --radius: 3px;
  --gutter: clamp(0.75rem, 3vw, 1.75rem);

  --shadow-lift: 0 1px 2px rgb(34 30 26 / 0.06), 0 8px 24px -12px rgb(34 30 26 / 0.18);
  --shadow-sheet: 0 -2px 8px rgb(34 30 26 / 0.06), 0 -24px 64px -24px rgb(34 30 26 / 0.30);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* iOS PWA: keep the safe-area padding honest in standalone mode */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--paper);
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* Paper grain. Cheap, single inline SVG, no network request. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* --- Masthead ------------------------------------------------------------ */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem var(--gutter) 0.75rem;
  border-bottom: var(--hair) solid var(--rule);
}

.masthead__title {
  margin: 0;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-variation-settings: 'SOFT' 40, 'WONK' 1;
  font-weight: 600;
  font-size: clamp(1.05rem, 4vw, 1.4rem);
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.masthead__sub {
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* --- Month header -------------------------------------------------------- */

.monthbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1.25rem var(--gutter) 0.5rem;
}

.monthbar__label { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }

.monthbar h2 {
  margin: 0;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-variation-settings: 'SOFT' 40, 'WONK' 1;
  font-weight: 500;
  font-size: clamp(1.75rem, 8vw, 3rem);
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.monthbar .year {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.monthbar__nav { display: flex; gap: 0.25rem; flex-shrink: 0; }

.navbtn {
  appearance: none;
  border: var(--hair) solid var(--rule-strong);
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  width: 2.5rem; height: 2.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 120ms ease, border-color 120ms ease;
}
.navbtn:hover { background: var(--paper-sunk); border-color: var(--ink-faint); }
.navbtn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* --- Calendar grid ------------------------------------------------------- */

.grid-wrap { padding: 0 var(--gutter) 6rem; }

.weekhead, .grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekhead {
  border-bottom: var(--hair) solid var(--rule-strong);
  margin-bottom: -1px;
}

.weekhead span {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 0 0.4rem 0.25rem;
}

.grid { border-left: var(--hair) solid var(--rule); }

.cell {
  position: relative;
  min-height: 5.75rem;
  border-right: var(--hair) solid var(--rule);
  border-bottom: var(--hair) solid var(--rule);
  padding: 0.3rem 0.35rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: transparent;
  /* Staggered reveal, set per-cell via --i */
  animation: cell-in 380ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
  animation-delay: calc(var(--i, 0) * 9ms);
}

@keyframes cell-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

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

.cell--pad { background: var(--paper-sunk); opacity: 0.5; }

.cell__num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  line-height: 1;
}

/* Coverage fills. The doc's pastels, unaltered. */
.cell--mark  { background-color: var(--mark-fill); }
.cell--linda { background-color: var(--linda-fill); }
.cell--ruhi  { background-color: var(--ruhi-fill); }

/* A continuous top rule across consecutive covered days, so a coverage block
   reads as one object and a handoff reads as a visible seam. This is the one
   thing the doc's per-cell fill could not express. */
.cell--covered::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--band, transparent);
}
.cell--mark  { --band: var(--mark-accent); }
.cell--linda { --band: var(--linda-accent); }
.cell--ruhi  { --band: var(--ruhi-accent); }
.cell--block-start::before { left: 0.35rem; border-top-left-radius: 2px; }
.cell--block-end::before   { right: 0.35rem; border-top-right-radius: 2px; }

/* Uncovered: a hole in the fabric. Hatch, not just a color, so it survives
   both grayscale printing and red-deficient vision. */
.cell--uncovered {
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 5px,
    rgb(179 38 30 / 0.13) 5px 6px
  );
}
.cell--uncovered .cell__num { color: var(--uncovered); font-weight: 700; }

/* Past months desaturate wholesale — replaces the manual gray recoloring. */
.grid--past .cell { filter: grayscale(0.82) opacity(0.72); }
.grid--past .cell__num { color: var(--ink-faint); }

/* Today */
.cell--today .cell__num {
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 0.15rem 0.4rem;
  margin: -0.15rem -0.1rem;
  font-weight: 700;
}

/* --- Entry chips --------------------------------------------------------- */

.chips { display: flex; flex-direction: column; gap: 0.12rem; min-width: 0; }

/* Wrap rather than ellipsis. At phone width a cell is ~57px, where
   "M/R@SF >" ellipsises to "M/R@..." and carries no information at all.
   Two wrapped lines of 8 characters do. Longer entries clamp and are read in
   full by tapping the day. */
.chip {
  font-size: 0.66rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  border-left: 2px solid transparent;
  padding-left: 0.25rem;
}

@media (max-width: 520px) {
  .chip { font-size: 0.6rem; -webkit-line-clamp: 2; }
  .cell { min-height: 6.25rem; padding: 0.25rem 0.2rem 0.3rem; }
}

.chip--mark   { border-left-color: var(--mark-accent); }
.chip--linda  { border-left-color: var(--linda-accent); }
.chip--ruhi   { border-left-color: var(--ruhi-accent); }
.chip--vahid  { border-left-color: var(--vahid-accent); }
.chip--milo   { border-left-color: var(--ink-faint); font-style: italic; }
.chip--event  { border-left-color: var(--ink); }

/* Codes, times, flight numbers get the mono/departure-board treatment */
.chip code, .chip .code {
  font-family: var(--font-mono);
  font-size: 0.94em;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* Status cues carry shape as well as color — color alone fails WCAG, and the
   doc's red-means-pending is invisible to a red-deficient reader. */
.chip--pending {
  color: var(--pending);
  border-left-style: dashed;
}
.chip--pending::after { content: '\00a0?'; font-weight: 700; }  /* nbsp keeps the ? on the same line */

.chip--temporary {
  color: var(--temporary);
  text-decoration: underline dotted 1px;
  text-underline-offset: 2px;
}

/* --- Legend -------------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  /* Clear the floating capture button, which sits bottom-centre. */
  padding: 0.85rem var(--gutter) calc(5rem + env(safe-area-inset-bottom));
  border-top: var(--hair) solid var(--rule);
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.legend__item { display: flex; align-items: center; gap: 0.4rem; }
.legend__sw {
  width: 0.85rem; height: 0.85rem;
  border-radius: 2px;
  border: var(--hair) solid rgb(34 30 26 / 0.18);
}

/* --- Needs attention ----------------------------------------------------- */

.alerts {
  margin: 0 var(--gutter) 1.25rem;
  border: var(--hair) solid var(--rule-strong);
  border-left: 3px solid var(--uncovered);
  border-radius: var(--radius);
  background: var(--paper-raised);
  padding: 0.75rem 0.9rem;
}
.alerts:empty { display: none; }
.alerts h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: -0.01em;
}
.alerts ul { margin: 0; padding-left: 1.1rem; font-size: 0.8rem; color: var(--ink-soft); }
.alerts li { margin-bottom: 0.15rem; }

/* --- Capture button ------------------------------------------------------ */

.capture-fab {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.4rem;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-lift);
  transition: transform 140ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
.capture-fab:active { transform: translateX(-50%) scale(0.97); }
.capture-fab:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* --- Day sheet -----------------------------------------------------------
   Tapping a day opens this. It is the escape hatch that lets the grid stay a
   grid on a phone: the cells carry the colour, the sheet carries the detail.
   ------------------------------------------------------------------------ */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  background: var(--paper-raised);
  border-top: var(--hair) solid var(--rule-strong);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-sheet);
  padding: 0.6rem var(--gutter) calc(1.5rem + env(safe-area-inset-bottom));
  max-height: 72vh;
  overflow-y: auto;
  transform: translateY(101%);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.25, 1);
}
.sheet[data-open='true'] { transform: none; }

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
}

.sheet__grip {
  width: 2.25rem; height: 0.25rem;
  background: var(--rule-strong);
  border-radius: 999px;
  margin: 0 auto 0.75rem;
}

.sheet__date {
  margin: 0 0 0.1rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.sheet__cover {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
  border-bottom: var(--hair) solid var(--rule);
}
.sheet__cover b { font-weight: 700; color: var(--ink); }

.sheet__list { list-style: none; margin: 0; padding: 0; }
.sheet__list li {
  padding: 0.5rem 0 0.5rem 0.6rem;
  border-left: 3px solid var(--rule-strong);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.sheet__list li b { font-weight: 700; }
.sheet__meta {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  margin-top: 0.1rem;
}
.sheet__empty { font-size: 0.85rem; color: var(--ink-faint); font-style: italic; }

.scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgb(34 30 26 / 0.28);
  opacity: 0; pointer-events: none;
  transition: opacity 260ms ease;
}
.scrim[data-open='true'] { opacity: 1; pointer-events: auto; }

.cell { cursor: pointer; }
.cell:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

/* --- Year view ----------------------------------------------------------- */

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.5rem 1.1rem;
  padding: 0 var(--gutter) 5rem;
}

.mini h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.mini__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--rule);
  border: var(--hair) solid var(--rule);
}

.mini__day {
  aspect-ratio: 1;
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
}
.mini__day--mark  { background: var(--mark-fill); color: var(--ink); }
.mini__day--linda { background: var(--linda-fill); color: var(--ink); }
.mini__day--ruhi  { background: var(--ruhi-fill); color: var(--ink); }
.mini__day--uncovered {
  background-image: repeating-linear-gradient(-45deg, transparent 0 3px, rgb(179 38 30 / 0.18) 3px 4px);
}
.mini__day--pad { background: var(--paper-sunk); }

/* Coverage totals */
.totals {
  padding: 0 var(--gutter) 2rem;
  font-size: 0.8rem;
}
.totals table { width: 100%; border-collapse: collapse; }
.totals th, .totals td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: var(--hair) solid var(--rule);
}
.totals th {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 400;
}
.totals td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* --- Utility ------------------------------------------------------------- */

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

.tabs {
  display: flex; gap: 0.15rem;
  padding: 0 var(--gutter);
  border-bottom: var(--hair) solid var(--rule);
}
.tabs a {
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a[aria-current='page'] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }

/* --- Print ---------------------------------------------------------------
   The paper copy that replaces the doc export. Grain and chrome drop out,
   fills stay (with print-color-adjust so browsers do not helpfully remove
   the one thing the page is for).
   ------------------------------------------------------------------------ */

@media print {
  @page { margin: 12mm; }

  html, body {
    background: #fff !important;
    background-image: none !important;
    font-size: 10pt;
  }

  .masthead__nav, .monthbar__nav, .capture-fab, .tabs, .navbtn { display: none !important; }

  .cell, .mini__day, .grid--past .cell {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    filter: none !important;
  }

  .cell { min-height: 3.2rem; animation: none; }
  .grid-wrap { padding: 0; }

  /* Never split a month across a page break */
  .month-block { break-inside: avoid; page-break-inside: avoid; }
  .year-grid { grid-template-columns: repeat(3, 1fr); }
}
