/* ============================================================
   E-Prescription System - Design System
   Professional Medical UI | RTL Arabic Support
   ============================================================ */

/* --- FONTS (local, offline-first — see assets/vendor/fonts/) --- */
@import url('../assets/vendor/fonts/fonts.css');

/* ============================================================
   CSS VARIABLES - DESIGN TOKENS
   ============================================================ */
:root {
  /* Primary Brand - Steel Blue (brand refresh 2026) */
  --primary-50:  #eef6ff;
  --primary-100: #d6ebff;
  --primary-200: #b5d9fd;
  --primary-300: #94bce3;
  --primary-400: #749dc4;
  --primary-500: #5980a6;
  --primary-600: #597ea3;
  --primary-700: #416180;
  --primary-800: #2c455d;
  --primary-900: #1d2d3d;

  /* Neutrals */
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Status Colors */
  --success-50:  #f0fdf4;
  --success-500: #22c55e;
  --success-700: #15803d;
  --warning-50:  #fffbeb;
  --warning-500: #f59e0b;
  --warning-700: #b45309;
  --danger-50:   #fef2f2;
  --danger-500:  #ef4444;
  --danger-700:  #b91c1c;
  --info-50:     #eff6ff;
  --info-500:    #3b82f6;
  --info-700:    #1d4ed8;

  /* Semantic */
  --bg-base:      #f0f4f8;
  --bg-surface:   #ffffff;
  --bg-elevated:  #ffffff;
  --border-light: #e2e8f0;
  --border-main:  #cbd5e1;
  --text-primary:   var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted:     var(--gray-400);

  /* Typography (brand refresh 2026: Barlow / Barlow Condensed) */
  --font-ar: 'Cairo', sans-serif;
  --font-en: 'Barlow', sans-serif;
  --font-main: var(--font-en);
  --font-heading: 'Barlow Condensed', var(--font-en);

  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:    0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius:    0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition:      200ms ease;
  --transition-slow: 300ms ease;

  /* Layout */
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --content-max: 1280px;
}

/* --- DARK MODE TOKENS --- */
[data-theme="dark"] {
  --bg-base:      #0f172a;
  --bg-surface:   #1e293b;
  --bg-elevated:  #273344;
  --border-light: #334155;
  --border-main:  #475569;
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow:    0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  direction: ltr;
  min-height: 100vh;
  overflow-x: hidden;
}

body.lang-en {
  direction: ltr;
  font-family: var(--font-en);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--gray-600); }

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}
/* English headings use the brand's condensed display face; Arabic keeps
   Cairo (set via body.lang-ar) so this is scoped to lang-en only. */
body.lang-en h1, body.lang-en h2, body.lang-en h3,
body.lang-en h4, body.lang-en h5, body.lang-en h6 {
  font-family: var(--font-heading);
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p { margin-bottom: var(--space-4); color: var(--text-secondary); }
a { color: var(--primary-600); text-decoration: none; }
a:hover { color: var(--primary-700); }

/* ============================================================
   ICON SYSTEM (Lucide, self-hosted inline SVG sprite)
   All icons are <svg class="icon"><use href="#icon-name"/></svg>.
   Sized in em so every existing font-size-based icon rule
   (.nav-icon, .card-title-icon, etc.) keeps working unchanged.
   ============================================================ */
.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

/* Toggled/"active" state (favorites, filled statuses) — solid fill
   instead of a second icon weight, mirrors the old *-fill glyphs. */
.icon--filled {
  fill: currentColor;
  stroke: currentColor;
}

/* Slightly heavier stroke for contexts that previously used the
   bold icon-font weight (e.g. primary call-to-action icons). */
.icon--bold { stroke-width: 2.5; }

@keyframes icon-spin { to { transform: rotate(360deg); } }
.icon--spin { animation: icon-spin 0.9s linear infinite; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
  box-shadow: var(--shadow-lg);
}

body.lang-en .sidebar {
  border-left: none;
  border-right: 1px solid var(--border-light);
  right: auto;
  left: 0;
}

.sidebar-logo {
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.sidebar-logo-text {
  flex: 1;
}

.sidebar-logo-text h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.sidebar-logo-text span {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
}

.nav-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: var(--space-3) var(--space-3) var(--space-2);
  margin-top: var(--space-4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: right;
}

body.lang-en .nav-item { text-align: left; }

.nav-item:hover {
  background: var(--primary-50);
  color: var(--primary-700);
}

.nav-item.active {
  background: var(--primary-600);
  color: white;
  box-shadow: var(--shadow-md);
}

.nav-item.active .nav-icon { color: white; }

.nav-icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  color: var(--gray-400);
  transition: color var(--transition-fast);
}

.nav-item:hover .nav-icon { color: var(--primary-600); }

.nav-badge {
  margin-right: auto;
  background: var(--primary-100);
  color: var(--primary-700);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

body.lang-en .nav-badge { margin-right: 0; margin-left: auto; }
.nav-item.active .nav-badge { background: rgba(255,255,255,0.2); color: white; }

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-light);
}

