/* ============================================================
   sp-design.css — shared editorial design system for Twelve
   Digital products. Consumed via <link href="/shared/sp-design.css">
   (Caddy serves /shared in prod; the Deno dev server serves it too
   — see packages/deno-server/server.ts).

   Contents:
     1. @font-face (Inter)
     2. Design tokens (:root custom properties)
     3. Base reset + document defaults
     4. Layout helpers (.sp-header, main, .sp-foot)
     5. Type helpers (.sp-title/.sp-subtitle/.sp-label-mini/.sp-mono)
     6. Section head + flat row primitives
     7. Buttons (.sp-btn variants) + inputs (.sp-field/.sp-input/…)
     8. Segmented control (.sp-segment) + counter chip (.sp-chip)
     9. Progress rail, checklist helpers, FAB, bottom sheet
    10. Review stats, notice strip, signature wrap, meter
    11. Empty states, photo grid, misc utilities
   ============================================================ */

/* ---------- 1. Fonts ---------- */
@font-face {
  font-family: 'Inter';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/shared/fonts/Inter-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Inter';
  font-weight: 600 700;
  font-style: normal;
  font-display: swap;
  src: url('/shared/fonts/Inter-Bold.ttf') format('truetype');
}

/* ---------- 2. Tokens ---------- */
:root {
  --ink: #1C2036;
  --ink-2: #2F3555;
  --paper: #F5F1E8;
  --surface: #FBF9F2;
  --muted: #6B6458;
  --faint: #9A9287;
  --rule: #E2DBC7;
  --rule-strong: #CFC6AE;
  --accent: #B14A28;
  --accent-ink: #7C3316;

  --ok: #2F6B3A;
  --ok-bg: #E8EFDB;
  --warn: #B17812;
  --warn-bg: #F6EBC6;
  --crit: #9B2914;
  --crit-bg: #F3D9CE;
  --info: #4B5A78;
  --info-bg: #DFE3EC;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --page-max: 520px;
  --page-px: 20px;
  --header-h: 52px;
}

/* ---------- 3. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 16px var(--page-px) 0;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: transparent; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }

/* ---------- 4. Layout shell ---------- */
.sp-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 var(--page-px);
  padding-top: env(safe-area-inset-top, 0);
  gap: 12px;
}
.sp-header-inner {
  max-width: var(--page-max);
  width: 100%;
  margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  height: var(--header-h);
}
.sp-wordmark {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-wordmark .sp-wm-serial {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
  margin-right: 8px;
  text-transform: uppercase;
}
.sp-iconbtn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
  border-radius: var(--radius-sm);
}
.sp-iconbtn:hover { color: var(--ink); background: rgba(0,0,0,.04); }
.sp-iconbtn svg { width: 20px; height: 20px; }
.sp-iconbtn[hidden] { display: none; }

.sp-foot {
  flex-shrink: 0;
  max-width: var(--page-max);
  margin: 40px auto 0;
  padding: 16px var(--page-px) calc(24px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex; flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}
.sp-foot a { color: var(--muted); text-decoration: none; }
.sp-foot a:hover { color: var(--ink); }
.sp-foot .sp-foot-spacer { flex: 1; }

/* ---------- 5. Type helpers ---------- */
.sp-title {
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: -0.015em;
  font-weight: 600;
  margin: 0 0 4px;
}
.sp-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 20px;
}
.sp-label-mini {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.sp-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- 6. Section head + flat row ---------- */
.sp-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 0 8px;
  border-top: 1px solid var(--rule);
  margin-top: 12px;
}
.sp-section-head:first-child { border-top: 0; margin-top: 0; }
.sp-section-head h3 {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.sp-section-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
}

