:root {
      --bg: #f8fafc;
      --surface: #ffffff;
      --surface-alt: #f1f5f9;
      --surface-hover: #e2e8f0;
      --border: #e2e8f0;
      --border-strong: #cbd5e1;
      --text: #0f172a;
      --text-muted: #475569;
      --text-light: #64748b;
      --primary: #0f766e;
      --primary-hover: #115e59;
      --primary-soft: #f0fdfa;
      --primary-border: #99f6e4;
      --accent: #0369a1;
      --accent-soft: #f0f9ff;
      --exposed: #dc2626;
      --exposed-soft: #fef2f2;
      --exposed-border: #fecaca;
      --control: #2563eb;
      --control-soft: #eff6ff;
      --control-border: #bfdbfe;
      --success: #15803d;
      --success-soft: #f0fdf4;
      --warn: #b45309;
      --warn-soft: #fffbeb;
      --danger: #b91c1c;
      --danger-soft: #fef2f2;
      --radius: 12px;
      --radius-sm: 8px;
      --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
      --tap-min: 44px;
    }

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

    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      overflow-x: hidden;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
      background: var(--bg);
      color: var(--text);
      line-height: 1.5;
      font-size: 14px;
    }

    body {
      padding-bottom: 84px;
    }

    /* Permanent Demo Banner */
    .demo-banner {
      position: sticky;
      top: 0;
      z-index: 1000;
      background: #0f172a;
      color: #f8fafc;
      padding: 8px 16px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      border-bottom: 2px solid #f59e0b;
    }

    .demo-banner-badge {
      display: inline-flex;
      align-items: center;
      background: #f59e0b;
      color: #0f172a;
      font-weight: 800;
      padding: 4px 10px;
      border-radius: 6px;
      letter-spacing: 0.03em;
      font-size: 12px;
    }

    .demo-controls {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
    }

    .demo-btn {
      background: #1e293b;
      color: #e2e8f0;
      border: 1px solid #334155;
      border-radius: 6px;
      padding: 6px 10px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      min-height: 32px;
      transition: background 0.15s;
    }

    .demo-btn:hover {
      background: #334155;
      color: #ffffff;
    }

    .demo-btn.active-offline {
      background: #dc2626;
      border-color: #f87171;
      color: #ffffff;
    }

    /* Header */
    .app-header {
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      padding: 12px 20px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

    .brand-title {
      display: flex;
      align-items: center;
      gap: 12px;
      min-width: 0;
    }

    .brand-icon {
      width: 38px;
      height: 38px;
      border-radius: 8px;
      background: var(--primary);
      color: #ffffff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 800;
      font-size: 15px;
      flex-shrink: 0;
    }

    .brand-text h1 {
      margin: 0;
      font-size: 16px;
      font-weight: 700;
      color: var(--text);
      line-height: 1.25;
    }

    .session-bar {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 8px;
    }

    .pill {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      padding: 4px 10px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 600;
      background: var(--surface-alt);
      color: var(--text-muted);
      border: 1px solid var(--border);
      white-space: nowrap;
    }

    .pill.role-admin {
      background: #f5f3ff;
      color: #6d28d9;
      border-color: #ddd6fe;
    }

    .pill.role-examiner {
      background: var(--primary-soft);
      color: var(--primary);
      border-color: var(--primary-border);
    }

    .pill.offline-pill {
      background: var(--warn-soft);
      color: var(--warn);
      border-color: #fde68a;
    }

    /* Navigation Tabs */
    .main-nav {
      display: flex;
      overflow-x: auto;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      padding: 0 20px;
      gap: 4px;
    }

    .nav-tab {
      appearance: none;
      background: transparent;
      border: none;
      border-bottom: 2px solid transparent;
      padding: 12px 16px;
      font-size: 13px;
      font-weight: 600;
      color: var(--text-muted);
      cursor: pointer;
      min-height: var(--tap-min);
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      transition: color 0.15s, border-color 0.15s;
    }

    .nav-tab:hover {
      color: var(--text);
    }

    .nav-tab.active {
      color: var(--primary);
      border-bottom-color: var(--primary);
    }

    .nav-badge {
      background: var(--surface-alt);
      color: var(--text-muted);
      border-radius: 999px;
      padding: 1px 7px;
      font-size: 11px;
      font-weight: 700;
    }

    .nav-tab.active .nav-badge {
      background: var(--primary-soft);
      color: var(--primary);
    }

    /* Main Container & Cards */
    .container {
      max-width: 1180px;
      margin: 0 auto;
      padding: 20px;
      width: 100%;
    }

    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 20px;
      margin-bottom: 16px;
      box-shadow: var(--shadow);
      width: 100%;
      overflow: hidden;
    }

    .card-header {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 16px;
      padding-bottom: 12px;
      border-bottom: 1px solid var(--border);
    }

    .card-title {
      margin: 0;
      font-size: 16px;
      font-weight: 700;
      color: var(--text);
    }

    /* Aligned Responsive Grids (min-width: 0 prevents leaking) */
    .grid-2 {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
      gap: 16px;
      align-items: start;
    }

    .grid-3 {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
      gap: 16px;
      align-items: start;
    }

    .grid-4 {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
      gap: 14px;
      align-items: start;
    }

    .grid-2 > *, .grid-3 > *, .grid-4 > * {
      min-width: 0;
      max-width: 100%;
    }

    /* Field Groups */
    .field-group {
      margin-bottom: 16px;
      min-width: 0;
      max-width: 100%;
    }

    .field-group:last-child {
      margin-bottom: 0;
    }

    .field-label {
      display: block;
      font-weight: 600;
      font-size: 13px;
      margin-bottom: 8px;
      color: var(--text);
    }

    .field-req {
      color: var(--danger);
      margin-left: 2px;
    }

    .field-hint {
      display: block;
      font-size: 12px;
      color: var(--text-muted);
      margin-top: 6px;
    }

    /* Buttons */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      min-height: var(--tap-min);
      padding: 8px 14px;
      border-radius: var(--radius-sm);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      border: 1px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      transition: all 0.15s ease;
      max-width: 100%;
      text-align: center;
    }

    .btn:hover:not(:disabled) {
      background: var(--surface-alt);
    }

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

    .btn-primary {
      background: var(--primary);
      color: #ffffff;
      border-color: var(--primary);
    }

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

    .btn-danger {
      background: var(--danger);
      color: #ffffff;
      border-color: var(--danger);
    }

    .btn-sm {
      min-height: 38px;
      padding: 6px 12px;
      font-size: 12px;
    }

    /* Chips */
    .chip-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: stretch;
    }

    .chip {
      min-height: var(--tap-min);
      padding: 8px 14px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      user-select: none;
      transition: all 0.12s ease;
      max-width: 100%;
      white-space: normal;
      text-align: center;
      line-height: 1.3;
    }

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

    .chip.selected {
      background: var(--primary);
      color: #ffffff;
      border-color: var(--primary);
    }

    .chip:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }

    /* Steppers (Strictly Aligned Grid) */
    .stepper-wrap {
      display: inline-grid;
      grid-template-columns: 44px minmax(80px, auto) 44px;
      align-items: center;
      background: var(--surface-alt);
      padding: 3px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-strong);
      max-width: 100%;
    }

    .stepper-btn {
      width: 44px;
      height: 38px;
      border-radius: 6px;
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text);
      font-size: 18px;
      font-weight: 700;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0;
    }

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

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

    .stepper-val {
      text-align: center;
      font-size: 15px;
      font-weight: 700;
      padding: 0 10px;
      color: var(--text);
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
    }

    /* Inputs */
    .input-box {
      width: 100%;
      max-width: 100%;
      min-height: var(--tap-min);
      padding: 8px 12px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-strong);
      font-size: 14px;
      background: var(--surface);
      color: var(--text);
      display: block;
    }

    .input-box:focus {
      outline: 2px solid var(--primary);
      border-color: var(--primary);
    }

    .input-box[readonly], .input-box:disabled {
      background: var(--surface-alt);
      color: var(--text-muted);
    }

    /* Alerts / Banners */
    .banner {
      padding: 12px 16px;
      border-radius: var(--radius-sm);
      margin-bottom: 16px;
      font-size: 13px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 10px;
      border: 1px solid transparent;
    }

    .banner-info {
      background: var(--accent-soft);
      color: var(--accent);
      border-color: #bae6fd;
    }

    .banner-warn {
      background: var(--warn-soft);
      color: var(--warn);
      border-color: #fde68a;
    }

    .banner-danger {
      background: var(--danger-soft);
      color: var(--danger);
      border-color: #fecaca;
    }

    .banner-success {
      background: var(--success-soft);
      color: var(--success);
      border-color: #bbf7d0;
    }

    /* Timers */
    .timer-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 10px;
      border-radius: 999px;
      font-size: 12px;
      font-weight: 700;
      font-variant-numeric: tabular-nums;
    }

    .timer-green {
      background: var(--success-soft);
      color: var(--success);
      border: 1px solid #86efac;
    }

    .timer-yellow {
      background: var(--warn-soft);
      color: var(--warn);
      border: 1px solid #fcd34d;
    }

    .timer-red {
      background: var(--danger-soft);
      color: var(--danger);
      border: 1px solid #fca5a5;
    }

    .stale-tag {
      background: #9a3412;
      color: #ffedd5;
      padding: 2px 7px;
      border-radius: 4px;
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
    }

    /* Wizard Stepper Bar */
    .wizard-steps {
      display: grid;
      grid-template-columns: repeat(7, minmax(105px, 1fr));
      gap: 6px;
      overflow-x: auto;
      padding-bottom: 4px;
      margin-bottom: 16px;
    }

    .wizard-step-btn {
      min-height: 48px;
      padding: 8px 10px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text-muted);
      font-size: 12px;
      font-weight: 600;
      text-align: left;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: 2px;
      transition: all 0.12s;
    }

    .wizard-step-btn.active {
      border-color: var(--primary);
      background: var(--primary-soft);
      color: var(--primary);
      font-weight: 700;
    }

    .wizard-step-btn.done {
      border-color: #bbf7d0;
      background: var(--success-soft);
      color: var(--success);
    }

    /* FDI Dental Arch Box */
    .dental-arch-box {
      background: var(--surface-alt);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      padding: 14px;
      margin-bottom: 14px;
      overflow-x: auto;
    }

    .arch-label {
      font-size: 11px;
      font-weight: 700;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.04em;
      text-align: center;
      margin-bottom: 8px;
    }

    .arch-row {
      display: grid;
      grid-template-columns: repeat(8, minmax(36px, 1fr)) 8px repeat(8, minmax(36px, 1fr));
      gap: 4px;
      min-width: 640px;
      align-items: center;
    }

    .arch-divider {
      width: 2px;
      height: 44px;
      background: var(--border-strong);
      justify-self: center;
    }

    .tooth-btn {
      width: 100%;
      min-height: 52px;
      border-radius: 6px;
      border: 1.5px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 4px 2px;
      gap: 3px;
      transition: all 0.12s ease;
    }

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

    .tooth-btn.tooth-touch {
      background: var(--warn-soft);
      border-color: #f59e0b;
      color: var(--warn);
    }

    .tooth-btn.tooth-E {
      background: var(--exposed-soft);
      border-color: var(--exposed);
      color: var(--exposed);
    }

    .tooth-btn.tooth-C {
      background: var(--control-soft);
      border-color: var(--control);
      color: var(--control);
    }

    .tooth-btn.tooth-active-exam {
      box-shadow: 0 0 0 2.5px var(--primary);
    }

    .tooth-tag {
      font-size: 10px;
      padding: 1px 5px;
      border-radius: 4px;
      font-weight: 800;
      line-height: 1.2;
    }

    /* 5x2 Zone Grid Table */
    .zone-grid-table {
      width: 100%;
      border-collapse: collapse;
      min-width: 620px;
      table-layout: fixed;
    }

    .zone-grid-table th,
    .zone-grid-table td {
      border: 1px solid var(--border);
      padding: 10px 8px;
      text-align: center;
      vertical-align: middle;
    }

    .zone-grid-table th {
      background: var(--surface-alt);
      font-size: 12px;
      font-weight: 700;
      color: var(--text);
    }

    .zone-cell-main {
      background: #fefce8 !important;
      box-shadow: inset 0 0 0 2px #eab308;
    }

    /* Compact Zone Stepper */
    .zone-stepper {
      display: inline-grid;
      grid-template-columns: 32px 38px 32px;
      align-items: center;
      background: var(--surface-alt);
      border: 1px solid var(--border-strong);
      border-radius: 6px;
      padding: 2px;
    }

    .zone-stepper button {
      width: 32px;
      height: 30px;
      border: 1px solid var(--border);
      background: var(--surface);
      border-radius: 4px;
      font-weight: 700;
      font-size: 15px;
      cursor: pointer;
      color: var(--text);
      padding: 0;
    }

    .zone-stepper span {
      font-weight: 700;
      font-size: 14px;
      text-align: center;
      font-variant-numeric: tabular-nums;
    }

    /* Data Tables */
    .data-table-wrap {
      width: 100%;
      overflow-x: auto;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
    }

    .data-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 13px;
    }

    .data-table th,
    .data-table td {
      border-bottom: 1px solid var(--border);
      padding: 10px 12px;
      text-align: left;
      vertical-align: middle;
    }

    .data-table tr:last-child td {
      border-bottom: none;
    }

    .data-table th {
      background: var(--surface-alt);
      font-weight: 700;
      color: var(--text-muted);
      font-size: 12px;
      white-space: nowrap;
    }

    .num-col {
      text-align: right !important;
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
    }

    /* KPI Cards */
    .kpi-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      padding: 14px 16px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .kpi-label {
      font-size: 11px;
      font-weight: 700;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }

    .kpi-value {
      font-size: 22px;
      font-weight: 800;
      color: var(--text);
      margin-top: 4px;
      font-variant-numeric: tabular-nums;
    }

    .kpi-sub {
      font-size: 12px;
      color: var(--text-light);
      margin-top: 2px;
      font-variant-numeric: tabular-nums;
    }

    /* Dual Comparison Bar inside Table */
    .comp-bar-track {
      width: 100%;
      min-width: 120px;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .comp-bar-row {
      display: flex;
      align-items: center;
      gap: 6px;
      height: 10px;
    }

    .comp-bar-fill {
      height: 8px;
      border-radius: 4px;
      min-width: 3px;
    }

    /* Wizard Bottom Bar */
    .wizard-footer {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      background: var(--surface);
      border-top: 1px solid var(--border);
      padding: 10px 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      z-index: 900;
      box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
    }

    /* Modal & Toast */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      z-index: 2000;
    }

    .modal-card {
      background: var(--surface);
      border-radius: var(--radius);
      max-width: 500px;
      width: 100%;
      padding: 20px;
      box-shadow: 0 12px 32px rgba(15, 23, 42, 0.2);
      max-height: 90vh;
      overflow-y: auto;
    }

    .toast-box {
      position: fixed;
      bottom: 72px;
      right: 20px;
      z-index: 2500;
      background: #0f172a;
      color: #f8fafc;
      padding: 10px 16px;
      border-radius: var(--radius-sm);
      font-size: 13px;
      font-weight: 600;
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
      max-width: 360px;
    }

    @media (max-width: 640px) {
      .container {
        padding: 12px;
      }
      .card {
        padding: 14px;
      }
      .app-header {
        padding: 10px 12px;
      }
      .main-nav {
        padding: 0 12px;
      }
    }
