:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f3;
  --text: #172126;
  --muted: #607078;
  --border: #cfd8dc;
  --accent: #126e68;
  --accent-hover: #0d5752;
  --accent-soft: #dcefed;
  --danger: #a53030;
  --focus: #d27c1d;
  --shadow: 0 8px 28px rgba(19, 39, 45, .1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111719;
  --surface: #192124;
  --surface-muted: #222d30;
  --text: #edf3f3;
  --muted: #a7b6b9;
  --border: #3b4a4e;
  --accent: #63c8bd;
  --accent-hover: #87d8cf;
  --accent-soft: #183f3c;
  --danger: #ff8b86;
  --focus: #f2ae61;
  --shadow: 0 10px 32px rgba(0, 0, 0, .3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111719; --surface: #192124; --surface-muted: #222d30;
    --text: #edf3f3; --muted: #a7b6b9; --border: #3b4a4e;
    --accent: #63c8bd; --accent-hover: #87d8cf; --accent-soft: #183f3c;
    --danger: #ff8b86; --focus: #f2ae61; --shadow: 0 10px 32px rgba(0,0,0,.3);
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) button.primary { color: #082523; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .badge.supports { background: #204333; color: #9cdbb7; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .badge.mixed { background: #483b20; color: #f0d486; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .badge.contradicts { background: #512b2b; color: #ffb4b0; }
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select, input, textarea { border: 1px solid var(--border); }
button, select { min-height: 42px; }
button { padding: .62rem .9rem; border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 650; }
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
:root[data-theme="dark"] button.primary { color: #082523; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.icon-button { width: 42px; padding: 0; font-size: 1.6rem; line-height: 1; }
.skip-link { position: fixed; z-index: 10; left: 1rem; top: -5rem; padding: .7rem 1rem; background: var(--surface); color: var(--text); }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.app-header { min-height: 92px; padding: 1.25rem clamp(1rem, 4vw, 3.5rem); display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.65rem, 3vw, 2.15rem); letter-spacing: 0; }
h2 { margin-bottom: .3rem; font-size: 1.15rem; letter-spacing: 0; }
.eyebrow { margin-bottom: .18rem; color: var(--accent); font-size: .72rem; text-transform: uppercase; font-weight: 800; letter-spacing: .08em; }
.header-actions, .file-actions { display: flex; align-items: center; gap: .6rem; }
.theme-control { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .86rem; }
select { padding: .55rem 2rem .55rem .65rem; border-radius: 6px; background: var(--surface); color: var(--text); }
main { width: min(1180px, calc(100% - 2rem)); margin: 1.5rem auto 4rem; }
.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto auto; align-items: end; gap: .8rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.toolbar > label:not(.search-field) { display: grid; gap: .35rem; color: var(--muted); font-size: .78rem; font-weight: 700; }
.search-field { display: flex; align-items: center; gap: .45rem; min-height: 44px; padding: 0 .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.search-field:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.summary { display: flex; justify-content: space-between; align-items: end; gap: 1rem; padding: 1.4rem 0 1rem; }
.summary p { margin-bottom: 0; color: var(--muted); font-size: .88rem; }
.local-note span { color: var(--accent); }
.message { margin: 0 0 1rem; padding: .75rem 1rem; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.message.error { border-color: var(--danger); }
.evidence-list { display: grid; gap: .8rem; }
.evidence-card { display: grid; grid-template-columns: 1fr auto; gap: 1rem; padding: 1.15rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.card-title-row { display: flex; align-items: flex-start; gap: .6rem; }
.card-title { margin: 0; overflow-wrap: anywhere; font-size: 1.06rem; }
.badge { flex: none; padding: .22rem .5rem; border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: .7rem; font-weight: 750; text-transform: uppercase; }
.badge.supports { background: #dcefe5; color: #246242; }
.badge.mixed { background: #fff0ca; color: #72531b; }
.badge.contradicts { background: #f8dddd; color: #873535; }
:root[data-theme="dark"] .badge.supports { background: #204333; color: #9cdbb7; }
:root[data-theme="dark"] .badge.mixed { background: #483b20; color: #f0d486; }
:root[data-theme="dark"] .badge.contradicts { background: #512b2b; color: #ffb4b0; }
.source-link { display: inline-block; max-width: 100%; margin-top: .55rem; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes { margin: .8rem 0 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.card-meta { margin: .8rem 0 0; color: var(--muted); font-size: .76rem; }
.card-actions { display: flex; align-items: flex-start; gap: .4rem; }
.card-actions button { width: 42px; padding: 0; font-size: 1.05rem; }
.empty-state { padding: clamp(3rem, 10vw, 7rem) 1rem; text-align: center; }
.empty-state p { max-width: 470px; margin: .5rem auto 1.25rem; color: var(--muted); }
.empty-mark { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto 1rem; border: 1px solid var(--border); border-radius: 50%; color: var(--accent); font-size: 1.8rem; }
dialog { width: min(600px, calc(100% - 2rem)); padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 17, 19, .58); }
#evidence-form, .confirm-content { padding: 1.35rem; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 1.25rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .38rem; font-size: .86rem; font-weight: 750; }
.field input, .field select, .field textarea { width: 100%; padding: .7rem .75rem; border-radius: 5px; background: var(--bg); color: var(--text); }
.field textarea { resize: vertical; min-height: 110px; }
.field-error { min-height: 1.1em; margin: .3rem 0 0; color: var(--danger); font-size: .78rem; }
.field [aria-invalid="true"] { border-color: var(--danger); }
.character-count { margin: .25rem 0 0; text-align: right; color: var(--muted); font-size: .72rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .theme-control span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .file-actions { justify-content: flex-end; }
}
@media (max-width: 520px) {
  .app-header { display: block; }
  .header-actions { justify-content: space-between; margin-top: 1rem; }
  .toolbar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .file-actions { justify-content: stretch; }
  .file-actions button { flex: 1; }
  .summary { align-items: flex-start; }
  .local-note { display: none; }
  .evidence-card { grid-template-columns: minmax(0, 1fr); }
  .card-actions { border-top: 1px solid var(--border); padding-top: .75rem; justify-content: flex-end; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .evidence-card { transition: border-color .15s ease, background-color .15s ease, transform .15s ease; }
  .evidence-card:hover { transform: translateY(-1px); }
}
