/* --- Base Layout --- */
.diet-main { 
  margin-top: 25px !important; 
  padding-top: 10px !important; 
  display: flex;
  flex-direction: column;
}
.header { margin-bottom: 24px !important; }

#diet-section { order: 99; }
footer { order: 100; margin-top: 30px; }

/* --- Top Navigation & Buttons --- */
.top-nav { margin-bottom: 16px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); padding: 6px 14px; border-radius: 8px;
  text-decoration: none; font-size: 0.85rem; font-weight: 600;
  transition: all 0.2s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.action-buttons-group { display: flex; gap: 12px; align-items: center; }
.print-btn {
  cursor: pointer; padding: 8px 16px; border-radius: 999px;
  border: none; background: var(--accent); color: var(--accent-contrast);
  font-size: 0.85rem; font-weight: 600; transition: all 0.25s ease;
  height: 38px; display: flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.print-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* --- 1. Emergency Banner --- */
.alert-card {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid #ef4444;
  border-radius: 12px; padding: 20px; margin-bottom: 20px;
}
[data-theme="dark"] .alert-card { background: rgba(239, 68, 68, 0.15); }
.alert-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.alert-icon { font-size: 1.4rem; }
.alert-header h3 { margin: 0; color: #ef4444; font-size: 1.2rem; }
.alert-list { margin: 0; padding-left: 20px; color: var(--text); font-size: 0.95rem; line-height: 1.6; }
.alert-list li { margin-bottom: 6px; }

/* --- Sections --- */
.section-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}
.section-title { margin-top: 0; margin-bottom: 20px; font-size: 1.3rem; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 10px; }

/* --- 2. Lab Protocol Steps --- */
.lab-steps { display: flex; flex-direction: column; gap: 12px; }
.step { display: flex; align-items: flex-start; gap: 14px; background: var(--bg); padding: 12px 16px; border-radius: 8px; border: 1px solid var(--border); }
.step-num { 
  background: var(--text); color: var(--bg); width: 28px; height: 28px; 
  border-radius: 50%; display: flex; align-items: center; justify-content: center; 
  font-weight: 700; font-size: 0.9rem; flex-shrink: 0;
}
.step-text { font-size: 0.95rem; line-height: 1.5; color: var(--text); padding-top: 3px; }

/* --- 3. Diet Timeline --- */
.special-note { background: var(--bg); padding: 12px 16px; border-radius: 8px; font-size: 0.9rem; color: var(--text); margin-bottom: 24px; border-left: 4px solid var(--accent); }
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 6px; top: 8px; bottom: 0;
  width: 2px; background: var(--border);
}
.time-block { position: relative; margin-bottom: 24px; }
.time-block:last-child { margin-bottom: 0; }
.time-block::before {
  content: ''; position: absolute; left: -24px; top: 5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--card);
}
.time-label { font-weight: 700; font-size: 1.05rem; color: var(--text); margin-bottom: 6px; }
.time-content { background: var(--bg); padding: 12px 16px; border-radius: 8px; border: 1px solid var(--border); }
.time-content p { margin: 0 0 6px 0; font-size: 0.95rem; line-height: 1.5; color: var(--muted); }
.time-content p:last-child { margin-bottom: 0; }
[data-theme="dark"] .time-content p { color: #d1d5db; }

.print-only { display: none; }

/* --- Mobile Header Fix --- */
@media (max-width: 600px) {
  .header { flex-direction: column !important; align-items: flex-start !important; gap: 16px; }
  .action-buttons-group { display: flex; flex-wrap: wrap; gap: 12px; }
  .theme-toggle { position: static !important; }
}

/* =========================================
   PRINT STYLES — SINGLE A4 PAGE
   ========================================= */
@media print {
  @page {
    size: A4 portrait;
    /* 35mm top for header, tight on other sides */
    margin: 35mm 6mm 4mm 6mm;
  }

  :root, [data-theme="dark"] {
    --bg: #ffffff !important;
    --card: #ffffff !important;
    --border: #cccccc !important;
    --text: #000000 !important;
    --muted: #222222 !important;
    --accent: #000000 !important;
  }

  html, body {
    background: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
    /* Base font size drives all rem/em — shrink globally */
    font-size: 9pt !important;
    line-height: 1.3 !important;
  }

  .diet-main {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #diet-section { order: unset !important; margin-bottom: 8px !important; }
  footer { display: none !important; }

  .no-print { display: none !important; }
  .print-only { display: block !important; }

  /* PRINT HEADER — sits inside the 35mm top margin area via fixed positioning */
  .print-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 33mm;
    padding: 4mm 6mm 2mm;
    box-sizing: border-box;
    text-align: center;
    background: white;
  }
  .print-header h2 { margin: 0 0 1mm; font-size: 14pt; color: black; }
  .print-header p  { margin: 0 0 1mm; font-size: 8pt; color: #444; }
  .print-meta { display: inline-block; padding: 1px 5px; font-size: 8pt; font-weight: bold; border: 1px solid #ccc; border-radius: 3px; }
  .print-header hr { margin: 2mm 0 1mm; border: none; border-top: 1.5px solid black; }
  .print-header h1 { font-size: 11pt; margin: 0; }

  /* ALERT CARD */
  .alert-card {
    background: transparent !important;
    border: 1.5px solid black !important;
    padding: 4px 8px !important;
    margin-bottom: 7px !important;
    border-radius: 4px !important;
  }
  .alert-header { margin-bottom: 2px !important; gap: 5px !important; }
  .alert-icon { font-size: 0.9rem !important; }
  .alert-header h3 { color: black !important; font-size: 10pt !important; margin: 0 !important; }
  .alert-list { font-size: 8pt !important; line-height: 1.3 !important; padding-left: 14px !important; margin: 0 !important; }
  .alert-list li { margin-bottom: 1px !important; }

  /* SECTION CARDS */
  .section-card { border: none !important; box-shadow: none !important; padding: 0 !important; margin-bottom: 7px !important; }
  .section-title {
    color: black !important; border-bottom: 1.5px solid black !important;
    font-size: 10pt !important; padding-bottom: 1px !important;
    margin-bottom: 4px !important; margin-top: 0 !important;
  }

  /* LAB STEPS */
  .lab-steps { gap: 2px !important; }
  .step {
    background: transparent !important; border-color: #aaa !important;
    padding: 2px 6px !important; gap: 7px !important;
    border-radius: 3px !important; page-break-inside: avoid;
  }
  .step-num {
    background: white !important; color: black !important;
    border: 1.5px solid black !important;
    width: 15px !important; height: 15px !important; font-size: 7pt !important; flex-shrink: 0 !important;
  }
  .step-text { font-size: 8pt !important; padding-top: 0 !important; line-height: 1.3 !important; }

  /* DIET TIMELINE */
  .special-note {
    background: transparent !important; border: 1px solid black !important;
    border-left: 3px solid black !important; border-radius: 0 !important;
    padding: 3px 8px !important; margin-bottom: 5px !important;
    font-size: 8pt !important; line-height: 1.3 !important; page-break-inside: avoid;
  }

  .timeline { padding-left: 16px !important; }
  .timeline::before { background: black !important; left: 3px !important; top: 5px !important; width: 1.5px !important; }

  .time-block { margin-bottom: 4px !important; page-break-inside: avoid; }
  .time-block::before {
    background: white !important; border: 2px solid black !important;
    top: 3px !important; left: -16px !important;
    width: 8px !important; height: 8px !important;
  }

  .time-label { font-size: 8.5pt !important; margin-bottom: 1px !important; font-weight: 700 !important; }
  .time-content {
    background: transparent !important; border-color: #aaa !important;
    padding: 2px 6px !important; border-radius: 3px !important;
  }
  .time-content p { font-size: 8pt !important; margin-bottom: 1px !important; line-height: 1.3 !important; color: black !important; }
  [data-theme="dark"] .time-content p { color: black !important; }
}
