/* Auditfold v2: calm, mobile-first styles, plus the print stylesheet.
 * Spacing uses only 4/8/12/16/24/32/48px. Palette follows the design brief. */
:root {
  --canvas: #F6F7F9; --surface: #FFFFFF; --ink: #1B2330; --muted: #556070;
  --accent: #0F6E6E; --accent-tint: #E6F2F2; --danger: #B42318; --danger-tint: #FDECEA;
  --caution: #8A5A00; --caution-tint: #FDF3E1; --low-tint: #EEF0F3;
  --line: #D9DEE5; --border: #8A94A3;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0; padding: 16px; max-width: 100vw; background: var(--canvas); color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
}
header, main, footer { display: block; width: 100%; max-width: 760px; min-width: 0; margin: 0 auto; }
h1 { font-size: 1.5rem; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; margin: 16px 0 8px; }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.25; margin: 0 0 12px; }
h3 { font-size: 1.0625rem; font-weight: 600; line-height: 1.25; margin: 0; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, pre, input, textarea, .card { overflow-wrap: anywhere; }

/* Header */
.site-header { margin-bottom: 24px; }
.brand-row { display: flex; flex-direction: column; gap: 4px; }
.wordmark { font-size: 1.125rem; font-weight: 700; }
.tag { margin: 0; }

/* Layout and cards */
.cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
.cols > *, .field, .results { min-width: 0; max-width: 100%; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 24px; box-shadow: 0 1px 2px rgba(27, 35, 48, 0.06);
}
.cols .card { margin-bottom: 0; }
.empty-state {
  border: 2px dashed var(--line); border-radius: 12px; padding: 32px 16px;
  text-align: center; color: var(--muted);
}
.empty-state p { margin-bottom: 16px; }
.site-footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); }
#print-area { display: none; }

