﻿:root {
  /* Apple HIG System Surfaces & Backgrounds */
  --bg-body: #f5f5f7;
  --bg-card: #ffffff;
  --bg-subtle: #f9f9fb;
  --bg-grouped-secondary: #f2f2f7;
  --bg-glass: rgba(255, 255, 255, 0.78);
  --bg-glass-heavy: rgba(255, 255, 255, 0.9);

  /* Apple Typography Colors */
  --text-main: #1d1d1f;
  --text-secondary: #515154;
  --text-muted: #86868b;

  /* Hairlines & Borders */
  --border-color: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.14);
  --hairline: 1px solid rgba(0, 0, 0, 0.065);

  /* CTI Theme — Apple System Pink / Red (Critical Care) */
  --cti-primary: #e11d48;
  --cti-primary-hover: #be123c;
  --cti-primary-light: rgba(225, 29, 72, 0.09);
  --cti-primary-border: rgba(225, 29, 72, 0.2);
  --cti-surface-tint: #fff8f9;

  /* Internação Theme — Apple System Blue / Teal (Clinical Care) */
  --ward-primary: #0071e3;
  --ward-primary-hover: #0077ed;
  --ward-primary-light: rgba(0, 113, 227, 0.09);
  --ward-primary-border: rgba(0, 113, 227, 0.2);
  --ward-surface-tint: #f5faff;

  /* Active Dynamic Theme Tokens */
  --accent-active: var(--cti-primary);
  --accent-hover: var(--cti-primary-hover);
  --accent-light: var(--cti-primary-light);
  --accent-border: var(--cti-primary-border);
  --accent-surface: var(--cti-surface-tint);

  /* Apple Semantic Colors */
  --success: #1d8348;
  --success-dot: #34c759;
  --success-bg: rgba(52, 199, 89, 0.12);

  --warning: #b25000;
  --warning-dot: #ff9500;
  --warning-bg: rgba(255, 149, 0, 0.14);

  --danger: #d70015;
  --danger-dot: #ff3b30;
  --danger-bg: rgba(255, 59, 48, 0.12);

  --info: #0066cc;
  --info-dot: #007aff;
  --info-bg: rgba(0, 122, 255, 0.1);

  --indigo: #5856d6;
  --indigo-bg: rgba(88, 86, 214, 0.1);

  /* Apple Continuous Corner Radii */
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --radius-pill: 980px;

  /* Apple Elevation Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.04), 0 0 1px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 44px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);

  --ease-apple: cubic-bezier(0.25, 1, 0.5, 1);
}

body.theme-internacao {
  --accent-active: var(--ward-primary);
  --accent-hover: var(--ward-primary-hover);
  --accent-light: var(--ward-primary-light);
  --accent-border: var(--ward-primary-border);
  --accent-surface: var(--ward-surface-tint);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.47059;
  font-weight: 400;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: 4rem;
  transition: background-color 0.3s var(--ease-apple);
}

/* Tabular numerals for clinical precision */
.leito-badge,
.patient-age,
.admission-pill,
.dih-badge,
.kpi-value,
.lab-date-cell,
.metric-pill {
  font-variant-numeric: tabular-nums;
}

/* ================= APPLE TRANSLUCENT TOP NAVIGATION BAR ================= */
.app-header {
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding: 0.85rem 1.75rem;
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-top {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent-active), #1d1d1f);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
  transition: background 0.3s var(--ease-apple);
}

.brand-title h1 {
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 1px;
}

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

/* ================= SEGMENTED DASHBOARD SWITCHER ================= */
.dashboard-nav-container {
  max-width: 1380px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
}

.dashboard-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  background: rgba(118, 118, 128, 0.1);
  padding: 6px;
  border-radius: var(--radius-xl);
  margin-bottom: 1.35rem;
}

.dashboard-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--radius-xl) - 4px);
  padding: 0.95rem 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.25s var(--ease-apple);
  text-align: left;
  color: var(--text-secondary);
}

.dashboard-tab:hover {
  background: rgba(255, 255, 255, 0.45);
}

