:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-soft: #ccfbf1;
  --blue: #0284c7;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --planned: #ef4444;
  --completed: #2563eb;
  --external: #16a34a;
  --implant: #7c3aed;
  --missing: #94a3b8;
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

/* Mobile-First Top Bar (< 960px default) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 56px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand-dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
.icon-btn {
  min-width: 44px; min-height: 44px;
  border: 1px solid var(--border);
  background: #fff; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; color: var(--text);
}
.btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-danger { background: #fee2e2; border-color: #fecaca; color: #b91c1c; }

/* Slide-over Drawer (Mobile) -> Persistent Left Sidebar (Desktop >= 960px) */
.backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  z-index: 45; display: none;
}
.backdrop.open { display: block; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #0f172a;
  color: #e2e8f0;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding: 16px 12px 24px;
}
.sidebar.open { transform: translateX(0); }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 8px 14px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand { font-weight: 700; font-size: 15px; color: #fff; display: flex; align-items: center; gap: 8px; }
.tenant-pill {
  margin: 12px 4px;
  padding: 10px 12px;
  background: rgba(13, 148, 136, 0.18);
  border: 1px solid rgba(45, 212, 191, 0.35);
  border-radius: 10px;
  font-size: 12px;
  color: #99f6e4;
}
.nav-group { margin-top: 14px; }
.nav-group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #94a3b8; padding: 0 10px 6px; font-weight: 600;
}
.nav-item {
  width: 100%; min-height: 44px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-radius: 10px;
  border: none; background: transparent; color: #cbd5e1;
  font-size: 14px; font-weight: 500; cursor: pointer; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--teal); color: #fff; font-weight: 600; }

/* Main Content */
.main {
  padding: 14px 14px calc(80px + env(safe-area-inset-bottom));
  max-width: 1240px;
  margin: 0 auto;
}

/* Bottom Tab Bar (Mobile only) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: #ffffff; border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.bnav-btn {
  min-height: 48px; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer;
}
.bnav-btn.active { color: var(--teal-dark); font-weight: 700; }
.bnav-ico { font-size: 18px; line-height: 1; }

/* Cards & Grids */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.card-title {
  font-size: 16px; font-weight: 700; margin: 0 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.kpi-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px;
}
.kpi {
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 22px; font-weight: 800; color: var(--text); margin-top: 4px; }

/* Patient Sidekick Header */
.sidekick {
  background: linear-gradient(135deg, #f0fdfa, #eff6ff);
  border: 1px solid #99f6e4;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.sidekick-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; }
.alert-bar {
  margin-top: 10px;
  padding: 8px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  color: #991b1b;
  font-size: 13px;
  font-weight: 600;
}
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge-teal { background: var(--teal-soft); color: var(--teal-dark); }
.badge-blue { background: #e0f2fe; color: #0369a1; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

/* Curve Dental 32-Tooth FDI Odontogram */
.odo-legend {
  display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; margin-bottom: 12px;
}
.leg-item { display: inline-flex; align-items: center; gap: 5px; }
.leg-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.arch-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.arch-row {
  display: grid; grid-template-columns: repeat(16, minmax(46px, 1fr));
  gap: 4px; min-width: 760px; margin-bottom: 8px;
}
.tooth-cell {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px 3px;
  text-align: center;
  cursor: pointer;
  transition: all 0.14s ease;
  min-height: 70px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
}
.tooth-cell:hover { border-color: var(--teal); transform: translateY(-1px); }
.tooth-cell.selected { border-color: var(--teal-dark); box-shadow: 0 0 0 3px rgba(13,148,136,0.22); }
.tooth-num { font-size: 12px; font-weight: 700; color: var(--text); }
.tooth-svg { width: 32px; height: 32px; }
.tooth-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; }

.status-planned { border-color: var(--planned); background: #fef2f2; }
.status-completed { border-color: var(--completed); background: #eff6ff; }
.status-external { border-color: var(--external); background: #f0fdf4; }
.status-implant { border-color: var(--implant); background: #faf5ff; }
.status-missing { border-color: var(--missing); background: #f1f5f9; opacity: 0.65; }

/* Tables & Forms */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 600px; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f8fafc; font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 16px; /* Prevents iOS Safari auto-zoom */
  font-family: inherit;
  background: #fff;
}
textarea { min-height: 84px; resize: vertical; }

.code-box {
  background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  overflow-x: auto; max-height: 420px; white-space: pre;
}

.tab-pills { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.pill {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
}
.pill.active { background: var(--teal); color: #fff; border-color: var(--teal); }

.view { display: none; }
.view.active { display: block; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  z-index: 60; display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-bg.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; max-width: 540px; width: 100%;
  max-height: 90vh; overflow-y: auto; padding: 20px;
}

/* Desktop Enhancement (>= 960px) */
@media (min-width: 960px) {
  .sidebar { transform: translateX(0); }
  .topbar { margin-left: var(--sidebar-w); padding: 0 24px; }
  .menu-toggle, .bottom-nav, .backdrop { display: none !important; }
  .main { margin-left: var(--sidebar-w); padding: 20px 24px 40px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .clinical-split { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }
}

/* Print / A4 PDF Preservation for MOH 16/BV-01 */
@media print {
  .noprint, .topbar, .sidebar, .bottom-nav, .backdrop { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; max-width: 100% !important; }
  .card { border: none; box-shadow: none; padding: 0; }
  body { background: #fff; font-size: 12pt; }
}
