/* School Needs: mobile-first styles. No build step, no external fonts,
   so the app loads fast on weak connections and works offline. */

:root {
  --ink: #1d3557;
  --ink-soft: #e4eaf3;
  --paper: #f3f5f8;
  --surface: #ffffff;
  --text: #1e232b;
  --muted: #5a6473;
  --line: #d5dce5;
  --pencil: #f2b21b;
  --pencil-edge: #c98f00;
  --urgent: #c8364e;
  --requested: #5f6b7c;
  --approved: #2f6fb2;
  --sourcing: #9a6210;
  --fulfilled: #2b7a4b;
  --declined: #8a8f98;
  --focus: #2f6fb2;

  --radius-sm: 6px;
  --radius: 10px;
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;

  color-scheme: light;
}

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

/* Components set their own display; make sure the hidden attribute still wins. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

body.login-page { padding-bottom: 32px; }

img { max-width: 100%; display: block; }

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

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

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 750; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 700; }
p { margin: 0 0 0.75rem; }

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

/* ------------------------------------------------------------ top bar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--ink);
  color: #fff;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem;
}
.brand img { border-radius: 7px; }
.net-pill {
  font-size: 0.8rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: #fff; color: var(--ink);
}

/* ------------------------------------------------------------- layout */

.page { max-width: 640px; margin: 0 auto; padding: 20px 16px; }

.lede { color: var(--muted); font-size: 1.02rem; }

