:root {
  --bg: #fafafa;
  --panel-bg: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #2b2b2b;
  --ok: #1e7d34;
  --warn: #a15c00;
  --error: #b3261e;
  --focus: #2b6cb0;
}

* { box-sizing: border-box; }

/* Any element toggled via the `hidden` attribute must actually hide,
   even if it (or a class on it) also sets its own `display` value —
   the UA stylesheet's [hidden]{display:none} loses that fight at equal
   specificity to a later author rule like `.rank-badge{display:flex}`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--focus); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}

.app-header nav a {
  margin-right: 16px;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}

.app-header-user {
  color: var(--text-muted);
  font-size: 13px;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.outstanding-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(161, 92, 0, 0.12);
  color: var(--warn);
}

.outstanding-badge.status-ok {
  background: rgba(30, 125, 52, 0.12);
  color: var(--ok);
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

h1 { font-size: 22px; margin-bottom: 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p.note, .note { color: var(--text-muted); font-size: 13px; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  margin: 20px 0;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-page .panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

input[type="text"], input[type="password"], input[type="file"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

button {
  margin-top: 12px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

button:hover { background: #000; }

.error { color: var(--error); font-size: 13px; }

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.report-table th, .report-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.report-table th { color: var(--text-muted); width: 260px; font-weight: 500; }

.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }

.empty-state { color: var(--text-muted); }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}

.icon-card {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
}

/* Candidate cards are <button>s (review.php, judge.php, the search
   results grid) so they'd otherwise inherit the browser's native button
   chrome — which follows system dark mode — while the Material glyphs
   inside them are unrecoloured, default-black SVGs. Dark button +
   black icon is unreadable, so force a light card explicitly rather
   than let it depend on the visitor's OS theme. */
button.icon-card {
  background: var(--panel-bg);
  color: var(--text);
  font: inherit;
}

.icon-render {
  width: 100%;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-render svg { width: 48px; height: 48px; }

.icon-card figcaption {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}

#progress-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

#progress-bar-fill, .progress-fill {
  height: 100%;
  width: 0;
  background: var(--focus);
  transition: width 0.2s ease;
}

#upload-log {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 260px;
  overflow-y: auto;
  font-size: 13px;
}

#upload-log li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.log-ok { color: var(--ok); }
.log-error { color: var(--error); }
.log-info { color: var(--text-muted); }

.page-wide { max-width: 1200px; }

.calibrate-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.calibrate-row input[type="text"], .calibrate-row input[type="file"] {
  width: 100%;
}

.row-remove {
  margin: 0;
  padding: 4px 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

#add-row-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.primary-action { margin-left: 8px; }

.locked-weight-row { font-weight: 600; }

.calibrate-figure-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 8px 0;
}

.calibrate-figure {
  margin: 0;
  text-align: center;
}

.calibrate-canvas {
  width: 96px;
  height: 96px;
  border: 1px solid var(--border);
  background: #fff;
}

