:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --text: #1c2521;
  --muted: #5a6660;
  --line: #d9dfda;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e3f0ec;
  --high: #b3261e;
  --high-soft: #fbeae8;
  --medium: #8a5a00;
  --medium-soft: #fbf1dc;
  --low: #3d5a80;
  --low-soft: #e6edf6;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131816;
    --surface: #1b221f;
    --text: #e8ece9;
    --muted: #9aa6a0;
    --line: #2d3733;
    --accent: #5cc3a6;
    --accent-text: #0d1512;
    --accent-soft: #1d2f29;
    --high: #f2a29b;
    --high-soft: #3a1f1c;
    --medium: #e8bf6a;
    --medium-soft: #372c14;
    --low: #9db8dc;
    --low-soft: #1e2a3a;
  }
}

* { box-sizing: border-box; }

/* Without this, any rule that sets display (like .status) beats the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.wrap { max-width: 44rem; margin: 0 auto; padding: 0 16px; }

.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { margin: 0; padding: 14px 0; font-weight: 700; font-size: 1.2rem; color: var(--accent); letter-spacing: -0.01em; }

h1 { font-size: 1.75rem; line-height: 1.2; margin: 1.5rem 0 0.75rem; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.25rem; }
p { margin: 0 0 0.75rem; }
.lede { font-size: 1.05rem; color: var(--muted); }
.steps { padding-left: 1.25rem; color: var(--muted); }
.steps li { margin-bottom: 0.25rem; }

.card, .flag, .summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 1.25rem 0;
}

.modes { border: 0; padding: 0; margin: 0 0 1rem; display: flex; gap: 8px; flex-wrap: wrap; }
.modes label {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
}
.modes label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.modes input { accent-color: var(--accent); }

.field-label { display: block; font-weight: 600; margin-bottom: 6px; }

textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
}

input[type='file'] { width: 100%; font: inherit; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }

.file-list { list-style: none; padding: 0; margin: 8px 0 0; }
.file-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.legal {
  margin: 1.25rem 0;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
}
.legal p { color: var(--muted); }
.ack { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; font-weight: 600; cursor: pointer; }
.ack input { margin-top: 5px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  padding: 12px 20px;
  font-weight: 600;
  min-height: 44px;
}
button[type='submit'] { width: 100%; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: transparent; color: var(--accent); }
button.link { background: none; border: 0; color: var(--accent); padding: 4px 8px; min-height: 0; font-weight: 500; text-decoration: underline; }

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

.restored { margin: 0 0 1rem; padding: 10px 12px; background: var(--accent-soft); border-radius: 8px; font-size: 0.92rem; }

.error { color: var(--high); background: var(--high-soft); padding: 10px 12px; border-radius: 8px; margin: 12px 0 0; }

.status { display: flex; gap: 12px; align-items: center; color: var(--muted); padding: 8px 4px; }
.spinner {
  width: 20px; height: 20px; flex: none;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.summary h2 { margin-bottom: 0.4rem; }
.flag { border-left-width: 5px; }
.flag.high { border-left-color: var(--high); }
.flag.medium { border-left-color: var(--medium); }
.flag.low { border-left-color: var(--low); }

.flag-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.badge { font-size: 0.78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.high { background: var(--high-soft); color: var(--high); }
.badge.medium { background: var(--medium-soft); color: var(--medium); }
.badge.low { background: var(--low-soft); color: var(--low); }
.ref { font-weight: 600; }

blockquote {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}
.unmatched { color: var(--muted); font-size: 0.88rem; font-style: italic; }

.flag dl { margin: 0; }
.flag dt { font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-top: 10px; }
.flag dd { margin: 2px 0 0; }
.act { font-size: 0.85rem; color: var(--muted); margin-top: 10px; }

.results-foot { color: var(--muted); font-size: 0.9rem; }
.results-foot .actions { margin-top: 12px; }

.site-footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 20px 0 40px; color: var(--muted); font-size: 0.9rem; }
a { color: var(--accent); }

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

@media (min-width: 640px) {
  h1 { font-size: 2.1rem; }
  button[type='submit'] { width: auto; }
}

/* -- Billing bar -------------------------------------------------------- */
.billing-bar {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
}
.billing-bar .wrap { padding: 10px 16px; }
.billing-lede, .billing-status, .billing-keep-note { margin: 0 0 8px; font-size: 0.92rem; color: var(--muted); }
.billing-notice { margin: 0 0 8px; font-size: 0.92rem; font-weight: 600; color: var(--accent); }
.billing-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.billing-actions .secondary,
.billing-actions .link,
#billing-portal-link {
  font: inherit;
  font-size: 0.88rem;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.billing-actions .secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}
.billing-actions .link, #billing-portal-link {
  background: transparent;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 6px 4px;
}

/* -- Saving a review ---------------------------------------------------------- */
.save-panel {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 1.25rem 0;
}
.save-panel h2 { margin-bottom: 0.25rem; }
.save-panel p { margin-bottom: 0.75rem; font-size: 0.95rem; }

.save-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 0.75rem; }
.save-panel .save-actions { margin-bottom: 0; }
.save-actions button { font-size: 0.92rem; padding: 8px 14px; min-height: 40px; }
.save-status { flex-basis: 100%; font-size: 0.88rem; color: var(--muted); min-height: 1.2em; }
.save-status:empty { display: none; }

.discard-warning {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--high-soft);
  border: 1px solid var(--high);
  border-radius: 8px;
  color: var(--text);
}
.discard-warning p { margin-bottom: 0.5rem; }
.discard-warning .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 0; }
button.danger { background: transparent; color: var(--high); border-color: var(--high); }

.print-only { display: none; }

/* Saving as PDF prints this page, so print only the review, in light colours
   whatever the screen theme (a dark-mode print would be pale text on white). */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --text: #111; --muted: #444; --line: #bbb;
    --accent: #1f6f5c; --accent-soft: #fff;
    --high: #b3261e; --high-soft: #fff; --medium: #8a5a00; --medium-soft: #fff; --low: #3d5a80; --low-soft: #fff;
  }
  body { font-size: 12pt; }
  .site-header, .billing-bar, .site-footer, .save-panel, .save-actions, .discard-warning,
  .results-foot .actions, main > *:not(#results) { display: none !important; }
  .print-only { display: block; }
  .print-only h1 { margin: 0 0 0.25rem; font-size: 1.6rem; }
  .summary, .flag { break-inside: avoid; border-color: #999; margin: 0.75rem 0; }
  .flag { border-left-width: 4px; }
  a { color: inherit; }
}

.plain-review { width: 100%; font: inherit; font-size: 0.9rem; }

/* Email address form in the billing bar (replaces a browser dialog). */
.billing-email-form { margin: 12px 0 4px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.billing-email-title { margin: 0 0 6px; font-weight: 600; font-size: 0.95rem; }
.billing-email-form label { display: block; font-size: 0.85rem; font-weight: 600; }
.billing-email-form .hint { margin: 2px 0 8px; }
.billing-email-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.billing-email-row input {
  flex: 1 1 14rem;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  /* 16px or more, or iOS Safari zooms the page when the field is focused. */
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.billing-email-form .error { margin-top: 8px; }

/* The note about the safety copy kept in this tab, inside the save panel. */
.save-panel .safety-note { margin: 0.75rem 0 0; font-size: 0.85rem; color: var(--muted); }
.safety-note button.link { padding: 0 2px; min-height: 0; font-size: inherit; }