.dashboard-tab.active-cti,
.dashboard-tab.active-internacao {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.tab-info {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.tab-badge-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: transform 0.25s var(--ease-apple);
}

.dashboard-tab.active-cti .tab-badge-icon,
.dashboard-tab.active-internacao .tab-badge-icon {
  transform: scale(1.03);
}

.tab-cti .tab-badge-icon {
  background: var(--cti-primary-light);
  color: var(--cti-primary);
}

.tab-internacao .tab-badge-icon {
  background: var(--ward-primary-light);
  color: var(--ward-primary);
}

.tab-text h2 {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.018em;
  color: var(--text-main);
}

.tab-text p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.tab-metrics {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.metric-pill {
  background: var(--bg-grouped-secondary);
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dashboard-tab.active-cti .metric-pill {
  background: var(--cti-primary-light);
  color: var(--cti-primary);
}

.dashboard-tab.active-internacao .metric-pill {
  background: var(--ward-primary-light);
  color: var(--ward-primary);
}

.metric-pill strong {
  font-size: 0.88rem;
  font-weight: 600;
}

/* ================= APPLE HEALTH STYLE KPI CARDS ================= */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: transform 0.2s var(--ease-apple), box-shadow 0.2s var(--ease-apple);
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.kpi-label {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: -0.005em;
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  margin-top: 0.1rem;
}

.kpi-sub {
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text-muted);
}

/* ================= SPOTLIGHT SEARCH & FILTER TOOLBAR ================= */
.toolbar {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.search-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 260px;
}

.search-input {
  width: 100%;
  max-width: 420px;
  padding: 0.52rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-grouped-secondary);
  font-size: 0.86rem;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s var(--ease-apple);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  background: #ffffff;
  border-color: var(--accent-active);
  box-shadow: 0 0 0 3.5px var(--accent-light);
}

.filter-select {
  padding: 0.5rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  background: var(--bg-grouped-secondary);
  color: var(--text-main);
  cursor: pointer;
  outline: none;
  transition: all 0.2s var(--ease-apple);
}

.filter-select:hover {
  background: rgba(118, 118, 128, 0.16);
}

.filter-select:focus {
  background: #ffffff;
  border-color: var(--accent-active);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.view-mode-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

/* ================= APPLE PILL & SYSTEM BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius-pill);
  font-size: 0.83rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s var(--ease-apple);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-active);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-grouped-secondary);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(118, 118, 128, 0.18);
}

.btn-dark-outline {
  background: rgba(118, 118, 128, 0.1);
  color: var(--text-main);
  border-color: transparent;
}

.btn-dark-outline:hover {
  background: rgba(118, 118, 128, 0.18);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  padding: 0.32rem 0.6rem;
}

.btn-danger-ghost:hover {
  background: var(--danger-bg);
}

.btn-sm {
  padding: 0.34rem 0.75rem;
  font-size: 0.77rem;
}

/* ================= MAIN CONTAINER & SECTOR HEADER ================= */
.main-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.sector-banner {
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.35rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--accent-active);
}

.sector-banner.banner-cti {
  border-left-color: var(--cti-primary);
}

.sector-banner.banner-internacao {
  border-left-color: var(--ward-primary);
}

.sector-banner-title {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.sector-banner-title h3 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.018em;
  color: var(--text-main);
}

.sector-fields-legend {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-grouped-secondary);
  padding: 0.32rem 0.8rem;
  border-radius: var(--radius-pill);
}

/* ================= APPLE INSET GROUPED PATIENT CARDS ================= */
.patients-list {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.patient-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.25s var(--ease-apple), transform 0.25s var(--ease-apple);
}

.patient-card:hover {
  box-shadow: var(--shadow-md);
}

/* Patient Card Header */
.patient-header {
  background: var(--bg-card);
  border-bottom: var(--hairline);
  padding: 1.05rem 1.4rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
}

.patient-identity {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.leito-badge {
  background: var(--accent-light);
  color: var(--accent-active);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.32rem 0.8rem;
  border-radius: var(--radius-pill);
  letter-spacing: -0.01em;
  min-width: 72px;
  text-align: center;
}

.patient-name {
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--text-main);
}

.patient-age {
  font-size: 0.83rem;
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--bg-grouped-secondary);
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-pill);
}

.patient-admission-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.admission-pill {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: var(--hairline);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
}

.dih-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-pill);
  background: var(--info-bg);
  color: var(--info);
}

