/* ============================================================
   components.css — Shared UI Components
   ============================================================ */

/* ─── Stat Cards ─────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; }
.stat-icon.red    { background: #fee2e2; }
.stat-icon.yellow { background: #fef3c7; }
.stat-icon.green  { background: #d1fae5; }
.stat-icon.teal   { background: #cffafe; }
.stat-icon.purple { background: #ede9fe; }

.stat-value {
  font-size: 26px; font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--navy-800); line-height: 1;
}
.stat-label { font-size: 11.5px; color: var(--slate-500); font-weight: 500; margin-top: 2px; }

/* ─── Section Headers ────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 16px; font-weight: 700; color: var(--navy-800); }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  font-family: 'IBM Plex Sans', sans-serif;
  cursor: pointer; border: 1px solid transparent;
  transition: var(--transition); white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--teal-600), var(--navy-500));
  color: white; border-color: var(--teal-600);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--teal-500), var(--navy-600));
  box-shadow: 0 2px 8px rgba(6,182,212,0.3);
}

.btn-success { background: var(--emerald-500); color: white; }
.btn-success:hover { background: var(--emerald-600); }

.btn-outline { background: transparent; color: var(--teal-600); border-color: var(--teal-600); }
.btn-outline:hover { background: rgba(6,182,212,0.05); }

.btn-ghost { background: transparent; color: var(--slate-600); border-color: var(--slate-300); }
.btn-ghost:hover { background: var(--slate-100); }

.btn-danger { background: var(--rose-600); color: white; }
.btn-danger:hover { background: var(--rose-700); }

.btn-danger-sm {
  background: #fee2e2; color: var(--rose-600);
  border: 1px solid #fecaca;
  padding: 3px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.btn-danger-sm:hover { background: var(--rose-600); color: white; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.card--has-dropdown { overflow: visible; }

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--slate-200);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--slate-50);
}
.card-title { font-size: 14px; font-weight: 700; color: var(--navy-800); }
.card-body  { padding: 20px; }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group  { margin-bottom: 16px; }

.form-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--slate-600); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.form-control {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--slate-300); border-radius: var(--radius);
  font-size: 13.5px; font-family: 'IBM Plex Sans', sans-serif;
  color: var(--slate-800); background: var(--white);
  transition: var(--transition); outline: none;
}
.form-control:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(6,182,212,0.12);
}
.form-control-mono { font-family: 'IBM Plex Mono', monospace; }
textarea.form-control { resize: vertical; min-height: 70px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

@media (max-width: 900px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}

/* ─── Search ─────────────────────────────────────────────────── */
.search-wrapper { position: relative; }

.search-icon {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--slate-400); font-size: 15px;
}
.search-wrapper .form-control { padding-left: 34px; }

.drug-search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--white); border: 1px solid var(--slate-200);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 200; max-height: 300px; overflow-y: auto;
}
.drug-search-results:empty { display: none; }

.drug-search-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--slate-100); transition: var(--transition);
}
.drug-search-item:hover { background: var(--slate-50); }
.drug-search-item:last-child { border-bottom: none; }

.drug-name       { font-weight: 600; color: var(--navy-800); font-size: 13.5px; }
.drug-category   { font-size: 11px; color: var(--slate-500); }
.drug-search-dose { font-size: 12px; font-family: 'IBM Plex Mono', monospace; color: var(--teal-600); font-weight: 500; }
.drug-tag.emergency { background: #fee2e2; color: var(--rose-600); font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 700; }
.no-results { padding: 12px 14px; color: var(--slate-500); font-size: 13px; text-align: center; }

/* ─── Status & Priority Badges ───────────────────────────────── */
.status-badge, .priority-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}