/* Forms */
.field { margin-bottom: 16px; }
label { display: block; font-size: 0.875rem; font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
input, textarea {
  width: 100%; max-width: 100%; min-height: 44px; padding: 12px; background: var(--surface);
  color: var(--ink); border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 1rem;
}
textarea { font-family: var(--mono); line-height: 1.4; resize: vertical; min-height: 180px; }
input:hover, textarea:hover { border-color: var(--ink); }
input:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, textarea:disabled { background: var(--low-tint); color: var(--muted); }
[aria-invalid="true"] { border-color: var(--danger); }
.help { margin: 4px 0 0; }
.error {
  margin: 8px 0 0; padding: 8px 12px; color: var(--danger); font-size: 0.875rem; font-weight: 600;
  background: var(--danger-tint); border-left: 4px solid var(--danger); border-radius: 4px;
}

/* Buttons */
button { font: inherit; cursor: pointer; }
.run { display: flex; flex-direction: column; gap: 8px; }
.primary, .secondary, .ghost { min-height: 48px; border-radius: 8px; padding: 12px 20px; width: 100%; }
.primary { background: var(--accent); color: #fff; font-weight: 600; border: 1px solid var(--accent); }
.primary:hover:not(:disabled) { background: #0B5858; }
.primary:active:not(:disabled) { background: #094848; }
.primary:focus-visible { outline: none; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.secondary:hover:not(:disabled) { background: var(--canvas); border-color: var(--ink); }
.ghost { background: transparent; color: var(--ink); border: 1px solid transparent; }
.ghost:hover:not(:disabled) { text-decoration: underline; }
.ghost.danger { color: var(--danger); }
.primary:disabled, .secondary:disabled, .ghost:disabled {
  background: var(--low-tint); color: var(--muted); border: 1px dashed var(--border); cursor: not-allowed;
}

/* How-to disclosure */
details summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before {
  content: ""; width: 8px; height: 8px; border-right: 2px solid var(--ink); border-top: 2px solid var(--ink);
  transform: rotate(45deg);
}
details[open] > summary::before { transform: rotate(135deg); }
details summary:hover { text-decoration: underline; }
#howto { margin-bottom: 12px; }

/* Results */
.summary { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px !important; }
.score { margin: 0 0 4px; font-size: 2.5rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.score .muted { font-size: 1rem; font-weight: 400; }
.bar { height: 8px; margin-top: 8px; background: var(--low-tint); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ink); }
.counts { margin: 0; color: var(--muted); }
.actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 16px; }
#fallback textarea { margin-bottom: 4px; }
.ok { background: var(--accent-tint); color: var(--accent); border-radius: 8px; padding: 16px; margin-bottom: 16px; }

/* Fix list */
.fixes { list-style: none; padding: 0; margin: 0 0 16px; }
.fix { padding: 16px 0; border-bottom: 1px solid var(--line); break-inside: avoid; }
.fix:last-child { border-bottom: 0; }
.fix-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fix-head h3 { flex-basis: 100%; }
.rank { color: var(--muted); font-weight: 600; }
.fix-text { margin: 8px 0 0; max-width: 70ch; }
.found { margin: 8px 0 0; padding: 4px 8px; background: var(--canvas); border-radius: 4px; overflow-wrap: anywhere; }

/* Severity and band badges: the word is always shown, with a border for print/greyscale */
.badge {
  display: inline-block; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 0.75rem; font-weight: 600; line-height: 1.25; letter-spacing: 0.04em; text-transform: uppercase;
}
.badge.high { color: var(--danger); background: var(--danger-tint); border-color: var(--danger); }
.badge.medium, .badge.needs-work { color: var(--caution); background: var(--caution-tint); border-color: var(--caution); }
.badge.low { color: var(--muted); background: var(--low-tint); border-color: var(--border); }
.badge.good { color: var(--accent); background: var(--accent-tint); border-color: var(--accent); }
.badge.poor { color: var(--danger); background: var(--danger-tint); border-color: var(--danger); }
.passed ul { list-style: none; padding: 0 0 0 8px; }
.passed li { padding: 4px 0; }
.tick, .passed-word { color: var(--accent); }
.passed-word { font-size: 0.875rem; }

/* History */
.hist { list-style: none; padding: 0; margin: 0 0 8px; }
.hist-row {
  display: flex; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px;
  padding: 8px 12px; text-align: left; background: none; color: var(--ink);
  border: 0; border-bottom: 1px solid var(--line); border-left: 4px solid transparent;
}
.hist-row:hover { background: var(--canvas); }
.hist-row:focus-visible { outline-offset: -2px; }
.hist-row.current { border-left-color: var(--accent); }
/* Pro panels */
.pro-h { margin-top: 32px; }
.pro-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
@media (min-width: 720px) { .pro-grid { grid-template-columns: 1fr 1fr; } }
.lock-note { background: var(--canvas); border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.lock-note p:last-child { margin-bottom: 0; }
.lock-note a { color: var(--accent); }
.pro-label { color: var(--accent); }
.hist-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; }
.hist-item:hover { background: var(--canvas); }
.hist-item .hist-left { flex: 1 1 160px; }
button:disabled { background: var(--low-tint); color: var(--muted); border: 1px dashed var(--border); cursor: not-allowed; }
input:disabled { background: var(--low-tint); color: var(--muted); }
.hist-left { display: flex; flex-direction: column; min-width: 0; }
.hist-client { font-weight: 600; }
.hist-url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-right { text-align: right; flex-shrink: 0; }
#clear-row .ghost, #confirm .ghost { width: auto; }

/* Toast */
.toast {
  position: fixed; bottom: 16px; left: 16px; right: 16px; margin: 0 auto; max-width: 360px;
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 8px 8px 8px 16px; box-shadow: 0 4px 12px rgba(27, 35, 48, 0.12);
}
.toast[hidden] { display: none; }
.toast.err { border-left-color: var(--danger); }
.toast button { min-width: 44px; min-height: 44px; background: none; border: 0; font-size: 1.25rem; color: var(--ink); }

/* Wider screens */
@media (min-width: 600px) {
  body { padding: 24px; }
  h1 { font-size: 1.75rem; }
  .brand-row { flex-direction: row; justify-content: space-between; align-items: baseline; }
  .card { padding: 24px; }
  textarea { min-height: 220px; }
  .run { flex-direction: row; }
  .primary, .secondary, .ghost { width: auto; min-height: 44px; }
  #clear-input { margin-left: auto; }
  .actions { display: flex; flex-wrap: wrap; }
  .summary { flex-direction: row; align-items: center; justify-content: space-between; }
  .toast { left: 50%; right: auto; transform: translateX(-50%); width: 360px; margin: 0; }
}
/* Phones: stop iOS zoom and keep every tap target tall enough */
@media (max-width: 599px) {
  .brand-row { flex-direction: column; }
  textarea { font-size: 1rem; }
  .hist-row { flex-wrap: wrap; }
  .hist-right { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .badge, .primary, .secondary, .ghost, .card { border: 1px solid CanvasText; }
}

@media print {
  @page { margin: 2cm; }
  body { background: #fff; color: #000; padding: 0; }
  header, .cols, .pro-h, .pro-h + p, .pro-grid, #history-card, footer, .toast { display: none !important; }
  #print-area { display: block; }
  #print-area .fix { border: 1px solid #000; border-radius: 0; padding: 8px; margin: 0 0 8px; break-inside: avoid; list-style-position: inside; }
  #print-area .meta, #print-area .found { color: #000; }
  #print-area .score { font-size: 2rem; font-weight: 700; }
}
