/* Farmacología — Nuevo Tratamiento */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border: #e2e5ea;
  --border-strong: #cdd2d9;
  --text: #1d2024;
  --text-muted: #6b7178;
  --text-faint: #9aa0a8;
  --accent: #2f6feb;
  --accent-soft: #e8efff;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b42318;
  --danger-soft: #fef0ef;
  --ok: #15803d;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.18);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
  padding: 0;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* App shell */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.search {
  flex: 0 0 320px;
  position: relative;
}
.search input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 36px 0 14px;
  background: var(--surface);
  color: var(--text);
}
.search input::placeholder { color: var(--text-faint); }
.search .search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
}
.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-2); }
.search-result-item .sr-title { color: var(--text); }
.search-result-item .sr-section { color: var(--text-muted); font-size: 11px; }
.search-result-item mark {
  background: #fff3a8;
  color: var(--text);
  padding: 0 1px;
  border-radius: 2px;
}
.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.topbar-spacer { flex: 1; }

.bell-btn {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  position: relative;
  color: var(--text);
  transition: background 0.15s;
}
.bell-btn:hover { background: var(--surface-3); }
.bell-btn .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 4px 12px;
  border-radius: 6px;
  cursor: not-allowed;
}
.profile-name {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}
.profile-name strong {
  font-weight: 600;
  font-size: 13px;
}
.profile-name span {
  color: var(--text-muted);
  font-size: 12px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #cdd2d9, #9aa0a8);
  display: grid;
  place-items: center;
  color: white;
  font-size: 13px;
  font-weight: 600;
}

/* Main layout */
.workspace {
  padding: 20px 28px 32px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* Patient bar */
.patient-bar {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  user-select: none;
}
.patient-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.patient-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.patient-vitals {
  display: flex;
  gap: 22px;
  color: var(--text-muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.patient-vitals span strong {
  color: var(--text);
  font-weight: 500;
}
.patient-warn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--warn);
  font-weight: 500;
}

/* Content grid: main + side */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.main-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px 18px;
  min-height: 560px;
  display: flex;
  flex-direction: column;
}

.main-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 18px;
  color: var(--text);
}

/* Stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.step {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-faint);
  background: transparent;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s;
}
.step.is-active {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
  font-weight: 500;
}
.step.is-done {
  color: var(--text-muted);
}
.step-divider {
  width: 16px;
  height: 1px;
  background: var(--border-strong);
}

/* Step body */
.step-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Med table (Step 1 & 2) */
.med-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.med-table-head {
  display: grid;
  grid-template-columns: 56px 100px 1fr 90px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
}
.med-table-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
}
.med-table-search input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 36px 0 12px;
  background: var(--surface);
}
.med-table-search .search-icon {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.med-list {
  overflow-y: auto;
  max-height: 360px;
  flex: 1;
}
.med-row {
  display: grid;
  grid-template-columns: 56px 100px 1fr 90px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.12s;
}
.med-row:last-child { border-bottom: none; }
.med-row:hover { background: var(--surface-2); }
.med-row.is-selected { background: var(--accent-soft); }
.med-row mark {
  background: #fff3a8;
  color: var(--text);
  padding: 0 1px;
  border-radius: 2px;
}
.add-btn {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  border: 1px solid var(--accent);
  color: var(--accent);
  display: grid;
  place-items: center;
  background: var(--surface);
  font-size: 16px;
  line-height: 1;
  transition: all 0.15s;
}
.add-btn:hover { background: var(--accent-soft); }
.add-btn.is-added {
  background: var(--accent);
  color: white;
}
.med-code {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.med-name { color: var(--text); }
.med-meta { color: var(--text-faint); font-size: 12px; text-align: right; }

.selection-count {
  font-size: 12px;
  color: var(--text-muted);
  margin: 10px 4px 0;
}

.empty-list {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Step 3 */
.dose-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
}
.dose-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.dose-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
}
.dose-head:hover { background: var(--surface-3); }
.status-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 4px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}
.status-pill.is-incomplete {
  background: #fff;
  color: var(--text-muted);
}
.status-pill.is-complete {
  background: #e6f4ec;
  color: var(--ok);
  border-color: #b8dec8;
}
.dose-title {
  flex: 1;
  font-size: 13px;
  color: var(--text);
}
.chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
}
.dose-card.is-open .chevron { transform: rotate(180deg); }

