@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --sidebar-bg: #0f172a;
  --sidebar-bg-hover: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --neutral: #e2e8f0;
  --neutral-hover: #cbd5e1;
  --bg: #f8fafc;
  --surface: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --sidebar-bg: #070c16;
  --sidebar-bg-hover: #16212f;
  --accent-soft: rgba(37, 99, 235, 0.18);
  --accent-border: rgba(37, 99, 235, 0.45);
  --danger-soft: rgba(220, 38, 38, 0.18);
  --danger-border: rgba(220, 38, 38, 0.45);
  --success-soft: rgba(22, 163, 74, 0.18);
  --success-border: rgba(22, 163, 74, 0.45);
  --neutral: #1f2937;
  --neutral-hover: #2b3648;
  --bg: #0b1220;
  --surface: #111827;
  --card-bg: #131c2e;
  --border: #263248;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: ltr;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.app {
  display: flex;
  min-height: 100vh;
}

#app-root[hidden] {
  display: none;
}

/* ---------- Login screen ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.login-card .login-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  margin-bottom: 4px;
}

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

.login-card .sidebar-sub {
  color: var(--text-muted);
  margin: -8px 0 6px;
  opacity: 1;
}

.login-card .form-field {
  width: 100%;
  text-align: left;
}

.login-error {
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Sidebar footer ---------- */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer #session-user-label {
  color: var(--sidebar-text);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 11.5px;
}

.sidebar-footer .icon-btn {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--sidebar-text);
}

.sidebar-footer .icon-btn:hover {
  color: var(--sidebar-text-active);
  background: var(--sidebar-bg-hover);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: relative;
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  transition: width 0.18s ease, padding 0.18s ease;
}

