/* ==========================================================================
   STYLING: Sistema de Recetas Médicas & Ópticas - Dra. Karina Brizuela
   Color Palette: Pure Clean White (#ffffff), Slate Slate (#f8fafc), 
                  Medical Blue (#1e40af / #2563eb), Accent Teal/Green (#059669)
   ========================================================================== */

:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --primary: #1e40af;
  --primary-hover: #1e3a8a;
  --primary-light: #eff6ff;
  
  --accent-gold: #d97706;
  --accent-green: #10b981;
  --accent-green-hover: #059669;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   APP HEADER
   ========================================================================== */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo-wrapper {
  background: #ffffff;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
}

#app-logo {
  height: 68px;
  width: auto;
  object-fit: contain;
  display: block;
}

.brand-text h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: -0.01em;
}

.brand-text p {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ecfdf5;
  color: #047857;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-status svg {
  width: 14px;
  height: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   BUTTONS & CONTROLS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}

.btn-secondary:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-outline {
  background: transparent;
  border-color: #cbd5e1;
  color: #475569;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

.btn-success {
  background: #16a34a;
  color: #ffffff;
}

.btn-success:hover {
  background: #15803d;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.btn-accent {
  background: #2563eb;
  color: #ffffff;
}

.btn-accent:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.85rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-md);
}

.btn-block {
  width: 100%;
}

.editor-card-footer {
  padding-top: 1.25rem;
  border-top: 1px dashed var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* ==========================================================================
   WORKSPACE LAYOUT (SINGLE CENTERED COLUMN FLOW)
   ========================================================================== */
.workspace-container {
  max-width: 900px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  flex: 1;
}

.editor-section,
.preview-section {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ==========================================================================
   LEFT COLUMN: FORM EDITOR CARD
   ========================================================================== */
.editor-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 1.75rem;
  width: 100%;
  margin: 0 auto;
}

.tab-buttons {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn svg {
  width: 18px;
  height: 18px;
}

.tab-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.form-block {
  background: #fafafa;
  border: 1px solid #f1f5f9;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  width: 100%;
}

.sub-blocks-horizontal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
}

@media (max-width: 820px) {
  .sub-blocks-horizontal {
    grid-template-columns: 1fr;
  }
}

.sub-form-block {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sub-form-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 1.25rem 0;
}

.block-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
}

.block-title svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.block-title-flex {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  text-align: center;
}

.block-title-flex span {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.block-title-flex svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.btn-toggle-strike {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 99px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-toggle-strike:hover {
  background: #f1f5f9;
}

.btn-toggle-strike.active {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #dc2626;
}

/* Form Fields */
.form-grid {
  display: grid;
  gap: 1rem;
}

.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 0.75rem; }
.mt-3 { margin-top: 1rem; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #475569;
  text-align: left;
}

input[type="text"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.875rem;
  color: #0f172a;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-icon-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon-group svg,
.input-icon-group i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: #64748b;
  pointer-events: none;
  z-index: 5;
}

.input-icon-group input[type="text"],
.input-icon-group input[type="tel"],
.input-icon-group input[type="date"],
.input-icon-group select,
.input-icon-group input {
  padding-left: 2.75rem !important;
  padding-right: 0.85rem !important;
}

/* Matrix Table Input */
.matrix-input-table {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.matrix-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
}

.matrix-row.header-row {
  font-size: 0.75rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #f1f5f9;
}

.tag-od {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1e40af;
}

.tag-oi {
  font-size: 0.8rem;
  font-weight: 700;
  color: #0284c7;
}

.stepper-input {
  display: flex;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #ffffff;
}

.stepper-input button {
  background: #f8fafc;
  border: none;
  width: 28px;
  height: 32px;
  font-weight: 700;
  font-size: 1rem;
  color: #475569;
  cursor: pointer;
  transition: background 0.15s ease;
}

.stepper-input button:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.stepper-input input {
  border: none;
  border-radius: 0;
  text-align: center;
  padding: 0.2rem 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: none !important;
}

/* Quick Presets Chips */
.quick-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.preset-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  margin-right: 0.25rem;
}

.chip-preset {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-preset:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Custom Checkboxes */
.treatment-checkboxes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 600px) {
  .treatment-checkboxes { grid-template-columns: 1fr; }
}

.custom-checkbox {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.custom-checkbox:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.custom-checkbox input[type="checkbox"] {
  display: none;
}

.checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid #94a3b8;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.custom-checkbox input:checked + .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.custom-checkbox input:checked + .checkmark::after {
  content: '✓';
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
}

