:root {
  --bg: #faf9f7;
  --surface: #fff;
  --surface-muted: #f5f4f1;
  --border: #e5e2dd;
  --border-soft: #f0ede8;
  --text: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #737373;
  --green: #2d6a4f;
  --green-dark: #245c43;
  --green-mid: #40916c;
  --green-soft: #d8f3dc;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", -apple-system, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

.sev-high { --sev-bg: #fee2e2; --sev-fg: #991b1b; --sev-hl: rgba(220, 38, 38, .10); --sev-hl-on: rgba(220, 38, 38, .20); --sev-line: #dc2626; }
.sev-med { --sev-bg: #fef3c7; --sev-fg: #92400e; --sev-hl: rgba(245, 158, 11, .14); --sev-hl-on: rgba(245, 158, 11, .28); --sev-line: #d97706; }
.sev-low { --sev-bg: #dbeafe; --sev-fg: #1e40af; --sev-hl: rgba(59, 130, 246, .10); --sev-hl-on: rgba(59, 130, 246, .22); --sev-line: #3b82f6; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); text-decoration: underline; }
button { font: inherit; color: inherit; }
h1, h3, p { margin: 0; }

.muted { font-size: .8125rem; color: var(--text-muted); }
.eyebrow { font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 40; background: rgba(255, 255, 255, .95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: 1400px; height: 64px; margin: 0 auto; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; gap: 2rem; }
.topbar__brand { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.topbar__divider { width: 1px; height: 20px; background: var(--border); }
.topbar__section { font-family: var(--serif); font-size: 1rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.brand, .brand:hover { display: flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; }
.brand__mark { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; background: var(--text); border-radius: 6px; color: #fff; font-family: var(--serif); font-size: 16px; font-weight: 700; }
.brand__name { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; letter-spacing: -.02em; }
.model-chip { display: inline-flex; align-items: center; gap: .5rem; padding: .375rem .875rem; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 100px; font-size: .75rem; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.model-chip__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green-mid); }

/* Page shells */
.page { margin: 0 auto; display: flex; flex-direction: column; }
.page--upload { max-width: 960px; padding: 3rem 2rem 4rem; gap: 2rem; }
.page--narrow { max-width: 560px; padding: 5rem 2rem; }
.page--result { max-width: 1400px; padding: 1.75rem 2rem 4rem; gap: 1.5rem; }

/* Shared pieces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.card--padded { padding: 1.5rem; display: flex; flex-direction: column; gap: .75rem; }
.card__header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.card__title { font-family: var(--serif); font-size: 1.125rem; font-weight: 600; }
.card__empty { padding: 1.5rem; color: var(--text-muted); font-size: .875rem; }

.button { display: inline-flex; align-items: center; gap: .5rem; padding: .625rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: .875rem; font-weight: 500; color: var(--text); white-space: nowrap; cursor: pointer; transition: all .15s ease; }
.button:hover { background: var(--surface-muted); border-color: var(--text-muted); color: var(--text); text-decoration: none; }
.button--primary { background: var(--green); border-color: var(--green); color: #fff; }
.button--primary:hover { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }
.button--small { gap: .375rem; padding: .375rem .75rem; font-size: .8125rem; color: var(--text-secondary); }
.button--small.button--primary { color: #fff; }
.button--ghost { padding-inline: .5rem; border-color: transparent; background: none; color: var(--text-muted); }
.button--ghost:hover { border-color: transparent; background: none; color: var(--text); }
.button:focus-visible, .chip:focus-visible, .stat:focus-visible, .risk__summary:focus-visible, .hl:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.badge { padding: .125rem .5rem; border-radius: 100px; background: var(--sev-bg); color: var(--sev-fg); font-size: .6875rem; font-weight: 600; }
.badge--caps { font-size: .625rem; text-transform: uppercase; letter-spacing: .03em; }

.notice { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; }
.notice--error { background: #fee2e2; color: #991b1b; }

/* Upload screen */
.intro { display: flex; flex-direction: column; gap: .5rem; }
.intro__title { font-family: var(--serif); font-size: 2rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.intro__lead { max-width: 620px; font-size: .9375rem; color: var(--text-muted); text-wrap: pretty; }

.dropzone { padding: 4rem 1.5rem; display: flex; flex-direction: column; align-items: center; gap: .25rem; text-align: center; background: var(--surface-muted); border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; transition: all .15s ease; }
.dropzone--active { background: var(--green-soft); border-color: var(--green); }
.dropzone__icon { margin-bottom: .75rem; color: var(--text-muted); }
.dropzone__title { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.dropzone__hint { font-size: .8125rem; color: var(--text-muted); }
.dropzone__button { margin-top: 1.25rem; }

.recent__row { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.4fr) minmax(0, 1fr) 140px; align-items: center; gap: .75rem; padding: .875rem 1.5rem; }
.recent__head { padding-block: .625rem; background: var(--surface-muted); font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.recent__item, .recent__item:hover { border-top: 1px solid var(--border-soft); color: var(--text); text-decoration: none; transition: background .1s ease; }
.recent__item:hover { background: var(--bg); }
.recent__name { display: flex; align-items: center; gap: .625rem; min-width: 0; font-weight: 500; }
.recent__name svg { flex-shrink: 0; color: var(--text-muted); }
.recent__name span, .recent__party { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent__party { color: var(--text-secondary); }
.recent__date { font-size: .8125rem; color: var(--text-muted); }
.recent__risks { display: flex; gap: .375rem; }

/* Processing and failure */
.progress__header { padding: 1.25rem 1.5rem; display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid var(--border-soft); color: var(--text-muted); }
.progress__header svg { flex-shrink: 0; }
.progress__file { display: flex; flex-direction: column; min-width: 0; }
.progress__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--serif); font-size: 1.0625rem; font-weight: 600; color: var(--text); }
.progress__hint { font-size: .75rem; }
.progress__steps { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .875rem; }
.progress__track { height: 3px; background: var(--border-soft); }
.progress__bar { height: 3px; background: var(--green); transition: width .6s ease; }

.step { display: flex; align-items: center; gap: .75rem; font-size: .875rem; color: var(--text-muted); }
.step--done, .step--current { color: var(--text); }
.step--current { font-weight: 600; }
.step__icon { width: 22px; height: 22px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--green); }
.step__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--green-soft); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.failed__title { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.failed__file { color: var(--text-muted); font-size: .875rem; overflow-wrap: anywhere; }

/* Result screen */
.result__header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.result__heading { display: flex; flex-direction: column; gap: .375rem; min-width: 0; }
.result__title { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; overflow-wrap: anywhere; }
.result__meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .8125rem; color: var(--text-muted); }
.back-link, .back-link:hover { display: inline-flex; align-items: center; gap: .25rem; align-self: flex-start; font-size: .8125rem; color: var(--text-muted); }

.summary { padding: 1.25rem 1.5rem; display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; }
.summary__verdict { flex: 2 1 300px; display: flex; flex-direction: column; gap: .25rem; }
.summary__text { font-family: var(--serif); font-size: 1rem; line-height: 1.45; text-wrap: pretty; }
.summary__stats { flex: 1 1 360px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.stat { display: flex; flex-direction: column; gap: .125rem; padding: .75rem 1rem; text-align: left; background: var(--bg); border: 1px solid var(--border-soft); border-radius: 8px; cursor: pointer; transition: all .15s ease; }
.stat[aria-pressed="true"] { background: var(--sev-bg); border-color: var(--sev-line); }
.stat__count { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; line-height: 1.6; color: var(--sev-fg); }
.stat__label { font-size: .75rem; font-weight: 500; color: var(--text-secondary); }

.workspace { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.5rem; }

.document { flex: 1 1 400px; min-width: 0; }
.document__bar { padding: .75rem 1.5rem; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; background: var(--surface-muted); border-bottom: 1px solid var(--border-soft); font-size: .75rem; color: var(--text-muted); }
.document__body { max-width: 760px; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1.25rem, 4vw, 3rem) 4rem; font-family: var(--serif); font-size: 1rem; line-height: 1.75; overflow-wrap: break-word; }
.document__title { margin-bottom: 2.25rem; text-align: center; font-size: .9375rem; color: var(--text-secondary); }
.document__title > :first-child { font-size: 1.375rem; font-weight: 700; letter-spacing: .02em; line-height: 1.35; color: var(--text); }
.block { margin-bottom: 1.5rem; text-wrap: pretty; }
.block--heading { margin-bottom: .375rem; font-weight: 600; }

.hl { padding: 1px 2px; background: var(--sev-hl); border-bottom: 2px solid var(--sev-line); border-radius: 2px; cursor: pointer; transition: all .15s ease; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.hl[data-selected="true"] { background: var(--sev-hl-on); box-shadow: 0 0 0 2px var(--sev-line); }
.hl[data-resolved="true"] { --sev-line: var(--green-mid); background: rgba(45, 106, 79, .08); }
.hl__number { margin-left: 2px; font-family: var(--sans); font-size: .625rem; font-weight: 700; color: var(--sev-line); }

.risks { flex: 0 1 400px; min-width: 320px; position: sticky; top: 88px; max-height: calc(100vh - 112px); display: flex; flex-direction: column; }
.risks__header { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; border-bottom: 1px solid var(--border-soft); }
.risks__heading { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.risks__resolved { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }
.risks__list { position: relative; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .625rem; }

.chips { display: flex; flex-wrap: wrap; gap: .375rem; }
.chip { padding: .25rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 100px; font-size: .75rem; font-weight: 500; color: var(--text-secondary); cursor: pointer; transition: all .15s ease; }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }

.risk { flex-shrink: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; transition: all .15s ease; }
.risk[data-open="true"] { border-color: var(--sev-line); }
.risk[data-resolved="true"]:not([data-open="true"]) { opacity: .6; }
.risk__summary { width: 100%; padding: .875rem 1rem; display: flex; flex-direction: column; gap: .375rem; text-align: left; background: none; border: 0; border-radius: 10px; cursor: pointer; }
.risk__tags { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.risk__number { font-family: var(--mono); font-size: .75rem; font-weight: 600; color: var(--sev-fg); }
.risk__status { margin-left: auto; font-size: .6875rem; font-weight: 600; color: var(--green); }
.risk__title { font-size: .875rem; font-weight: 600; line-height: 1.4; }
.risk__text { font-size: .8125rem; line-height: 1.5; color: var(--text-secondary); text-wrap: pretty; }
.risk__details { padding: .875rem 1rem; display: flex; flex-direction: column; gap: .75rem; border-top: 1px solid var(--border-soft); }
.risk__field { display: flex; flex-direction: column; gap: .25rem; }
.risk__suggestion { padding: .625rem .75rem; background: var(--surface-muted); border: 1px solid var(--border-soft); border-radius: 8px; font-family: var(--serif); font-size: .875rem; line-height: 1.55; }
.risk__mirror { padding: .625rem .75rem; display: flex; gap: .625rem; background: var(--green-soft); border-radius: 8px; }
.risk__mirror svg { flex-shrink: 0; margin-top: 2px; color: var(--green); }
.risk__mirror > div { display: flex; flex-direction: column; }
.risk__mirror .eyebrow { color: var(--green); }
.risk__mirror-text { font-size: .8125rem; line-height: 1.5; }
.risk__actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (max-width: 640px) {
  .topbar__inner, .page--upload, .page--narrow, .page--result { padding-inline: 1rem; }
  .topbar__divider, .topbar__section { display: none; }
  .recent__row { grid-template-columns: minmax(0, 1fr) auto; }
  .recent__head span:nth-child(2), .recent__head span:nth-child(3), .recent__party, .recent__date { display: none; }
  .risks { position: static; max-height: none; min-width: 0; flex-basis: 100%; }
}
