:root {
  --bg: #070b14;
  --bg-elevated: #0f1626;
  --bg-card: #131c2e;
  --bg-card-hover: #182338;
  --bg-input: #0a101d;
  --border: #22304a;
  --border-strong: #314466;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  --primary-soft: rgba(14, 165, 233, 0.14);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --purple: #8b5cf6;
  --purple-soft: rgba(139, 92, 246, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

/* Boot & Spinner */
.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Demo Banner */
.demo-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.16), rgba(14, 165, 233, 0.14));
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}

.demo-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fde68a;
}

.demo-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Top Navigation */
.topbar {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tab.active {
  color: #fff;
  background: var(--primary-soft);
  border-color: rgba(14, 165, 233, 0.4);
}

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

.user-meta {
  text-align: right;
  line-height: 1.25;
}

.user-name {
  font-size: 13.5px;
  font-weight: 600;
}

.user-desig {
  font-size: 12px;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-rad {
  font-family: var(--font-mono);
  background: var(--primary-soft);
  color: #7dd3fc;
  border: 1px solid rgba(14, 165, 233, 0.35);
}

.badge-admin {
  font-family: var(--font-mono);
  background: var(--purple-soft);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.4);
}

.badge-success {
  background: var(--success-soft);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-warning {
  background: var(--warning-soft);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-danger {
  background: var(--danger-soft);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.badge-neutral {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #031525;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #022c22;
  font-weight: 600;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 12px;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

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

.field-hint {
  font-size: 12px;
  color: var(--text-dim);
}

/* Cards & Layout */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.card-subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Entry Gate (New User / Already Registered) */
.auth-shell {
  min-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}

.auth-hero {
  text-align: center;
  max-width: 620px;
  margin-bottom: 28px;
}

.auth-hero h1 {
  margin: 14px 0 8px;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.auth-hero p {
  margin: 0;
  color: var(--text-muted);
}

.gate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 340px));
  gap: 18px;
  width: 100%;
  max-width: 720px;
}

.gate-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.gate-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: var(--bg-card-hover);
}

.gate-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}

.gate-card h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

.gate-card p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.auth-card {
  width: 100%;
  max-width: 460px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.demo-quick-box {
  margin-top: 22px;
  width: 100%;
  max-width: 720px;
  background: rgba(15, 22, 38, 0.8);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Main Workspace Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 20px;
  align-items: start;
}

.case-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 102px);
  overflow-y: auto;
}

.case-sidebar-title {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 4px 6px 10px;
  font-weight: 600;
}

.case-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.case-item {
  width: 100%;
  text-align: left;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.15s ease;
}

.case-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.case-item.active {
  border-color: var(--primary);
  background: rgba(14, 165, 233, 0.1);
}

.case-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.case-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.case-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

/* Radiology PACS Image Viewer */
.viewer-shell {
  background: #03050a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
}

.viewer-toolbar {
  background: #0c1322;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.viewer-toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.viewer-wl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.viewer-wl input[type="range"] {
  width: 68px;
  accent-color: var(--primary);
}

.viewer-stage {
  position: relative;
  height: 460px;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.viewer-stage.zoomed {
  cursor: grab;
}

.viewer-stage.zoomed:active {
  cursor: grabbing;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.06s ease-out;
  pointer-events: none;
}

.viewer-overlay-caption {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(7, 11, 20, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: #e2e8f0;
  backdrop-filter: blur(6px);
}

.viewer-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(15, 22, 38, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  display: grid;
  place-items: center;
}

.viewer-nav-btn:hover {
  background: rgba(14, 165, 233, 0.85);
}

.viewer-nav-prev { left: 12px; }
.viewer-nav-next { right: 12px; }

.viewer-thumbs {
  background: #0a0f1c;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
}

.viewer-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #04070d;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 84px;
}

.viewer-thumb.active {
  border-color: var(--primary);
}

.viewer-thumb img {
  width: 74px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
}

.viewer-thumb span {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 78px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Question Prompt & Below-Question Sections */
.clinical-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.clinical-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 4px;
}

.publish-time-bar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.mcq-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.mcq-option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mcq-option:hover {
  border-color: var(--border-strong);
}

.mcq-option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.mcq-option.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.mcq-letter {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.section-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.official-answer-box {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.09), rgba(16, 185, 129, 0.03));
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius);
  padding: 18px;
}

.locked-answer-box {
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
}

/* Stats & Tables */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

.stat-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Admin Forms & Grids */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.upload-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.upload-preview-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-preview-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}

.grade-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Lightbox Modal */
.lightbox-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
}

.lightbox-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-body img {
  max-width: 96vw;
  max-height: 86vh;
  object-fit: contain;
}

/* Toasts */
.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: slideIn 0.2s ease-out;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

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

/* Responsive */
@media (max-width: 960px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .case-sidebar {
    position: static;
    max-height: none;
  }
  .viewer-stage {
    height: 340px;
  }
}

@media (max-width: 680px) {
  .gate-grid, .two-col {
    grid-template-columns: 1fr;
  }
  .user-meta {
    display: none;
  }
}

/* OSCE Runner Top Timer Bar & Station Builder */
.osce-timer-bar {
  position: sticky;
  top: 66px;
  z-index: 30;
  background: linear-gradient(90deg, #0d172a, #111f38);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.osce-timer-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.osce-timer-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.osce-timer-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
}

.osce-timer-value.warn { color: var(--warning); }
.osce-timer-value.crit { color: var(--danger); }

.station-builder-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.submitted-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(14, 165, 233, 0.12));
  border: 1px solid rgba(16, 185, 129, 0.45);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