/* --- MAIN CONTENT --- */
.main-content {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.lang-en .main-content { margin-right: 0; margin-left: var(--sidebar-width); }

/* --- TOP BAR --- */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- PAGE CONTENT --- */
.page-content {
  flex: 1;
  padding: var(--space-6);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* --- CARD --- */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card-title-icon {
  color: var(--primary-600);
  font-size: 1.1rem;
}

.card-body { padding: var(--space-6); }
.card-body-sm { padding: var(--space-4); }
.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-light);
  background: var(--gray-50);
}
[data-theme="dark"] .card-footer { background: var(--bg-base); }

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.875rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
  height: 40px;
}

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

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

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border-color: var(--gray-200);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }
[data-theme="dark"] .btn-secondary { background: var(--gray-800); color: var(--gray-200); border-color: var(--gray-700); }

.btn-success {
  background: var(--success-500);
  color: white;
  border-color: var(--success-500);
}
.btn-success:hover:not(:disabled) { background: var(--success-700); border-color: var(--success-700); }

.btn-danger {
  background: var(--danger-500);
  color: white;
  border-color: var(--danger-500);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-700); }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--text-primary); }
[data-theme="dark"] .btn-ghost:hover:not(:disabled) { background: var(--gray-800); }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius);
}

.btn-sm { height: 34px; padding: var(--space-1) var(--space-4); font-size: 0.8rem; }
.btn-lg { height: 48px; padding: var(--space-3) var(--space-8); font-size: 1rem; }
.btn-full { width: 100%; }

/* --- FORM ELEMENTS --- */
.form-group { margin-bottom: var(--space-4); }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-label .required { color: var(--danger-500); margin-right: 2px; }

.form-control {
  display: block;
  width: 100%;
  height: 42px;
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-main);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(26, 157, 176, 0.12);
}

.form-control::placeholder { color: var(--text-muted); font-size: 0.85rem; }

textarea.form-control {
  height: auto;
  min-height: 100px;
  padding-top: var(--space-3);
  resize: vertical;
}

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}

body:not(.lang-en) select.form-control {
  background-position: left 12px center;
}

body.lang-en select.form-control {
  background-position: right 12px center;
  padding-left: var(--space-4);
  padding-right: 36px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger-500);
  margin-top: var(--space-1);
  display: none;
}

.form-control.is-invalid { border-color: var(--danger-500); }
.form-control.is-invalid + .form-error { display: block; }

/* Input Group */
.input-group {
  display: flex;
  flex-direction: row-reverse;
  align-items: stretch;
}

.input-group .form-control {
  border-radius: 0;
  flex: 1;
}

.input-group .form-control:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .form-control:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }
body.lang-en .input-group .form-control:first-child { border-radius: 0 var(--radius) var(--radius) 0; }
body.lang-en .input-group .form-control:last-child  { border-radius: var(--radius) 0 0 var(--radius); }

.input-addon {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--gray-100);
  border: 1.5px solid var(--border-main);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}

.input-addon:first-child { border-left: none; border-radius: 0 var(--radius) var(--radius) 0; }
.input-addon:last-child  { border-right: none; border-radius: var(--radius) 0 0 var(--radius); }

/* Grid */
.form-grid { display: grid; gap: var(--space-4); }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* --- BADGE --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-primary { background: var(--primary-100); color: var(--primary-700); }
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-700);  }
.badge-gray    { background: var(--gray-100);   color: var(--gray-600);    }

/* --- DIVIDER --- */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-6) 0;
}

/* --- ALERT --- */
.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 0.875rem;
}

.alert-success { background: var(--success-50); border-color: var(--success-500); color: var(--success-700); }
.alert-warning { background: var(--warning-50); border-color: var(--warning-500); color: var(--warning-700); }
.alert-danger  { background: var(--danger-50);  border-color: var(--danger-500);  color: var(--danger-700);  }
.alert-info    { background: var(--info-50);    border-color: var(--info-500);    color: var(--info-700);    }

/* --- STATS CARD --- */
.stat-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon-primary { background: var(--primary-100); color: var(--primary-600); }
.stat-icon-success { background: var(--success-50); color: var(--success-700); }
.stat-icon-warning { background: var(--warning-50); color: var(--warning-700); }
.stat-icon-info    { background: var(--info-50); color: var(--info-700); }

.stat-content { flex: 1; }
.stat-value {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-1);
}
.stat-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.stat-change {
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: var(--space-2);
}
.stat-change.positive { color: var(--success-700); }
.stat-change.negative { color: var(--danger-700); }

