[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #667085;
  --line: #d8dde6;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}
h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
h2 { font-size: 0.95rem; margin: 0 0 0.5rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.8rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; gap: 0.1rem; }
.inline-form { margin: 0; }
.who { display: flex; align-items: center; gap: 0.6rem; }
a.link-button { display: inline-block; }
.top-actions { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; justify-content: flex-end; }
a.guide-button {
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
  padding: 0.45rem 0.9rem; border-radius: 6px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 0.92rem; text-decoration: none; border: 1px solid var(--accent);
}
a.guide-button:hover { filter: brightness(1.1); }
a.guide-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .top-actions { width: 100%; justify-content: space-between; }
}

.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem;
  padding: 1rem 1.25rem; max-width: 1600px; margin: 0 auto;
}
.pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; min-width: 0;
}
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.pane-head h2 { margin: 0; }

textarea {
  width: 100%; min-height: 320px; resize: vertical; font-family: var(--mono); font-size: 13px;
  padding: 0.6rem; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff;
}
textarea:focus, select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#raw { min-height: 420px; }

.row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
select, input[type="password"] {
  font: inherit; padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}

fieldset.options { min-width: 0; 
  border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem 0.8rem; margin: 0;
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem;
}
fieldset.options legend { font-size: 0.8rem; color: var(--muted); padding: 0 0.3rem; }
fieldset.options label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.92rem; }
.select-label { gap: 0.5rem; flex-wrap: wrap; max-width: 100%; }
.select-label select { min-width: 0; max-width: 100%; }
input.meta-input { width: 14em; max-width: 100%; font: inherit; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 6px; }
input.num { width: 5.5em; font: inherit; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 6px; }

.actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
button {
  font: inherit; padding: 0.45rem 0.9rem; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.secondary { background: #fff; }
.link-button { border: none; background: none; color: var(--accent); text-decoration: underline; padding: 0.2rem; }
.status { font-size: 0.9rem; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); }
.tab {
  border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 0.4rem 0.7rem; color: var(--muted); font-weight: 600;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: flex; flex-direction: column; gap: 0.5rem; }

.file-drop {
  display: flex; align-items: center; justify-content: center; min-height: 160px;
  border: 2px dashed var(--line); border-radius: 8px; padding: 1rem; cursor: pointer; text-align: center; color: var(--muted);
}
.file-drop.has-file { border-color: var(--accent); color: var(--ink); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.rich {
  min-height: 320px; max-height: 60vh; overflow: auto; padding: 0.6rem 0.8rem;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 14px;
}
.rich:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rich img { max-width: 100%; height: auto; }
.rich h1, .rich h2, .rich h3 { text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0.6rem 0 0.3rem; }
.rich h1 { font-size: 1.4rem; } .rich h2 { font-size: 1.2rem; } .rich h3 { font-size: 1.05rem; }
.rich p { margin: 0.4rem 0; }
.captured { min-height: 1.2em; font-size: 0.85rem; }
details.exif { display: block; }
details.exif summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }
details.exif .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 0.8rem; width: 100%; margin-top: 0.5rem; }
details.exif .grid2 label { display: flex; flex-direction: column; align-items: stretch; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
details.exif .grid2 label.wide { grid-column: 1 / -1; }
details.exif input[type="text"], details.exif input[type="url"], details.exif input[type="tel"], details.exif select, details.exif textarea {
  font: inherit; font-size: 0.9rem; color: var(--ink); padding: 0.3rem 0.45rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
details.exif textarea { min-height: 0; font-family: var(--sans); resize: vertical; }
details.exif > p { width: 100%; margin: 0.3rem 0; }
@media (max-width: 600px) { details.exif .grid2 { grid-template-columns: 1fr; } }

.preview {
  min-height: 420px; max-height: 70vh; overflow: auto; padding: 0.75rem 1rem;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.preview h1, .preview h2, .preview h3 { color: var(--ink); text-transform: none; letter-spacing: 0; }
.preview h1 { font-size: 1.5rem; margin: 1rem 0 0.5rem; }
.preview h2 { font-size: 1.25rem; margin: 1rem 0 0.4rem; }
.preview h3 { font-size: 1.05rem; margin: 0.8rem 0 0.3rem; }
.preview p { margin: 0.5rem 0; }
.preview pre { background: #f2f4f7; padding: 0.6rem; border-radius: 6px; overflow: auto; font-family: var(--mono); font-size: 13px; }
.preview code { font-family: var(--mono); font-size: 0.92em; background: #f2f4f7; padding: 0 0.2em; border-radius: 3px; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin: 0.6rem 0; padding: 0.2rem 0.9rem; border-left: 3px solid var(--line); color: #344054; }
.preview table { border-collapse: collapse; margin: 0.6rem 0; max-width: 100%; }
.preview th, .preview td { border: 1px solid var(--line); padding: 0.3rem 0.6rem; text-align: left; vertical-align: top; }
.preview th { background: #f2f4f7; }
.preview a { color: var(--accent); }
.preview img { max-width: 100%; height: auto; }
.preview table { display: block; max-width: 100%; overflow-x: auto; }
.preview mark, .og-text mark { background: #ffe8a3; padding: 0 0.1em; }
body { overflow-x: hidden; }
.score-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.4rem; }
.score-result { display: inline-flex; align-items: baseline; gap: 0.6rem; }
.score-result .score-big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-result.err { color: var(--danger); }
button.busy { opacity: 0.7; cursor: progress; }
.preview.plain { white-space: pre-wrap; font-family: var(--mono); font-size: 13px; }

.report { display: flex; flex-direction: column; gap: 0.75rem; }
.report .summary { white-space: pre-wrap; font-size: 0.92rem; }
.report table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.report th, .report td { border-bottom: 1px solid var(--line); padding: 0.3rem 0.4rem; text-align: left; vertical-align: top; }
.report th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.report td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report .samples { font-family: var(--mono); font-size: 12px; color: #344054; word-break: break-word; }
.report .samples div { margin: 0.1rem 0; }
.report-json pre { font-size: 12px; max-height: 300px; overflow: auto; background: #f2f4f7; padding: 0.6rem; border-radius: 6px; }
.report .kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; font-size: 0.9rem; }
.report .kv dt { color: var(--muted); }
.report .kv dd { margin: 0; }
.report .warn { color: var(--danger); }
.report .ai-scores { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 0.2rem 0 0.4rem; }
.report .ai-score { text-align: center; }
.report .ai-num { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.report .ai-arrow { font-size: 28px; color: var(--muted); }
.report .ai-meta { font-size: 0.9rem; }
.detector-verdict { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.7rem; border-radius: 6px; font-weight: 600; margin: 0.3rem 0 0.5rem; border: 1px solid var(--line); }
.detector-verdict .verdict-flag { font-size: 1.1rem; }
.detector-verdict.verdict-both_clean { background: rgba(34,160,80,0.12); border-color: rgba(34,160,80,0.5); }
.detector-verdict.verdict-both_ai { background: rgba(200,40,40,0.12); border-color: rgba(200,40,40,0.5); }
.detector-verdict.verdict-disagree { background: rgba(220,160,20,0.14); border-color: rgba(220,160,20,0.55); }
.detector-verdict.verdict-incomplete { background: rgba(120,120,120,0.10); }
.score-result .score-big { font-weight: 700; margin-right: 0.6rem; }
.report .coverage-bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; max-width: 420px; margin: 0.1rem 0 0.4rem; }
.report .coverage-bar span { display: block; height: 100%; background: var(--accent); }
.report .coverage-warn { border-left: 3px solid var(--danger); padding-left: 0.6rem; margin: 0.3rem 0; }
.report table.coverage-reasons { font-size: 0.88rem; margin: 0.2rem 0 0.4rem; }
.report .og-text pre { white-space: pre-wrap; font-family: var(--sans); font-size: 0.92rem; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem; max-height: 320px; overflow: auto; }
.report .og-text mark { background: #ffe8a3; padding: 0 0.1em; }
.report h3 { font-size: 0.95rem; margin: 0.6rem 0 0.2rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.report .note { font-size: 0.85rem; color: var(--muted); border-left: 3px solid var(--line); padding-left: 0.6rem; margin: 0; }
.report .rw-status { font-size: 0.95rem; font-weight: 600; margin: 0.2rem 0; text-transform: none; letter-spacing: 0; color: var(--ink); }

/* progress panel: replaces the output views while a job runs */
.progress {
  min-height: 220px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0.6rem;
  padding: 1.5rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: center;
  opacity: 1; transition: opacity 300ms ease;
}
.progress.fading { opacity: 0; }
.progress-percent { font-size: 56px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); }
.progress-unit { font-size: 28px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.progress-track { width: 100%; max-width: 640px; height: 14px; background: #e6e9ef; border-radius: 7px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 7px; transition: width 600ms linear; }
.progress.error .progress-bar { background: var(--danger); }
.progress-stage { font-size: 1.15rem; font-weight: 600; }
.progress-detail { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.progress-error { color: var(--danger); font-weight: 600; max-width: 640px; }
.progress-actions { justify-content: center; }
@media (prefers-reduced-motion: reduce) {
  .progress, .progress-bar { transition: none; }
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem;
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 0.6rem;
}
.login-card form { display: flex; flex-direction: column; gap: 0.5rem; }
.login-card input { width: 100%; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; padding: 0.75rem; }
  textarea { min-height: 220px; }
  .preview { min-height: 260px; }
}

/* v0.17 rewrite library: nav, duplicate dialog, other versions, push lower, library page */
a.nav-link { color: var(--accent); font-weight: 600; text-decoration: none; padding: 0.3rem 0.4rem; }
a.nav-link:hover { text-decoration: underline; }
a.button-link {
  display: inline-block; padding: 0.45rem 0.9rem; border-radius: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--accent); text-decoration: none; font-size: 0.95rem;
}
a.button-link:hover { border-color: var(--accent); }
.dup-dialog { border: 1px solid var(--line); border-radius: 10px; padding: 1.2rem 1.4rem; max-width: 560px; width: calc(100% - 32px); color: var(--ink); }
.dup-dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.dup-dialog h2 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 1.15rem; }
.dup-lead { font-size: 1rem; font-weight: 600; margin: 0.2rem 0 0.6rem; }
.dup-dialog .kv, .lib-detail .kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; font-size: 0.92rem; margin: 0 0 0.6rem; }
.dup-dialog .kv dt, .lib-detail .kv dt { color: var(--muted); }
.dup-dialog .kv dd, .lib-detail .kv dd { margin: 0; word-break: break-word; }
.versions { border-top: 1px solid var(--line); margin-top: 0.8rem; padding-top: 0.6rem; display: flex; flex-direction: column; gap: 0.5rem; }
.versions-head { display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap; }
.versions-head h3 { font-size: 0.95rem; margin: 0; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.push-lower { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; }
.push-lower label { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.92rem; }
details.para-versions { border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.7rem; background: #fff; }
details.para-versions > summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }
.version { border-top: 1px solid var(--line); padding: 0.5rem 0; }
.version.winner { background: #f0f7ff; margin: 0 -0.7rem; padding: 0.5rem 0.7rem; }
.version.rejected .version-text { color: var(--muted); }
.version-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.85rem; }
.version-text { margin: 0.3rem 0; font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: #eef1f5; color: #344054; }
.badge.scored { background: #e7f0fd; color: #1849a9; }
.badge.chosen { background: var(--ok); color: #fff; }
.badge.bad { background: #fde8e7; color: var(--danger); }
button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.lib-main { max-width: 1200px; margin: 0 auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.8rem; }
.lib-search { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.lib-search input { flex: 1 1 260px; font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; }
.lib-list { display: flex; flex-direction: column; gap: 0.5rem; }
.lib-entry { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.lib-entry > summary { cursor: pointer; padding: 0.7rem 0.9rem; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) auto; gap: 0.3rem 1rem; align-items: baseline; }
.lib-entry[open] > summary { border-bottom: 1px solid var(--line); }
.lib-title { font-weight: 650; word-break: break-word; }
.lib-meta { font-size: 0.88rem; color: var(--muted); word-break: break-word; }
.lib-score { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lib-warn { font-weight: 500; font-size: 0.8rem; color: var(--danger); white-space: normal; }
.lib-detail { padding: 0.8rem 0.9rem; display: flex; flex-direction: column; gap: 0.6rem; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 0.5rem; }
.timeline li { position: relative; font-size: 0.9rem; }
.timeline li::before { content: ""; position: absolute; left: -1.38rem; top: 0.4rem; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--accent); }
.timeline li.ev-duplicate_shown::before, .timeline li.ev-rewrite_anyway::before { background: #dc6803; }
.timeline li.ev-view::before, .timeline li.ev-download::before, .timeline li.ev-copy::before { background: var(--line); }
.timeline .ev-when { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 0.4rem; }
.timeline .ev-who { font-weight: 600; }
@media (max-width: 700px) {
  .lib-entry > summary { grid-template-columns: 1fr; }
  .lib-main { padding: 0.75rem 16px; }
}
.lib-main .warn { color: var(--danger); }

.credit-estimate { display: block; margin: 4px 0; color: var(--warn, #9a3412); }
