/* ==========================================================================
   Koreksi ASTS - Mobile-First OMR Scanner Stylesheet
   Tema: Edu-Tech Emerald & Slate (Bersih, Kontras Tinggi, Ramah Sentuhan HP)
   ========================================================================== */

:root {
  --primary: #0f766e;
  --primary-dark: #0d5e57;
  --primary-light: #ccfbf1;
  --primary-soft: #f0fdfa;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.14);
  --nav-height: 68px;
  --header-height: 58px;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  background: linear-gradient(135deg, var(--primary) 0%, #0e7490 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 12px rgba(15, 118, 110, 0.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  backdrop-filter: blur(4px);
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.2px;
  line-height: 1.15;
}

.brand-text span {
  font-size: 11px;
  opacity: 0.88;
  display: block;
}

.header-btn {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.header-btn:active {
  transform: scale(0.96);
}

/* ---------- Main Container ---------- */
.app-main {
  max-width: 780px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--nav-height) + 24px);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-subtitle {
  margin: -6px 0 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ---------- Key Selector Pills ---------- */
.key-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.key-pills::-webkit-scrollbar {
  display: none;
}

.key-pill {
  flex: 0 0 auto;
  border: 2px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  min-width: 138px;
}

.key-pill strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.key-pill small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.key-pill.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.key-pill.active small {
  color: var(--primary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  line-height: 1.2;
}

.btn:active {
  transform: scale(0.97);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #0d9488 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.28);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.26);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-danger-outline {
  background: #fff;
  color: var(--danger);
  border: 1.5px solid #fecaca;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 9px;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* ---------- Auto-process Toggle ---------- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.toggle-row span {
  font-size: 13px;
  font-weight: 600;
}

.toggle-row small {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 400;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.slider-toggle::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider-toggle {
  background: var(--primary);
}

.switch input:checked + .slider-toggle::before {
  transform: translateX(20px);
}

/* ---------- Tips Banner ---------- */
.tips-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 12.5px;
  margin-top: 12px;
}

.tips-box strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.tips-box ul {
  margin: 0;
  padding-left: 18px;
}

.tips-box li {
  margin-bottom: 2px;
}

/* ---------- Live Camera Overlay Modal ---------- */
.camera-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: flex;
  flex-direction: column;
}

.camera-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#liveVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide-wrap {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.camera-guide-box {
  width: min(92vw, 620px);
  aspect-ratio: 2.72 / 1;
  border: 3px solid #34d399;
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.52);
  position: relative;
}

.camera-guide-box::before,
.camera-guide-box::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(52, 211, 153, 0.45);
}

.camera-guide-box::before { top: 50%; }
.camera-guide-box::after { display: none; }

.guide-label {
  margin-top: 12px;
  background: rgba(15, 23, 42, 0.8);
  color: #ecfdf5;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
}

.camera-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), transparent);
}

.cam-pill-btn {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.camera-controls {
  padding: 18px 20px 26px;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid #34d399;
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.28);
  transition: transform 0.1s;
}

.shutter-btn:active {
  transform: scale(0.92);
}

/* ---------- Step 2: Adjust 4 Corners Canvas ---------- */
.canvas-wrapper {
  position: relative;
  width: 100%;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  margin-bottom: 12px;
}

#adjustCanvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
}

.loupe-canvas {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 3px solid #10b981;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  background: #000;
  pointer-events: none;
  z-index: 15;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.ok {
  background: var(--success-bg);
  color: var(--success);
}

.status-pill.warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.calibration-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0 12px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.range-row:last-child {
  margin-bottom: 0;
}

.range-row label {
  width: 96px;
  font-weight: 600;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.range-row input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.range-row output {
  width: 46px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Step 3: Result Hero ---------- */
.score-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-radius: var(--radius);
  color: #fff;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lg);
}

.score-hero.pass {
  background: linear-gradient(135deg, #059669 0%, #0f766e 100%);
}

.score-hero.fail {
  background: linear-gradient(135deg, #dc2626 0%, #ea580c 100%);
}

.score-main-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  opacity: 0.9;
  font-weight: 700;
}

.score-big {
  font-size: 48px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
}

.score-meta {
  font-size: 12.5px;
  opacity: 0.92;
  margin-top: 4px;
}

.pass-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.score-right {
  text-align: right;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}

.stat-chip strong {
  display: block;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.stat-chip span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-chip.good strong { color: var(--success); }
.stat-chip.bad strong { color: var(--danger); }

/* ---------- Warped Result Canvas ---------- */
.result-canvas-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  margin-bottom: 10px;
}

#resultCanvas {
  display: block;
  width: 100%;
  height: auto;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.dot.green { background: #10b981; }
.dot.red { background: #ef4444; }
.dot.amber { border: 2px dashed #f59e0b; background: transparent; }

/* ---------- Form Inputs ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
}

.input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

/* ---------- 50-Question Detail Grid ---------- */
.filter-pills {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.q-detail-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

@media (max-width: 420px) {
  .q-detail-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.q-cell {
  border-radius: 10px;
  padding: 7px 5px;
  text-align: center;
  border: 1.5px solid var(--border);
  cursor: pointer;
  background: #fff;
  transition: transform 0.1s;
}

.q-cell:active {
  transform: scale(0.95);
}

.q-cell .q-num {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.q-cell .q-ans {
  font-size: 14px;
  font-weight: 800;
  margin: 2px 0;
}

.q-cell .q-key {
  font-size: 10px;
  color: var(--text-muted);
}

.q-cell.correct {
  background: #ecfdf5;
  border-color: #6ee7b7;
}
.q-cell.correct .q-ans { color: var(--success); }

.q-cell.partial {
  background: #fffbeb;
  border-color: #fcd34d;
}
.q-cell.partial .q-ans { color: var(--warning); }

.q-cell.wrong, .q-cell.invalid {
  background: #fef2f2;
  border-color: #fca5a5;
}
.q-cell.wrong .q-ans, .q-cell.invalid .q-ans { color: var(--danger); }

.q-cell.blank {
  background: #f8fafc;
  border-color: #cbd5e1;
}
.q-cell.blank .q-ans { color: #94a3b8; }

/* ---------- Answer Key Editor ---------- */
.section-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 10px 0 8px;
}

.key-editor-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (max-width: 480px) {
  .key-editor-list {
    grid-template-columns: 1fr;
  }
}

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.key-row-num {
  font-weight: 800;
  font-size: 13.5px;
  width: 30px;
  color: var(--text);
}

.bubble-group {
  display: flex;
  gap: 7px;
}

.bubble-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #94a3b8;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}

.bubble-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.35);
}

/* ---------- Scoring Config Grid ---------- */
.config-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.config-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

/* ---------- Rekap Nilai ---------- */
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  margin-bottom: 8px;
}

.record-info strong {
  display: block;
  font-size: 14.5px;
}

.record-info small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.record-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.record-score {
  min-width: 54px;
  text-align: center;
  padding: 7px 10px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.record-score.pass {
  background: var(--success-bg);
  color: var(--success);
}

.record-score.fail {
  background: var(--danger-bg);
  color: var(--danger);
}

.icon-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 60;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
}

.nav-btn .nav-icon {
  font-size: 21px;
  line-height: 1;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-btn.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 38px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--primary);
}

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 24px);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  border-radius: 999px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 18px;
  box-shadow: var(--shadow-lg);
}

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

.modal-head h3 {
  margin: 0;
  font-size: 16.5px;
}

.modal-close {
  border: none;
  background: var(--surface-alt);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