/* --- TABLE --- */
.table-wrapper { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  background: var(--gray-50);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-3) var(--space-4);
  text-align: right;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

body.lang-en .table th { text-align: left; }

.table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:hover td { background: var(--primary-50); }
[data-theme="dark"] .table th { background: var(--bg-base); }
[data-theme="dark"] .table tr:hover td { background: rgba(26,157,176,0.06); }

/* --- MODAL --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-slow);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(20px);
  transition: transform var(--transition-slow);
}

.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }

.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-body  { padding: var(--space-6); overflow-y: auto; flex: 1; }
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* --- DRUG SEARCH AUTOCOMPLETE --- */
.drug-search-wrapper {
  position: relative;
}

.drug-autocomplete {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--bg-surface);
  border: 1.5px solid var(--primary-400);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 280px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  display: none;
}

.drug-autocomplete.show { display: block; }

.drug-autocomplete-item {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
}

.drug-autocomplete-item:last-child { border-bottom: none; }
.drug-autocomplete-item:hover,
.drug-autocomplete-item.highlighted { background: var(--primary-50); }

.drug-name-ar { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); }
.drug-name-en { font-size: 0.75rem; color: var(--text-muted); }
.drug-strength-badge { font-size: 0.7rem; background: var(--gray-100); color: var(--gray-600); padding: 2px 8px; border-radius: var(--radius-full); white-space: nowrap; }

/* --- PRESCRIPTION ITEM --- */
.rx-item {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  position: relative;
  transition: border-color var(--transition-fast);
}

.rx-item:hover { border-color: var(--primary-300); }
.rx-item-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.rx-item-number {
  width: 28px;
  height: 28px;
  background: var(--primary-600);
  color: white;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.rx-item-title {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-700);
}

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  left: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  pointer-events: none;
}

body.lang-en .toast-container { left: auto; right: var(--space-6); }

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--gray-900);
  color: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  font-size: 0.875rem;
  font-weight: 500;
  pointer-events: all;
  transform: translateX(-20px);
  opacity: 0;
  transition: all var(--transition-slow);
  min-width: 260px;
  max-width: 380px;
}

body.lang-en .toast { transform: translateX(20px); }

.toast.show { transform: translateX(0); opacity: 1; }
.toast-success { background: var(--success-700); }
.toast-danger  { background: var(--danger-700); }
.toast-warning { background: #92400e; }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }

/* --- LOADING SPINNER --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner-primary {
  border-color: var(--primary-200);
  border-top-color: var(--primary-600);
}

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

/* --- EMPTY STATE --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state h3 { color: var(--text-secondary); margin-bottom: var(--space-2); }
.empty-state p  { font-size: 0.875rem; margin-bottom: var(--space-6); }

/* --- AVATAR --- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-400), var(--primary-700));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* --- SECTION HEADER --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}

.section-header h2 { margin: 0; font-size: 1.25rem; }

/* ============================================================
   PRESCRIPTION PRINT STYLES
   ============================================================ */
.print-area { display: none; }

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body { background: white !important; direction: rtl; }

  .app-wrapper { display: block; }
  .sidebar, .topbar, .page-content > :not(.print-preview),
  .no-print { display: none !important; }

  .print-area { display: block !important; }
  .main-content { margin: 0 !important; }

  .rx-print-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 15mm 15mm;
    font-family: 'Cairo', sans-serif;
    font-size: 11pt;
    color: #1a1a1a;
    background: white;
  }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.d-none    { display: none !important; }
.d-flex    { display: flex; }
.d-block   { display: block; }
.d-grid    { display: grid; }

