:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --ink: #1e2522;
  --muted: #64706a;
  --line: #d9ddd7;
  --accent: #2f6b5f;
  --accent-soft: #e2efeb;
  --warn: #9a6415;
  --warn-soft: #f8edd8;
  --bad: #9b3535;
  --bad-soft: #f7e3e3;
  --good: #2d6a3f;
  --good-soft: #e2f0e5;
  --shadow: 0 1px 2px rgba(30, 37, 34, .06), 0 8px 24px rgba(30, 37, 34, .05);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.5rem, 2.4vw, 2.1rem); letter-spacing: -.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.2rem; }
p { margin: .35rem 0 .8rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: .86rem; }
.muted { color: var(--muted); }
.warn-text { color: var(--warn); }
.center { text-align: center; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .8rem clamp(1rem, 3vw, 2rem);
  background: #fbfaf6;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2rem; height: 2rem;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .03em;
}
.brand-mark.big { width: 3rem; height: 3rem; font-size: 1rem; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a {
  padding: .45rem .7rem;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
  font-size: .94rem;
}
.mainnav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.mainnav a.active { background: var(--accent); color: #fff; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; font-size: .88rem; }
.user-name { color: var(--muted); }
.smalllink { font-size: .86rem; font-weight: 600; }
.linkbtn {
  border: 0; background: none; padding: 0; color: var(--accent);
  font: inherit; font-weight: 700; cursor: pointer;
}
.linkbtn:hover { text-decoration: underline; }
.linkbtn.danger { color: var(--bad); }

.container { width: min(1220px, 100%); margin: 0 auto; padding: 1.4rem clamp(1rem, 3vw, 2rem) 3rem; }
.footer {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1rem clamp(1rem, 3vw, 2rem) 2rem;
  color: var(--muted); font-size: .8rem;
}

.pagehead {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem;
}
.pagehead p { margin-bottom: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 800; color: var(--muted); margin-bottom: .4rem; }
.head-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.stats.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat {
  display: flex; flex-direction: column; gap: .15rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.05rem;
  color: var(--ink); box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
}
a.stat:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.stat.warn { border-left-color: var(--warn); }
.stat.bad { border-left-color: var(--bad); }
.stat.good { border-left-color: var(--good); }
.stat.accent { border-left-color: var(--accent); }
.stat-label { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat strong { font-size: 1.9rem; line-height: 1.1; }
.stat-note { font-size: .8rem; color: var(--muted); }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(.9rem, 2vw, 1.3rem);
  margin-bottom: 1rem; box-shadow: var(--shadow);
  min-width: 0;
}
.panel.narrow { max-width: 560px; margin-inline: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 980px) { .split { grid-template-columns: 1fr; } }

.tablewrap { overflow-x: auto; margin: 0 -.25rem; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
th a { color: var(--muted); }
tbody tr:hover { background: #faf9f5; }
td input[type="text"] { min-width: 8rem; }
.subline { display: block; font-size: .78rem; color: var(--muted); margin-top: .12rem; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  border-radius: 999px; padding: .18rem .55rem;
  font-size: .76rem; font-weight: 800; white-space: nowrap;
  background: #eceeea; color: #3e4843;
}
.badge-soft { background: var(--accent-soft); color: var(--accent); }
.badge-needs_review { background: var(--warn-soft); color: var(--warn); }
.badge-ready, .badge-approved { background: var(--good-soft); color: var(--good); }
.badge-archived, .badge-classified { background: var(--accent-soft); color: var(--accent); }
.badge-failed, .badge-rejected { background: var(--bad-soft); color: var(--bad); }
.badge-processing, .badge-received { background: #e8edf5; color: #34527a; }

.conf { font-weight: 800; font-variant-numeric: tabular-nums; }
.conf.good { color: var(--good); }
.conf.warn { color: var(--warn); }
.conf.bad { color: var(--bad); }
.conf.unknown { color: var(--muted); }

.filters {
  display: flex; gap: .7rem; flex-wrap: wrap; align-items: end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem; margin-bottom: 1rem;
}
.filters label { min-width: 9rem; }
.filters .grow { flex: 1 1 16rem; }
.filter-actions { display: flex; gap: .5rem; }

label { display: flex; flex-direction: column; gap: .28rem; font-size: .82rem; font-weight: 700; color: #414b46; }
input, select, textarea {
  width: 100%; border: 1px solid #c9d0ca; border-radius: 9px;
  background: #fff; color: var(--ink); padding: .5rem .6rem;
  font: inherit; font-size: .9rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; margin: 0 0 .8rem; }
legend { font-size: .8rem; font-weight: 800; color: var(--muted); padding: 0 .35rem; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .7rem; align-items: end; }
.formgrid .align-end { display: flex; align-items: end; }
.stack { display: flex; flex-direction: column; gap: .7rem; }
.inline { display: inline; }
.inline-form { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; margin-top: .8rem; }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .45rem; }
.check { flex-direction: row; align-items: flex-start; gap: .55rem; font-weight: 500; padding: .35rem .4rem; border-radius: 8px; }
.check input { width: auto; margin-top: .2rem; }
.check:hover { background: #faf9f5; }
.check.confirm { background: var(--accent-soft); border: 1px solid #cfe3dc; padding: .6rem .7rem; }
.check span { font-size: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid #c9d0ca; border-radius: 9px; background: #fff;
  color: var(--ink); padding: .5rem .8rem; font: inherit; font-size: .88rem;
  font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #25574e; color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #7f2a2a; color: #fff; }
.btn.small { padding: .3rem .55rem; font-size: .8rem; }
.btn.wide { width: 100%; }
.btn.disabled { opacity: .45; pointer-events: none; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding-top: .9rem; flex-wrap: wrap; }
.pager span { color: var(--muted); font-size: .85rem; }

.pdf-frame { width: 100%; height: 68vh; min-height: 380px; border: 1px solid var(--line); border-radius: 10px; background: #e9ece8; }
.pdf-frame.short { height: 46vh; min-height: 300px; }
.meta { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .3rem .8rem; margin: .6rem 0 1rem; font-size: .9rem; }
.meta dt { color: var(--muted); font-weight: 700; }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.rawbox { margin: .8rem 0; }
.rawbox summary { cursor: pointer; color: var(--accent); font-weight: 700; font-size: .86rem; }
.ocrpage { border: 1px solid var(--line); border-radius: 10px; margin: .5rem 0; background: #fcfbf8; }
.ocrpage summary { cursor: pointer; display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; padding: .6rem .7rem; font-weight: 700; }
.ocr-text {
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: #f7f6f1; border: 1px solid var(--line); border-radius: 8px;
  padding: .8rem; max-height: 24rem; overflow: auto;
  font-size: .82rem; line-height: 1.45; margin: .6rem 0 0;
}
.ocrpage .ocr-text { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; max-height: 30rem; }

.eventlist { list-style: none; margin: 0; padding: 0; }
.eventlist li { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.eventlist li:last-child { border-bottom: 0; }
.event-action { font-weight: 700; font-family: ui-monospace, monospace; font-size: .82rem; }

.flashes { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1rem; }
.flash { border-radius: 10px; padding: .65rem .8rem; font-size: .9rem; border: 1px solid transparent; }
.flash-ok { background: var(--good-soft); border-color: #c7e0cd; color: #1f4d2c; }
.flash-error { background: var(--bad-soft); border-color: #e7c3c3; color: #6f2323; }
.flash-warn { background: var(--warn-soft); border-color: #ead3a9; color: #6e470d; }
.notice { border-radius: 10px; padding: .7rem .85rem; margin-bottom: 1rem; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); border-color: #ead3a9; color: #6e470d; }
.notice.good { background: var(--good-soft); border-color: #c7e0cd; color: #1f4d2c; }

.login-body { background: radial-gradient(circle at 20% 10%, #e6efe9, transparent 42%), var(--bg); min-height: 100vh; }
.login-card {
  width: min(420px, 100%); margin: 8vh auto 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; padding: 1.6rem;
  box-shadow: 0 18px 60px rgba(30, 37, 34, .12);
}
.login-head { text-align: center; margin-bottom: 1.3rem; }
.login-head h1 { margin-top: .7rem; }
.login-head .brand-mark { margin: 0 auto; }
.login-card code { background: #f1f2ed; padding: .1rem .3rem; border-radius: 5px; }

@media (max-width: 760px) {
  .topbar { position: static; }
  .userbox { margin-left: 0; width: 100%; justify-content: space-between; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .6rem; padding: .35rem .55rem; background: #fff; }
  table.responsive td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .32rem 0; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-weight: 700; font-size: .78rem; flex: 0 0 42%; }
  table.responsive td input[type="text"] { min-width: 0; }
  .meta { grid-template-columns: 1fr; gap: .1rem; }
  .meta dt { margin-top: .4rem; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label, .filters .grow { flex: 1 1 auto; }
  .filter-actions { justify-content: stretch; }
  .filter-actions .btn { flex: 1; }
  .pdf-frame { height: 55vh; }
}

/* Review workspace v2 */
.review-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.45fr); gap: 1rem; align-items: start; }
.page-panel { position: sticky; top: 5.2rem; }
.page-tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin: .3rem 0 .7rem; }
.page-tab { display: inline-flex; align-items: center; gap: .25rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: .82rem; font-weight: 700; }
.page-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-tab .rot { font-size: .68rem; opacity: .75; }
.page-image { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 10px 26px rgba(30,37,34,.08); }
.rotate-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0; }
.btn.small { padding: .3rem .55rem; font-size: .78rem; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: #8a2323; border-color: #e0b4b4; }
.meta.compact { grid-template-columns: 8rem minmax(0,1fr); font-size: .82rem; }
.bulkbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; padding: .6rem; margin-bottom: .6rem; border: 1px solid var(--line); border-radius: 10px; background: #f7f8f4; }
.bulkbar label { display: flex; flex-direction: column; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 700; }
.bulkbar .grow { flex: 1 1 18rem; }
.bulkbar input[type="text"], .bulkbar select { min-width: 9rem; }
.candidate-table td { vertical-align: top; }
.cell-input { width: 100%; min-width: 6.5rem; border: 1px solid #dfe2da; border-radius: 6px; padding: .32rem .4rem; font: inherit; font-size: .82rem; background: #fff; }
.cell-input.term { font-weight: 700; }
.cell-input.translation { min-width: 11rem; }
.cell-input:disabled { background: #f2f2ee; color: #555; }
tr.lowconf { background: #fff8e8; }
tr.lowconf .cell-input { border-color: #e2bf7e; }
tr.reviewed { opacity: .78; }
.sourcebox summary { cursor: pointer; color: var(--accent); font-size: .76rem; font-weight: 700; }
.cells { list-style: none; padding: 0; margin: .35rem 0 0; font-size: .76rem; }
.cells li { padding: .15rem 0; border-bottom: 1px dotted var(--line); }
.subline { display: block; color: var(--muted); font-size: .72rem; font-weight: 500; }
.notice.warn-text, .warn-text { color: #6e470d; }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .5rem; }
@media (max-width: 1100px) { .review-grid { grid-template-columns: 1fr; } .page-panel { position: static; } }
@media (max-width: 760px) {
  .bulkbar { align-items: stretch; }
  .bulkbar label, .bulkbar .grow, .bulkbar .btn { flex: 1 1 100%; }
  .candidate-table td { align-items: flex-start; }
  .candidate-table td::before { flex-basis: 34%; }
}

