/* CrownAI review UI — large targets, few words, high contrast, fits 1366x768. */

:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #e9edf1;
  --text: #15202b;
  --muted: #4f5b66;
  --border: #c9d1d9;
  --primary: #0b57d0;
  --primary-text: #ffffff;
  --ok: #1b7f3b;
  --ok-bg: #d9f2e1;
  --bad: #c62828;
  --bad-bg: #fbdcdc;
  --warn: #8a5a00;
  --warn-bg: #fff2c4;
  --info-bg: #dce8fb;
  --radius: 10px;
  --header-h: 56px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.35;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---- header ---------------------------------------------------------- */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.2rem; }
.brand-mark { color: var(--primary); font-size: 1.3rem; }
.brand small { font-weight: 400; color: var(--muted); font-size: 0.85rem; margin-left: 6px; }
.app-nav { display: flex; gap: 8px; }
.nav-link { text-decoration: none; font-weight: 600; padding: 8px 14px; border-radius: var(--radius); color: var(--text); }
.nav-link.active, .nav-link:hover { background: var(--surface-2); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.user-name { font-weight: 600; color: var(--muted); }
.lang-toggle { display: inline-flex; border: 2px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-btn { border: 0; background: transparent; padding: 6px 14px; font-weight: 700; cursor: pointer; font-size: 0.95rem; color: var(--muted); }
.lang-btn.active { background: var(--primary); color: var(--primary-text); }

.app-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 16px 20px; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.page h1 { margin: 0; font-size: 1.5rem; }
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---- buttons --------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 1.05rem; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: #0947ad; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 0.95rem; }
.btn-lg { min-height: 56px; font-size: 1.15rem; }
.btn-ok { border-color: var(--ok); color: var(--ok); }
.btn-ok.active, .btn-ok:hover { background: var(--ok); color: #fff; }
.btn-bad { border-color: var(--bad); color: var(--bad); }
.btn-bad.active, .btn-bad:hover { background: var(--bad); color: #fff; }
.btn-block { width: 100%; }

/* ---- chips / badges -------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--text);
}
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.chip.status-queued { background: var(--surface-2); color: var(--muted); }
.chip.status-running { background: var(--info-bg); color: var(--primary); }
.chip.status-predicted { background: var(--warn-bg); color: var(--warn); }
.chip.status-reviewed { background: var(--info-bg); color: #164a9a; }
.chip.status-corrected { background: #ead9ff; color: #5b22a8; }
.chip.status-validated { background: var(--ok-bg); color: var(--ok); }
.chip.status-failed { background: var(--bad-bg); color: var(--bad); }
.chip.status-running::before { animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.3; } to { opacity: 1; } }

.badge-tooth {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 32px; padding: 0 10px;
  border-radius: 8px; font-weight: 800; font-size: 1.05rem; border: 2px solid rgba(0, 0, 0, 0.25); color: #111;
}
.badge-tooth.none { background: var(--surface-2); color: var(--muted); border-color: var(--border); font-weight: 600; }
.star { color: #d08a00; }

.note { padding: 10px 14px; border-radius: var(--radius); font-weight: 600; }
.note-warn { background: var(--warn-bg); color: var(--warn); border-left: 5px solid var(--warn); }
.note-info { background: var(--info-bg); color: #164a9a; border-left: 5px solid var(--primary); }
.note-error { background: var(--bad-bg); color: var(--bad); border-left: 5px solid var(--bad); }
.note-ok { background: var(--ok-bg); color: var(--ok); border-left: 5px solid var(--ok); }

/* ---- forms ----------------------------------------------------------- */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  font: inherit; font-size: 1.05rem; min-height: 46px; padding: 8px 12px; border: 2px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.field textarea { min-height: 60px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid var(--primary); outline-offset: 1px; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice {
  flex: 1 1 140px; display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 14px;
  border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 600; cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.choice:has(input:focus-visible) { outline: 3px solid var(--primary); }

/* ---- login ----------------------------------------------------------- */
.login-page { align-items: center; justify-content: center; }
.login-card { width: min(440px, 100%); background: var(--surface); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 1.6rem; }

/* ---- cases table ----------------------------------------------------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 150px; }
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; flex: 1 1 auto; min-height: 0; }
table.cases { width: 100%; border-collapse: collapse; font-size: 1rem; }
table.cases th, table.cases td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.cases th { position: sticky; top: 0; background: var(--surface-2); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.cases tr:hover td { background: #f7f9fb; }
.case-name { font-weight: 700; font-size: 1.05rem; }
.case-sub { color: var(--muted); font-size: 0.85rem; }
.jaw-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.jaw-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 8px; background: var(--surface-2); font-size: 0.9rem; font-weight: 600; }
.jaw-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.status-queued { background: #9aa5b1; }
.dot.status-running { background: var(--primary); }
.dot.status-predicted { background: #e0a800; }
.dot.status-reviewed { background: #164a9a; }
.dot.status-corrected { background: #5b22a8; }
.dot.status-validated { background: var(--ok); }
.dot.status-failed { background: var(--bad); }
.actions { display: flex; gap: 8px; }
.empty { padding: 40px; text-align: center; color: var(--muted); font-size: 1.1rem; }

/* ---- dialog ---------------------------------------------------------- */
dialog { border: 0; border-radius: 14px; padding: 0; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); width: min(720px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(10, 20, 30, 0.5); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; overflow: auto; max-height: 92vh; }
.dialog-body h2 { margin: 0; font-size: 1.4rem; }
.dialog-actions { display: flex; gap: 12px; justify-content: flex-end; }
.confirm-dialog { width: min(520px, 94vw); }
.confirm-dialog p { font-size: 1.1rem; margin: 0; }

/* ---- dental chart ---------------------------------------------------- */
.dental-chart { width: 100%; max-width: 680px; display: block; user-select: none; }
.dental-chart .tooth { cursor: pointer; }
.dental-chart .tooth circle { stroke: rgba(0, 0, 0, 0.35); stroke-width: 1.5; }
.dental-chart .tooth:hover circle, .dental-chart .tooth:focus-visible circle { stroke: var(--primary); stroke-width: 3; }
.dental-chart .tooth.selected circle { stroke: #111; stroke-width: 4; }
.dental-chart .tooth.disabled { cursor: not-allowed; opacity: 0.3; }
.dental-chart .tooth-number { font-size: 13px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; fill: #111; pointer-events: none; }
.dental-chart .chart-row-label { font-size: 12px; font-weight: 700; fill: var(--muted); }
.prep-pick { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ---- review ---------------------------------------------------------- */
.review-page { gap: 10px; overflow: auto; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar h1 { font-size: 1.35rem; }
.jaw-tabs { display: inline-flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.jaw-tab { border: 0; border-radius: 9px; padding: 8px 16px; min-height: 44px; font: inherit; font-weight: 700; cursor: pointer; background: transparent; color: var(--text); display: inline-flex; align-items: center; gap: 8px; }
.jaw-tab.active { background: var(--surface); box-shadow: var(--shadow); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 600; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.toggle:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }

.panels { flex: 1 0 auto; display: flex; flex-direction: column; gap: 0; }
.panel-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; border: 2px solid var(--border); border-bottom: 0; min-height: 50px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 1.15rem; }
.panel-head .meta { color: var(--muted); font-size: 0.85rem; margin-left: auto; white-space: nowrap; }
.panel-warn { padding: 4px 12px; background: var(--warn-bg); color: var(--warn); font-size: 0.9rem; font-weight: 600; border-left: 2px solid var(--border); border-right: 2px solid var(--border); }
.viewports { position: relative; flex: 1 1 auto; min-height: 240px; }
.viewports .panel-row { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.vp { position: relative; border: 2px solid var(--border); border-top: 0; border-bottom: 0; overflow: hidden; }
.viewer-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; z-index: 1; display: block; touch-action: none; }
.vp-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; background: rgba(243, 245, 247, 0.85); font-weight: 700; color: var(--muted); font-size: 1.05rem; text-align: center; padding: 20px; }
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; max-width: calc(100% - 16px); }
.legend span { display: inline-flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, 0.9); border-radius: 6px; padding: 1px 6px; font-size: 0.8rem; font-weight: 700; }
.legend i { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.3); display: inline-block; }
.validated-badge { position: absolute; top: 8px; right: 8px; background: var(--ok); color: #fff; padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 0.95rem; box-shadow: var(--shadow); }
.panel-foot { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--surface); border: 2px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.verdict-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.verdict-row .btn { font-size: 1.15rem; min-height: 50px; }
.foot-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.foot-row .grow { flex: 1; }
.comment-field { display: flex; gap: 6px; }
.comment-field input { flex: 1; min-height: 40px; font: inherit; padding: 6px 10px; border: 2px solid var(--border); border-radius: 8px; }
.verdict-info { font-size: 0.85rem; color: var(--muted); text-align: center; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.versions { background: var(--surface); border-radius: var(--radius); padding: 8px 14px; box-shadow: var(--shadow); flex: 0 0 auto; }
.versions h3 { margin: 0 0 6px; font-size: 1rem; }
.version-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.version-row .grow { flex: 1; }

/* ---- history --------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 26px; border-left: 3px solid var(--border); display: flex; flex-direction: column; gap: 14px; }
.timeline li { position: relative; background: var(--surface); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.timeline li::before { content: ""; position: absolute; left: -36px; top: 16px; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 3px solid var(--bg); }
.timeline li.ev-review::before { background: #e0a800; }
.timeline li.ev-version_validated::before { background: var(--ok); }
.timeline li.ev-prediction_failed::before { background: var(--bad); }
.ev-title { font-weight: 700; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ev-when { color: var(--muted); font-size: 0.85rem; font-weight: 400; margin-left: auto; }
.ev-detail { color: var(--muted); margin-top: 4px; }

/* ---- misc ------------------------------------------------------------ */
.centered { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 40px; color: var(--muted); font-size: 1.1rem; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: #fff; padding: 12px 18px; border-radius: var(--radius); font-weight: 600; box-shadow: var(--shadow); animation: fadein 0.2s; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--bad); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }
.coming-soon { background: var(--surface); border-radius: 14px; padding: 48px; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.coming-soon h2 { margin: 0; font-size: 1.6rem; }

@media (max-width: 1100px) {
  .panel-row { grid-template-columns: 1fr; }
  .viewports { min-height: 900px; }
}

/* ---- fix editor ------------------------------------------------------ */
.fix-page { gap: 10px; }
.fix-layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 12px; }
.tool-strip { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.tool-btn { justify-content: space-between; }
.tool-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.tool-btn kbd { font-family: inherit; font-size: 0.8rem; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.12); }
.tool-panel { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.selected-box { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; font-weight: 600; }
.selected-box.muted { color: var(--muted); font-weight: 400; }
.target-row { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.fix-main { display: flex; flex-direction: column; min-height: 0; gap: 6px; }
.fix-viewport { flex: 1 1 auto; min-height: 300px; border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.fix-viewport .vp { position: absolute; inset: 0; border: 0; }
.fix-hint { color: var(--muted); font-size: 0.95rem; text-align: center; min-height: 1.3em; }
.brush-size-tip { position: absolute; pointer-events: none; padding: 2px 8px; border-radius: 6px; background: rgba(11, 87, 208, 0.92); color: #fff; font-weight: 700; font-size: 0.9rem; white-space: nowrap; z-index: 5; }
.keys { font-size: 0.8rem; margin-top: auto; }
input[type="range"] { width: 100%; accent-color: var(--primary); height: 32px; }

/* ---- admin ----------------------------------------------------------- */
.admin-page { overflow: auto; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 14px; align-items: start; }
.admin-col { display: flex; flex-direction: column; gap: 14px; }
.admin-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.admin-card h2 { margin: 0; font-size: 1.15rem; }
.admin-card table.cases th { position: static; }
.admin-card tr.inactive td { opacity: 0.55; }
.queue-text { margin: 0; font-size: 1.1rem; font-weight: 600; }
.small-list { margin: 0; padding-left: 20px; font-size: 0.9rem; color: var(--muted); max-height: 160px; overflow: auto; }
.small-list.error { color: var(--bad); }
@media (max-width: 1100px) { .admin-grid { grid-template-columns: 1fr; } }
