:root {
  --bg: #0f1216;
  --bg-elev: #171b21;
  --bg-hover: #1e242c;
  --line: #2a313b;
  --text: #eceff3;
  --muted: #8b95a3;
  --accent: #6ea8ff;
  --ok: #3dd68c;
  --ok-bg: #143325;
  --ko: #ff6b6b;
  --ko-bg: #3a1717;
  --fix: #e7c065;
  --fix-bg: #3a2f14;
  --warn: #e7c065;
  --tech: #7ee0c6;
  --com: #9bb7ff;
  --oth: #c9b8a6;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  flex: 0 0 auto;
  min-height: 64px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand strong { font-size: 14px; letter-spacing: 0.02em; }
.brand span { font-size: 12px; color: var(--muted); }

.review-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 420px;
  min-width: 0;
  flex-wrap: wrap;
}

.review-actions select {
  width: auto;
  min-width: 148px;
  max-width: 210px;
  flex: 0 1 auto;
}

.justification {
  flex: 1 1 160px;
  min-width: 140px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  outline: none;
}
.justification:focus { border-color: #4a5d78; }

.btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms var(--ease), filter 140ms var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-ok { background: var(--ok); color: #062113; }
.btn-correct { background: var(--fix); color: #2a1e04; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 500;
  padding: 5px 10px;
  font-size: 12px;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.06); }
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 22%) minmax(360px, 38%) minmax(320px, 40%);
  flex: 1;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.pane:last-child { border-right: 0; }

.pane-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #14181e;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.search, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
}
.search { grid-column: 1 / -1; }

.list {
  overflow: auto;
  flex: 1;
}
.row {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #222831;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 120ms var(--ease);
}
.row:hover { background: var(--bg-hover); }
.row.active { background: #243044; }
.row-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  font-weight: 600;
}
.badge.com { background: #1c2a4a; color: var(--com); }
.badge.tech { background: #16332c; color: var(--tech); }
.badge.oth { background: #2c261f; color: var(--oth); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.ko { background: var(--ko-bg); color: var(--ko); }
.badge.corrected { background: var(--fix-bg); color: var(--fix); }
.row-fix { color: var(--fix); }

.detail {
  overflow: auto;
  flex: 1;
  padding: 16px 18px 32px;
}
.kicker { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.h-title { font-size: 20px; margin: 4px 0 12px; }
.grid-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin-bottom: 18px;
  font-size: 13px;
}
.grid-facts dt { color: var(--muted); }
.grid-facts dd { margin: 0; word-break: break-word; }

.evidence { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.ev-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.ev-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.ev-score { color: var(--accent); font-family: var(--mono); font-size: 12px; }
.snippet {
  font-size: 12px;
  color: #c5ccd6;
  white-space: pre-wrap;
  max-height: 140px;
  overflow: auto;
  line-height: 1.45;
}

.extract {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  background: #10141a;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.viewer {
  flex: 1;
  min-height: 0;
  background: #0b0d10;
}
.viewer iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #525659;
}
.empty {
  padding: 24px;
  color: var(--muted);
  font-size: 14px;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}
.login-card {
  width: min(380px, calc(100% - 32px));
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-card input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
.login-card input:focus { border-color: #4a5d78; }
.login-card .btn { margin-top: 8px; }
.login-error { margin: 0; color: var(--ko); font-size: 13px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #243044;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
.toast.show { opacity: 1; transform: translateY(0); }

.stats-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 8, 12, 0.62);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms var(--ease);
}
.stats-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.stats-panel {
  width: min(720px, 100%);
  max-height: calc(100vh - 72px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px 24px;
  transform: translateY(8px);
  transition: transform 180ms var(--ease);
}
.stats-overlay.open .stats-panel { transform: translateY(0); }
.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.stats-head h2 { margin: 0; font-size: 18px; }
.stats-meta { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.stats-section { margin-top: 18px; }
.stats-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stats-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  color: inherit;
}
.stats-row:hover { background: var(--bg-hover); }
.stats-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.stats-count { font-family: var(--mono); font-size: 12px; color: var(--accent); white-space: nowrap; }
.stats-pct { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 4.5em; text-align: right; }
.stats-bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: #222831;
  overflow: hidden;
}
.stats-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.stats-bar.com > span { background: var(--com); }
.stats-bar.tech > span { background: var(--tech); }
.stats-bar.oth > span { background: var(--oth); }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; overflow: auto; }
  .pane { min-height: 50vh; }
  .review-actions select { max-width: none; flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
  .stats-overlay, .stats-panel { transition: none; }
  .stats-panel { transform: none; }
}
