/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root {
  --accent-h: 225;
  --accent: hsl(var(--accent-h) 65% 48%);
  --accent-soft: hsl(var(--accent-h) 65% 96%);
  --accent-hover: hsl(var(--accent-h) 65% 42%);
  --accent-ring: hsl(var(--accent-h) 70% 55% / 0.25);

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e7e9ee;
  --border-soft: #eef0f4;
  --text: #0e1726;
  --text-soft: #4a5468;
  --text-muted: #8b93a7;
  --text-faint: #b6bcca;

  --ok: #0d9668;
  --ok-soft: #e7f6ef;
  --warn: #c77400;

  --shadow-sm: 0 1px 2px rgba(15, 22, 40, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 22, 40, 0.06), 0 1px 3px rgba(15, 22, 40, 0.04);
  --shadow-lg: 0 24px 60px rgba(15, 22, 40, 0.12), 0 4px 12px rgba(15, 22, 40, 0.06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

button { font: inherit; color: inherit; }

/* ========== HEADER ========== */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 40;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 32px;
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 32px;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  display: grid; place-items: center;
  box-shadow: 0 4px 10px hsl(var(--accent-h) 65% 48% / 0.25);
}
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.brand-name span { color: var(--accent); font-weight: 500; }
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500; }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute; left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  border-color: var(--accent);
  background: white;
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.kbd {
  position: absolute; right: 10px;
  font: 11px/1 'SF Mono', ui-monospace, monospace;
  background: white;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: 5px;
  letter-spacing: 0.05em;
}

.header-right { display: flex; align-items: center; gap: 16px; justify-content: flex-end; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
  transition: all .15s;
}
.icon-btn:hover { background: white; border-color: var(--text-faint); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 9px; right: 9px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #e04d4d; border: 2px solid var(--surface);
  box-sizing: content-box;
}

.doctor { display: flex; align-items: center; gap: 10px; }
.doctor-avatar { flex-shrink: 0; }
.doctor-name { font-size: 13.5px; font-weight: 600; line-height: 1.3; white-space: nowrap; }
.doctor-crm { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.doctor-wide .doctor-info { min-width: 0; max-width: 280px; }
.doctor-wide .doctor-name { font-size: 14px; }

.header-strip {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.date-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-soft);
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 5px 11px;
  border-radius: 999px;
  font-weight: 500;
}
.stat-strip { display: flex; align-items: center; gap: 16px; font-size: 12.5px; color: var(--text-muted); }
.stat { display: flex; align-items: baseline; gap: 5px; }
.stat-n { font-size: 14px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-faint); }