.flex-1    { flex: 1; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end   { justify-content: flex-end; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.w-full { width: 100%; }
.text-center { text-align: center; }
.text-start  { text-align: right; }
.text-end    { text-align: left; }

.text-sm   { font-size: 0.875rem; }
.text-xs   { font-size: 0.75rem; }
.text-lg   { font-size: 1.125rem; }
.text-xl   { font-size: 1.25rem; }
.font-bold   { font-weight: 700; }
.font-medium { font-weight: 500; }
.text-muted  { color: var(--text-muted); }
.text-primary-color { color: var(--primary-600); }
.text-success { color: var(--success-700); }
.text-danger  { color: var(--danger-700); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.rounded { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }
.shadow { box-shadow: var(--shadow); }
.shadow-md { box-shadow: var(--shadow-md); }
.overflow-hidden { overflow: hidden; }
.cursor-pointer { cursor: pointer; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-width: 240px; }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --topbar-height: 56px;
  }

  .sidebar {
    transform: translateX(100%);
    width: 280px;
    right: 0;
  }

  body.lang-en .sidebar {
    transform: translateX(-100%);
    left: 0;
    right: auto;
  }

  .sidebar.open { transform: translateX(0); }

  .main-content { margin-right: 0 !important; margin-left: 0 !important; }

  .page-content { padding: var(--space-4); }

  .form-grid-2,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr; }

  .topbar { padding: 0 var(--space-4); }

  .modal { border-radius: var(--radius-lg); }
  .modal-overlay { padding: var(--space-2); align-items: flex-end; }
  .modal { max-width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 95vh; }

  .sidebar-toggle-btn { display: flex !important; }

  .stat-card { padding: var(--space-4); }
  .stat-value { font-size: 1.4rem; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .page-content { padding: var(--space-3); }
  .card-body { padding: var(--space-4); }
  .table th, .table td { padding: var(--space-2) var(--space-3); }
}

/* --- SIDEBAR OVERLAY (Mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.active { display: block; }
.sidebar-toggle-btn { display: none !important; }

/* ============================================================
   BILINGUAL OVERRIDE — Arabic (RTL) when lang-ar is active
   ============================================================ */

/* Default body is now LTR/English. Arabic overrides follow. */
body.lang-ar {
  direction: rtl;
  font-family: var(--font-ar);
}

body.lang-ar .sidebar {
  right: 0;
  left: auto;
  border-right: none;
  border-left: 1px solid var(--border-light);
}

body.lang-ar .main-content {
  margin-right: var(--sidebar-width);
  margin-left: 0;
}

body.lang-ar .nav-item { text-align: right; }
body.lang-ar .nav-badge { margin-left: 0; margin-right: auto; }
body.lang-ar .table th { text-align: right; }
body.lang-ar .toast-container { right: auto; left: var(--space-6); }
body.lang-ar .toast { transform: translateX(-20px); }
body.lang-ar .toast.show { transform: translateX(0); }

body.lang-ar select.form-control {
  background-position: left 12px center;
  padding-right: var(--space-3);
  padding-left: 36px;
}

body.lang-ar .input-group .form-control:first-child { border-radius: var(--radius) 0 0 var(--radius); }
body.lang-ar .input-group .form-control:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }
body.lang-ar .input-addon { border-radius: 0 var(--radius) var(--radius) 0; border-right: none; border-left: 1px solid var(--border-main); }

@media (max-width: 768px) {
  body.lang-ar .sidebar {
    transform: translateX(100%);
    right: 0;
    left: auto;
  }
  body.lang-ar .sidebar.open {
    transform: translateX(0);
  }
  body.lang-ar .main-content {
    margin-right: 0;
    margin-left: 0;
  }
}

/* Language toggle button */
#btn-lang-toggle {
  font-family: 'Cairo', sans-serif;
  min-width: 38px;
  height: 36px;
  border: 1px solid var(--border-main);
  border-radius: var(--radius);
  font-size: .85rem;
  letter-spacing: 0;
}

/* ============================================================
   DRUG MANAGER MODULE  — dm-* namespace
   ============================================================ */

/* ROOT & LAYOUT */
.dm-root { display: flex; flex-direction: column; gap: var(--space-5); }

.dm-page-title {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 1.4rem; font-weight: 800; color: var(--text-primary);
  margin: 0;
}
.dm-title-icon { color: var(--primary-500); font-size: 1.3rem; }
.dm-page-sub   { margin: 2px 0 0; font-size: .82rem; color: var(--text-muted); }

/* SEARCH BAR */
.dm-search-bar {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-3);
  box-shadow: var(--shadow-sm);
}

.dm-search-input-wrap {
  position: relative; display: flex; align-items: center;
}
.dm-search-icon {
  position: absolute;
  inset-inline-start: var(--space-4);
  font-size: 1.15rem; color: var(--text-muted);
  pointer-events: none;
}
.dm-search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  padding-inline-start: calc(var(--space-4) + 1.5rem + var(--space-2));
  padding-inline-end: var(--space-10);
  border: 1.5px solid var(--border-main);
  border-radius: var(--radius-full);
  font-size: .95rem;
  font-family: var(--font-en);
  background: var(--bg-base);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.dm-search-input:focus {
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px rgba(26,157,176,.12);
  background: var(--bg-surface);
}
.dm-search-clear {
  position: absolute; inset-inline-end: var(--space-3);
  width: 28px; height: 28px; border-radius: var(--radius-full);
  border: none; background: var(--gray-200); color: var(--gray-600);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: .85rem; transition: background var(--transition-fast);
}
.dm-search-clear:hover { background: var(--gray-300); }

/* CATEGORY FILTER CHIPS */
.dm-filter-row {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
  padding-top: var(--space-1);
}
.dm-cat-chip {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-main);
  background: transparent;
  color: var(--text-secondary);
  font-size: .78rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: all var(--transition-fast);
  font-family: var(--font-main);
}
.dm-cat-chip:hover { border-color: var(--primary-400); color: var(--primary-600); background: var(--primary-50); }
.dm-cat-chip.active {
  background: var(--primary-600); border-color: var(--primary-600);
  color: white; box-shadow: var(--shadow-sm);
}

