:root {
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --sidebar: #0F172A;
  --border: #E2E8F0;
  --ink: #0F172A;
  --ink-soft: #334155;
  --muted: #64748B;
  --teal: #0D9488;
  --teal-dark: #0F766E;
  --teal-soft: rgba(13, 148, 136, 0.12);
  --sky: #0EA5E9;
  --ok: #10B981;
  --warn: #F59E0B;
  --danger: #EF4444;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.14);
}

body.theme-dark {
  --bg: #080D16;
  --surface: #0F172A;
  --surface-2: #162033;
  --sidebar: #0B111D;
  --border: rgba(255, 255, 255, 0.09);
  --ink: #F8FAFC;
  --ink-soft: #CBD5E1;
  --muted: #94A3B8;
  --teal-soft: rgba(20, 184, 166, 0.16);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Alexandria', 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  direction: rtl;
}

.hidden { display: none !important; }
.mono { font-family: 'Manrope', monospace; font-variant-numeric: tabular-nums; }

.pd-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.pd-sidebar {
  background: var(--sidebar);
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.pd-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.pd-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0D9488, #0EA5E9);
  color: #FFF;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.pd-brand-copy { display: flex; flex-direction: column; min-width: 0; }
.pd-brand-copy strong { font-size: 0.92rem; color: #FFF; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pd-brand-copy span { font-size: 0.68rem; color: #94A3B8; }

.pd-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.pd-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(13, 148, 136, 0.25);
  color: #5EEAD4;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.pd-user-info { display: flex; flex-direction: column; min-width: 0; }
.pd-user-info strong { font-size: 0.84rem; color: #FFF; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pd-user-info span { font-size: 0.72rem; color: #5EEAD4; }

.pd-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.pd-nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: #94A3B8;
  padding: 9px 11px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s, color 0.15s;
}
.pd-nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #FFF; }
.pd-nav-item.active { background: rgba(13, 148, 136, 0.22); color: #5EEAD4; font-weight: 700; }
.pd-nav-txt { flex: 1; }
.pd-nav-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.2);
  color: #7DD3FC;
}
.pd-nav-pill--ok { background: rgba(16, 185, 129, 0.22); color: #6EE7B7; }

.pd-sidebar-foot { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.pd-foot-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px; border-radius: 10px;
  background: rgba(13, 148, 136, 0.18); color: #5EEAD4;
  text-decoration: none; font-size: 0.82rem; font-weight: 700;
}
.pd-foot-reset {
  border: 0; background: transparent; color: #64748B; font-family: inherit; font-size: 0.74rem; cursor: pointer; padding: 4px;
}
.pd-foot-reset:hover { color: #CBD5E1; }

.pd-main { display: flex; flex-direction: column; min-width: 0; }
.pd-topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.pd-topbar-title { display: flex; align-items: center; gap: 10px; }
.pd-topbar-title h1 { margin: 0; font-size: 1.15rem; font-weight: 800; }
.pd-topbar-title p { margin: 2px 0 0; font-size: 0.78rem; color: var(--muted); }

.pd-topbar-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pd-select-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 10px; height: 38px;
}
.pd-select-wrap--accent { border-color: var(--teal); background: var(--teal-soft); }
.pd-select-kicker { font-size: 0.7rem; color: var(--muted); font-weight: 700; }
.pd-select {
  border: 0; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 0.82rem; font-weight: 700; outline: none; cursor: pointer;
}

.pd-btn {
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font-family: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.pd-btn-primary { background: var(--teal); color: #FFF; }
.pd-btn-primary:hover { background: var(--teal-dark); }
.pd-btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.pd-btn-outline { background: transparent; color: var(--teal); border-color: var(--teal); }
.pd-btn-sm { height: 30px; padding: 0 10px; font-size: 0.76rem; border-radius: 8px; }
.pd-icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); cursor: pointer; display: grid; place-items: center;
}
.pd-mobile-only { display: none; }

.pd-content { padding: 20px 22px 40px; display: flex; flex-direction: column; gap: 18px; max-width: 1520px; width: 100%; margin-inline: auto; }

.pd-kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.pd-kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 5px;
}
.pd-kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.pd-kpi-val { font-size: 1.45rem; font-weight: 800; color: var(--ink); }
.pd-kpi-sub { font-size: 0.74rem; color: var(--ink-soft); }

.pd-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pd-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.pd-card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.pd-card-head h2, .pd-card-head h3 { margin: 0; font-size: 0.98rem; font-weight: 800; }
.pd-card-body { padding: 16px 18px; }

.pd-table-wrap { overflow-x: auto; }
.pd-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.pd-table th, .pd-table td { padding: 10px 10px; border-bottom: 1px solid var(--border); text-align: right; }
.pd-table th { font-size: 0.76rem; color: var(--muted); font-weight: 700; background: var(--surface-2); }

.pd-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.pd-badge--ok { background: rgba(16, 185, 129, 0.14); color: #059669; }
.pd-badge--warn { background: rgba(245, 158, 11, 0.16); color: #D97706; }
.pd-badge--info { background: rgba(14, 165, 233, 0.15); color: #0284C7; }
.pd-badge--danger { background: rgba(239, 68, 68, 0.15); color: #DC2626; }
.pd-badge--teal { background: var(--teal-soft); color: var(--teal); }

/* FDI Dental Chart */
.pd-arch { display: flex; flex-direction: column; gap: 10px; }
.pd-arch-row { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 5px; }
.pd-tooth {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 2px;
  background: var(--surface-2); color: var(--ink); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.72rem; font-weight: 700;
}
.pd-tooth:hover { border-color: var(--teal); }
.pd-tooth--planned { background: rgba(245, 158, 11, 0.18); border-color: #F59E0B; }
.pd-tooth--in_progress { background: rgba(14, 165, 233, 0.18); border-color: #0EA5E9; }
.pd-tooth--completed { background: rgba(16, 185, 129, 0.18); border-color: #10B981; }
.pd-tooth--implant { background: rgba(139, 92, 246, 0.18); border-color: #8B5CF6; }

.pd-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.pd-dot--ok { background: #10B981; }
.pd-dot--info { background: #0EA5E9; }
.pd-dot--warn { background: #F59E0B; }
.pd-dot--teal { background: #0D9488; }

.pd-arch-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.74rem; color: var(--muted); margin-bottom: 10px; }
.pd-arch-legend span { display: inline-flex; align-items: center; gap: 5px; }

.pd-switch { position: relative; display: inline-block; width: 34px; height: 20px; }
.pd-switch input { opacity: 0; width: 0; height: 0; }
.pd-switch-slider {
  position: absolute; inset: 0; cursor: pointer; background: var(--border);
  border-radius: 999px; transition: background 0.18s;
}
.pd-switch-slider::before {
  content: ""; position: absolute; height: 14px; width: 14px; right: 3px; bottom: 3px;
  background: #FFF; border-radius: 50%; transition: transform 0.18s;
}
.pd-switch input:checked + .pd-switch-slider { background: var(--teal); }
.pd-switch input:checked + .pd-switch-slider::before { transform: translateX(-14px); }

/* Progress bar */
.pd-prog-track { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.pd-prog-fill { height: 100%; border-radius: 999px; background: var(--teal); }

/* Modal & Form */
.pd-modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); z-index: 60;
  display: grid; place-items: center; padding: 16px;
}
.pd-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: min(760px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.pd-modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.pd-modal-head h2 { margin: 0; font-size: 1rem; font-weight: 800; }
.pd-modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.pd-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pd-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; font-weight: 700; }
.pd-input {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font-family: inherit; font-size: 0.84rem;
}

.pd-toast-wrap { position: fixed; bottom: 18px; left: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.pd-toast {
  background: var(--sidebar); color: #FFF; padding: 10px 16px; border-radius: 10px;
  font-size: 0.82rem; font-weight: 700; box-shadow: var(--shadow-lg); border-right: 4px solid var(--teal);
}

@media (max-width: 1024px) {
  .pd-shell { grid-template-columns: 1fr; }
  .pd-sidebar { position: fixed; inset-block: 0; right: 0; width: 260px; z-index: 50; transform: translateX(100%); transition: transform 0.2s; }
  .pd-sidebar.open { transform: translateX(0); }
  .pd-mobile-only { display: grid; }
  .pd-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pd-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .pd-arch-row { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .pd-form-grid { grid-template-columns: 1fr; }
}
