:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #eef1f4;
  --text: #17212b;
  --muted: #5b6875;
  --border: #ccd4dc;
  --accent: #006d5b;
  --accent-hover: #005446;
  --accent-soft: #d9f1eb;
  --danger: #b42318;
  --danger-hover: #8d1b13;
  --focus: #e0a800;
  --shadow: 0 10px 30px rgba(23, 33, 43, .12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11171c;
  --surface: #192128;
  --surface-subtle: #232d35;
  --text: #edf2f5;
  --muted: #aebbc5;
  --border: #3b4852;
  --accent: #62d4bd;
  --accent-hover: #81e2cf;
  --accent-soft: #173d36;
  --danger: #ff8d83;
  --danger-hover: #ffaba4;
  --focus: #ffd166;
  --shadow: 0 12px 34px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --bg: #11171c; --surface: #192128; --surface-subtle: #232d35;
    --text: #edf2f5; --muted: #aebbc5; --border: #3b4852;
    --accent: #62d4bd; --accent-hover: #81e2cf; --accent-soft: #173d36;
    --danger: #ff8d83; --danger-hover: #ffaba4; --focus: #ffd166;
    --shadow: 0 12px 34px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: fixed; z-index: 10; top: .75rem; left: .75rem; transform: translateY(-150%); background: var(--surface); color: var(--text); padding: .75rem 1rem; border: 1px solid var(--border); }
.skip-link:focus { transform: translateY(0); }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding: 1.5rem clamp(1rem, 4vw, 4rem); background: var(--surface); border-bottom: 1px solid var(--border); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.55rem, 3vw, 2.1rem); letter-spacing: 0; }
h2 { font-size: 1.2rem; letter-spacing: 0; }
.eyebrow { margin-bottom: .25rem; color: var(--accent); font-size: .78rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.header-actions { display: flex; flex-wrap: wrap; align-items: end; justify-content: flex-end; gap: .6rem; }
.theme-control { min-width: 7rem; }
main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 1.5rem 0 4rem; }
.toolbar { display: grid; grid-template-columns: minmax(16rem, 1fr) minmax(10rem, auto) minmax(13rem, auto); gap: 1rem; align-items: end; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
label { display: grid; gap: .4rem; color: var(--muted); font-size: .82rem; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 2.7rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: .65rem .75rem; }
textarea { resize: vertical; }
input[aria-invalid="true"] { border-color: var(--danger); }
.button { min-height: 2.7rem; border: 1px solid transparent; border-radius: 6px; padding: .62rem .9rem; font-weight: 700; white-space: nowrap; }
.primary { background: var(--accent); color: #fff; }
[data-theme="dark"] .primary { color: #08241e; }
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .primary { color: #08241e; }
}
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.secondary:hover { background: var(--surface-subtle); }
.danger { background: var(--danger); color: #fff; }
.danger:hover { background: var(--danger-hover); }
.text-button { border: 0; background: transparent; color: var(--accent); padding: .5rem; font-weight: 700; }
.icon-button { width: 2.7rem; height: 2.7rem; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); font-size: 1.6rem; line-height: 1; }
.results-heading { display: flex; align-items: end; justify-content: space-between; padding: 1.5rem 0 1rem; }
.results-heading h2, .results-heading p { margin-bottom: 0; }
.muted { color: var(--muted); }
.evidence-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); gap: 1rem; }
.evidence-card { display: flex; min-width: 0; flex-direction: column; gap: 1rem; padding: 1.1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 2px rgba(23,33,43,.04); }
.card-top { display: flex; align-items: start; justify-content: space-between; gap: .75rem; }
.card-title { margin: 0; font-size: 1.08rem; overflow-wrap: anywhere; }
.status { flex: none; padding: .28rem .5rem; border-radius: 999px; background: var(--surface-subtle); color: var(--muted); font-size: .72rem; font-weight: 750; text-transform: uppercase; }
.status-supports { background: var(--accent-soft); color: var(--accent); }
.status-contradicts { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.status-mixed { border: 1px solid var(--border); color: var(--text); }
.card-source { color: var(--accent); font-weight: 650; overflow-wrap: anywhere; }
.card-notes { margin-bottom: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-meta { margin: auto 0 0; color: var(--muted); font-size: .78rem; }
.card-actions { display: flex; gap: .5rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.card-actions button { flex: 1; }
.empty-state { padding: clamp(3rem, 10vw, 7rem) 1rem; text-align: center; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface); }
.empty-state p { max-width: 34rem; margin-right: auto; margin-left: auto; color: var(--muted); }
.notice { margin: 1rem 0 0; padding: .8rem 1rem; border-left: 4px solid var(--accent); background: var(--accent-soft); color: var(--text); }
.notice.error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
dialog { width: min(42rem, calc(100% - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(7, 15, 20, .62); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: 1.25rem; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1.25rem; }
.full { grid-column: 1 / -1; }
.field-error { min-height: 1em; color: var(--danger); font-size: .78rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.confirm-content { padding-top: 1.25rem; }
.confirm-content > h2, .confirm-content > p { padding: 0 1.25rem; }
.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; }
[hidden] { display: none !important; }

@media (max-width: 760px) {
  .app-header { align-items: stretch; flex-direction: column; gap: 1rem; }
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .header-actions .theme-control { grid-column: 1 / -1; }
  #add-button { grid-column: 1 / -1; }
  .toolbar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid > * { grid-column: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  button, a, input, select { transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease; }
  .evidence-card:hover { transform: translateY(-2px); }
}