/* TWO-COLUMN LAYOUT */
.dm-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-5);
  align-items: start;
}

/* SIDEBAR PANELS */
.dm-sidebar { display: flex; flex-direction: column; gap: var(--space-4); position: sticky; top: var(--space-4); }

.dm-panel {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.dm-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-light);
}
.dm-panel-title {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: .82rem; font-weight: 700; color: var(--text-primary);
}
.dm-panel-badge {
  background: var(--primary-100); color: var(--primary-700);
  border-radius: var(--radius-full); padding: 1px 8px;
  font-size: .72rem; font-weight: 700;
}
.dm-panel-body { max-height: 320px; overflow-y: auto; }
.dm-panel-empty {
  padding: var(--space-5) var(--space-4);
  text-align: center; font-size: .8rem; color: var(--text-muted);
  font-style: italic;
}

/* SIDEBAR DRUG ITEM */
.dm-sidebar-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.dm-sidebar-item:last-child { border-bottom: none; }
.dm-sidebar-item:hover { background: var(--primary-50); }
.dm-sidebar-item-info { flex: 1; min-width: 0; }
.dm-sidebar-item-name {
  font-size: .82rem; font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dm-sidebar-item-sub {
  font-size: .7rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dm-sidebar-item-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ICON BUTTONS */
.dm-icon-btn {
  width: 28px; height: 28px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; transition: all var(--transition-fast);
}
.dm-icon-btn:hover { background: var(--gray-100); color: var(--text-primary); }
.dm-icon-btn.is-fav { color: var(--warning-500); }
.dm-icon-btn.is-fav:hover { background: var(--warning-50); }
.dm-icon-btn--add:hover { background: var(--primary-50); color: var(--primary-600); border-color: var(--primary-200); }
.dm-icon-btn--del:hover { background: var(--danger-50); color: var(--danger-600); border-color: var(--danger-200); }

/* MAIN TABLE AREA */
.dm-main { min-width: 0; }
.dm-table-wrap {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* DRUG TABLE */
.dm-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
.dm-table thead tr {
  background: var(--bg-base);
  border-bottom: 2px solid var(--border-main);
}
.dm-table th {
  padding: var(--space-3) var(--space-4);
  text-align: start; font-size: .75rem; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px;
  white-space: nowrap;
}
.dm-row {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer; transition: background var(--transition-fast);
}
.dm-row:last-child { border-bottom: none; }
.dm-row:hover { background: var(--primary-50); }
.dm-row td { padding: var(--space-3) var(--space-4); vertical-align: middle; }

.dm-row-name  { font-weight: 700; color: var(--text-primary); font-size: .88rem; }
.dm-row-sub   { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }
.dm-row-generic { font-size: .82rem; color: var(--text-secondary); }
.dm-row-form  { font-size: .8rem; color: var(--text-muted); }
.dm-row-company { font-size: .78rem; color: var(--text-muted); }
.dm-row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.dm-dash      { color: var(--text-muted); }

.dm-strength-tag {
  background: var(--primary-50); color: var(--primary-700);
  border: 1px solid var(--primary-100);
  border-radius: var(--radius-full); padding: 2px 8px;
  font-size: .72rem; font-weight: 700; white-space: nowrap;
}
.dm-cat-tag {
  background: var(--gray-100); color: var(--gray-600);
  border-radius: var(--radius-full); padding: 2px 8px;
  font-size: .72rem; font-weight: 600; white-space: nowrap;
}

/* LOADING / EMPTY */
.dm-loading {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-3); padding: var(--space-10);
  color: var(--text-muted); font-size: .9rem;
}
.dm-empty {
  text-align: center; padding: var(--space-10) var(--space-4);
  color: var(--text-muted);
}
.dm-empty-icon { font-size: 2.5rem; opacity: .3; display: block; margin-bottom: var(--space-3); }
.dm-empty p { font-size: .95rem; font-weight: 600; margin: 0 0 4px; color: var(--text-secondary); }
.dm-empty span { font-size: .8rem; }

/* PAGINATION */
.dm-pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-4); padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-light); background: var(--bg-base);
  font-size: .82rem; color: var(--text-muted);
}

/* DRUG DETAIL MODAL */
.dm-detail { display: flex; flex-direction: column; gap: var(--space-5); }
.dm-detail-header {
  display: flex; align-items: flex-start; gap: var(--space-4);
  padding-bottom: var(--space-4); border-bottom: 1.5px solid var(--border-light);
}
.dm-detail-icon {
  width: 52px; height: 52px; border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary-100), var(--primary-200));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--primary-600); flex-shrink: 0;
}
.dm-detail-title-block { flex: 1; }
.dm-detail-name     { font-size: 1.2rem; font-weight: 800; color: var(--text-primary); }
.dm-detail-name-alt { font-size: .9rem; color: var(--text-muted); margin-top: 2px; }

