/* ===== CDL English Roadside Readiness — Design System v2 ===== */

/* --- CSS Custom Properties --- */
:root {
  --bg: #f1f5f9;
  --bg2: #ffffff;
  --bg3: #f8fafc;
  --ink: #0f172a;
  --ink2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line2: #cbd5e1;
  --brand: #1d4ed8;
  --brand-dark: #1e3a8a;
  --brand-light: #dbeafe;
  --brand-text: #1e40af;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-border: #6ee7b7;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow: 0 4px 16px rgba(15,23,42,.07), 0 2px 6px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.10), 0 4px 12px rgba(15,23,42,.05);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --transition: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg2: #1e293b;
    --bg3: #1e293b;
    --ink: #f1f5f9;
    --ink2: #cbd5e1;
    --muted: #94a3b8;
    --line: #2d3f55;
    --line2: #3d5068;
    --brand: #3b82f6;
    --brand-dark: #2563eb;
    --brand-light: #1e3a5f;
    --brand-text: #93c5fd;
    --green: #10b981;
    --green-bg: #052e1a;
    --green-border: #064e35;
    --amber: #f59e0b;
    --amber-bg: #1a1200;
    --amber-border: #713f12;
    --red: #f87171;
    --red-bg: #1f0808;
    --red-border: #7f1d1d;
    --purple: #a78bfa;
    --purple-bg: #1e1433;
  }
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: .75rem; color: var(--ink); }
h3 { font-size: .95rem; font-weight: 600; margin-bottom: .5rem; color: var(--ink2); }
p  { color: var(--ink2); }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Topbar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #0f172a;
  color: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--topbar-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.topbar-logo {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.topbar h1 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar p {
  font-size: .72rem;
  color: #94a3b8;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-plan-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}
.topbar-plan-label {
  font-size: .72rem;
  color: #94a3b8;
}
.badge-plan {
  background: #1e3a8a;
  color: #93c5fd;
  border: 1px solid #2563eb;
}

/* --- Layout --- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 0;
  min-height: calc(100vh - var(--topbar-h) - 48px);
}

/* --- Sidebar --- */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Content --- */
.content {
  padding: 20px;
  min-width: 0;
  max-width: 860px;
}

/* --- Cards & Panels --- */
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card:last-child { margin-bottom: 0; }

.panel {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.panel.small { font-size: 13px; }

/* --- Navigation Buttons --- */
.navbtn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  padding: 9px 10px;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink2);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.navbtn:hover { background: var(--bg3); border-color: var(--line2); color: var(--ink); }
.navbtn.active {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand-text);
  font-weight: 700;
}
.navbtn .nav-icon { font-size: 1rem; flex-shrink: 0; }
.navbtn .nav-num {
  font-size: .7rem;
  background: var(--line);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 1px 5px;
  font-weight: 700;
  flex-shrink: 0;
}
.navbtn.active .nav-num { background: var(--brand); color: #fff; }

/* --- Buttons --- */
.btn, button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg2);
  color: var(--ink);
  transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn:hover, button:hover { background: var(--bg3); border-color: var(--line2); }
.btn:active, button:active { transform: scale(.98); }

.btn-primary, button.primary, .primary {
  background: var(--brand) !important;
  border-color: var(--brand) !important;
  color: #fff !important;
  box-shadow: 0 1px 4px rgba(29,78,216,.25);
}
.btn-primary:hover, button.primary:hover { background: var(--brand-dark) !important; }

.btn-success, button.success {
  background: var(--green) !important;
  border-color: var(--green) !important;
  color: #fff !important;
}

.btn-warn, button.warn, .warn-btn {
  background: var(--amber-bg) !important;
  border-color: var(--amber-border) !important;
  color: #92400e !important;
}
@media (prefers-color-scheme: dark) {
  .btn-warn, button.warn, .warn-btn { color: #fde68a !important; }
}

.btn-danger, button.danger {
  background: var(--red-bg) !important;
  border-color: var(--red-border) !important;
  color: #991b1b !important;
}

.btn-outline {
  background: transparent !important;
  border-color: #334155 !important;
  color: #cbd5e1 !important;
}
.btn-outline:hover { background: #1e293b !important; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  font-size: 1.1rem;
}

/* --- Form Elements --- */
label, .label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  display: block;
  margin-bottom: 5px;
}

select, input[type="text"], input[type="email"], input[type="search"], textarea {
  width: 100%;
  border: 1px solid var(--line2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  background: var(--bg2);
  color: var(--ink);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

textarea { min-height: 110px; resize: vertical; line-height: 1.6; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink2);
  cursor: pointer;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.checkbox-row input[type="checkbox"] { width: auto; accent-color: var(--brand); }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 700;
  background: var(--brand-light);
  color: var(--brand-text);
}
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-red    { background: var(--red-bg);   color: var(--red); }
.badge-gray   { background: var(--bg3);      color: var(--muted); border: 1px solid var(--line); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }

/* --- Progress Bar --- */
.bar {
  height: 10px;
  background: var(--line);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin: 6px 0 12px;
}
.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, #34d399 100%);
  border-radius: var(--radius-pill);
  transition: width .5s ease;
}
.bar.red span { background: linear-gradient(90deg, var(--red) 0%, #f87171 100%); }
.bar.amber span { background: linear-gradient(90deg, var(--amber) 0%, #fbbf24 100%); }

/* --- Toolbar (filter row) --- */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: flex-start;
}
.toolbar > * { flex: 1 1 160px; }
.toolbar > .checkbox-row { flex: 0 0 auto; }

/* --- Question Display --- */
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.q-text-officer { font-size: 1.15rem; font-weight: 700; color: var(--ink); line-height: 1.4; margin: 8px 0 4px; }
.answer-block {
  background: var(--green-bg);
  border-left: 4px solid var(--green);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  font-size: .95rem;
  color: var(--ink);
  margin: 8px 0;
}

details {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin: 8px 0;
  overflow: hidden;
}
details summary {
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink2);
  background: var(--bg3);
  user-select: none;
}
details summary:hover { background: var(--line); }
details[open] summary { border-bottom: 1px solid var(--line); }
details > *:not(summary) { padding: 10px 12px; }

/* --- Chips (keywords) --- */
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  background: var(--bg3);
  border: 1px solid var(--line2);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  font-size: 12px;
  color: var(--ink2);
}

/* --- Actions row --- */
.actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* --- Pagination nav --- */
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 14px;
}
.pager-center { display: flex; gap: 8px; }

/* --- Sign Display --- */
.sign-image-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 14px 0;
  min-height: 180px;
}
.sign-img {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.sign-text-fallback {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--ink);
  text-align: center;
  border: 3px solid var(--ink2);
  border-radius: var(--radius-sm);
  padding: 20px;
  background: var(--bg2);
  letter-spacing: .04em;
}