.calibrate-figure figcaption {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.calibrate-card {
  border-top: 1px solid var(--border);
  padding: 16px 0;
}

.calibrate-card:first-child { border-top: none; padding-top: 0; }

.calibrate-card h3 { margin: 0 0 8px; font-size: 15px; }

.calibrate-weight-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.calibrate-weight-group.best-match {
  border-color: var(--ok);
  background: rgba(30, 125, 52, 0.06);
}

.calibrate-weight-heading {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.calibrate-score {
  margin: 6px 0 0;
  font-size: 12px;
}

#run-log {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  max-height: 400px;
  overflow-y: auto;
  font-size: 13px;
}

#run-log li { padding: 4px 0; border-bottom: 1px solid var(--border); }

/* judgement-card is a plain div (icon-card gives it border/padding/
   background) so a real <button> can sit beside the clickable link
   without nesting interactive elements inside each other. */
.judgement-card a {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.judgement-card .retry-judgement-btn {
  margin-top: 10px;
  padding: 6px 10px;
  font-size: 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.judgement-card .retry-status:empty { display: none; }

.candidate-btn {
  position: relative;
  width: 100%;
  text-align: center;
  cursor: pointer;
  font: inherit;
  padding: 12px;
}

.candidate-btn.best-match {
  border-color: var(--ok);
  background: rgba(30, 125, 52, 0.06);
}

.rank-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.pick-row strong { min-width: 140px; }
.pick-row button { margin: 0; padding: 6px 10px; background: transparent; color: var(--text); border: 1px solid var(--border); }
.pick-row button.preset-active { background: var(--accent); color: #fff; }
.pick-row input[type="number"] { width: 70px; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.pick-row input[type="text"] { flex: 1; min-width: 160px; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }

.prompt-preview {
  white-space: pre-wrap;
  font-size: 12px;
  background: var(--bg);
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
}

kbd {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  background: var(--bg);
}

/* --- Phase 4: dashboard, review, to-do, export --- */

.status-banner {
  padding: 16px 20px;
  border-radius: 6px;
  margin: 20px 0;
  font-size: 15px;
}

.status-banner.status-ok { background: rgba(30, 125, 52, 0.08); color: var(--ok); }
.status-banner.status-warn { background: rgba(161, 92, 0, 0.08); color: var(--warn); }

.progress-segmented {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--border);
  margin: 12px 0;
}

.progress-segment { height: 100%; }
.segment-pending { background: var(--border); }
.segment-needs_review { background: var(--warn); }
.segment-approved { background: var(--ok); }
.segment-needs_rework { background: var(--error); }
.segment-rework_done { background: #4a7dbd; }

.state-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.state-counts a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}

.state-counts a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.table-scroll { overflow-x: auto; }
.icon-table { min-width: 640px; }
.icon-table td, .icon-table th { vertical-align: middle; white-space: nowrap; }
.icon-render-sm { width: 60px; height: 48px; padding: 4px !important; }
.icon-render-sm svg { width: 28px; height: 28px; }

.review-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.review-nav a.disabled { color: var(--border); pointer-events: none; }

.compare-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.compare-cell {
  border-radius: 6px;
  padding: 20px;
  text-align: center;
}

.compare-light { background: #ffffff; border: 1px solid var(--border); }
.compare-dark { background: #1a1a1a; }
.compare-dark .note { color: #999; }

.compare-render { height: 96px; }
.compare-render svg { width: 64px; height: 64px; }

.compare-sizes {
  display: flex;
  gap: 32px;
  margin-top: 16px;
  align-items: flex-end;
}

.compare-sizes > div { text-align: center; }
.size-24 svg { width: 24px; height: 24px; }
.size-48 svg { width: 48px; height: 48px; }

.decision-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.decision-btn { margin: 0; }

#search-box {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 12px;
}

#notes-field, #rework-note-field {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  margin-bottom: 8px;
}

.todo-row {
  display: grid;
  grid-template-columns: minmax(100px, 120px) minmax(100px, 120px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  align-items: start;
}

.todo-row:first-child { border-top: none; }
.todo-row .download-links { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.todo-row p { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

@media (max-width: 560px) {
  .todo-row { grid-template-columns: 1fr; }
}
.rework-note-display {
  background: rgba(161, 92, 0, 0.08);
  border-left: 3px solid var(--warn);
  padding: 8px 12px;
  margin: 8px 0;
}

.export-group {
  border-top: 1px solid var(--border);
  padding: 16px 0;
}
.export-group:first-child { border-top: none; }
.export-group h3 { margin: 0 0 8px; }
.export-file-list { font-size: 13px; }
.export-file-list a { margin-right: 12px; }

.status-banner p { margin: 0 0 8px; }
.status-banner p:last-child { margin-bottom: 0; }

.next-steps {
  margin: 0;
  padding-left: 20px;
}

.next-steps li { margin-bottom: 4px; }
.next-steps li:last-child { margin-bottom: 0; }

.illustrator-steps {
  padding-left: 20px;
}

.illustrator-steps li { margin-bottom: 6px; }

.upload-limits {
  font-size: 13px;
  color: var(--text-muted);
}

.button-link {
  display: inline-block;
  margin-top: 8px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-size: 14px;
}

.button-link:hover { background: #000; }
