:root {
  --primary: #1e5f8c;
  --primary-dark: #164a6d;
  --accent: #2fa6a6;
  --purple: #6b46c1;
  --purple-dark: #553399;
  --bg: #f5f7fa;
  --border: #e2e8f0;
  --text-secondary: #64748b;
  --danger: #d64545;
  --success: #2e9e5b;
}

body {
  background: var(--bg);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1a202c;
}

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

.sidebar {
  width: 230px;
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { padding: 0 20px 20px; }
.brand-title { font-size: 22px; font-weight: 700; }
.brand-sub { font-size: 13px; color: #cfe3f0; }
.sidebar-nav { flex: 1; }
.sidebar-bottom { margin-top: auto; }
.sidebar .nav-link {
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  margin: 2px 10px;
  font-size: 14px;
}
.sidebar .nav-link:hover, .sidebar .nav-link.active { background: #2a6e9b; }

.content { flex: 1; padding: 30px; max-width: 1400px; }

.card-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  margin-bottom: 20px;
}

.stat-card { text-align: left; }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; }

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

.table-locked-icon { font-size: 48px; }

.section-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.medicine-row { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 10px; }
.medicine-row.card-panel { border-bottom: 1px solid var(--border); padding: 18px; }
.medicine-row .remove-medicine-btn { font-size: 12px; padding: 3px 10px; }
.test-row { background: #f8fafc; border-radius: 6px; padding: 8px; }
#vision-fields-panel { border-top: 1px solid var(--border); }

.btn-purple {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}
.btn-purple:hover { background: var(--purple-dark); border-color: var(--purple-dark); color: #fff; }
.btn-outline-purple { color: var(--purple); border-color: var(--purple); background: #fff; }
.btn-outline-purple:hover { background: var(--purple); border-color: var(--purple); color: #fff; }

.vision-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.vision-table th {
  background: #f5f3ff;
  color: var(--purple);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.vision-table th .sub-label { display: block; color: #9c94c4; font-size: 10px; text-transform: none; font-weight: 400; }
.vision-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.vision-table td input { min-width: 90px; }
.vision-eye-label { font-weight: 600; white-space: nowrap; }
.vision-eye-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.vision-eye-dot.od { background: var(--purple); }
.vision-eye-dot.os { background: var(--accent); }

/* --------------------------------------------------------------
   Print styles — used by prescription/ultrasound/report print
   views. The browser's own "Print > Save as PDF" produces the
   downloadable PDF; no server-side PDF library is required.
   -------------------------------------------------------------- */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .print-sheet { box-shadow: none !important; border: none !important; margin: 0 !important; }
  .rx-section { break-inside: avoid; }
  .rx-medicine-card { break-inside: avoid; }
}

.print-body { background: #eef1f6; font-family: 'Inter', 'Segoe UI', sans-serif; }

.print-toolbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.print-sheet {
  background: #fff;
  max-width: 210mm;
  margin: 24px auto;
  padding: 15mm;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(30,95,140,0.08);
}

/* ---- Header band (bleeds to the sheet's edges via negative margins,
   since .print-sheet keeps 15mm padding for the older print views that
   place content directly with no padding of their own) ---- */
.rx-header-band {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: -15mm -15mm 16px -15mm;
  padding: 20px 15mm 16px;
  background: linear-gradient(135deg, #f0f7fc 0%, #f7f5fd 100%);
  border-bottom: 3px solid var(--primary);
}
.rx-clinic-logo { height: 56px; margin-right: 14px; border-radius: 6px; }
.rx-clinic-name { font-size: 20px; font-weight: 700; color: var(--primary-dark); letter-spacing: -0.01em; }
.rx-doctor-line { font-size: 13px; color: #334155; margin-top: 2px; }
.rx-meta-line { font-size: 11.5px; color: var(--text-secondary); margin-top: 1px; }
.rx-doc-badge {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 7px 16px;
  border-radius: 999px;
  white-space: nowrap;
  margin-top: 2px;
}
.rx-header-note { font-size: 12px; font-style: italic; color: var(--text-secondary); margin-bottom: 12px; }

/* ---- Body sections ---- */
.rx-section { margin-bottom: 18px; }
.rx-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.rx-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---- Patient info card ---- */
.rx-patient-card {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  background: #f8fafc;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px 18px;
}
.rx-patient-field { min-width: 140px; }
.rx-patient-field .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); display: block; }
.rx-patient-field .val { font-size: 14px; font-weight: 600; color: #1a202c; }
.rx-patient-field .val.rx-number { color: var(--primary); font-family: 'Courier New', monospace; }

/* ---- Clinical notes ---- */
.rx-notes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; }
.rx-note-row { font-size: 13px; }
.rx-note-row .k { font-weight: 600; color: #334155; }
.rx-note-row .v { color: #1a202c; }

/* ---- Vitals pills ---- */
.rx-vitals { display: flex; flex-wrap: wrap; gap: 8px; }
.rx-vital-pill {
  background: #ecfdf5;
  color: #0d7a4f;
  border: 1px solid #b9ecd6;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 600;
}

/* ---- Rx medicines ---- */
.rx-symbol-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.rx-symbol-big { font-size: 30px; font-weight: 700; color: var(--purple); font-family: Georgia, serif; }
.rx-symbol-row .rule { flex: 1; height: 2px; background: linear-gradient(to right, var(--purple), transparent); }

.rx-medicine-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--purple);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
}
.rx-medicine-card .num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rx-medicine-card .name { font-size: 14.5px; font-weight: 700; color: #1a202c; }
.rx-medicine-card .name .strength { font-weight: 500; color: var(--purple); font-size: 12px; }
.rx-medicine-card .details { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: 12px; color: #475569; }
.rx-medicine-card .details b { color: #1a202c; font-weight: 600; }

/* ---- Lab tests ---- */
.rx-test-list { display: flex; flex-wrap: wrap; gap: 8px; }
.rx-test-chip {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e5f8c;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.rx-test-chip .note { font-weight: 400; color: var(--text-secondary); }

/* ---- Follow-up ---- */
.rx-followup-card {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
}

/* ---- Signature ---- */
.rx-signature-area { display: flex; justify-content: flex-end; margin-top: 24px; }
.rx-signature-box { width: 230px; text-align: center; }
.rx-signature-box img { height: 42px; margin-bottom: 4px; }
.rx-signature-box .line { border-top: 1.5px solid #1a202c; margin-bottom: 4px; }
.rx-signature-box .name { font-size: 13px; font-weight: 700; }
.rx-signature-box .meta { font-size: 11px; color: var(--text-secondary); }

/* ---- Footer ---- */
.rx-footer { margin-top: 24px; }
.rx-footer-line { height: 1px; background: var(--border); margin-bottom: 8px; }
.rx-footer-text { font-size: 10.5px; color: var(--text-secondary); }
.rx-footer-brand { font-size: 9.5px; color: #94a3b8; }

.rx-symbol { font-size: 28px; font-weight: bold; margin: 10px 0; }
.medicine-table th, .medicine-table td { font-size: 13px; padding: 6px 8px; }