.sidebar-toggle-btn {
  position: absolute;
  top: 28px;
  right: -12px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  z-index: 5;
  transition: transform 0.18s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover {
  color: var(--accent);
}

.sidebar.collapsed {
  width: 76px;
  padding: 24px 10px;
}

.sidebar.collapsed .sidebar-toggle-btn {
  transform: rotate(180deg);
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar.collapsed .sidebar-header-text,
.sidebar.collapsed .nav-btn span,
.sidebar.collapsed #session-user-label {
  display: none;
}

.sidebar.collapsed .nav-btn {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .sidebar-footer {
  justify-content: center;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.sidebar-header-text {
  min-width: 0;
  overflow: hidden;
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--sidebar-text-active);
  margin: 0;
  line-height: 1.2;
}

.sidebar-sub {
  font-size: 12px;
  color: var(--sidebar-text);
  margin: 2px 0 0;
  opacity: 0.75;
}

/* ---------- Dashboard switch (aHUS / PNH) ---------- */
.dashboard-switch {
  display: flex;
  background: var(--sidebar-bg-hover);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.dashboard-switch-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.dashboard-switch-btn:hover {
  color: var(--sidebar-text-active);
}

.dashboard-switch-btn.active {
  background: var(--accent);
  color: #fff;
}

.sidebar.collapsed .dashboard-switch {
  display: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn .icon {
  opacity: 0.8;
}

.nav-btn:hover {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
}

.nav-btn.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.nav-btn.active .icon {
  opacity: 1;
}

/* ---------- Content ---------- */
.content {
  flex: 1;
  padding: 36px 44px;
  max-width: 1280px;
}

.section {
  display: none;
}

.section.active {
  display: block;
  animation: fadeIn 0.15s ease;
}

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

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.section-heading h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.section-subtitle {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ---------- Add button (opens the add/edit modal) ---------- */
.icon-btn-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-inline-start: auto;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn-add:hover {
  background: var(--accent-hover);
}

.icon-btn-add:active {
  transform: scale(0.92);
}

/* ---------- Modal (add / edit forms) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: modalIn 0.15s ease;
}

.modal-lg {
  max-width: 920px;
}

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

.modal-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.modal-close-btn:hover {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.modal-body {
  padding: 20px 22px 22px;
}

.modal-body .entity-form,
.modal-body .patients-form {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  margin-bottom: 0;
}

body.modal-open {
  overflow: hidden;
}

/* ---------- Form ---------- */
.entity-form {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field-wide {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-field input:disabled {
  background: var(--surface);
  color: var(--text-muted);
}

.form-field textarea {
  resize: vertical;
}

.form-actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
  background: var(--neutral);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--neutral-hover);
}

/* Icon-only buttons (primary form actions: Save / Cancel) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-icon:active {
  transform: scale(0.94);
}

.btn-icon-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-icon-primary:hover {
  background: var(--accent-hover);
}

.btn-icon-secondary {
  background: var(--neutral);
  color: var(--text);
}

.btn-icon-secondary:hover {
  background: var(--neutral-hover);
}

/* Icon-only buttons (row actions: Edit / Delete) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  margin-inline-end: 6px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:last-child {
  margin-inline-end: 0;
}

.icon-btn-view:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}

.icon-btn-edit:hover {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.icon-btn-delete:hover {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

/* ---------- Search ---------- */
.search-box {
  position: relative;
  max-width: 320px;
  margin-bottom: 16px;
}

.search-box .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin-bottom: 4px;
}

.filters-row .search-box {
  margin-bottom: 16px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  margin-bottom: 16px;
}

.filter-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.filter-field select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
}

/* ---------- Table ---------- */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

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

.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.data-table tbody tr:hover {
  background: var(--surface);
}

.actions-cell {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-yes {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.badge-no {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.badge-neutral {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.cell-truncate {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 28px !important;
}

/* ---------- Visit preview panel ---------- */
.visit-preview {
  margin-top: 16px;
  padding: 18px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
}

.visit-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.visit-preview-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.visit-preview-grid span {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.visit-preview-grid strong {
  font-size: 15px;
  color: var(--text);
}

.visit-preview-warning {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

/* ---------- Stock summary ---------- */
.stock-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.stat-card span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat-card strong {
  font-size: 25px;
  font-weight: 700;
  color: var(--text);
}

.stat-card-highlight {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.stat-card-highlight strong {
  color: var(--accent);
}

.stat-card-highlight.stock-negative {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.stat-card-highlight.stock-negative strong {
  color: var(--danger);
}

.stock-subheading {
  margin: 30px 0 14px;
  font-size: 15px;
  font-weight: 700;
}

/* ---------- Settings page ---------- */
.settings-block {
  margin-bottom: 22px;
}

.settings-block h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}

.settings-hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.icon-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.icon-swatch {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.icon-swatch:hover {
  border-color: var(--accent-border);
}

.icon-swatch.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.theme-toggle {
  display: flex;
  gap: 10px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 9px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.theme-option:hover {
  border-color: var(--accent-border);
}

.theme-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.accent-gallery {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.accent-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.accent-swatch.active {
  border-color: var(--card-bg);
  box-shadow: 0 0 0 2px var(--text);
  transform: scale(1.08);
}

.reset-row {
  margin-top: 8px;
}

.reset-row .btn svg {
  margin-inline-end: 6px;
}

/* ---------- Reports ---------- */
.reports-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
  align-items: start;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.bar-label {
  flex: 0 0 120px;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.bar-value {
  flex: 0 0 28px;
  text-align: right;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.bar-empty {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Patient form (cards) ---------- */
.patients-form {
  margin-bottom: 24px;
}

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

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

.patient-form-card h3 {
  margin: 0 0 14px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.patient-form-card .form-grid {
  gap: 14px;
}

.form-field-checkbox {
  flex-direction: row;
  align-self: end;
}

.form-field-checkbox label {
  display: flex;
  align-items: center;
  gap: 9px;
  text-transform: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  padding: 9px 0;
}

.form-field-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Vaccination date field: lets the value be a real date OR an explicit
   "No" (not vaccinated) instead of leaving the date blank. */
.vaccination-no-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  font-size: 12.5px;
  font-weight: 500;
  text-transform: none;
  color: var(--text-muted);
  cursor: pointer;
}

.vaccination-no-toggle input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Patients table: expandable row detail ---------- */
.icon-btn-expand {
  width: 26px;
  height: 26px;
  margin-inline-end: 8px;
  vertical-align: middle;
}

.icon-btn-expand.active {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

/* ---------- Patient photos: upload row, thumbnail grid, lightbox ---------- */
.photo-upload-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.photo-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm, 8px);
  cursor: pointer;
  transition: background 0.15s ease;
}

.photo-upload-btn:hover {
  background: var(--accent-border);
}

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

.photo-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm, 8px);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb-remove {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
  line-height: 1;
}

.photo-thumb-remove:hover {
  background: rgba(200, 30, 30, 0.85);
}

.photo-thumb-empty {
  font-size: 12.5px;
  color: var(--text-muted);
}

.modal-lightbox {
  max-width: min(92vw, 900px);
}

.modal-lightbox .modal-body {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.photo-lightbox-img {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  display: block;
  margin: 0 auto;
}

.patient-detail-row td {
  background: var(--surface);
  white-space: normal;
  padding: 20px 22px;
}

.patient-detail-row .profile-fields-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

/* ---------- Patient profile ---------- */
.profile-header-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.profile-header-card h3 {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 700;
}

.profile-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
  align-items: start;
}

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

.profile-card h4 {
  margin: 0 0 16px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.profile-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 16px 18px;
}

.profile-field-wide {
  grid-column: 1 / -1;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.profile-field span {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.profile-field strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

/* ---------- Staff (read-only) role ---------- */
/* Staff can browse and search every page but cannot add, edit, or delete
   anything: every add/edit form and every edit/delete row action is
   hidden. Database export and the Excel report stay available since
   those only read data, they don't change it. */
body.role-readonly .entity-form {
  display: none;
}

body.role-readonly .icon-btn-edit,
body.role-readonly .icon-btn-delete,
body.role-readonly .icon-btn-add {
  display: none;
}

body.role-readonly .settings-block:has(#settings-title),
body.role-readonly .settings-block:has(#settings-icon-gallery),
body.role-readonly .settings-block:has(#settings-theme-toggle),
body.role-readonly .settings-block:has(#settings-pagenames-grid),
body.role-readonly .reset-row,
body.role-readonly #db-import-input,
body.role-readonly label[for="db-import-input"] {
  display: none !important;
}

/* ---------- Dashboard-specific fields (aHUS vs PNH) ---------- */
/* Some patient fields only make sense for one disease's work-up — the
   body carries a dashboard-x class (set on load and on every switch) and
   these rules hide whichever side doesn't apply. */
body.dashboard-pnh .disease-ahus-only {
  display: none;
}

body.dashboard-ahus .disease-pnh-only {
  display: none;
}

/* ---------- Sync error banner ---------- */
.sync-error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--danger);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 16px;
  box-shadow: var(--shadow-md);
}

.sync-error-banner[hidden] {
  display: none;
}

.sync-error-banner button {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

/* ---------- Responsive ---------- */
.table-wrap {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }

  .sidebar,
  .sidebar.collapsed {
    width: 100%;
    padding: 12px 16px;
    gap: 12px;
  }

  .sidebar.collapsed .sidebar-header-text,
  .sidebar.collapsed .nav-btn span,
  .sidebar.collapsed #session-user-label {
    display: initial;
  }

  .sidebar.collapsed .nav-btn {
    justify-content: flex-start;
    padding: 9px 14px;
  }

  .sidebar.collapsed .dashboard-switch {
    display: flex;
  }

  .sidebar.collapsed .sidebar-header {
    justify-content: flex-start;
  }

  .sidebar-toggle-btn {
    display: none;
  }

  .sidebar-header {
    padding: 0;
  }

  .modal {
    max-height: calc(100vh - 32px);
  }

  .nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav::-webkit-scrollbar {
    height: 4px;
  }

  .nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 9px 14px;
  }

  .sidebar-footer {
    padding-top: 10px;
    margin-top: 0;
  }

  .content {
    padding: 22px 20px;
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 16px;
  }

  .section-heading {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .section-heading h2 {
    font-size: 19px;
  }

  .section-subtitle {
    margin: 0 0 16px;
  }

  .login-screen {
    padding: 16px;
  }

  .login-card {
    max-width: 100%;
    padding: 26px 20px;
  }

  .entity-form {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-field input,
  .form-field select,
  .form-field textarea,
  .filter-field select,
  .search-box input {
    font-size: 16px;
  }

  .filters-row {
    gap: 10px;
  }

  .filter-field {
    min-width: 0;
    flex: 1 1 140px;
    margin-bottom: 12px;
  }

  .search-box {
    max-width: none;
    width: 100%;
    flex: 1 1 100%;
    margin-bottom: 12px;
  }

  .filters-row .search-box {
    margin-bottom: 12px;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal,
  .modal-lg {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: calc(100vh - 16px);
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .patient-form-cards,
  .profile-grid,
  .reports-grid,
  .stock-summary {
    grid-template-columns: 1fr;
  }

  .patient-form-card,
  .profile-card,
  .stat-card {
    padding: 16px 18px;
  }

  .profile-header-card {
    padding: 18px;
  }

  .profile-fields-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px 14px;
  }

  .bar-label {
    flex-basis: 88px;
  }

  .data-table {
    font-size: 12.5px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 10px;
  }

  .btn {
    padding: 9px 16px;
  }

  .icon-gallery,
  .accent-gallery,
  .theme-toggle,
  .upload-row {
    gap: 8px;
  }
}

@media (max-width: 420px) {
  .dashboard-switch-btn {
    font-size: 11.5px;
    padding: 7px 4px;
  }

  .nav-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .sidebar-header h1 {
    font-size: 15.5px;
  }

  .stat-card strong {
    font-size: 21px;
  }

  .profile-header-card h3 {
    font-size: 19px;
  }

  .modal-header h3 {
    font-size: 15px;
  }
}