.label-txt {
  font-size: 0.825rem;
  font-weight: 600;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.label-txt svg {
  width: 16px;
  height: 16px;
  color: #64748b;
}

/* Drugs Table Dynamic */
.drug-item-row {
  display: grid;
  grid-template-columns: 1.5fr 2fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  background: #ffffff;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
}

.btn-del-drug {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
}

.btn-del-drug:hover {
  background: #fef2f2;
}

/* ==========================================================================
   RIGHT COLUMN: LIVE PREVIEW & PRINTABLE SHEET
   ========================================================================== */
.preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  margin: 0 auto;
}

.preview-toolbar {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.preview-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.preview-title svg {
  color: var(--accent-gold);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
}

.prescription-sheet-wrapper {
  background: #cbd5e1;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.1);
}

/* Physical Paper Sheet Representation */
.prescription-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 620px;
  min-height: 780px;
  padding: 2rem;
  border-radius: 4px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  color: #0f172a;
  border: 1px solid #e2e8f0;
}

/* Header Banner in Sheet */
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2.5px solid #d97706;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
}

.header-logo-box {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
}

.sheet-logo-img {
  max-height: 85px;
  width: auto;
  max-width: 440px;
  object-fit: contain;
  display: block;
}

.sheet-rx-badge {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.15rem;
  background: transparent;
  border: none;
  padding: 0;
}

.rx-label {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: 0.03em;
}

.rx-no {
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  color: #dc2626;
}

/* Unified & Simplified Metadata Grid */
.sheet-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1.25rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.meta-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px dashed #cbd5e1;
  padding-bottom: 4px;
}

.meta-field.span-2 {
  grid-column: span 2;
}

.meta-label {
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
}

.meta-value {
  font-weight: 600;
  color: #0f172a;
  flex: 1;
}

.bold-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: #1e40af;
}

/* Optical Matrix Tables Grid */
.sheet-tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
}

.sheet-table-box {
  border: 1.5px solid #0f172a;
  border-radius: 4px;
  padding: 0.5rem;
  position: relative;
  background: #ffffff;
}

.table-title {
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  color: #1e293b;
  border-bottom: 1.5px solid #0f172a;
  padding-bottom: 4px;
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: center;
}

.sheet-table th {
  font-size: 0.75rem;
  font-weight: 700;
  color: #334155;
  padding: 3px;
  border-bottom: 1px solid #cbd5e1;
}

.sheet-table td {
  padding: 6px 3px;
  border-bottom: 1px dashed #e2e8f0;
  font-weight: 600;
  min-height: 28px;
}

.sheet-table td.row-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-align: left;
  color: #1e40af;
}

.table-color-row {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid #cbd5e1;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.color-label {
  font-weight: 600;
  color: #475569;
}

.color-val {
  font-weight: 700;
  color: #0f172a;
}

/* Strikethrough overlay line */
.strike-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  display: none;
}

.strike-overlay.active {
  display: block;
}

.strike-overlay svg {
  width: 100%;
  height: 100%;
}

/* Specs Row */
.sheet-specs-row {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #94a3b8;
  border-bottom: 1px solid #94a3b8;
  padding: 0.5rem 0.25rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.spec-lbl {
  font-weight: 700;
  color: #475569;
}

.spec-val {
  font-weight: 600;
  color: #0f172a;
}

/* Medical Drugs Section */
.sheet-drugs-section {
  display: none;
  margin-bottom: 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 0.6rem;
}

.sheet-drugs-section.active {
  display: block;
}

.drugs-header {
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  color: #1e40af;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 3px;
  margin-bottom: 6px;
}

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

.drugs-table th {
  text-align: left;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
  padding: 4px;
}

.drugs-table td {
  padding: 4px;
  border-bottom: 1px dashed #f1f5f9;
}

.medical-notes-box {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #334155;
  background: #f8fafc;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Footer & Observations */
.sheet-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  border-top: 1px solid #cbd5e1;
  padding-top: 1rem;
  margin-top: 1rem;
}

.sheet-obs-block {
  font-size: 0.775rem;
  color: #334155;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #cbd5e1;
  text-align: left;
}

.footer-clinic-info p {
  font-size: 0.75rem;
  color: #475569;
  line-height: 1.3;
}

.signature-box {
  text-align: center;
  width: 200px;
  min-height: 65px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}

.signature-img-box {
  height: 65px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: -10px;
  z-index: 2;
}

.sheet-signature-img {
  max-height: 85px;
  width: auto;
  max-width: 185px;
  object-fit: contain;
  mix-blend-mode: multiply;
  filter: contrast(1.2);
  display: block;
}

.signature-line {
  border-bottom: 1px solid #475569;
  width: 100%;
  margin-bottom: 4px;
}

.signature-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
}

