[hidden] { display: none !important; }

:root {
  --ink: #17202b;
  --muted: #5f6c79;
  --paper: #ffffff;
  --page: #eef1f4;
  --line: #d7dde3;
  --line-strong: #b7c1cc;
  --accent: #1e5a92;
  --accent-soft: #e8f1f9;
  --success: #176b43;
  --warning: #895d00;
  --danger: #9c2f2f;
  --shadow: 0 8px 24px rgba(28, 42, 56, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 0; background: var(--page); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
img { display: block; max-width: 100%; }

.app-shell { min-height: 100vh; }
.site-header {
  position: relative; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 18px clamp(16px, 3vw, 44px);
  background: rgba(255,255,255,.97); border-bottom: 1px solid var(--line);
}
.brand-block, .header-actions, .progress-block, .case-heading, .review-column, .case-card, .choice-row, .field-grid { min-width: 0; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, h3, h4, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(20px, 2vw, 28px); line-height: 1.15; }
h2 { margin: 0; font-size: 19px; line-height: 1.25; }
h3 { margin: 0; font-size: 17px; line-height: 1.3; }
h4 { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.header-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.progress-block { width: min(240px, 26vw); }
.progress-label { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.progress-track { height: 7px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: #e3e7eb; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.save-status { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.save-status[data-state="saved"] { color: var(--success); border-color: #acd3be; background: #f2faf5; }
.save-status[data-state="saving"], .save-status[data-state="unsaved"] { color: var(--warning); border-color: #e1ca8d; background: #fffaf0; }
.save-status[data-state="conflict"], .save-status[data-state="failed"] { color: var(--danger); border-color: #e1adad; background: #fff5f5; }

.button, .icon-button { min-height: 44px; border: 1px solid transparent; border-radius: 6px; padding: 9px 14px; font-weight: 750; text-decoration: none; }
.button-primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.button-primary:hover, .button-primary:focus-visible { background: #154873; }
.button-secondary { color: var(--ink); background: var(--paper); border-color: var(--line-strong); }
.button-secondary:hover, .button-secondary:focus-visible { background: #f5f7f9; }
.button-small { min-height: 44px; padding: 8px 11px; font-size: 12px; }
.full-width { width: 100%; }
.icon-button { width: 44px; padding: 0; color: var(--muted); background: transparent; font-size: 28px; line-height: 1; }

.global-notice { max-width: 1180px; margin: 16px auto 0; padding: 12px 14px; border: 1px solid #e1ca8d; border-radius: 6px; color: #694800; background: #fffaf0; font-size: 14px; }
.global-notice[data-tone="error"] { color: var(--danger); border-color: #e1adad; background: #fff5f5; }
.global-notice[data-tone="success"] { color: var(--success); border-color: #acd3be; background: #f2faf5; }
.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 26px; width: min(1480px, 100%); margin: 0 auto; padding: 28px clamp(16px, 3vw, 44px) 64px; }
.case-sidebar { align-self: start; position: sticky; top: 16px; min-width: 0; padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.sidebar-heading { display: flex; align-items: start; justify-content: space-between; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.count-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 7px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 12px; font-weight: 800; }
.case-nav { display: grid; gap: 6px; padding: 14px 0; }
.case-link { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 50px; width: 100%; padding: 7px 8px; border: 1px solid transparent; border-radius: 6px; color: var(--ink); background: transparent; text-align: left; }
.case-link:hover { background: #f5f7f9; }
.case-link[aria-current="page"] { border-color: #aac4da; background: var(--accent-soft); }
.case-number { font-weight: 800; }
.case-file { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.case-progress { color: var(--muted); font-size: 11px; font-weight: 750; }
.privacy-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.review-column { width: 100%; max-width: 1010px; }
.case-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.case-heading-main { min-width: 0; }
.case-heading h2 { font-size: clamp(22px, 3vw, 31px); }
.case-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.case-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.case-card { margin-bottom: 18px; padding: clamp(16px, 2.2vw, 26px); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 15px; }
.section-kicker { margin: 0; color: var(--muted); font-size: 12px; }
.metadata-row { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.metadata-row strong { color: var(--ink); }

.source-layout { display: grid; grid-template-columns: minmax(0, 1fr) 245px; gap: 18px; align-items: start; }
.source-viewport { min-height: 270px; max-height: 520px; overflow: hidden; display: flex; justify-content: center; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: #f4f5f6; }
.source-image { width: 100%; max-height: 490px; object-fit: contain; transform-origin: center center; transition: transform .12s ease; }
.source-fallback { color: var(--muted); font-size: 13px; }
.source-tools { display: grid; gap: 12px; }
.source-tools label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.range-input { width: 100%; min-height: 44px; accent-color: var(--accent); }
.image-caption { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.reading-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.reading { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 5px; background: #fbfcfd; }
.reading-label { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.reading-label span { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; border-radius: 4px; color: #fff; background: var(--accent); }
.reading-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: Georgia, "Times New Roman", serif; font-size: 16px; line-height: 1.65; }
.reading-third { grid-column: 1 / -1; }

.difference-list { display: grid; gap: 14px; }
.difference-card { min-width: 0; padding: 16px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
.difference-card[data-save-state="conflict"], .difference-card[data-save-state="failed"] { border-color: #d98c8c; }
.difference-card[data-save-state="saved"] { border-color: #b5d9c5; }
.difference-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.difference-title { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.difference-number { color: var(--accent); font-size: 13px; font-weight: 850; }
.card-save-state { flex: 0 0 auto; color: var(--muted); font-size: 12px; font-weight: 750; }
.context-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.context-box { min-width: 0; padding: 10px; border-left: 3px solid var(--line-strong); background: #f7f8fa; }
.context-box[data-side="a"] { border-left-color: #6e9bc2; }
.context-box[data-side="b"] { border-left-color: #9b7ab8; }
.context-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.context-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.choice-fieldset { min-width: 0; margin: 0 0 14px; padding: 0; border: 0; }
.choice-fieldset legend { margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
.choice-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.choice-option { position: relative; min-width: 0; }
.choice-option input { position: absolute; opacity: 0; pointer-events: none; }
.choice-option label { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 7px 5px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); background: #fff; font-size: 12px; font-weight: 800; text-align: center; }
.choice-option label:hover { background: #f5f7f9; }
.choice-option input:checked + label { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-option input:focus-visible + label { outline: 3px solid rgba(30,90,146,.28); outline-offset: 2px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field-label { color: var(--muted); font-size: 12px; font-weight: 800; }
.text-input, .select-input, .note-input { width: 100%; min-width: 0; min-height: 44px; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); background: #fff; }
.note-input { min-height: 76px; resize: vertical; }
.text-input:focus, .select-input:focus, .note-input:focus { outline: 3px solid rgba(30,90,146,.18); border-color: var(--accent); }
.text-input:disabled { color: var(--muted); background: #f1f3f5; }
.element-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.element-help { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.conflict-message { margin: 10px 0 0; padding: 9px 10px; border-left: 3px solid var(--danger); color: var(--danger); background: #fff5f5; font-size: 12px; line-height: 1.45; }

.submission-panel { position: relative; width: min(1180px, calc(100% - 32px)); margin: 16px auto; padding: 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.submission-panel h2 { margin-bottom: 6px; }
.submission-panel p { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.submission-panel[data-status="received"] { border-color: #acd3be; }
.submission-panel[data-status="failed"] { border-color: #e1adad; }
.submission-panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(23,32,43,.48); }
.access-dialog { width: min(420px, 100%); padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.access-dialog h2 { margin-bottom: 9px; }
.access-dialog p:not(.eyebrow):not(.inline-error) { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.access-dialog form { display: grid; gap: 8px; }
.inline-error { margin: 12px 0 0; color: var(--danger); font-size: 13px; }
.image-dialog { width: min(960px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.image-dialog::backdrop { background: rgba(23,32,43,.72); }
.dialog-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.dialog-image-wrap { max-height: calc(100vh - 160px); overflow: auto; margin-bottom: 12px; background: #f4f5f6; }
.dialog-image-wrap img { width: 100%; height: auto; }

@media (max-width: 940px) {
  .site-header { align-items: flex-start; flex-direction: column; gap: 14px; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .progress-block { width: min(300px, 100%); }
  .workspace { grid-template-columns: 205px minmax(0, 1fr); gap: 16px; }
  .source-layout { grid-template-columns: 1fr; }
  .source-tools { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; }
  .source-tools .image-caption { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .workspace { display: block; padding-top: 16px; }
  .case-sidebar { position: static; margin-bottom: 18px; }
  .case-nav { display: flex; overflow-x: auto; gap: 7px; padding-bottom: 8px; }
  .case-link { flex: 0 0 150px; grid-template-columns: 27px minmax(0, 1fr); }
  .case-progress { grid-column: 2; }
  .privacy-note { max-width: 620px; }
  .case-heading { align-items: flex-start; flex-direction: column; }
  .case-actions { justify-content: flex-start; }
  .reading-grid, .context-grid, .field-grid { grid-template-columns: 1fr; }
  .reading-third, .field-wide { grid-column: auto; }
  .source-tools { grid-template-columns: 1fr 1fr; }
  .source-tools .image-caption { grid-column: 1 / -1; }
}

@media (max-width: 430px) {
  .site-header { padding: 14px 12px; }
  .workspace { padding-right: 12px; padding-left: 12px; }
  .header-actions { gap: 7px; }
  .progress-block { flex: 1 1 100%; }
  .save-status { order: 4; width: 100%; justify-content: center; }
  .button { padding-right: 11px; padding-left: 11px; }
  .case-card { padding: 14px; }
  .choice-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-option:last-child { grid-column: 1 / -1; }
  .difference-header, .element-footer { align-items: flex-start; flex-direction: column; }
  .element-footer .button { width: 100%; }
  .source-tools { grid-template-columns: 1fr; }
  .submission-panel { right: 12px; bottom: 12px; width: calc(100% - 24px); }
}
