:root {
  --navy: #01196e;
  --blue: #032388;
  --blue-2: #184da3;
  --sky: #0199f5;
  --ink: #071330;
  --muted: #62708f;
  --line: #dce5f5;
  --paper: #ffffff;
  --bg: #f3f7ff;
  --green: #0a9b62;
  --red: #d93945;
  --orange: #ef8b16;
  --shadow: 0 16px 45px rgba(2, 35, 136, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: radial-gradient(circle at 85% 0, #d8efff 0, transparent 32rem), var(--bg); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.topbar { min-height: 76px; padding: 0 24px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 26px; color: #fff; background: linear-gradient(115deg, var(--navy), var(--blue) 55%, var(--blue-2)); box-shadow: 0 9px 30px rgba(1, 25, 110, .25); position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 210px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 900; font-size: 24px; color: var(--blue); background: #fff; box-shadow: inset 0 -4px 0 #bde6ff; }
.brand strong, .brand span { display: block; line-height: 1.1; }
.brand strong { font-size: 15px; letter-spacing: .08em; }
.brand span { margin-top: 4px; font-size: 12px; color: #bde7ff; }
.main-nav { display: flex; justify-content: center; gap: 5px; }
.nav-button { border: 0; border-radius: 11px; padding: 11px 14px; color: #dcecff; background: transparent; cursor: pointer; font-weight: 700; }
.nav-button:hover, .nav-button.active { color: var(--navy); background: #fff; }
.site-box { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 10px; display: inline-grid; place-items: center; background: rgba(255,255,255,.16); color: inherit; font-size: 22px; cursor: pointer; }

.main-content { width: min(1500px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 70px; }
.view { display: none; }
.active-view { display: block; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin: 12px 0 24px; }
.page-heading.compact { align-items: center; }
.page-heading h1 { margin: 2px 0 8px; font-size: clamp(28px, 4vw, 43px); letter-spacing: -.04em; color: var(--navy); }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0 !important; color: var(--sky) !important; font-size: 12px; font-weight: 900; letter-spacing: .16em; }
.heading-actions { display: flex; gap: 10px; }

.button { border: 0; border-radius: 11px; padding: 11px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 800; text-decoration: none; cursor: pointer; transition: transform .15s, box-shadow .15s, opacity .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .52; cursor: wait; transform: none; }
.button.primary { color: #fff; background: linear-gradient(115deg, var(--blue), var(--sky)); box-shadow: 0 8px 20px rgba(3, 35, 136, .22); }
.button.ghost { color: var(--blue); background: #eaf2ff; }
.button.success { color: #fff; background: var(--green); }
.button.danger { color: #fff; background: var(--red); }
.button.danger-soft { color: var(--red); background: #fff0f2; }
.button.large { min-height: 50px; padding-inline: 24px; }

.panel { margin-bottom: 20px; padding: 22px; border: 1px solid rgba(205, 220, 244, .85); border-radius: var(--radius); background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.panel-head h2, .panel h2 { margin: 0; color: var(--navy); font-size: 20px; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.summary-card { padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: 0 9px 24px rgba(5, 44, 129, .07); }
.summary-card span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.summary-card strong { display: block; margin-top: 7px; color: var(--navy); font-size: 29px; }

.exam-list { display: grid; gap: 11px; }
.exam-row { display: grid; grid-template-columns: minmax(260px, 1.8fr) minmax(130px, .8fr) 110px 110px minmax(310px, auto); align-items: center; gap: 14px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.exam-name strong { display: block; color: var(--navy); font-size: 17px; }
.exam-name span, .exam-meta span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.exam-stat { text-align: center; }
.exam-stat strong { display: block; font-size: 20px; color: var(--blue); }
.exam-stat span { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.exam-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.mini-button { border: 0; border-radius: 9px; padding: 8px 10px; background: #edf3ff; color: var(--blue); font-size: 12px; font-weight: 800; cursor: pointer; }
.mini-button.hot { color: #fff; background: var(--blue); }

.form-grid { display: grid; gap: 15px; }
.form-grid.four { grid-template-columns: 2fr 1.3fr .8fr .8fr; }
.form-grid.two { grid-template-columns: 1fr 1.6fr; }
label { display: grid; gap: 7px; color: #344263; font-size: 12px; font-weight: 800; }
input, select, textarea { width: 100%; border: 1px solid #cdd9ec; border-radius: 10px; padding: 11px 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--sky); box-shadow: 0 0 0 3px rgba(1,153,245,.12); }
textarea { resize: vertical; }

.section-labels, .section-row { display: grid; grid-template-columns: 80px 80px minmax(190px, 1fr) 130px 130px 130px 42px; gap: 9px; align-items: center; }
.section-labels { padding: 0 5px 7px; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.section-rows { display: grid; gap: 9px; }
.section-row { padding: 9px; border-radius: 12px; background: #f6f9ff; }
.section-row input { padding: 9px; }
.remove-row { width: 35px; height: 35px; border: 0; border-radius: 9px; color: var(--red); background: #ffeef0; font-size: 18px; cursor: pointer; }
.key-head { align-items: flex-start; }
.key-tools { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto; gap: 8px; width: min(730px, 65%); }
.key-tools textarea { min-height: 55px; }
.key-grid { display: grid; grid-template-columns: repeat(10, minmax(75px, 1fr)); gap: 8px; }
.key-item { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 5px; padding: 7px; border: 1px solid var(--line); border-radius: 9px; background: #fbfdff; }
.key-item span { color: var(--blue); font-size: 12px; font-weight: 900; text-align: right; }
.key-item select { padding: 7px 4px; font-weight: 900; }

.upload-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, .8fr); gap: 20px; }
.drop-zone { min-height: 275px; border: 2px dashed #8fb6ed; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; text-align: center; background: linear-gradient(145deg, #f9fcff, #eef6ff); transition: .2s; }
.drop-zone.dragging { border-color: var(--sky); background: #e3f4ff; transform: scale(1.005); }
.drop-zone h2 { margin: 5px 0; }
.drop-zone p { margin: 0 0 18px; color: var(--muted); }
.upload-symbol { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; color: #fff; background: linear-gradient(135deg, var(--blue), var(--sky)); font-size: 34px; font-weight: 900; }
.selected-files { margin: 15px 0; display: grid; gap: 7px; }
.selected-files.empty { padding: 12px; color: var(--muted); text-align: center; }
.file-chip { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: #f1f6ff; color: var(--blue); font-size: 13px; font-weight: 700; }
.upload-options { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.upload-options label { min-width: 270px; }
.progress-panel { align-self: start; position: sticky; top: 96px; }
.batch-empty { color: var(--muted); padding: 24px 0; text-align: center; }
.progress-ring { width: 110px; height: 110px; margin: 15px auto; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--sky) var(--progress), #e5edfa 0); position: relative; }
.progress-ring::before { content: ''; position: absolute; width: 82px; height: 82px; border-radius: inherit; background: #fff; }
.progress-ring strong { position: relative; font-size: 22px; color: var(--blue); }
.job-list { display: grid; gap: 8px; margin-top: 14px; }
.job-item { padding: 9px 11px; border-radius: 9px; background: #f4f7fd; font-size: 12px; }
.job-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filters { display: grid; grid-template-columns: 1fr 240px auto; gap: 10px; margin-bottom: 16px; }
.scan-list { display: grid; gap: 9px; }
.scan-row { display: grid; grid-template-columns: 58px 125px minmax(220px, 1fr) 120px 130px 160px; align-items: center; gap: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.scan-thumb { width: 56px; height: 42px; object-fit: cover; border-radius: 7px; background: #eaf0fa; }
.scan-person strong { display: block; color: var(--navy); }
.scan-person span { color: var(--muted); font-size: 12px; }
.score { color: var(--blue); font-size: 18px; font-weight: 900; }
.status-badge { display: inline-flex; width: max-content; padding: 6px 9px; border-radius: 99px; font-size: 11px; font-weight: 900; text-transform: uppercase; }
.status-ready { color: #087448; background: #dff8ed; }
.status-needs_review { color: #a35d00; background: #fff0d6; }
.status-duplicate { color: #8c3e9f; background: #f7e8fb; }
.status-error { color: #a61f2b; background: #ffe7ea; }
.scan-actions { display: flex; justify-content: flex-end; gap: 7px; }
.trash-button { border: 0; border-radius: 9px; padding: 8px 10px; color: var(--red); background: #fff0f2; cursor: pointer; }
.pagination { display: flex; justify-content: center; gap: 8px; padding-top: 17px; }

.table-panel { padding: 0; overflow: hidden; }
.table-scroll { overflow: auto; }
.results-table { width: 100%; min-width: 900px; border-collapse: collapse; }
.results-table th { padding: 13px 15px; color: #fff; background: var(--blue); text-align: left; font-size: 12px; text-transform: uppercase; }
.results-table td { padding: 12px 15px; border-bottom: 1px solid var(--line); }
.results-table tbody tr:hover { background: #f5f9ff; }
.results-pagination { padding: 15px; border-top: 1px solid var(--line); }
.rank { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--blue); background: #e8f2ff; font-weight: 900; }
.rank.top { color: #fff; background: linear-gradient(135deg, #f5b900, #e47a00); }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; background: rgba(1, 13, 50, .72); backdrop-filter: blur(5px); }
.modal-card { width: min(1560px, 100%); max-height: calc(100vh - 36px); overflow: hidden; border-radius: 20px; background: #fff; box-shadow: 0 30px 100px #0008; }
.modal-head, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 2px 0 0; color: var(--navy); }
.modal-head .icon-button { color: var(--navy); background: #edf3ff; }
.modal-actions { border-top: 1px solid var(--line); border-bottom: 0; }
.scan-detail-layout { height: calc(100vh - 180px); min-height: 520px; display: grid; grid-template-columns: minmax(500px, 1.25fr) minmax(500px, .9fr); }
.scan-preview-wrap { overflow: auto; display: grid; place-items: start center; padding: 15px; background: #dce5f0; }
.scan-preview-wrap img { width: 100%; height: auto; border-radius: 8px; box-shadow: 0 8px 30px #07133033; }
.scan-editor { overflow: auto; padding: 18px; }
.error-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 13px; }
.error-chip { padding: 6px 9px; border-radius: 99px; color: #9e2530; background: #ffe8eb; font-size: 10px; font-weight: 900; }
.check-row { display: grid; gap: 8px; margin: 14px 0; padding: 12px; border-radius: 11px; background: #f5f8fe; }
.check-row label { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.answers-head { display: flex; align-items: baseline; justify-content: space-between; }
.answers-head h3 { margin: 8px 0; color: var(--navy); }
.answers-head span { color: var(--muted); font-size: 12px; }
.answer-editor { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.answer-editor > .empty-state { grid-column: 1 / -1; }
.answer-cell { display: grid; grid-template-columns: 28px 1fr 30px 12px; align-items: center; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.answer-cell strong { color: var(--blue); font-size: 11px; text-align: right; }
.answer-cell select { padding: 6px 3px; }
.correct-key { color: var(--green); font-size: 11px; font-weight: 900; }
.answer-result { width: 9px; height: 9px; border-radius: 50%; background: #b7c2d4; }
.answer-result.correct { background: var(--green); }
.answer-result.wrong { background: var(--red); }
.answer-result.ambiguous { background: var(--orange); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 120; max-width: 430px; padding: 14px 18px; border-radius: 12px; color: #fff; background: var(--navy); box-shadow: 0 18px 60px #001b5c55; font-weight: 700; }
.toast.error { background: var(--red); }
.empty-state { padding: 45px 20px; color: var(--muted); text-align: center; }
.login-block { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(470px, 100%); padding: 34px; border-radius: 22px; text-align: center; background: #fff; box-shadow: var(--shadow); }
.login-card .brand-mark { margin: auto; color: #fff; background: var(--blue); }
.login-card h1 { color: var(--navy); }
.login-card p { color: var(--muted); }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: auto 1fr; }
  .site-box { display: none; }
  .main-nav { justify-content: flex-end; overflow-x: auto; }
  .exam-row { grid-template-columns: 1.4fr .7fr 90px 90px; }
  .exam-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .key-grid { grid-template-columns: repeat(5, 1fr); }
  .form-grid.four { grid-template-columns: 1fr 1fr; }
  .scan-row { grid-template-columns: 58px 115px 1fr 100px; }
  .scan-row .status-badge, .scan-actions { grid-column: auto; }
  .scan-detail-layout { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .topbar { position: static; display: block; padding: 13px 14px; }
  .brand { margin-bottom: 10px; }
  .main-nav { justify-content: flex-start; padding-bottom: 2px; }
  .nav-button { flex: 0 0 auto; padding: 9px 11px; }
  .main-content { width: min(100% - 20px, 1500px); padding-top: 15px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .exam-row { grid-template-columns: 1fr 1fr; }
  .exam-name, .exam-actions { grid-column: 1 / -1; }
  .form-grid.four, .form-grid.two { grid-template-columns: 1fr; }
  .section-labels { display: none; }
  .section-row { grid-template-columns: 1fr 1fr; }
  .section-row input:nth-child(3) { grid-column: 1 / -1; }
  .key-head { display: block; }
  .key-tools { width: 100%; margin-top: 12px; grid-template-columns: 1fr 1fr; }
  .key-tools textarea { grid-column: 1 / -1; }
  .key-grid { grid-template-columns: repeat(3, 1fr); }
  .upload-layout { grid-template-columns: 1fr; }
  .progress-panel { position: static; }
  .upload-options { align-items: stretch; flex-direction: column; }
  .upload-options label { min-width: 0; }
  .filters { grid-template-columns: 1fr; }
  .scan-row { grid-template-columns: 55px 1fr; }
  .scan-row > *:not(.scan-thumb):not(.scan-person) { grid-column: 2; }
  .scan-actions { justify-content: flex-start; }
  .scan-detail-layout { height: calc(100vh - 175px); display: block; overflow: auto; }
  .scan-preview-wrap, .scan-editor { overflow: visible; }
  .answer-editor { grid-template-columns: repeat(3, 1fr); }
  .modal-actions { align-items: stretch; flex-direction: column; }
  .modal-actions > div { display: flex; }
  .modal-actions .button { flex: 1; }
}

@media (max-width: 480px) {
  .panel { padding: 15px; border-radius: 14px; }
  .summary-grid { grid-template-columns: 1fr; }
  .key-grid { grid-template-columns: repeat(2, 1fr); }
  .answer-editor { grid-template-columns: repeat(2, 1fr); }
}