.sp-list { list-style: none; padding: 0; margin: 0; }
.sp-row {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--rule);
  padding: 14px 0;
  min-height: 60px;
}
.sp-row:last-child { border-bottom: 0; }
.sp-row-body {
  flex: 1; min-width: 0;
  display: block; text-align: left;
  padding: 0;
}
.sp-row-title {
  display: block;
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
  margin-bottom: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-row-sub {
  display: block;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-row-chev {
  width: 16px; height: 16px;
  color: var(--faint);
  flex-shrink: 0;
}
.sp-row-del {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--faint);
  border-radius: var(--radius-sm);
  opacity: .55;
}
.sp-row-del:hover { color: var(--crit); opacity: 1; background: rgba(155,41,20,.06); }
.sp-row-del svg { width: 16px; height: 16px; }

/* ---------- 7. Buttons + inputs ---------- */
.sp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
  text-decoration: none;
  min-width: 0;
}
.sp-btn-primary { background: var(--ink); color: var(--paper); }
.sp-btn-primary:hover { background: var(--ink-2); }
.sp-btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}
.sp-btn-secondary:hover { background: rgba(0,0,0,.03); border-color: var(--ink); }
.sp-btn-accent { background: var(--accent); color: #FFF8F1; }
.sp-btn-accent:hover { background: var(--accent-ink); }
.sp-btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.sp-btn-block { width: 100%; }
.sp-btn-ghost { color: var(--muted); height: 32px; padding: 0 8px; font-size: 13px; }
.sp-btn-ghost:hover { color: var(--ink); }
.sp-btn-danger { color: var(--crit); }
.sp-btn-danger:hover { background: rgba(155,41,20,.06); }
.sp-btn-primary:disabled,
.sp-btn-secondary:disabled,
.sp-btn[disabled] {
  background: transparent;
  color: var(--faint);
  border: 1px dashed var(--rule-strong);
  cursor: not-allowed;
}
.sp-btn-primary:disabled:hover,
.sp-btn-secondary:disabled:hover { background: transparent; border-color: var(--rule-strong); }

.sp-field { display: block; margin-bottom: 16px; }
.sp-field-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
.sp-input, .sp-textarea, .sp-select {
  display: block; width: 100%;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 15px;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
  outline: none;
}
.sp-input::placeholder, .sp-textarea::placeholder { color: var(--faint); }
.sp-input:focus, .sp-textarea:focus, .sp-select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(28,32,54,.12);
}
.sp-textarea { resize: vertical; min-height: 72px; }
.sp-select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B6458' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.sp-field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* ---------- 8. Segmented + chip ---------- */
.sp-segment {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.sp-segment > button {
  flex: 1;
  height: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-right: 1px solid var(--rule);
  transition: background-color .15s ease, color .15s ease;
}
.sp-segment > button:last-child { border-right: 0; }
.sp-segment > button:hover { color: var(--ink); }
.sp-segment > button.is-active { background: var(--ink); color: var(--paper); }
.sp-segment > button.is-active.is-ok { background: var(--ok); color: #fff; }
.sp-segment > button.is-active.is-warn { background: var(--warn); color: #fff; }
.sp-segment > button.is-active.is-crit { background: var(--crit); color: #fff; }
.sp-segment > button.is-active.is-muted { background: var(--info); color: #fff; }
.sp-segment-sm > button { height: 32px; font-size: 12px; }

.sp-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  background: var(--info-bg);
  color: var(--info);
  white-space: nowrap;
  flex-shrink: 0;
}
.sp-chip.is-ok { background: var(--ok-bg); color: var(--ok); }
.sp-chip.is-warn { background: var(--warn-bg); color: var(--warn); }
.sp-chip.is-crit { background: var(--crit-bg); color: var(--crit); }
.sp-chip.is-neutral { background: rgba(0,0,0,.05); color: var(--muted); }

/* ---------- 9. Progress, checklist, FAB, sheet ---------- */
.sp-progress {
  position: sticky;
  top: var(--header-h);
  z-index: 35;
  background: var(--paper);
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--rule);
  margin: -24px calc(-1 * var(--page-px)) 16px;
  padding-left: var(--page-px);
  padding-right: var(--page-px);
}
.sp-progress-top {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}
.sp-progress-label { font-size: 13px; color: var(--muted); }
.sp-progress-label strong { color: var(--ink); font-weight: 500; margin-right: 6px; }
.sp-progress-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
}
.sp-progress-bar { height: 2px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.sp-progress-bar > span { display: block; height: 100%; background: var(--ink); transition: width .25s ease; }

.sp-category {
  padding: 18px 0 4px;
  border-top: 1px solid var(--rule);
}
.sp-category:first-child { border-top: 0; padding-top: 4px; }
.sp-category-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}
.sp-category-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.sp-category-right { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sp-category-all-ok {
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}
.sp-category-all-ok:hover { color: var(--ok); }
.sp-check-item {
  padding: 12px 0;
  border-top: 1px dashed var(--rule);
}
.sp-check-item:first-child { border-top: 0; }
.sp-check-label {
  display: block;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink);
  margin-bottom: 8px;
}
.sp-check-defect {
  margin-top: 10px;
  padding: 12px;
  border-left: 2px solid var(--crit);
  background: rgba(155,41,20,.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.sp-check-defect > .sp-input { margin-top: 8px; }

.sp-fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  width: 52px; height: 52px;
  border-radius: 26px;
  background: var(--ink);
  color: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(28,32,54,.18);
  z-index: 30;
}
.sp-fab:hover { background: var(--ink-2); }
.sp-fab svg { width: 22px; height: 22px; }

.sp-sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(28,32,54,.35);
  z-index: 90;
  opacity: 0;
  animation: spBackdrop .16s ease-out forwards;
}
@keyframes spBackdrop { to { opacity: 1; } }
.sp-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 91;
  background: var(--paper);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: 0 -8px 24px rgba(28,32,54,.15);
  padding: 8px var(--page-px) calc(24px + env(safe-area-inset-bottom, 0));
  max-width: var(--page-max);
  margin: 0 auto;
  transform: translateY(100%);
  animation: spSheet .2s cubic-bezier(.2,.8,.2,1) forwards;
}
@keyframes spSheet { to { transform: translateY(0); } }
.sp-sheet-grip {
  width: 40px; height: 4px;
  background: var(--rule-strong);
  border-radius: 2px;
  margin: 8px auto 14px;
}
.sp-sheet-title { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.sp-sheet-sub { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.sp-sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ---------- 10. Review stats, notice, signature, meter ---------- */
.sp-stats {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 6px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 0 0 20px;
  padding: 0;
  line-height: 1.3;
}
.sp-stats .sp-stats-item { display: inline-flex; align-items: baseline; gap: 6px; margin: 0; }
.sp-stats dt {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin: 0;
}
.sp-stats dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.sp-stats dd.is-crit { color: var(--crit); font-weight: 600; }
.sp-stats dd.is-warn { color: var(--warn); font-weight: 600; }
.sp-stats dd.is-ok { color: var(--ok); font-weight: 600; }

.sp-notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  border-left: 2px solid var(--warn);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
  margin-bottom: 20px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.sp-notice.is-crit { border-color: var(--crit); background: var(--crit-bg); color: var(--crit); }

.sp-sig-wrap {
  position: relative;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 10px 4px;
}
.sp-sig-wrap canvas { width: 100%; display: block; border-bottom: 1px solid var(--rule); }
.sp-sig-hint {
  position: absolute;
  top: 12px; left: 14px;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}
.sp-sig-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 6px; }
.sp-sig-foot span {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sp-meter {
  font-size: 12px;
  color: var(--muted);
  margin: -6px 0 16px;
  display: flex; align-items: center; gap: 6px;
}
.sp-meter .sp-meter-val { font-family: var(--font-mono); color: var(--ink); }
.sp-meter a { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }

/* ---------- 11. Empty states, photos, utilities ---------- */
.sp-empty { padding: 48px 16px; text-align: center; }
.sp-empty-icon {
  display: inline-flex; width: 40px; height: 40px;
  border-radius: 999px;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.035);
  color: var(--faint);
  margin-bottom: 12px;
}
.sp-empty-icon svg { width: 20px; height: 20px; }
.sp-empty-text { font-size: 14px; color: var(--muted); margin: 0 0 12px; }

.sp-photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.sp-photo {
  position: relative;
  width: 68px; height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--rule);
}
.sp-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sp-photo-del {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  background: rgba(28,32,54,.78); color: #fff;
  border-radius: 999px;
  font-size: 12px; line-height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}

.sp-inline-actions { display: flex; gap: 10px; margin-top: 12px; }
.sp-hidden { display: none !important; }
.sp-sr {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Small screens */
@media (max-width: 380px) {
  :root { --page-px: 16px; }
}

/* ---------- Screen cross-fade (opt-in via .screen.active) ---------- */
.screen { display: none; }
.screen.active { display: block; animation: spFade 140ms ease-out; }
@keyframes spFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