.dih-badge.dih-long {
  background: var(--warning-bg);
  color: var(--warning);
}

.dih-badge.dih-critical {
  background: var(--danger-bg);
  color: var(--danger);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Patient Card Grid Body */
.patient-body {
  padding: 1.25rem 1.4rem 1.4rem;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.9rem;
}

.field-box {
  background: var(--bg-subtle);
  border: var(--hairline);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-box.col-12 { grid-column: span 12; }
.field-box.col-8 { grid-column: span 8; }
.field-box.col-6 { grid-column: span 6; }
.field-box.col-4 { grid-column: span 4; }
.field-box.col-3 { grid-column: span 3; }

/* Subtle Apple Tinted Surface Cards */
.field-box.highlight-trs {
  background: #fff8f9;
  border-color: rgba(225, 29, 72, 0.14);
}

.field-box.highlight-ward {
  background: #f5faff;
  border-color: rgba(0, 113, 227, 0.14);
}

.field-box.highlight-pendencia {
  background: #fffcf5;
  border-color: rgba(255, 149, 0, 0.2);
}

.field-box.highlight-objetivo {
  background: #f6f9ff;
  border-color: rgba(0, 122, 255, 0.15);
}

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.field-box.highlight-trs .field-label { color: var(--cti-primary); }
.field-box.highlight-ward .field-label { color: var(--ward-primary); }
.field-box.highlight-pendencia .field-label { color: var(--warning); }
.field-box.highlight-objetivo .field-label { color: var(--info); }

.field-content {
  font-size: 0.9rem;
  line-height: 1.52;
  color: var(--text-main);
  white-space: pre-line;
}

.field-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
}

/* Badges inside fields */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.atb-tag {
  background: var(--indigo-bg);
  color: var(--indigo);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.24rem 0.7rem;
  border-radius: var(--radius-pill);
}

.trs-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-pill);
  width: fit-content;
  text-transform: none;
  letter-spacing: 0;
}

.trs-active {
  background: var(--cti-primary-light);
  color: var(--cti-primary);
}

.trs-inactive {
  background: var(--bg-grouped-secondary);
  color: var(--text-secondary);
}

/* ================= APPLE NUMBERS STYLE LAB EVOLUTION TABLE ================= */
.lab-section {
  grid-column: span 12;
  background: var(--bg-card);
  border: var(--hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 0.15rem;
}

.lab-header {
  background: var(--bg-subtle);
  padding: 0.7rem 1.05rem;
  border-bottom: var(--hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.lab-header-title {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.lab-table-wrapper {
  overflow-x: auto;
}

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

.lab-table th,
.lab-table td {
  padding: 0.6rem 1.05rem;
  border-bottom: var(--hairline);
  text-align: left;
}

.lab-table th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lab-table tr:last-child td {
  border-bottom: none;
}

.lab-table tr:hover td {
  background: var(--bg-subtle);
}

.lab-date-cell {
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  width: 145px;
}

.lab-biomarker-cell {
  font-weight: 500;
  color: var(--text-main);
}

.lab-trend-up {
  color: var(--danger);
  font-weight: 600;
}

.lab-trend-down {
  color: var(--info);
  font-weight: 600;
}

.lab-trend-normal {
  color: var(--success);
  font-weight: 500;
}

/* ================= COMPACT SUMMARY TABLE VIEW ================= */
.summary-table-container {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.summary-table th,
.summary-table td {
  padding: 0.85rem 1rem;
  border-bottom: var(--hairline);
  vertical-align: top;
  text-align: left;
}

.summary-table th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-table tr:last-child td {
  border-bottom: none;
}

/* ================= APPLE SHEET MODALS & MAXIMIZED EDITOR ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
  animation: appleFadeIn 0.22s var(--ease-apple);
}

@keyframes appleFadeIn {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

/* Maximized full-screen layout for Patient Edit / Create Modal */
#patient-modal.modal-backdrop {
  padding: 0;
  background: var(--bg-body);
}

#patient-modal .modal-dialog {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg-body);
}

#patient-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#patient-modal .modal-header {
  background: var(--bg-glass-heavy);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  color: var(--text-main);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  padding: 1rem 2.5rem;
}

#patient-modal .modal-close {
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-grouped-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background 0.15s;
}

#patient-modal .modal-close:hover {
  background: rgba(118, 118, 128, 0.22);
}