.dm-fav-toggle {
  display: flex; align-items: center; gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--border-main); border-radius: var(--radius);
  background: transparent; cursor: pointer; font-size: .82rem; font-weight: 600;
  color: var(--text-secondary); transition: all var(--transition-fast);
  white-space: nowrap; font-family: var(--font-main);
}
.dm-fav-toggle:hover { border-color: var(--warning-500); color: var(--warning-600); background: var(--warning-50); }
.dm-fav-toggle.is-fav { border-color: var(--warning-400); color: var(--warning-600); background: var(--warning-50); }
.dm-fav-toggle i { font-size: 1rem; }

.dm-detail-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3);
}
.dm-detail-field {
  background: var(--bg-base); border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}
.dm-detail-field-label { font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 4px; }
.dm-detail-field-value { font-size: .92rem; font-weight: 600; color: var(--text-primary); }

.dm-detail-section {}
.dm-detail-section-title {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: .82rem; font-weight: 700; color: var(--text-secondary);
  margin-bottom: var(--space-3);
}
.dm-alts-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dm-alt-card {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-base); border: 1.5px solid var(--border-main);
  border-radius: var(--radius); cursor: pointer; font-family: var(--font-main);
  font-size: .82rem; font-weight: 600; color: var(--text-primary);
  transition: all var(--transition-fast);
}
.dm-alt-card:hover { border-color: var(--primary-400); background: var(--primary-50); color: var(--primary-700); }
.dm-alt-name { font-weight: 700; font-size: .85rem; }
.dm-alt-sub  { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }

/* ADD DRUG FORM */
.dm-add-form { display: flex; flex-direction: column; gap: var(--space-4); }
.dm-add-section-title {
  font-size: .75rem; font-weight: 800; color: var(--primary-700);
  text-transform: uppercase; letter-spacing: .5px;
  padding: var(--space-2) 0 var(--space-1);
  border-bottom: 2px solid var(--primary-100);
}

/* HIGHLIGHT */
mark.dm-highlight {
  background: var(--warning-100); color: var(--warning-800);
  border-radius: 2px; padding: 0 2px;
  font-weight: 700;
}

/* ============================================================
   DRUG AUTOCOMPLETE v2  — dac-* namespace
   ============================================================ */
.drug-autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0; inset-inline-end: 0;
  background: var(--bg-surface);
  border: 1.5px solid var(--primary-300);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.12), 0 2px 8px rgba(26,157,176,.08);
  display: none;
  animation: dacFadeIn .12s ease;
}
@keyframes dacFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.drug-autocomplete.show { display: block; }

.dac-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-base); border-bottom: 1px solid var(--border-light);
  font-size: .7rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; z-index: 1;
}
.dac-count {
  background: var(--primary-100); color: var(--primary-700);
  border-radius: var(--radius-full); padding: 0 6px; font-size: .68rem;
}

.dac-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer; border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
}
.dac-item:last-child { border-bottom: none; }
.dac-item:hover, .dac-item.dac-active { background: var(--primary-50); }
.dac-item-main { flex: 1; min-width: 0; }
.dac-item-name {
  font-weight: 700; font-size: .88rem; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dac-item-generic { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }
.dac-item-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  flex-shrink: 0;
}
.dac-form    { font-size: .68rem; color: var(--text-muted); }
.dac-company { font-size: .65rem; color: var(--text-muted); }
.dac-fav-dot { color: var(--warning-500); font-size: .7rem; vertical-align: middle; }

.dac-empty {
  padding: var(--space-4);
  text-align: center; font-size: .82rem; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
}
.dac-add-new {
  display: flex; align-items: center; gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: var(--primary-50); border: 1.5px solid var(--primary-200);
  border-radius: var(--radius); cursor: pointer;
  font-size: .8rem; font-weight: 600; color: var(--primary-700);
  font-family: var(--font-main); transition: all var(--transition-fast);
}
.dac-add-new:hover { background: var(--primary-100); border-color: var(--primary-400); }

/* Alternatives chips (inside prescription item) */
.dm-alt-chip {
  padding: var(--space-1) var(--space-3);
  background: var(--bg-base); border: 1px solid var(--border-main);
  border-radius: var(--radius-full); cursor: pointer;
  font-size: .75rem; font-weight: 600; color: var(--text-secondary);
  font-family: var(--font-main); transition: all var(--transition-fast);
}
.dm-alt-chip:hover { border-color: var(--primary-400); color: var(--primary-700); background: var(--primary-50); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .dm-layout { grid-template-columns: 1fr; }
  .dm-sidebar { position: static; flex-direction: row; flex-wrap: wrap; }
  .dm-panel  { flex: 1; min-width: 240px; }
  .dm-panel-body { max-height: 200px; }
}
@media (max-width: 640px) {
  .dm-search-bar { padding: var(--space-3); }
  .dm-filter-row { gap: var(--space-1); }
  .dm-cat-chip   { font-size: .72rem; padding: 2px var(--space-2); }
  .dm-detail-grid { grid-template-columns: 1fr; }
}