/* --- Score Display --- */
.score-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 10px 0;
}
.score-num {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}
.score-label { font-size: .8rem; color: var(--muted); }

/* --- Stat Cards (sidebar) --- */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-val { font-size: 14px; font-weight: 700; color: var(--ink); }

/* --- Status panels --- */
.status-ok {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13.5px;
}
.status-warn {
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13.5px;
}
.status-bad {
  background: var(--red-bg);
  border-left: 4px solid var(--red);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  font-size: 13.5px;
}

/* --- Pricing Grid --- */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.price-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  background: var(--bg2);
  text-align: center;
  transition: box-shadow var(--transition);
}
.price-card:hover { box-shadow: var(--shadow); }
.price-card.active { outline: 2px solid var(--brand); }
.price-card h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.price-card .price-amt { font-size: 1.5rem; font-weight: 900; color: var(--ink); margin: 4px 0 8px; }
.price-card ul { list-style: none; font-size: 12px; color: var(--muted); margin-bottom: 12px; text-align: left; }
.price-card ul li { padding: 2px 0; }
.price-card ul li::before { content: "✓  "; color: var(--green); }

/* --- Report Grid --- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.report-metric {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: center;
}
.report-metric .metric-val { font-size: 1.6rem; font-weight: 900; color: var(--brand); }
.report-metric .metric-label { font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

/* --- Listening Mode --- */
.listen-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--bg3);
  margin-bottom: 12px;
}
.listen-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

/* --- Speaking / Scoring --- */
.speaking-prompt {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--brand-light);
  border-left: 4px solid var(--brand);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin-bottom: 14px;
}

/* --- Mock Inspection --- */
.mock-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg2);
}
.mock-item-num { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }

/* --- Security Panel --- */
.security-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}
.security-metric {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.security-metric .sec-val { font-size: 1.1rem; font-weight: 800; color: var(--ink); }
.security-metric .sec-label { font-size: 11px; color: var(--muted); }

.event-log {
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg3);
}
.event-log li { padding: 3px 0; border-bottom: 1px solid var(--line); }
.event-log li:last-child { border-bottom: none; }

/* --- Database Panel --- */
pre {
  white-space: pre-wrap;
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.55;
}

/* --- Misc helpers --- */
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 5px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hidden { display: none !important; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }

/* --- Watermark --- */
.watermark {
  position: fixed;
  z-index: 9;
  pointer-events: none;
  top: 38%;
  left: 8%;
  font-weight: 900;
  opacity: .055;
  transform: rotate(-18deg);
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
}

/* --- Loading --- */
.loading-card {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.loader-ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Disclaimer panel --- */
.disclaimer-panel {
  border-color: var(--amber-border);
  background: var(--amber-bg);
}
.disclaimer-panel .hint { color: var(--amber); }

/* --- Footer --- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: var(--bg2);
}

/* --- Mobile Only toggle --- */
.mobile-only { display: none; }

/* === RESPONSIVE === */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .content { padding: 14px; }

  .sidebar {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { display: block; }

  .mobile-only { display: inline-flex; }
  .topbar h1 { font-size: .9rem; }
  .topbar p { display: none; }

  .report-grid { grid-template-columns: 1fr 1fr; }
  .security-grid { grid-template-columns: 1fr; }
  .pricing-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 500px) {
  .pricing-grid { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: column; }
  .toolbar > * { flex: none; width: 100%; }
  .actions { flex-direction: column; }
  .actions button { width: 100%; justify-content: center; }
}