#patient-modal .modal-body {
  flex: 1;
  padding: 1.75rem 2.5rem;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
}

#patient-modal .form-grid {
  background: var(--bg-card);
  padding: 1.25rem 1.4rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

#patient-modal textarea.form-control {
  min-height: 115px;
}

.modal-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 1.1rem 1.5rem;
  background: var(--bg-card);
  color: var(--text-main);
  border-bottom: var(--hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.018em;
}

.modal-close {
  background: var(--bg-grouped-secondary);
  border: none;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

.form-group.col-12 { grid-column: span 12; }
.form-group.col-8 { grid-column: span 8; }
.form-group.col-6 { grid-column: span 6; }
.form-group.col-5 { grid-column: span 5; }
.form-group.col-4 { grid-column: span 4; }
.form-group.col-3 { grid-column: span 3; }

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.008em;
}

.form-control {
  padding: 0.6rem 0.85rem;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-main);
  background: var(--bg-subtle);
  transition: all 0.18s var(--ease-apple);
}

.form-control:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent-active);
  box-shadow: 0 0 0 3.5px var(--accent-light);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.calculated-days-preview {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--info);
  margin-top: 0.15rem;
}

.section-divider {
  padding-top: 0.4rem;
}

.section-divider-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  padding: 0 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#modal-lab-list {
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.lab-editor-row {
  display: grid;
  grid-template-columns: 165px 1fr 170px auto;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.lab-editor-row:last-child {
  margin-bottom: 0;
}

.modal-footer {
  padding: 1rem 2.5rem;
  background: var(--bg-glass-heavy);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .dashboard-tabs {
    grid-template-columns: 1fr;
  }
  .field-box.col-8,
  .field-box.col-6,
  .field-box.col-4,
  .field-box.col-3,
  .form-group.col-8,
  .form-group.col-6,
  .form-group.col-5,
  .form-group.col-4,
  .form-group.col-3 {
    grid-column: span 12;
  }
  .lab-editor-row {
    grid-template-columns: 1fr;
    border-bottom: var(--hairline);
    padding-bottom: 0.75rem;
  }
  #patient-modal .modal-header,
  #patient-modal .modal-body,
  .modal-footer {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }
}

/* Print Layout (Passômetro / Passagem de Plantão) */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    font-size: 9.5pt;
  }

  .no-print,
  .app-header .header-actions,
  .dashboard-tabs,
  .toolbar,
  .card-actions,
  .kpi-strip {
    display: none !important;
  }

  .app-header {
    position: static;
    background: #ffffff !important;
    color: #000000 !important;
    border-bottom: 1.5px solid #000000;
    padding: 0 0 6px 0;
    box-shadow: none;
    margin-bottom: 10px;
  }

  .brand-icon {
    display: none;
  }

  .brand-subtitle {
    color: #334155 !important;
  }

  .main-container,
  .dashboard-nav-container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .sector-banner {
    background: #f8fafc !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1;
    border-left: 4px solid #0f172a !important;
    padding: 6px 10px;
    margin-bottom: 8px;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .patient-card {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    box-shadow: none !important;
    margin-bottom: 10px;
  }

  .patient-header {
    padding: 6px 10px;
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .patient-body {
    padding: 8px 10px;
    gap: 6px;
  }

  .field-box {
    padding: 5px 8px;
    border: 1px solid #cbd5e1;
  }

  .lab-table th,
  .lab-table td {
    padding: 3px 6px;
    font-size: 8.5pt;
  }
}

/* Modo Outros (Consulta / Sem Edição) */
body.role-viewer .card-actions {
  display: none !important;
}
body.role-viewer button[onclick*="abrirModalPaciente"],
body.role-viewer button[onclick*="abrirModalRapidoLab"],
body.role-viewer button[onclick*="excluirPaciente"],
body.role-viewer button[onclick*="restaurarDadosExemplo"] {
  display: none !important;
}
/* ================= BALANCO HIDRICO DIARIO & DIURESE 24H SECTION ================= */
.bh-section {
  grid-column: span 12;
  background: var(--bg-card);
  border: 1.5px solid rgba(2, 132, 199, 0.25);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: 0.35rem;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.bh-header {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(14, 165, 233, 0.03) 100%);
  padding: 0.75rem 1.05rem;
  border-bottom: 1px solid rgba(2, 132, 199, 0.16);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.bh-header-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #0369a1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bh-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
  padding: 0.95rem 1.05rem;
  background: var(--bg-card);
}

.bh-metric-card {
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: all 0.2s ease;
}

/* Destaque 1: Diurese de 24 horas */
.bh-metric-card.diurese-highlight {
  background: linear-gradient(145deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1.5px solid #38bdf8;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.12);
}

/* Destaque 2: Balanco Hidrico Diario */
.bh-metric-card.bh-highlight-negativo {
  background: linear-gradient(145deg, #f0fdf4 0%, #dcfce7 100%);
  border: 1.5px solid #4ade80;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.12);
}

.bh-metric-card.bh-highlight-positivo {
  background: linear-gradient(145deg, #f8fafc 0%, #eff6ff 100%);
  border: 1.5px solid #60a5fa;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.12);
}

.bh-metric-card.bh-highlight-alerta {
  background: linear-gradient(145deg, #fff7ed 0%, #ffedd5 100%);
  border: 1.5px solid #fb923c;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.12);
}

.bh-metric-card.detalhes-highlight {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
}

.bh-metric-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.diurese-highlight .bh-metric-label { color: #0369a1; }
.bh-highlight-negativo .bh-metric-label { color: #15803d; }
.bh-highlight-positivo .bh-metric-label { color: #1d4ed8; }
.bh-highlight-alerta .bh-metric-label { color: #c2410c; }
.detalhes-highlight .bh-metric-label { color: var(--text-secondary); }

.bh-metric-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.bh-metric-number {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.diurese-highlight .bh-metric-number { color: #0284c7; }
.bh-highlight-negativo .bh-metric-number { color: #16a34a; }
.bh-highlight-positivo .bh-metric-number { color: #2563eb; }
.bh-highlight-alerta .bh-metric-number { color: #ea580c; }
.detalhes-highlight .bh-metric-number { color: var(--text-main); font-size: 1.15rem; }

.bh-metric-unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.bh-metric-footer {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-top: 0.3rem;
  padding-top: 0.35rem;
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

.bh-status-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.pill-diurese-normal { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.pill-diurese-warning { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.pill-diurese-danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.pill-diurese-polyuria { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }

.pill-bh-negativo { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.pill-bh-positivo { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
.pill-bh-alerta { background: #ffedd5; color: #c2410c; border: 1px solid #fed7aa; }
.pill-bh-neutro { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

/* Interactive Calculator inside Quick Modal */
.bh-calculator-preview {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 0.35rem;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
}

.bh-calc-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.bh-calc-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
}

.bh-calc-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.bh-calc-val-final {
  font-size: 1.45rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #0284c7;
}

.bh-calc-divider {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-muted);
}

.highlight-calc-final {
  background: #ffffff;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid #38bdf8;
  box-shadow: 0 2px 4px rgba(14, 165, 233, 0.08);
}

.bh-input-highlight-in {
  border-color: #7dd3fc !important;
  background-color: #f0f9ff !important;
}

.bh-input-highlight-diurese {
  border-color: #38bdf8 !important;
  background-color: #e0f2fe !important;
  font-weight: 700 !important;
  color: #0369a1 !important;
}

.badge-mini-calc {
  font-size: 0.72rem;
  font-weight: 700;
  background: #0284c7;
  color: #ffffff;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

/* History table */
.bh-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.bh-history-table th,
.bh-history-table td {
  padding: 0.55rem 0.85rem;
  border-bottom: var(--hairline);
  text-align: left;
}

.bh-history-table th {
  background: var(--bg-subtle);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.bh-history-table tr:hover td {
  background: var(--bg-subtle);
}

/* Badges for summary table */
.table-bh-badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.table-diurese-badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #7dd3fc;
}

/* Hide action buttons in read-only mode */
body.role-viewer button[onclick*="abrirModalRapidoBH"],
body.role-viewer button[onclick*="excluirBalancoHidrico"] {
  display: none !important;
}