/* RTL (Arabic) adjustments */
body.lang-ar .dm-search-clear { inset-inline-end: auto; inset-inline-start: var(--space-3); }
body.lang-ar .dac-item-meta   { align-items: flex-start; }

/* ============================================================
   PRESCRIPTION SAVE — SUCCESS PANEL (#1, #2)
   Replaces the editor form after a brand-new prescription is
   saved: confirms the save, offers Print/PDF/PNG/WhatsApp inline
   on the same page, and a clear path to the next prescription.
   ============================================================ */
.rx-success-panel {
  max-width: 640px;
  margin: var(--space-8) auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.rx-success-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--space-4);
  border-radius: 50%;
  background: var(--success-50);
  color: var(--success-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.25rem;
}

.rx-success-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

.rx-success-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

.rx-success-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.rx-success-actions .btn {
  justify-content: center;
  gap: var(--space-2);
}

.rx-success-divider {
  height: 1px;
  background: var(--border-light);
  margin-bottom: var(--space-5);
}

.rx-success-secondary {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  .rx-success-panel { margin: var(--space-4); padding: var(--space-6) var(--space-4); }
  .rx-success-actions { grid-template-columns: 1fr; }
  .rx-success-secondary { flex-direction: column; }
  .rx-success-secondary .btn { width: 100%; }
}

/* RTL: keep icon/text gaps consistent (flex gap already handles
   direction correctly via logical properties, but SVG vertical
   alignment can look off-baseline in RTL contexts — nudge it back) */
body.lang-ar .rx-success-actions .btn svg { vertical-align: -3px; }

/* ============================================================
   PRESCRIPTION LAYOUT SETTINGS (#8)
   Two-column page: controls on one side, instant live preview
   on the other. Stacks to a single column on narrow screens.
   ============================================================ */
.ls-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: var(--space-6);
  align-items: start;
}

.ls-controls { min-width: 0; }

.ls-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-secondary);
}
.ls-toggle-row:last-child { border-bottom: none; }
.ls-toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-500);
  cursor: pointer;
  flex-shrink: 0;
}

.ls-preview {
  position: sticky;
  top: var(--space-4);
}

.ls-preview-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
  margin-bottom: var(--space-3);
}

.ls-preview-frame-wrap {
  background: var(--bg-base);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  justify-content: center;
  max-height: calc(100vh - 160px);
  overflow: auto;
}