.badge-critical { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-moderate { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-stable   { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-pending  { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-prepared { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.badge-released { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.badge-stopped  { background: var(--slate-100); color: var(--slate-500); border: 1px solid var(--slate-200); }
.badge-default  { background: var(--slate-100); color: var(--slate-600); border: 1px solid var(--slate-200); }

.badge-stat    { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-urgent  { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-routine { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.allergy-tag {
  display: inline-flex; align-items: center;
  background: #fff7ed; color: #c2410c;
  border: 1px solid #fed7aa;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
}
.nkda-tag {
  display: inline-flex; align-items: center;
  background: #f0fdf4; color: #166534;
  border: 1px solid #bbf7d0;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 4px;
}
.orders-count-badge {
  background: var(--navy-800); color: var(--teal-400);
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 4px;
}

/* ─── Warnings ───────────────────────────────────────────────── */
.warning-banner {
  border-radius: var(--radius); padding: 12px 16px;
  margin-bottom: 16px; animation: slideDown 0.2s ease;
}
.warning-moderate { background: #fffbeb; border: 1px solid #fde68a; }
.warning-critical { background: #fff1f2; border: 1px solid #fecdd3; }

.warning-header {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 13px; margin-bottom: 8px;
}
.warning-moderate .warning-header { color: #92400e; }
.warning-critical .warning-header { color: #be123c; }
.warning-icon { font-size: 16px; }

.warning-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.warning-list li { font-size: 12.5px; padding-left: 4px; }
.warning-moderate .warning-list li { color: #78350f; }
.warning-critical .warning-list li { color: #9f1239; }

/* ─── Tables ─────────────────────────────────────────────────── */
.order-draft-table, .orders-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.order-draft-table th, .orders-table th {
  background: var(--slate-50); color: var(--slate-500);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 10px 12px;
  text-align: left; border-bottom: 2px solid var(--slate-200); white-space: nowrap;
}
.order-draft-table td, .orders-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--slate-100);
  color: var(--slate-700); vertical-align: middle;
}
.order-draft-table tr:hover td, .orders-table tr:hover td { background: var(--slate-50); }

.row-has-warning  { background: #fffbeb !important; }
.overridden-dose  { color: var(--amber-600); font-weight: 600; }
.warn-count       { background: #fef3c7; color: #92400e; font-size: 11px; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.empty-order, .empty-table { text-align: center; color: var(--slate-400); font-size: 13px; padding: 32px; }

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(5,12,26,0.7); z-index: 1000;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay[style*="flex"] { animation: fadeIn 0.15s ease; }

.modal-container {
  background: var(--white); border-radius: var(--radius-lg);
  max-width: 720px; width: 100%; max-height: 85vh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 25px 50px rgba(0,0,0,0.3);
  animation: slideUp 0.2s ease;
}

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

.modal-header {
  padding: 16px 20px; background: var(--navy-800); color: white;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  background: rgba(255,255,255,0.1); border: none; color: white;
  width: 30px; height: 30px; border-radius: 6px;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: rgba(255,255,255,0.2); }
.modal-body { padding: 20px; overflow-y: auto; }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--navy-800); color: white;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-lg);
  transform: translateX(120%); transition: transform 0.3s ease;
  max-width: 320px; border-left: 3px solid transparent;
}
.toast-show    { transform: translateX(0); }
.toast-success { border-left-color: var(--emerald-500); }
.toast-error   { border-left-color: var(--rose-500); }
.toast-info    { border-left-color: var(--teal-500); }

/* ─── Form Card (shared by formulary-form + patient-form) ────── */
.form-card {
  background: var(--white); border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; margin-bottom: 24px; animation: fadeIn 0.2s ease-out;
}
.form-card-header {
  background: linear-gradient(135deg, var(--navy-900), var(--navy-800));
  padding: 20px 24px; color: white;
  display: flex; align-items: center; justify-content: space-between;
}
.form-card-title    { font-size: 16px; font-weight: 700; }
.form-card-subtitle { font-size: 12px; color: var(--teal-300); margin-top: 2px; }

.form-tabs {
  display: flex; background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200); padding: 0 16px;
}
.form-tab-btn {
  padding: 14px 20px; border: none; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--slate-500);
  cursor: pointer; position: relative; transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
}
.form-tab-btn:hover { color: var(--navy-800); }
.form-tab-btn.active { color: var(--teal-600); }
.form-tab-btn.active::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0;
  height: 3px; background: var(--teal-500); border-radius: 3px 3px 0 0;
}

.form-section { padding: 24px; animation: fadeIn 0.15s ease-out; }
.form-section.hidden { display: none; }

.form-actions-footer {
  padding: 16px 24px; background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
  display: flex; justify-content: flex-end; gap: 12px;
}

.form-info-block {
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a;
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 12.5px; margin-bottom: 16px;
  display: flex; gap: 8px; align-items: flex-start;
}
.form-info-icon { font-size: 15px; line-height: 1; }

/* ─── Loading shimmer ────────────────────────────────────────── */
[data-loading="true"] { position: relative; overflow: hidden; }
[data-loading="true"]::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ─── Image Lightbox ─────────────────────────────────────────── */
.lightbox-container {
  background: var(--navy-900);
  border-radius: var(--radius-lg);
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
  animation: slideUp 0.2s ease;
  overflow: hidden;
}

.lightbox-header {
  padding: 14px 20px;
  background: var(--navy-800);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.lightbox-body {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--navy-950);
}

.lightbox-body img {
  max-width: 100%;
  max-height: calc(90vh - 60px);
  object-fit: contain;
  border-radius: 4px;
}