/* ========== CATEGORY NAV ========== */
.cat-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 108px; z-index: 30;
}
.cat-nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 32px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-nav-inner::-webkit-scrollbar { display: none; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.cat-pill:hover { background: var(--bg); color: var(--text); }
.cat-pill.active {
  background: var(--text);
  color: white;
  border-color: var(--text);
}
.cat-count {
  font-size: 11px;
  background: rgba(0,0,0,0.06);
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.cat-pill.active .cat-count { background: rgba(255,255,255,0.18); }

/* ========== MAIN ========== */
.main { flex: 1; padding: 28px 0 80px; }
.main-inner { max-width: 1400px; margin: 0 auto; padding: 0 32px; }

.sec { margin-bottom: 36px; }
.sec-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
}
.sec-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
}
.sec-star { color: #e8b004; }
.sec-count {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  border: 1px solid var(--border);
}

/* ========== CARD GRID ========== */
.card-grid { display: grid; gap: 10px; }
.card-grid.grid-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card-grid.grid-list { grid-template-columns: 1fr; gap: 4px; }
.card-grid.grid-tile { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }

.density-compacto .card-grid.grid-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.density-compacto .card-grid.grid-tile { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  position: relative;
  transition: all .14s ease;
  width: 100%;
  box-shadow: var(--shadow-sm);
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px hsl(var(--accent-h) 40% 40% / 0.08);
}
.card:active { transform: translateY(0); }

.card-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.card-body { flex: 1; min-width: 0; }
.card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub {
  display: flex; align-items: center; gap: 8px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.card-cat { font-weight: 500; }
.card-cid {
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', ui-monospace, monospace;
  font-size: 10.5px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}

.card-star {
  position: absolute;
  top: 10px; right: 10px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  color: var(--text-faint);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: all .15s;
}
.card:hover .card-star { opacity: 1; }
.card-star:hover { background: var(--bg); color: #e8b004; }
.card-star.on { opacity: 1; color: #e8b004; }

/* TILE variant - bigger */
.card-tile {
  flex-direction: column;
  align-items: flex-start;
  padding: 18px;
  min-height: 130px;
}
.card-tile .card-icon { width: 40px; height: 40px; }
.card-tile .card-body { margin-top: auto; flex: 0; }
.card-tile .card-name { font-size: 15px; white-space: normal; }

/* LIST variant - compact row */
.card-list {
  padding: 10px 14px;
  border-radius: 8px;
}
.card-list .card-icon { width: 32px; height: 32px; border-radius: 7px; }
.card-list .card-icon svg { width: 16px; height: 16px; }

/* ========== CATEGORY COLORS (icon backgrounds) ========== */
.cat-bg-prescries        { background: #eff6ff; color: #1d4ed8; }
.cat-bg-encaminhamentos  { background: #ecfdf5; color: #047857; }
.cat-bg-emergncia        { background: #fef2f2; color: #b91c1c; }
.cat-bg-gestantes        { background: #fdf2f8; color: #be185d; }
.cat-bg-outros           { background: #fefce8; color: #a16207; }
.cat-bg-condutamdica     { background: #fef2f2; color: #b91c1c; }

.cat-chip {
  display: inline-flex; align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.cat-prescries        { background: #eff6ff; color: #1d4ed8; }
.cat-encaminhamentos  { background: #ecfdf5; color: #047857; }
.cat-emergncia        { background: #fef2f2; color: #b91c1c; }
.cat-gestantes        { background: #fdf2f8; color: #be185d; }
.cat-outros           { background: #fefce8; color: #a16207; }

/* Category-tinted active pills */
.cat-pill.active.cat-pill-prescries        { background: #1d4ed8; border-color: #1d4ed8; }
.cat-pill.active.cat-pill-encaminhamentos  { background: #047857; border-color: #047857; }
.cat-pill.active.cat-pill-emergncia        { background: #b91c1c; border-color: #b91c1c; }
.cat-pill.active.cat-pill-gestantes        { background: #be185d; border-color: #be185d; }
.cat-pill.active.cat-pill-outros           { background: #a16207; border-color: #a16207; }

/* ========== DRAWER ========== */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 22, 40, 0.28);
  backdrop-filter: blur(2px);
  z-index: 100;
  animation: fade-in .2s ease;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 560px;
  max-width: 100vw;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 101;
  display: flex;
  flex-direction: column;
  animation: slide-in .28s cubic-bezier(0.22, 0.8, 0.3, 1);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(28px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.drawer-header {
  padding: 20px 24px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.drawer-head-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.close-btn { width: 34px; height: 34px; }

.drawer-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.drawer-title {
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
  color: var(--text);
}
.fav-btn {
  border: none;
  background: transparent;
  color: var(--text-faint);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.fav-btn:hover { background: var(--bg); color: #e8b004; }
.fav-btn.on { color: #e8b004; }

.drawer-meta {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.meta-item { display: inline-flex; align-items: center; gap: 5px; }
.meta-label { font-weight: 600; color: var(--text-soft); letter-spacing: 0.02em; }
.meta-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-faint); }

/* In-drawer section tabs (sticky under header) */
.drawer-tabs {
  position: relative;
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  z-index: 2;
}
.drawer-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 14px;
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.18s ease;
  position: relative;
}
.drawer-tab:hover { color: var(--text-soft); }
.drawer-tab.active { color: var(--accent); }
.drawer-tab svg { opacity: 0.9; }
.drawer-tabs-indicator {
  position: absolute;
  bottom: -1px;
  left: 24px;
  width: calc((100% - 48px) / 2);
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: transform 0.24s cubic-bezier(.4,0,.2,1);
}
.drawer-tabs-indicator.right { transform: translateX(100%); }

.drawer-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: hsl(220 12% 80%) transparent;
  padding: 16px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.drawer-body::-webkit-scrollbar { width: 10px; }
.drawer-body::-webkit-scrollbar-track { background: transparent; }
.drawer-body::-webkit-scrollbar-thumb {
  background: hsl(220 14% 82%);
  border-radius: 8px;
  border: 2px solid var(--surface);
}
.drawer-body::-webkit-scrollbar-thumb:hover { background: hsl(220 14% 70%); }

/* ========== RX BLOCKS (Medicamentos + Conduta) ========== */
.rx-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.rx-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
}
.rx-block-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.rx-block-title svg { color: var(--accent); }
.rx-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.rx-copy-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.rx-block .editor-area {
  padding: 14px 18px;
  background: white;
  font-size: 14px;
  line-height: 1.6;
}
.rx-block .editor-toolbar { padding: 6px 12px; }
.rx-block-conduta {
  border-color: hsl(28 80% 82%);
  background: hsl(35 100% 98.5%);
}
.rx-block-conduta .rx-block-head {
  background: hsl(35 100% 96%);
  border-bottom-color: hsl(28 80% 82%);
}
.rx-block-conduta .rx-block-title svg { color: hsl(22 85% 50%); }
.rx-block-conduta .editor-area { background: hsl(40 100% 99%); }
.rx-block-conduta .rx-copy-btn:hover { background: hsl(22 85% 50%); border-color: hsl(22 85% 50%); }

/* ========== PRINT MODAL INCLUDE GRID ========== */
.print-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: hsl(var(--accent-h) 70% 97%);
  border: 1px solid hsl(var(--accent-h) 60% 85%);
  border-radius: 8px;
  font-size: 12.5px;
  color: hsl(var(--accent-h) 50% 35%);
  font-weight: 500;
}
.print-info-row svg { color: var(--accent); flex-shrink: 0; }

.form-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 0 0 10px;
  font-style: italic;
}
.form-optional {
  font-style: normal;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85em;
  margin-left: 4px;
}

/* TIPO TOGGLE — choose Prescrição vs Conduta Médica in new modal */
.tipo-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 4px;
  background: var(--bg-soft);
  border-radius: 12px;
  margin-bottom: 18px;
}
.tipo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 12px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  line-height: 1.25;
}
.tipo-btn svg { flex-shrink: 0; }
.tipo-btn:hover { color: var(--text); background: rgba(255,255,255,0.6); }
.tipo-btn.active {
  background: white;
  border-color: var(--accent);
  color: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.tipo-btn.tipo-btn-red.active {
  border-color: #d04c2c;
  color: #b91c1c;
  box-shadow: 0 2px 8px rgba(208, 76, 44, 0.12);
}

/* ========== PREVIEW VIA (2-vias preview) ========== */
.preview-paper.preview-via {
  padding: 18px 20px;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 11.5px;
  line-height: 1.55;
  color: #222;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}
.preview-via-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 14px 0 12px;
  font-family: Inter, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: #666;
}
.preview-via-date {
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #333;
}
.preview-paciente-line {
  border-bottom: 1px solid #333;
  padding-bottom: 3px;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-height: 20px;
}
.pp-label {
  font-family: Inter, sans-serif;
  font-weight: 700;
  font-size: 10.5px;
}
.pp-name { flex: 1; font-size: 12px; }
.pp-empty { color: transparent; }
.preview-rx {
  font-size: 30px;
  font-weight: 700;
  color: #0050a3;
  line-height: 1;
  margin-bottom: 6px;
}
.preview-paper.preview-via .preview-content {
  font-size: 1em;
  line-height: 1.7;
  margin-bottom: 10px;
}
.preview-paper.preview-via .preview-content h3 {
  font-size: 0.82em;
  font-family: Inter, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: #666;
  margin: 8px 0 3px;
}
.preview-paper.preview-via .preview-content ul,
.preview-paper.preview-via .preview-content ol {
  padding-left: 18px;
  margin: 0 0 6px;
}
.preview-paper.preview-via .preview-content li { margin-bottom: 3px; }
.preview-paper.preview-via .preview-content ol.med-list {
  list-style: none;
  padding-left: 0;
  margin: 0 0 10px;
  counter-reset: medcounter;
}
.preview-paper.preview-via .preview-content ol.med-list li.med-item {
  counter-increment: medcounter;
  padding-left: 22px;
  position: relative;
  margin-bottom: 8px;
}
.preview-paper.preview-via .preview-content ol.med-list li.med-item::before {
  content: counter(medcounter) " —";
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 700;
  color: #111;
}
.preview-paper.preview-via .preview-content .med-name {
  font-weight: 700;
  color: #111;
  line-height: 1.35;
}
.preview-paper.preview-via .preview-content .med-dose {
  font-style: italic;
  color: #333;
  line-height: 1.4;
  font-size: 0.96em;
  margin-top: 1px;
}
.preview-paper.preview-via .preview-content::after { display: none; }
.preview-sign {
  margin-top: auto;
  padding-top: 30px;
  text-align: center;
}
.preview-sign-line {
  width: 70%;
  margin: 0 auto 4px;
  border-top: 1px solid #333;
}
.preview-sign-caption {
  font-family: Inter, sans-serif;
  font-size: 9px;
  color: #666;
  letter-spacing: 0.05em;
}

.print-include-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.toggle-row.toggle-inline {
  margin-bottom: 0;
  padding: 10px 12px;
  font-size: 13px;
}
.toggle-row.toggle-inline.on {
  background: hsl(var(--accent-h) 70% 96%);
  border-color: hsl(var(--accent-h) 60% 75%);
  color: var(--accent);
}

/* ========== PREVIEW CONDUTA ========== */
.preview-conduta {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1.5px dashed hsl(28 60% 65%);
  border-radius: 6px;
  background: hsl(35 100% 98%);
  position: relative;
}
.preview-conduta::before {
  content: "CONDUTA PS";
  position: absolute;
  top: -8px;
  left: 10px;
  background: white;
  padding: 0 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: hsl(22 60% 45%);
}

@media (max-width: 720px) {
  .drawer-body { padding: 12px 16px 16px; gap: 10px; }
  .rx-block-head { padding: 8px 12px; }
  .rx-block .editor-area { padding: 12px 14px; font-size: 13.5px; }
  .print-include-grid { grid-template-columns: 1fr; }
}

/* ========== EDITOR ========== */
.editor { display: flex; flex-direction: column; height: 100%; }
.editor-toolbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
}
.tb-btn {
  border: 1px solid transparent;
  background: transparent;
  width: 30px; height: 30px;
  border-radius: 6px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--text-soft);
  transition: all .12s;
}
.tb-btn:hover { background: var(--bg); color: var(--text); }
.tb-btn.active { background: var(--accent-soft); color: var(--accent); }
.tb-text { width: auto; padding: 0 10px; font-size: 12.5px; font-weight: 500; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

.editor-area {
  padding: 20px 24px 40px;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text-soft);
  outline: none;
  min-height: 100%;
}
.editor-area.editable {
  background: linear-gradient(to right, var(--accent-soft) 3px, transparent 3px);
  background-size: 3px 100%;
}
.editor-area h3 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 22px 0 10px;
  letter-spacing: -0.01em;
}
.editor-area h3:first-child { margin-top: 0; }
.editor-area p { margin: 0 0 10px; }
.editor-area ul, .editor-area ol { margin: 0 0 14px; padding-left: 22px; }
.editor-area li { margin-bottom: 4px; }
.editor-area b, .editor-area strong { color: var(--text); font-weight: 600; }

/* ========== MED LIST (Nome + Posologia) ========== */
.editor-area ol.med-list {
  list-style: none;
  padding-left: 0;
  margin: 0 0 14px;
  counter-reset: medcounter;
}
.editor-area ol.med-list li.med-item {
  counter-increment: medcounter;
  margin: 0 0 14px;
  padding: 0 0 0 28px;
  position: relative;
}
.editor-area ol.med-list li.med-item::before {
  content: counter(medcounter) " —";
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.editor-area ol.med-list li.med-item:last-child { margin-bottom: 4px; }
.editor-area .med-name {
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 2px;
}
.editor-area .med-name em {
  font-style: italic;
  font-weight: 500;
  color: var(--text-muted);
  margin-right: 4px;
}
.editor-area .med-dose {
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.45;
  font-weight: 400;
  font-size: 0.96em;
}

/* ========== DRAWER FOOTER ========== */
.drawer-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.footer-actions-left, .footer-actions-right {
  display: flex; align-items: center; gap: 8px;
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 1px 2px hsl(var(--accent-h) 65% 30% / 0.2);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border-color: var(--border);
}
.btn-ghost:hover { background: white; border-color: var(--text-faint); color: var(--text); }
.btn-ghost.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-soft); }

.saved-flash {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px;
  color: var(--ok);
  font-weight: 500;
  animation: fade-out 1.8s ease;
}
@keyframes fade-out { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

/* ========== EMPTY ========== */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty p { font-size: 14px; margin: 14px 0; }
.empty svg { color: var(--text-faint); }

/* ========== HINT BAR ========== */
.hint-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 9px 16px;
  background: rgba(14, 23, 38, 0.92);
  color: #d1d6e0;
  border-radius: 10px;
  font-size: 12px;
  z-index: 20;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
}
.hint-bar span { display: inline-flex; align-items: center; gap: 6px; }
.hint-bar .kbd {
  position: static;
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
  color: #e5e9f0;
}

/* ========== MODAL (base, high specificity, loaded early) ========== */
.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  background: rgba(15, 22, 40, 0.4);
  backdrop-filter: blur(3px);
  z-index: 110 !important;
  animation: fade-in .2s ease;
}
.modal {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: 640px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 60px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 111 !important;
  display: flex !important;
  flex-direction: column;
  animation: modal-pop .24s cubic-bezier(0.22, 0.8, 0.3, 1);
  overflow: hidden;
}
.modal.modal-wide { width: 900px; }
@keyframes modal-pop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ========== TOAST ========== */
.toast-stack {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px 11px 12px;
  background: #0e1726;
  color: white;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  animation: toast-in .25s cubic-bezier(0.3, 0.8, 0.3, 1.2);
  pointer-events: auto;
  min-width: 240px;
}
.toast-success { background: #0d9668; }
.toast-error { background: #c93b3b; }
.toast-info { background: #1f3a5f; }
.toast-icon {
  width: 22px; height: 22px;
  background: rgba(255,255,255,0.18);
  border-radius: 6px;
  display: grid; place-items: center;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========== META DIRTY ========== */
.meta-dirty { color: var(--warn); font-weight: 600; }

/* ========== PRINT MODAL ========== */
.modal-wide { width: 900px; }
.print-modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.print-left, .print-right { min-width: 0; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  margin-bottom: 16px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--accent-hover);
}
.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; }

.font-size-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.fs-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}
.fs-options {
  display: flex;
  gap: 4px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px;
}
.fs-option {
  padding: 6px 10px;
  border-radius: 5px;
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background .12s, color .12s;
}
.fs-option:hover { color: var(--text); }
.fs-option.active {
  background: var(--accent);
  color: white;
}

/* ========== COMPACT PRINT MODAL ========== */
.print-info-row {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.compact-section {
  padding: 10px 12px !important;
  margin-bottom: 10px;
}
.section-head-row { margin-bottom: 8px; }
.section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.section-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.form-row.tight { margin-bottom: 6px; }
.form-grid.tight { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.form-row.tight .form-input,
.form-grid.tight .form-input {
  padding: 7px 10px;
  font-size: 12.5px;
  height: 32px;
}
.compact-options {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
}
.opt-line {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  border-radius: 5px;
  margin: 0 4px;
}
.opt-line:hover { background: white; }
.opt-line input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  margin: 0;
}
.opt-line.opt-disabled { opacity: 0.45; cursor: not-allowed; }
.opt-line.opt-fs {
  justify-content: space-between;
  cursor: default;
}
.opt-line.opt-fs:hover { background: transparent; }
.opt-fs-label { font-weight: 500; }
.opt-line.opt-fs .fs-options { padding: 2px; gap: 2px; }
.opt-line.opt-fs .fs-option { padding: 4px 8px; font-size: 11.5px; min-width: 26px; }
.opt-line.opt-pac {
  cursor: default;
  padding: 6px 8px;
}
.opt-line.opt-pac:hover { background: transparent; }
.form-input-sm {
  width: 100%;
  padding: 7px 10px !important;
  font-size: 12.5px !important;
  height: 32px !important;
}

.form-section {
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: opacity .2s;
}
.form-section.disabled { opacity: 0.45; pointer-events: none; }
.form-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.preview-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.preview-paper {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.04);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 12px;
  color: #333;
  min-height: 380px;
  position: sticky;
  top: 20px;
}
.rx-header-preview { margin-bottom: 14px; }
.rxh-top { display: flex; gap: 12px; align-items: center; }
.rxh-logo {
  width: 40px; height: 40px;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 7px;
  display: grid; place-items: center;
  flex-shrink: 0;
  font-family: 'Inter', sans-serif;
}
.rxh-main { flex: 1; min-width: 0; }
.rxh-unidade { font-size: 15px; font-weight: 700; color: #111; margin-bottom: 2px; line-height: 1.2; }
.rxh-addr { font-size: 11px; color: #666; line-height: 1.35; }
.rxh-divider { border-top: 1.5px solid #333; margin: 8px 0 6px; }
.rxh-doctor { font-size: 11px; color: #444; display: flex; gap: 6px; flex-wrap: wrap; }

.preview-empty {
  padding: 16px;
  border: 1px dashed var(--border);
  text-align: center;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  border-radius: 6px;
  margin-bottom: 14px;
}
.preview-paciente {
  border: 1px solid #333;
  padding: 6px 10px;
  font-size: 11px;
  margin-bottom: 12px;
  border-radius: 2px;
}
.preview-title {
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #333;
  padding-bottom: 6px;
  margin: 10px 0 6px;
}
.preview-meta {
  font-size: 10px;
  color: #666;
  text-align: right;
  margin-bottom: 10px;
}
.preview-content {
  font-size: 11px;
  line-height: 1.45;
  color: #555;
  max-height: 150px;
  overflow: hidden;
  position: relative;
}
.preview-content::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  background: linear-gradient(to bottom, transparent, white);
}
.preview-content h3 { font-size: 11.5px; margin: 8px 0 3px; color: #111; }
.preview-content ul, .preview-content ol { padding-left: 16px; margin: 0 0 6px; }
.preview-content li { margin-bottom: 2px; }
.preview-content ol.med-list {
  list-style: none;
  padding-left: 0;
  counter-reset: medcounter;
}
.preview-content ol.med-list li.med-item {
  counter-increment: medcounter;
  padding-left: 18px;
  position: relative;
  margin-bottom: 4px;
}
.preview-content ol.med-list li.med-item::before {
  content: counter(medcounter) " —";
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 700;
  color: #111;
  font-size: 10.5px;
}
.preview-content .med-name { font-weight: 700; color: #111; }
.preview-content .med-dose { font-style: italic; color: #444; font-size: 0.95em; }

/* ========== MODAL RESPONSIVE FIXES ========== */
.modal-editor { min-height: 220px; }
.modal-editor .editor { min-height: 220px; display: flex; flex-direction: column; }
.modal-editor .editor-area {
  min-height: 180px;
  padding: 14px 16px;
  font-size: 13.5px;
  flex: 1;
  background: white;
}
.modal-editor .editor-area.editable { background: white; }
.modal-editor .editor-toolbar {
  padding: 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

@media (max-width: 860px) {
  .print-modal-body { grid-template-columns: 1fr; gap: 16px; }
  .preview-paper { position: static; min-height: 280px; }
  .modal-wide { width: 100vw; }
}
@media (max-height: 800px) {
  .preview-paper { position: static !important; }
  .print-modal-body { grid-template-columns: 1fr 1fr; }
}

/* ========== RESPONSIVE ========== */
.mobile-only { display: none; }
.mobile-search-bar { display: none; }

/* ========== FAB (Floating Action Button) ========== */
.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px 14px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 8px 24px hsl(var(--accent-h) 65% 35% / 0.35), 0 2px 6px hsl(var(--accent-h) 65% 35% / 0.2);
  transition: all .18s cubic-bezier(0.3, 0.8, 0.3, 1);
}
.fab:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px hsl(var(--accent-h) 65% 35% / 0.45), 0 4px 10px hsl(var(--accent-h) 65% 35% / 0.25);
}
.fab:active { transform: translateY(0); }
.fab-label { display: inline-block; }

/* ========== NEW PRESCRIPTION MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 22, 40, 0.4);
  backdrop-filter: blur(3px);
  z-index: 110;
  animation: fade-in .2s ease;
}
.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 640px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 60px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 111;
  display: flex;
  flex-direction: column;
  animation: modal-pop .24s cubic-bezier(0.22, 0.8, 0.3, 1);
  overflow: hidden;
}
@keyframes modal-pop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px;
}
.modal-eyebrow {
  font-size: 11.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 4px;
}
.modal-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.form-row { margin-bottom: 16px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
  margin-bottom: 16px;
}
.form-label, .form-label-text {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.form-label em { color: #e04d4d; font-style: normal; }
.form-label > span { display: block; margin-bottom: 6px; }
.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: all .15s;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.icon-pick {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-soft);
  cursor: pointer;
  transition: all .15s;
}
.icon-pick:hover { border-color: var(--text-faint); color: var(--text); }
.icon-pick.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.modal-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 280px;
  display: flex;
  flex-direction: column;
}
.modal-editor .editor { max-height: 280px; }
.modal-editor .editor-toolbar { padding: 6px 10px; }
.modal-editor .editor-area { padding: 14px 16px; font-size: 13.5px; flex: 1; overflow-y: auto; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ========== RESPONSIVE (TABLET) ========== */
@media (max-width: 1100px) {
  .header-inner {
    grid-template-columns: auto 1fr auto;
    gap: 16px;
  }
  .brand-sub { display: none; }
  .kbd { display: none; }
  .drawer { width: min(560px, 100vw); }
}
@media (max-width: 880px) {
  .doctor-info { display: none; }
}

/* ========== RESPONSIVE (MOBILE) ========== */
@media (max-width: 720px) {
  .header-inner {
    grid-template-columns: 1fr auto;
    padding: 12px 16px;
    gap: 12px;
  }
  .brand-mark { width: 36px; height: 36px; border-radius: 9px; }
  .brand-name { font-size: 16px; }
  .brand-sub { display: none; }
  .search-wrap { display: none; }
  .header-right { gap: 8px; }
  .header-right .icon-btn { width: 40px; height: 40px; }
  .mobile-only { display: grid; }
  .doctor-info { display: none; }
  .doctor-avatar svg { width: 32px; height: 32px; }

  .mobile-search-bar {
    display: block;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 62px;
    z-index: 35;
  }
  .mobile-search-bar .search-wrap { display: flex; }
  .mobile-search-bar .search-input { padding-right: 42px; }
  .mobile-search-close {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px; height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    display: grid; place-items: center;
    cursor: pointer;
  }

  .header-strip {
    padding: 0 16px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .stat-strip { gap: 10px; font-size: 11.5px; }

  .cat-nav { position: sticky; top: 62px; }
  .cat-nav-inner { padding: 10px 16px; }

  .main { padding: 16px 0 120px; }
  .main-inner { padding: 0 16px; }

  .sec { margin-bottom: 24px; }
  .sec-head { margin-bottom: 10px; }

  /* On mobile, force a tighter 2-column grid regardless of chosen variant */
  .card-grid.grid-grid,
  .card-grid.grid-tile {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }
  .card-grid.grid-list { gap: 6px; }

  .card {
    padding: 14px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    min-height: 110px;
    border-radius: 12px;
  }
  .card-tile { flex-direction: column; }
  .card-list {
    flex-direction: row;
    align-items: center;
    min-height: 0;
    padding: 10px 12px;
  }
  .card-icon { width: 38px; height: 38px; }
  .card-name { font-size: 13.5px; white-space: normal; line-height: 1.25; }
  .card-sub { gap: 6px; font-size: 10.5px; }
  .card-star { opacity: 1; top: 6px; right: 6px; }

  /* Drawer full-screen on mobile */
  .drawer-overlay { display: none; }
  .drawer {
    width: 100vw;
    max-width: 100vw;
    inset: 0;
    animation: slide-up .25s cubic-bezier(0.22, 0.8, 0.3, 1);
  }
  @keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .drawer-header { padding: 14px 16px 12px; }
  .drawer-title { font-size: 22px; }
  .editor-toolbar { padding: 6px 12px; overflow-x: auto; scrollbar-width: none; }
  .editor-toolbar::-webkit-scrollbar { display: none; }
  .editor-area { padding: 16px; }
  .drawer-footer {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    flex-wrap: wrap;
    gap: 6px;
  }
  .footer-actions-left, .footer-actions-right { gap: 6px; }
  .btn { padding: 10px 12px; font-size: 13px; }
  .btn span { display: inline; }

  .hint-bar { display: none; }

  /* FAB smaller + icon-only on mobile */
  .fab {
    bottom: 18px;
    right: 18px;
    padding: 0;
    width: 56px;
    height: 56px;
    justify-content: center;
  }
  .fab-label { display: none; }

  /* Modal fullscreen-ish on mobile */
  .modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    top: 0; left: 0;
    transform: none;
    border-radius: 0;
    animation: slide-up .25s cubic-bezier(0.22, 0.8, 0.3, 1);
  }
  .modal-header { padding: 16px; }
  .modal-title { font-size: 20px; }
  .modal-body { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-footer {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .card-grid.grid-grid,
  .card-grid.grid-tile { grid-template-columns: 1fr !important; }
  .btn { padding: 10px; font-size: 12.5px; }
  .btn svg { width: 14px; height: 14px; }
}


/* ========== PROMINENT PATIENT FIELD ========== */
.paciente-prominent {
  background: linear-gradient(135deg, hsl(var(--accent-h) 70% 96%), hsl(var(--accent-h) 70% 92%));
  border: 1.5px solid hsl(var(--accent-h) 50% 80%);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.paciente-label-big {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: hsl(var(--accent-h) 60% 35%);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.paciente-input-big {
  width: 100%;
  background: white;
  border: 1.5px solid hsl(var(--accent-h) 50% 75%);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.paciente-input-big:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px hsl(var(--accent-h) 70% 85% / 0.5);
}
.paciente-input-big::placeholder {
  color: var(--muted);
  font-weight: 400;
}

/* ========== ATESTADO BUTTON IN HEADER ========== */
.btn-atestado {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: white;
  border: 1.5px solid hsl(var(--accent-h) 60% 80%);
  border-radius: 10px;
  color: hsl(var(--accent-h) 60% 35%);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-atestado:hover {
  background: hsl(var(--accent-h) 70% 96%);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* ========== ATESTADO FIELDS ROW ========== */
.atest-fields-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.atest-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.atest-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-input-lg {
  padding: 10px 12px !important;
  font-size: 15px !important;
  font-weight: 500 !important;
}

/* ========== ATESTADO PREVIEW ========== */
.preview-atestado {
  font-family: Georgia, 'Times New Roman', serif;
  text-align: justify;
  line-height: 1.7;
  padding: 18px 22px !important;
}
.preview-atestado p {
  margin: 0 0 8px;
}
.atest-preview-title {
  text-align: center;
  font-size: 1.05em;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0 0 14px;
}

/* ========== ATESTADO BUTTON DESKTOP/MOBILE ========== */
.desktop-only { display: inline-flex; }
@media (max-width: 720px) {
  .desktop-only { display: none; }
}


/* ========== NEW LIST CARD LAYOUT ========== */
.cards-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card.card-list {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .12s, background .15s;
  position: relative;
  width: 100%;
  font-family: inherit;
  outline: none;
}
.card.card-list:hover {
  border-color: hsl(var(--accent-h) 50% 70%);
  box-shadow: 0 4px 14px rgba(15, 22, 40, 0.06);
  transform: translateY(-1px);
}
.card.card-list:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px hsl(var(--accent-h) 70% 85% / 0.5);
}

/* favorite emphasis — golden border on left */
.card.card-list.card-fav {
  background: linear-gradient(90deg, #fffbed 0%, white 70%);
  border-color: #f3d273;
}
.card.card-list.card-fav:hover {
  border-color: #e8b004;
  box-shadow: 0 4px 14px rgba(232, 176, 4, 0.18);
}
.card.card-list.card-fav::before {
  content: "";
  position: absolute;
  left: -1.5px;
  top: -1.5px; bottom: -1.5px;
  width: 4px;
  background: linear-gradient(180deg, #f5c84b, #e8b004);
  border-top-left-radius: 12px;
  border-bottom-left-radius: 12px;
}

/* star button — left side, prominent */
.card.card-list .card-star {
  position: static;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 1;
  transition: all .15s;
}
.card.card-list .card-star:hover {
  background: #fff7dd;
  color: #e8b004;
  transform: scale(1.08);
}
.card.card-list .card-star.on {
  background: linear-gradient(135deg, #fff0b8, #ffe184);
  color: #c89500;
  box-shadow: 0 2px 6px rgba(232, 176, 4, 0.25);
}
.card.card-list .card-star.on svg {
  fill: #e8b004;
  stroke: #c89500;
  filter: drop-shadow(0 1px 1px rgba(200, 149, 0, 0.4));
}

.card.card-list .card-body {
  flex: 1;
  min-width: 0;
}
.card.card-list .card-name {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card.card-list .card-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.card.card-list .card-cid {
  font-family: 'SF Mono', ui-monospace, monospace;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.card-cat-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* edit + delete actions on the right */
.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.card-action {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.card-action:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-muted);
}
.card-action-delete:hover {
  background: #ffe5e0;
  color: #d04c2c;
  border-color: #f5a896;
}

/* hide old grid + tile variants — list is now the only one */
.card-grid { display: none; }

/* ========== HERO SEARCH ========== */
.hero-search {
  position: relative;
  margin: 0 0 22px;
  animation: heroSlideIn 0.5s cubic-bezier(0.22, 0.8, 0.3, 1);
}
@keyframes heroSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.hero-search-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, white 0%, hsl(var(--accent-h) 60% 99%) 100%);
  border: 2px solid hsl(var(--accent-h) 50% 82%);
  border-radius: 16px;
  padding: 6px 18px 6px 22px;
  height: 64px;
  box-shadow:
    0 1px 3px rgba(15, 22, 40, 0.04),
    0 8px 24px hsl(var(--accent-h) 60% 50% / 0.08);
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
.hero-search-inner:hover {
  transform: translateY(-1px);
  box-shadow:
    0 2px 6px rgba(15, 22, 40, 0.06),
    0 12px 32px hsl(var(--accent-h) 60% 50% / 0.12);
}
.hero-search-inner:focus-within {
  border-color: var(--accent);
  background: white;
  box-shadow:
    0 0 0 4px hsl(var(--accent-h) 70% 85% / 0.4),
    0 8px 24px hsl(var(--accent-h) 60% 50% / 0.15);
}

.hero-search-icon-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--accent);
}
.hero-search-icon {
  position: relative;
  z-index: 2;
  animation: heroIconBob 3.5s ease-in-out infinite;
}
@keyframes heroIconBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}
.hero-search-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: hsl(var(--accent-h) 70% 70% / 0.35);
  animation: heroPulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  z-index: 1;
}
@keyframes heroPulse {
  0% { transform: scale(0.6); opacity: 0.7; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}
.hero-search-inner:focus-within .hero-search-pulse {
  animation-play-state: paused;
  opacity: 0;
}

.hero-search-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  min-width: 0;
  padding: 0;
  position: relative;
  z-index: 2;
}

.hero-search-placeholder {
  position: absolute;
  left: 76px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 18px;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}
.hp-static { color: var(--text-muted); }
.hp-rotator {
  position: relative;
  display: inline-block;
  height: 1.4em;
  overflow: hidden;
  vertical-align: bottom;
  min-width: 180px;
}
.hp-word {
  display: block;
  height: 1.4em;
  line-height: 1.4em;
  color: hsl(var(--accent-h) 60% 45%);
  font-weight: 600;
  animation: hpRotate 9s steps(1, end) infinite;
}
.hp-word:nth-child(1) { animation-delay: 0s; }
.hp-word:nth-child(2) { animation-delay: -6.75s; }
.hp-word:nth-child(3) { animation-delay: -4.5s; }
.hp-word:nth-child(4) { animation-delay: -2.25s; }
@keyframes hpRotate {
  0%, 22% { transform: translateY(0); opacity: 1; }
  25%, 100% { transform: translateY(-100%); opacity: 0; }
}
.hp-rotator .hp-word { position: absolute; top: 0; left: 0; }
.hp-rotator .hp-word:nth-child(1) { animation: hpShow1 9s ease-in-out infinite; }
.hp-rotator .hp-word:nth-child(2) { animation: hpShow2 9s ease-in-out infinite; }
.hp-rotator .hp-word:nth-child(3) { animation: hpShow3 9s ease-in-out infinite; }
.hp-rotator .hp-word:nth-child(4) { animation: hpShow4 9s ease-in-out infinite; }
@keyframes hpShow1 {
  0%, 20% { transform: translateY(0); opacity: 1; }
  25%, 95% { transform: translateY(-100%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes hpShow2 {
  0%, 20% { transform: translateY(100%); opacity: 0; }
  25%, 45% { transform: translateY(0); opacity: 1; }
  50%, 100% { transform: translateY(-100%); opacity: 0; }
}
@keyframes hpShow3 {
  0%, 45% { transform: translateY(100%); opacity: 0; }
  50%, 70% { transform: translateY(0); opacity: 1; }
  75%, 100% { transform: translateY(-100%); opacity: 0; }
}
@keyframes hpShow4 {
  0%, 70% { transform: translateY(100%); opacity: 0; }
  75%, 95% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-100%); opacity: 0; }
}

.hero-search-clear {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.hero-search-clear:hover {
  background: #ffe5e0;
  color: #d04c2c;
}

.hero-search-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 22px;
}
.kbd-hero {
  background: white;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  font-size: 11px;
  padding: 2px 7px;
}

/* ========== HEADER MINI SEARCH (replaces big one) ========== */
.header-search-mini {
  max-width: 320px !important;
}
.header-search-mini .search-input {
  font-size: 13px;
  padding: 9px 14px 9px 36px;
}

/* ========== SECTION FAV HINT ========== */
.sec-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sec-fav-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 4px 10px;
  background: #fff7dd;
  border: 1px solid #f3d273;
  border-radius: 100px;
  color: #8c6800;
  font-size: 11px;
  font-weight: 600;
}
.sec-fav-hint svg { color: #e8b004; fill: #e8b004; }

/* ========== MOBILE OVERRIDES (new card-list) ========== */
@media (max-width: 720px) {
  .card.card-list {
    padding: 12px 14px;
    gap: 10px;
    flex-direction: row !important;
  }
  .card.card-list .card-star {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }
  .card.card-list .card-name {
    font-size: 13px;
    white-space: normal;
    line-height: 1.25;
  }
  .card.card-list .card-sub {
    gap: 6px;
    font-size: 10.5px;
    flex-wrap: wrap;
  }
  .card-actions { gap: 4px; }
  .card-action {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }
  .card-action svg { width: 14px; height: 14px; }
  .cards-stack { gap: 6px; }

  /* hero search adjusts on mobile */
  .hero-search-inner {
    height: 56px;
    padding: 6px 12px 6px 16px;
    gap: 10px;
  }
  .hero-search-icon-wrap { width: 32px; height: 32px; }
  .hero-search-input,
  .hero-search-placeholder { font-size: 16px; }
  .hero-search-placeholder { left: 60px; }
  .hero-search-hint { font-size: 11px; padding-left: 16px; }

  .header-search-mini { display: none !important; }
  .sec-fav-hint { font-size: 10.5px; padding: 3px 8px; }
}
@media (max-width: 380px) {
  .card.card-list .card-name { font-size: 12.5px; }
  .hero-search-inner { height: 52px; }
  .hero-search-input, .hero-search-placeholder { font-size: 15px; }
}

/* ========== STICKY HERO SEARCH ========== */
.hero-search-sticky {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0 -28px 22px;
  padding: 14px 28px 14px;
  background: var(--bg);
  transition: box-shadow .2s, background .2s;
}
.hero-search-sticky::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -10px;
  height: 10px;
  background: linear-gradient(to bottom, hsl(220 20% 96% / 0.6), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.hero-search-sticky.is-stuck {
  box-shadow: 0 4px 14px hsl(220 30% 30% / 0.06);
  background: var(--bg);
}
.hero-search-sticky.is-stuck::after { opacity: 1; }
.hero-search-sticky .hero-search { margin: 0; }

/* Inline kbd inside hero search */
.kbd-inline {
  margin-right: 12px;
  flex-shrink: 0;
  background: white;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  box-shadow: 0 1px 0 hsl(220 15% 88%);
  letter-spacing: 0.02em;
}

/* ========== FAB STACK (Atestado + Nova Prescrição) ========== */
.fab-stack {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 90;
  align-items: flex-end;
}
.fab-stack .fab {
  position: static;
  bottom: auto;
  right: auto;
}
.fab-atestado {
  background: white !important;
  color: var(--accent) !important;
  border: 1.5px solid var(--accent);
  box-shadow: 0 6px 16px hsl(220 15% 30% / 0.12), 0 2px 6px hsl(220 15% 30% / 0.08) !important;
  padding: 14px 22px !important;
  font-size: 14px !important;
}
.fab-atestado:hover {
  background: hsl(var(--accent-h) 70% 96%) !important;
  border-color: var(--accent-hover);
  color: var(--accent-hover) !important;
  box-shadow: 0 10px 24px hsl(var(--accent-h) 65% 35% / 0.2) !important;
}

/* Hide the now-removed header atestado button + bell + mobile-search */
.btn-atestado, .header-icon, .mobile-search-bar, .header-search-mini { display: none !important; }

@media (max-width: 720px) {
  .hero-search-sticky {
    margin: 0 -16px 14px;
    padding: 10px 16px 8px;
  }
  .fab-stack {
    bottom: 18px;
    right: 18px;
    gap: 10px;
  }
  .fab-stack .fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0 !important;
    justify-content: center;
  }
  .fab-stack .fab-label { display: none; }
  .fab-atestado { font-size: 0 !important; }
}

/* Wider doctor area on desktop so name fits */
@media (min-width: 1100px) {
  .doctor-wide .doctor-info { max-width: 360px; }
  .doctor-wide .doctor-name { font-size: 14.5px; }
}


/* ========== 2-COLUMN LAYOUT ========== */
.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
.col {
  min-width: 0;
}
.col-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px dashed var(--border);
}
.col-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.col-dot-blue { background: hsl(var(--accent-h) 60% 55%); box-shadow: 0 0 0 3px hsl(var(--accent-h) 60% 88%); }
.col-dot-red { background: #d04c2c; box-shadow: 0 0 0 3px #ffd9d0; }

/* ========== CONDUTAS COLUMN — all red ========== */
.col-condutas .card.card-list:hover {
  border-color: #f3a896;
  box-shadow: 0 4px 14px rgba(208, 76, 44, 0.10);
}
.col-condutas .card.card-list:focus-visible {
  border-color: #d04c2c;
  box-shadow: 0 0 0 3px #ffd9d0;
}
.col-condutas .card.card-list .card-cat-tag {
  background: #fef2f2;
  color: #b91c1c;
}
.col-condutas .sec-title { color: #c0392b; }

@media (max-width: 900px) {
  .cols-2 { grid-template-columns: 1fr; gap: 18px; }
}


/* ========== HISTORY RAIL (vertical button on right edge) ========== */
.history-rail {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 12px 0 0 12px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  z-index: 95;
  box-shadow: -4px 0 12px hsl(220 25% 30% / 0.06);
  transition: all .2s;
  font-family: inherit;
}
.history-rail:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding-right: 14px;
}
.history-rail.is-open {
  right: 360px;
}
.history-rail-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.history-rail:hover .history-rail-text { color: var(--accent-hover); }
.history-rail-badge {
  background: var(--accent);
  color: white;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

/* ========== HISTORY DRAWER ========== */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 40, 0.18);
  z-index: 96;
  animation: fade-in .2s ease;
}
.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  background: var(--surface);
  z-index: 97;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 30px hsl(220 25% 30% / 0.12);
  animation: hist-slide .25s cubic-bezier(0.22, 0.8, 0.3, 1);
}
@keyframes hist-slide {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.history-eyebrow {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.history-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  margin: 2px 0 0;
}
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}
.history-empty p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.history-empty span { font-size: 12.5px; line-height: 1.4; }

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 10px;
  background: var(--surface);
  transition: border-color .15s, transform .15s;
}
.history-item:hover { border-color: var(--accent); }
.history-prescricao { border-left: 3px solid var(--accent); }
.history-atestado { border-left: 3px solid #d97706; }

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.history-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
}
.tag-prescricao {
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.tag-atestado {
  background: #fef3e7;
  color: #b45309;
}
.tag-conduta {
  background: #fef2f2;
  color: #b91c1c;
}
.history-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.history-paciente {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-paciente em {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 500;
}
.history-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.35;
}
.history-actions {
  display: flex;
  gap: 6px;
}
.history-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}
.history-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}
.history-btn-print {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  flex: 1;
  justify-content: center;
}
.history-btn-print:hover {
  background: var(--accent-hover);
  color: white;
}
.history-btn-del {
  width: 32px;
  padding: 0;
  justify-content: center;
}
.history-btn-del:hover {
  background: #ffece8;
  color: #c33b1f;
  border-color: #f3c0b8;
}
.history-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border-soft);
}

@media (max-width: 720px) {
  .history-drawer { width: 100vw; }
  .history-rail.is-open { right: calc(100vw - 50px); }
  .history-rail { padding: 14px 8px; }
  .history-rail-text { font-size: 11px; }
}