.ls-preview-iframe {
  width: 380px;
  height: 538px; /* A4-proportioned fallback; JS resizes to match the actual selected paper size/orientation on every render */
  border: none;
  background: #fff;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

@media (max-width: 1100px) {
  .ls-layout { grid-template-columns: 1fr; }
  .ls-preview { position: static; }
  .ls-preview-frame-wrap { max-height: 700px; }
}

@media (max-width: 560px) {
  .ls-preview-iframe { width: 100%; max-width: 380px; height: 538px; }
}

/* ============================================================
   RESPONSIVE ENHANCEMENT LAYER
   Layout / overflow / touch fixes only — no color, font-family,
   branding or business-logic changes. Desktop (≥1024px) visuals
   are preserved: every clamp() maximum equals the previous fixed
   value, so type only scales DOWN on smaller screens.
   Breakpoints covered:
     320–480 (small mobile) · 481–767 (large mobile)
     768–1023 (tablet) · 1024–1439 (laptop) · 1440+ (desktop)
   Print/PDF/PNG exports render in an isolated iframe with their
   own stylesheet (js/modules/printer.js) and are untouched; the
   rules below are scoped to @media screen where they could
   otherwise leak into in-page printing.
   ============================================================ */

@media screen {
  /* --- Global overflow guards -------------------------------- */
  .main-content { min-width: 0; max-width: 100%; }
  .page-content { min-width: 0; }

  /* Responsive media: never wider than their container */
  .page-content img,
  .page-content video,
  .page-content canvas,
  .modal img { max-width: 100%; height: auto; }

  /* --- Fluid typography (max = previous fixed size) ---------- */
  h1 { font-size: clamp(1.5rem,  1.1rem + 1.8vw, 2rem); }
  h2 { font-size: clamp(1.2rem,  1rem   + 1.1vw, 1.5rem); }
  h3 { font-size: clamp(1.05rem, 0.95rem + 0.7vw, 1.25rem); }
  .stat-value      { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem); }
  .dm-page-title   { font-size: clamp(1.15rem, 1rem + 0.8vw, 1.4rem); }
  .rx-success-title { font-size: clamp(1.1rem, 1rem + 0.7vw, 1.35rem); }

  /* --- Topbar: title truncates instead of pushing actions out */
  .topbar-title   { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { flex-shrink: 0; }

  /* --- Headers wrap instead of overflowing -------------------- */
  .section-header { flex-wrap: wrap; }
  .card-header    { flex-wrap: wrap; }

  /* --- Tables scroll inside their wrapper, never the page ----- */
  .table-wrapper { max-width: 100%; -webkit-overflow-scrolling: touch; }
  /* Fix: was overflow:hidden, which CLIPPED the 7-column drug
     table on narrow screens instead of letting it scroll. */
  .dm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* --- Toasts fit a 320px viewport ----------------------------- */
  .toast {
    min-width: 0;
    max-width: min(380px, calc(100vw - 2 * var(--space-6)));
  }

  /* --- Modals: dynamic-viewport height (mobile URL bar safe) --- */
  .modal { max-height: 90vh; max-height: 90dvh; }
  .modal-footer { flex-wrap: wrap; }

  /* --- Drug-database sidebar panels never force overflow ------- */
  .dm-sidebar { min-width: 0; }
}

/* --- MOBILE NAVIGATION FIX (≤768px) ---------------------------
   `.sidebar-toggle-btn { display:none !important }` above is
   declared AFTER the earlier mobile override, so the hamburger
   button never appeared and the off-canvas sidebar was
   unreachable on phones. This later rule restores it. */
@media screen and (max-width: 768px) {
  .sidebar-toggle-btn { display: flex !important; }
}

/* --- TABLET (769–1023px): sidebar is visible, content is ~500px.
   3/4-column form grids become 2 columns so fields stay usable.
   (≤768px they already collapse to a single column.) */
@media screen and (min-width: 769px) and (max-width: 1023.98px) {
  .form-grid-3, .form-grid-4 { grid-template-columns: 1fr 1fr; }
}

/* --- LARGE MOBILE (≤767px) ------------------------------------- */
@media screen and (max-width: 767.98px) {
  /* 16px inputs prevent iOS Safari's auto-zoom on focus */
  input.form-control,
  select.form-control,
  textarea.form-control,
  .dm-search-input { font-size: 16px; }

  /* Search boxes in card headers span the full row
     (overrides the inline max-width:320/360px) */
  .card-header .input-group { max-width: 100% !important; width: 100%; }

  /* Modal action buttons share the row and wrap gracefully */
  .modal-footer .btn { flex: 1 1 auto; min-width: 0; }

  /* Toast starts from the small-screen margins */
  .toast { max-width: calc(100vw - 2 * var(--space-4)); }
}

/* --- SMALL MOBILE (≤480px) -------------------------------------- */
@media screen and (max-width: 480px) {
  .topbar { gap: var(--space-2); }

  .modal-header  { padding: var(--space-4); }
  .modal-body    { padding: var(--space-4); }
  .modal-footer  { padding: var(--space-3) var(--space-4); }

  .card-header   { padding: var(--space-4); }
  .empty-state   { padding: var(--space-10) var(--space-4); }

  .btn-lg { padding-left: var(--space-5); padding-right: var(--space-5); }

  /* Success-panel & pagination controls stay inside the screen */
  .dm-pagination { flex-wrap: wrap; gap: var(--space-2); }
}

/* --- TOUCH-FRIENDLY CONTROLS (phones/tablets only) --------------
   Comfortable ≥36-40px hit areas for the smallest controls,
   scoped to coarse pointers at tablet width and below so
   desktop/laptop visuals are untouched. */
@media (pointer: coarse) and (max-width: 1023.98px) {
  .btn, .nav-item, .form-control, .dm-cat-chip { touch-action: manipulation; }
  .dm-icon-btn     { width: 36px; height: 36px; }
  .dm-search-clear { width: 36px; height: 36px; }
  .btn-sm          { min-height: 40px; }
  .nav-item        { min-height: 44px; }
}

/* --- PRINT SAFETY: never print app chrome ------------------------ */
@media print {
  .sidebar-overlay,
  .toast-container,
  #app-loader,
  .modal-overlay { display: none !important; }
}

/* --- FIX: open the off-canvas sidebar in ENGLISH mode too --------
   Arabic already had `body.lang-ar .sidebar.open { translateX(0) }`,
   but English had no matching rule, so the higher-specificity
   `body.lang-en .sidebar { translateX(-100%) }` kept the menu
   permanently off-screen on mobile. */
@media screen and (max-width: 768px) {
  body.lang-en .sidebar.open { transform: translateX(0); }
}