.dose-body {
  padding: 18px 16px 16px;
  display: grid;
  gap: 16px;
}
.field-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.field-row.r2 {
  grid-template-columns: 2fr 1fr 1fr 1fr;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.field input, .field select {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  background: var(--surface);
}
.field input::placeholder { color: var(--text-faint); }

.day-toggles {
  display: flex;
  gap: 4px;
}
.day-toggle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: all 0.12s;
}
.day-toggle.is-on {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

.binary-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
  height: 30px;
}
.binary-toggle button {
  padding: 0 14px;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
}
.binary-toggle button.is-on {
  background: var(--text);
  color: white;
}

.dose-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}
.btn-save {
  height: 32px;
  padding: 0 16px;
  background: var(--text);
  color: white;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 500;
}
.btn-save:hover { background: #000; }

/* Step 4 — review */
.review-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
}
.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
}
.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.review-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
}
.review-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px 18px;
}
.review-cell label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.review-cell .v {
  font-size: 13px;
  color: var(--text);
}
.review-cell .v.empty {
  color: var(--text-faint);
  font-style: italic;
}
.review-pauta {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.review-pauta span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  background: var(--surface-3);
  color: var(--text-faint);
}
.review-pauta span.is-on {
  background: var(--text);
  color: white;
}

.review-summary {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.review-summary .label {
  font-size: 12px;
  color: var(--text-muted);
}
.review-summary .value {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

/* Footer actions */
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  gap: 10px;
}
.actions-right { display: flex; gap: 10px; }
.btn {
  height: 38px;
  padding: 0 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.12s;
  border: 1px solid transparent;
}
.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--text);
  color: white;
}
.btn-primary:hover { background: #000; }
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--text);
}
.btn-ghost {
  background: var(--surface-3);
  color: var(--text);
}
.btn-ghost:hover { background: var(--border); }

/* Side column */
.side-col {
  display: grid;
  gap: 16px;
}
.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
}
.side-card h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.side-card h3 .count {
  color: var(--text-muted);
  font-weight: 500;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}
.alert-item {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 12.5px;
  border-left: 3px solid var(--border-strong);
}
.alert-item.sev-high { border-left-color: var(--danger); }
.alert-item.sev-med { border-left-color: var(--warn); }
.alert-item.sev-low { border-left-color: var(--accent); }
.alert-item strong {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}
.alert-item p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.45;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.history-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.history-item .h-info strong {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 3px;
}
.history-item .h-info span {
  font-size: 12px;
  color: var(--text-muted);
}
.history-item .h-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 2px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: grid;
  place-items: center;
  z-index: 100;
  animation: fadeIn 0.18s ease;
  padding: 20px;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}
.modal-close:hover { background: var(--surface-3); }
.modal-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
}

.notif-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
}
.notif-item:last-child { border-bottom: none; }
.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
}
.notif-dot.read { background: var(--border-strong); }
.notif-content { flex: 1; }
.notif-content .nt {
  font-size: 13px;
  font-weight: 500;
  margin: 0 0 3px;
}
.notif-content .nm {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 4px;
  line-height: 1.45;
}
.notif-content .nd {
  font-size: 11.5px;
  color: var(--text-faint);
}

.history-detail-section {
  margin-bottom: 16px;
}
.history-detail-section:last-child { margin-bottom: 0; }
.history-detail-section h4 {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.history-detail-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 18px;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 12px 14px;
}
.history-detail-meta div span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.history-detail-meta div strong {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.med-row-h {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12.5px;
}
.med-row-h .mh-name { font-weight: 500; }
.med-row-h .mh-pauta { color: var(--text-muted); margin-top: 2px; font-size: 12px; }

/* Tweaks panel */
.tweaks {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  font-size: 12px;
}
.tweaks-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
}
.tweaks-body {
  padding: 12px 14px;
  display: grid;
  gap: 14px;
}
.tweak-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tweak-row label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tweak-options {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tweak-options button {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11.5px;
  background: var(--surface);
}
.tweak-options button.is-on {
  background: var(--text);
  color: white;
  border-color: var(--text);
}
.swatch-row {
  display: flex;
  gap: 6px;
}
.swatch-row button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
}
.swatch-row button.is-on {
  border-color: var(--text);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: #b1b6bd; }