.block { margin-top: 28px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-head h1, .block-head h2 { margin-bottom: 0.75rem; }

.crumb { margin-bottom: 4px; font-size: 0.9rem; }
.crumb a { color: var(--muted); }

.empty {
  color: var(--muted);
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stack > * + * { margin-top: 16px; }

/* ----------------------------------------------------------- messages */

.messages { margin-bottom: 16px; }
.message {
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--ink-soft); color: var(--ink); font-weight: 500;
}
.message-success { background: #e2f1e8; color: #1f5c38; }
.message-error { background: #fbe4e8; color: #8d1f33; }

.notice {
  margin-bottom: 16px; padding: 14px 16px;
  border-left: 4px solid var(--pencil);
  background: #fff8e3; border-radius: var(--radius-sm);
}
.notice:focus { outline: none; }

.outbox-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: #fff8e3; border-bottom: 1px solid #f0dca0;
}
.outbox-banner p { margin: 0; font-weight: 600; }
.outbox-banner-actions { display: flex; align-items: center; gap: 14px; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  font: inherit; font-weight: 650; text-decoration: none;
  border: 1px solid var(--ink); border-radius: var(--radius-sm);
  background: var(--ink); color: #fff; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-block { display: flex; width: 100%; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 0.92rem; }

/* The pencil: the one loud element in the interface. */
.btn-primary {
  background: var(--pencil); color: var(--text);
  border: 0; border-bottom: 4px solid var(--pencil-edge);
  font-size: 1.05rem;
}
.btn-primary:active { border-bottom-width: 1px; margin-top: 3px; }

.btn-secondary { background: var(--surface); color: var(--ink); }
.btn-quiet { background: transparent; color: var(--muted); border-color: var(--line); }

.link-btn {
  font: inherit; font-size: 0.9rem; color: var(--urgent);
  background: none; border: 0; padding: 6px 0; cursor: pointer; text-decoration: underline;
}

/* -------------------------------------------------------------- forms */

.form-section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.form-section > * + * { margin-top: 14px; }

.field { margin: 0; border: 0; padding: 0; min-width: 0; }
.field label, .field legend {
  display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; padding: 0;
}
.optional { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.help { color: var(--muted); font-size: 0.9rem; margin: 6px 0 0; }
.inline-help { margin-top: 6px; }
.error { color: var(--urgent); font-size: 0.9rem; font-weight: 600; margin: 6px 0 0; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--urgent); }

input[type="text"], input[type="search"], input[type="password"], input[type="email"],
input[type="tel"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: 48px;
  font: inherit; font-size: 1rem; /* 16px stops iOS zooming into fields */
  color: var(--text); background: var(--surface);
  border: 1px solid #b9c3cf; border-radius: var(--radius-sm);
  padding: 10px 12px;
}
textarea { min-height: 0; resize: vertical; }
input[type="file"] { font: inherit; font-size: 0.95rem; max-width: 100%; }

.field-row { display: grid; grid-template-columns: 1fr 96px; gap: 12px; }

/* Priority as a segmented control */
.field input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
fieldset.field > div {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid #b9c3cf; border-radius: var(--radius-sm); overflow: hidden;
}
fieldset.field > div > div { display: flex; }
fieldset.field > div > div + div { border-left: 1px solid #b9c3cf; }
fieldset.field > div label {
  flex: 1; margin: 0; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 500; cursor: pointer; background: var(--surface);
}
fieldset.field > div label.is-checked,
fieldset.field > div label:has(input:checked) { background: var(--ink); color: #fff; font-weight: 650; }
fieldset.field > div label.is-urgent,
fieldset.field > div label:has(input[value="urgent"]:checked) { background: var(--urgent); }
fieldset.field > div label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: -3px; }

.item-form { border-top: 1px solid var(--line); padding-top: 14px; }
.item-form > * + * { margin-top: 12px; }
.item-form-head { display: flex; align-items: center; justify-content: space-between; }
.item-form-head h3 { margin: 0; }
.photo-preview { margin-top: 8px; max-height: 140px; border-radius: var(--radius-sm); border: 1px solid var(--line); }

.form-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 12px 0 8px;
  background: linear-gradient(to bottom, rgba(243, 245, 248, 0), var(--paper) 18%);
}
.form-actions .help { text-align: center; }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search .btn { min-height: 48px; }

/* -------------------------------------------------------------- lists */

.rows {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.rows > li + li { border-top: 1px solid var(--line); }
.rows > li > a, .rows > li > div {
  display: grid; grid-template-columns: 1fr auto; column-gap: 12px;
  padding: 12px 16px; color: inherit; text-decoration: none;
}
.rows > li > a:active { background: var(--ink-soft); }
.row-title { font-weight: 600; grid-column: 1; }
.row-meta { color: var(--muted); font-size: 0.9rem; grid-column: 1; }
.row-side {
  grid-column: 2; grid-row: 1 / span 2; align-self: center;
  color: var(--muted); font-size: 0.9rem; text-align: right;
}
.rows.compact .chips { margin-top: 4px; }

.qty {
  display: inline-block; min-width: 2.2em; margin-right: 4px; padding: 0 6px;
  border-radius: 4px; background: var(--ink-soft); color: var(--ink);
  font-weight: 700; font-variant-numeric: tabular-nums; text-align: center;
}

.facts { margin: 0 0 16px; display: grid; gap: 8px; }
.facts div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.note-text {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px;
}

.item-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.item-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.item-main { display: flex; gap: 12px; align-items: flex-start; }
.item-title { font-weight: 600; margin-bottom: 2px; }
.thumb { flex: none; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); }

.chips { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 650; border: 1px solid currentColor;
}
.chip-requested { color: var(--requested); }
.chip-approved { color: var(--approved); }
.chip-sourcing { color: var(--sourcing); }
.chip-fulfilled { color: #fff; background: var(--fulfilled); border-color: var(--fulfilled); }
.chip-declined { color: var(--declined); text-decoration: line-through; }
.chip-urgent { color: #fff; background: var(--urgent); border-color: var(--urgent); }
.chip-low { color: var(--muted); border-style: dashed; }
.text-urgent { color: var(--urgent); font-weight: 600; }

.status-form {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.status-form select, .status-form input { min-height: 40px; padding: 6px 10px; font-size: 1rem; }
.status-form input { grid-column: 1; }
.status-form .btn { grid-column: 2; grid-row: 1 / span 2; }

.history { margin-top: 10px; font-size: 0.88rem; color: var(--muted); }
.history summary { cursor: pointer; font-weight: 600; }
.history ol { margin: 6px 0 0; padding-left: 18px; }

/* Status summary on the volunteer home screen */
.status-strip {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
/* Each cell sets a pastel --tint for the background and a deeper --deep for its text. */
.status-strip li {
  text-align: center; border-top: 4px solid var(--deep, transparent);
  background: var(--tint, var(--surface)); color: var(--deep, var(--text));
}
.status-strip a { display: block; height: 100%; padding: 10px 4px; color: inherit; text-decoration: none; }
.status-strip a:hover, .status-strip a:focus-visible { background: rgb(0 0 0 / 0.05); }
.status-strip li + li { border-left: 1px solid var(--line); }
.status-strip strong { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.status-strip span { font-size: 0.75rem; font-weight: 500; }
.status-strip .status-requested { --tint: #eef1f5; --deep: #4a5566; }
.status-strip .status-approved { --tint: #e3eefa; --deep: #1f5a96; }
.status-strip .status-sourcing { --tint: #fdf1dc; --deep: #8a560b; }
.status-strip .status-fulfilled { --tint: #e2f3e8; --deep: #23683f; }
.status-strip .status-declined { --tint: #fde7ea; --deep: #b02a40; }

.intro .btn { margin-top: 8px; }

/* -------------------------------------------------------------- reports */

.summary {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.summary th, .summary td { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.summary tr:last-child th, .summary tr:last-child td { border-bottom: 0; }
.summary th { text-align: left; font-weight: 500; color: var(--muted); }
.summary td {
  text-align: right; font-weight: 750; font-size: 1.2rem; font-variant-numeric: tabular-nums;
}

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.bars a {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 8px 0; color: inherit; text-decoration: none;
}
.bar-label { font-weight: 500; }
.bar-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 10px; background: var(--ink-soft); border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--ink); border-radius: 5px; min-width: 2px; }
.bar-fill.status-requested { background: var(--requested); }
.bar-fill.status-approved { background: var(--approved); }
.bar-fill.status-sourcing { background: var(--sourcing); }
.bar-fill.status-fulfilled { background: var(--fulfilled); }
.bar-fill.status-declined { background: var(--declined); }

.filters {
  margin-bottom: 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.filters summary { padding: 12px 16px; font-weight: 600; cursor: pointer; }
.filter-grid { display: grid; gap: 12px; padding: 0 16px 16px; }
.filter-actions { display: flex; align-items: center; gap: 16px; }

.pagination {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 16px; font-size: 0.95rem;
}

/* --------------------------------------------------------------- outbox */

.outbox-list { margin-top: 16px; display: grid; gap: 12px; }
.outbox-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.outbox-item.is-failed { border-color: var(--urgent); }
.outbox-item p { margin: 0 0 4px; }
.outbox-item .actions { margin-top: 8px; }

.install-help .btn { margin-bottom: 8px; }
form[data-logout] { margin-top: 28px; }

/* --------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.tabbar svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a[aria-current="page"] { color: var(--ink); }
.tabbar a[aria-current="page"] span { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.tabbar .tab-new svg {
  width: 38px; height: 38px; padding: 8px; border-radius: 50%;
  background: var(--pencil); color: var(--text); stroke-width: 2.6;
  box-shadow: 0 3px 0 var(--pencil-edge);
}

@media (min-width: 700px) {
  .page { padding-top: 32px; }
  .tabbar { left: 50%; transform: translateX(-50%); max-width: 640px; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid .field:first-child, .filter-actions { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