/* ==========================================================================
   MODAL DIALOG: HISTORIAL
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1rem;
}

.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 850px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar svg {
  position: absolute;
  left: 0.85rem;
  color: #94a3b8;
}

.search-bar input {
  padding-left: 2.5rem;
}

.table-responsive {
  overflow-x: auto;
}

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

.history-table th {
  background: #f8fafc;
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
}

.history-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #f1f5f9;
}

/* ==========================================================================
   PRINT MEDIA STYLES: ONLY PRINT PHYSICAL SHEET
   ========================================================================== */
@media print {
  @page {
    size: auto;
    margin: 0mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide everything on the page visually during print */
  body * {
    visibility: hidden !important;
  }

  /* Make ONLY the printable prescription sheet and its children visible */
  #printable-sheet,
  #printable-sheet * {
    visibility: visible !important;
  }

  /* Position printable sheet at the top of the printed document */
  #printable-sheet {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    padding: 12mm 15mm !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .sheet-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 2px solid #000000 !important;
    padding-bottom: 0.5rem !important;
    margin-bottom: 0.75rem !important;
    width: 100% !important;
  }

  .sheet-logo-img {
    max-height: 75px !important;
    width: auto !important;
    mix-blend-mode: normal !important;
    filter: none !important;
  }

  .sheet-rx-badge {
    text-align: right !important;
  }

  .rx-label, .rx-no {
    color: #000000 !important;
  }

  .sheet-meta-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    background: #ffffff !important;
    border: 1.5px solid #000000 !important;
    padding: 0.5rem 0.75rem !important;
    margin-bottom: 0.75rem !important;
    gap: 0.35rem 1rem !important;
  }

  .meta-field {
    border-bottom: 1px dotted #666666 !important;
  }

  .meta-label, .meta-value, .bold-text {
    color: #000000 !important;
  }

  .sheet-tables-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.75rem !important;
    margin: 0.75rem 0 !important;
  }

  .sheet-table-box {
    border: 1.5px solid #000000 !important;
    padding: 0.4rem !important;
    background: #ffffff !important;
  }

  .table-title {
    color: #000000 !important;
    border-bottom: 1.5px solid #000000 !important;
    font-weight: 800 !important;
  }

  .sheet-table th, .sheet-table td {
    color: #000000 !important;
    border-bottom: 1px dashed #666666 !important;
  }

  .sheet-table td.row-label {
    color: #000000 !important;
    font-weight: 800 !important;
  }

  .table-color-row {
    border-top: 1px solid #000000 !important;
  }

  .color-label, .color-val {
    color: #000000 !important;
  }

  .strike-overlay svg line {
    stroke: #000000 !important;
    stroke-width: 3 !important;
  }

  .sheet-specs-row {
    display: flex !important;
    justify-content: space-between !important;
    border-top: 1.5px solid #000000 !important;
    border-bottom: 1.5px solid #000000 !important;
    padding: 0.4rem 0 !important;
    margin-bottom: 0.75rem !important;
  }

  .spec-lbl, .spec-val {
    color: #000000 !important;
  }

  .sheet-drugs-section {
    border: 1.5px solid #000000 !important;
    padding: 0.5rem !important;
    margin-bottom: 0.75rem !important;
  }

  .sheet-drugs-section.active {
    display: block !important;
  }

  .drugs-header {
    color: #000000 !important;
    border-bottom: 1px solid #000000 !important;
    font-weight: 800 !important;
  }

  .drugs-table th, .drugs-table td {
    color: #000000 !important;
    border-bottom: 1px solid #cccccc !important;
  }

  .medical-notes-box {
    color: #000000 !important;
  }

  .sheet-footer {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-end !important;
    margin-top: 1rem !important;
    padding-top: 0.5rem !important;
    page-break-inside: avoid !important;
  }

  .footer-clinic-info p {
    color: #000000 !important;
    font-size: 0.75rem !important;
  }

  .signature-box {
    width: 200px !important;
    min-height: 55px !important;
  }

  .sheet-signature-img {
    max-height: 70px !important;
    mix-blend-mode: normal !important;
    filter: none !important;
  }

  .signature-line {
    border-bottom: 1.5px solid #000000 !important;
  }

  .signature-title {
    color: #000000 !important;
    font-weight: 700 !important;
  }

  .sheet-obs-block {
    margin-top: 0.5rem !important;
    color: #000000 !important;
    font-size: 0.85rem !important;
    border-top: 1px solid #cccccc !important;
    padding-top: 0.35rem !important;
  }
}
