[hidden] {
  display: none !important;
}

:root {
  --brand: #0e7c86;
  --brand-dark: #0a5c63;
  --brand-light: #e6f4f5;
  --accent: #f0a63a;
  --danger: #c0392b;
  --success: #1e8a4c;
  --bg: #f4f7f8;
  --card-bg: #ffffff;
  --text: #1c2b2e;
  --text-muted: #647578;
  --border: #e1e8ea;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 3px rgba(20, 40, 45, 0.08), 0 1px 2px rgba(20, 40, 45, 0.06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--brand); }

/* ---------- LOGIN ---------- */
/* Fundo exclusivo: rede molecular monocromática em tons de teal, evocando
   química farmacêutica / manipulação, sobre um gradiente escuro elegante.
   O SVG já inclui gradiente, glows e vinheta — cobre a tela toda. */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05363c url("login-bg.svg") center center / cover no-repeat;
  padding: 16px;
}

.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(2, 24, 27, 0.45), 0 2px 0 rgba(255,255,255,0.4) inset;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  position: relative;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin: -4px auto 16px;
  display: block;
  box-shadow: 0 8px 22px rgba(10, 92, 99, 0.35);
}

.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
  color: var(--brand-dark);
  letter-spacing: 0.2px;
  text-align: center;
}

.login-card p.subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 0.9rem;
  text-align: center;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  transition: filter 0.15s ease;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-block { width: 100%; }

#login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 10px;
  min-height: 1em;
}

/* Tela de login congelada: mantém exatamente a aparência publicada.
   Os tokens e botões refinados do app não se aplicam aqui. */
#login-screen { --radius: 10px; }

/* ---------- BOTÕES: refinamento do app (fora da tela de login) ---------- */
#app-shell .btn, #modal-root .btn { border-radius: 10px; transition: filter 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease; }
#app-shell .btn-primary, #modal-root .btn-primary { box-shadow: 0 2px 8px rgba(14, 124, 134, 0.28); }
#app-shell .btn-primary:active, #modal-root .btn-primary:active { transform: translateY(1px); }

/* ---------- APP SHELL ---------- */
#app-shell { display: none; min-height: 100vh; }
#app-shell.visible { display: flex; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.02rem;
  padding: 0 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 12px;
}
.sidebar .brand-logo { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.28); flex-shrink: 0; }
.sidebar .brand-text { min-width: 0; }
.sidebar .brand-text small { display: block; font-weight: 400; opacity: 0.75; font-size: 0.7rem; margin-top: 3px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 12px;
  padding: 9px 12px;
  border-radius: 10px;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  font-size: 0.9rem;
}
.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  font-size: 0.98rem;
  transition: background 0.15s ease;
}
.nav-label { flex: 1; min-width: 0; }
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item:hover .nav-icon { background: rgba(255,255,255,0.16); }
.nav-item.active { background: rgba(255,255,255,0.16); color: #fff; font-weight: 600; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1); }
.nav-item.active .nav-icon { background: var(--accent); box-shadow: 0 0 0 3px rgba(240, 166, 58, 0.2); }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px 0;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.8rem;
}
.sidebar-footer .user-email { opacity: 0.85; word-break: break-all; margin-bottom: 4px; }
.sidebar-footer .user-papel { opacity: 0.65; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 8px; }

/* Perfil de visualização: barra lateral ocultável, revelada ao passar o
   mouse perto da borda esquerda (mantém o botão "Sair" acessível). */
#app-shell.sidebar-autohide .sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 500;
  transform: translateX(calc(-100% + 10px));
  transition: transform 0.22s ease;
  box-shadow: 3px 0 16px rgba(0,0,0,0.28);
}
#app-shell.sidebar-autohide .sidebar:hover,
#app-shell.sidebar-autohide .sidebar:focus-within {
  transform: translateX(0);
}
#app-shell.sidebar-autohide .main {
  margin-left: 0;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px 60px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 1.35rem; }
.page-header .desc { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }
.page-header-title { display: flex; align-items: center; gap: 14px; }
.page-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--brand-light);
  font-size: 1.25rem;
}
:root[data-theme="dark"] .page-icon { background: rgba(23, 179, 171, 0.16); }
#page-dashboard .page-icon { width: 32px; height: 32px; border-radius: 9px; font-size: 1rem; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.filters-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}
.filters-row .field { margin-bottom: 0; min-width: 140px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  border-top: 4px solid var(--brand);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(20, 40, 45, 0.14); }
.kpi-card .kpi-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4em;
  line-height: 1.2;
  width: 100%;
}
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--brand-dark); margin-top: 4px; }
.kpi-card.accent { border-top-color: var(--accent); }
.kpi-card.accent .kpi-value { color: #a8631a; }
.kpi-card .kpi-variacao { font-size: 0.72rem; font-weight: 700; margin-top: 6px; }

/* ---------- DASHBOARD: ABAS ---------- */
.dash-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.dash-tab {
  background: transparent;
  border: none;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  border-radius: 8px 8px 0 0;
}
.dash-tab:hover { background: var(--brand-light); color: var(--brand-dark); }
.dash-tab.active { color: var(--brand-dark); border-bottom-color: var(--accent); background: var(--brand-light); }

/* Cada aba do Dashboard tem sua própria identidade de cor (mesmas cores já
   usadas nos badges do sistema), para reforçar que é um recorte de análise
   diferente — não apenas o mesmo painel com dados trocados. */
#dash-tab-content.dash-theme-manipulacoes { --brand: #a8631a; --brand-dark: #7c4a13; --brand-light: #fdf1de; --accent: #0e7c86; }
#dash-tab-content.dash-theme-dispensacoes { --brand: #0e7c86; --brand-dark: #0a5c63; --brand-light: #e6f4f5; --accent: #1e8a4c; }
#dash-tab-content.dash-theme-clinico { --brand: #0b3d5c; --brand-dark: #072a40; --brand-light: #e7eef3; --accent: #a3312a; }
#dash-tab-content.dash-theme-qualidade { --brand: #146b8c; --brand-dark: #0d4a60; --brand-light: #eaf6f9; --accent: #c0392b; }

/* ---------- HEATMAP (matriz hora x dia da semana) ---------- */
.heatmap-table { border-collapse: collapse; width: 100%; font-size: 0.72rem; }
.heatmap-table th, .heatmap-table td { padding: 5px 6px; text-align: center; border: 1px solid var(--border); white-space: nowrap; }
.heatmap-table thead th { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; }
.heatmap-table tbody th { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; text-align: left; padding-left: 10px; }
.heatmap-cell { border-radius: 3px; color: #0b2226; font-weight: 700; }

/* ---------- GRÁFICOS: CARTÃO CLICÁVEL / TELA CHEIA ---------- */
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.chart-card-header h3 { margin: 0; font-size: 1rem; }
.chart-clickable {
  cursor: pointer;
  position: relative;
  border-radius: 8px;
  padding: 4px;
  margin: -4px;
  transition: background 0.15s ease;
}
.chart-clickable:hover { background: var(--brand-light); }
.chart-clickable::after {
  content: "⛶ Ampliar";
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--brand-dark);
  background: rgba(255,255,255,0.85);
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.chart-clickable:hover::after { opacity: 1; }

.chart-fullscreen-overlay { z-index: 200; }
.modal-box.chart-fullscreen-box {
  width: 94vw;
  max-width: 1200px;
  height: 86vh;
  max-height: 860px;
  display: flex;
  flex-direction: column;
}
.chart-fullscreen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.chart-fullscreen-header h3 { margin: 0; }
.chart-fullscreen-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}
.chart-fullscreen-canvas-wrap canvas { width: 100% !important; height: 100% !important; }

.charts-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
table.data-table th, table.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
table.data-table th {
  background: var(--brand-light);
  color: var(--brand-dark);
  font-weight: 600;
  position: sticky;
  top: 0;
}
table.data-table tbody tr:hover { background: #fafcfc; }
.table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border-radius: 10px; border: 1px solid var(--border); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge.disp { background: #e6f4f5; color: var(--brand-dark); }
.badge.manip { background: #fdf1de; color: #a8631a; }
.badge.quimio { background: #fbe7e7; color: #a3312a; }
.badge.hormonio { background: #eaf3fc; color: #2360a3; }
.badge.perfil-admin { background: #fdf1de; color: #a8631a; }
.badge.perfil-operador { background: #e6f4f5; color: var(--brand-dark); }
.badge.perfil-visualizador { background: #eef0fb; color: #4b4fa8; }
.badge.status-ativo { background: #e5f6ec; color: var(--success); }
.badge.status-inativo { background: #f6e8e8; color: var(--danger); }

.perfis-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.perfil-info-item p { margin: 8px 0 0; font-size: 0.85rem; color: var(--text-muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 16px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar input[type=search] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 220px;
}

.action-icon {
  cursor: pointer;
  background: none;
  border: none;
  color: var(--brand);
  font-size: 0.85rem;
  padding: 3px 6px;
}
.action-icon.danger { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  z-index: 999;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.hidden { display: none !important; }

/* ---------- NOTIFICAÇÕES ---------- */
.notif-bell {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 150;
}
.notif-bell-btn {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.notif-bell-btn:hover { filter: brightness(0.97); }
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  min-width: 17px;
  height: 17px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg);
}
.notif-panel {
  position: absolute;
  top: 50px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(20, 40, 45, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.notif-panel-header strong { font-size: 0.92rem; }
.btn-link {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.notif-list {
  max-height: 420px;
  overflow-y: auto;
}
.notif-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 28px 14px;
}
.notif-item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: flex-start;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--brand-light); }
:root[data-theme="dark"] .notif-item:hover { background: #16323a; }
.notif-item.unread { background: var(--brand-light); }
:root[data-theme="dark"] .notif-item.unread { background: #16323a; }
.notif-item-icon { font-size: 1.05rem; flex: 0 0 auto; margin-top: 1px; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 2px; }
.notif-item-msg { font-size: 0.8rem; color: var(--text-muted); line-height: 1.35; }
.notif-item-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; }
.notif-item-dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand);
  margin-top: 6px;
}

@media (max-width: 720px) {
  .notif-bell { top: 8px; right: 10px; }
  .notif-panel { top: 46px; width: calc(100vw - 20px); }
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 10px;
  font-size: 0.9rem;
}

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 30, 33, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(2, 24, 27, 0.28);
}
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.field-inline input[type="checkbox"] { width: auto; }
.field-inline label { margin: 0; font-size: 0.88rem; font-weight: 600; color: var(--text); }
.field-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

@media print {
  .sidebar, #toast, #modal-root, .notif-bell, .filters-row, .page-header button { display: none !important; }
  #app-shell.visible { display: block !important; }
  .main { padding: 0 !important; overflow: visible !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; break-inside: avoid; }
  .table-wrap { max-height: none !important; overflow: visible !important; }
}

.mobile-topbar { display: none; }
@media (max-width: 820px) {
  #app-shell.visible { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .sidebar .brand { display: none; }
  .sidebar-footer { display: none; }
  .nav-item { white-space: nowrap; margin: 0 3px; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; }
  .nav-item.active { border-bottom-color: var(--accent); }
  .main { padding: 18px 14px 40px; }
  .charts-grid { grid-template-columns: 1fr; }
}

/* ---------- CHECKLISTS ---------- */
.badge.geral { background: #eef0f2; color: #4b5a5e; }

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.checklist-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.checklist-card-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.checklist-card h4 { margin: 0; font-size: 1rem; color: var(--text); }
.checklist-card p { margin: 0; font-size: 0.82rem; color: var(--text-muted); flex-grow: 1; }
.checklist-card .checklist-card-meta { font-size: 0.76rem; color: var(--text-muted); }
.checklist-card-actions { display: flex; gap: 8px; margin-top: 4px; }
.checklist-card-actions .btn { flex: 1; }

.checklist-itens-form { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.checklist-item-row { display: flex; gap: 8px; align-items: flex-start; }
.checklist-item-row input[type="text"] { flex: 1; }
.checklist-item-row .action-icon.danger { flex-shrink: 0; }

.exec-item-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.exec-item-row:last-child { border-bottom: none; }
.exec-item-row input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; }
.exec-item-descricao { flex: 1; }
.exec-item-descricao .exec-item-ref { display: block; font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
.exec-item-descricao.marcado label { text-decoration: line-through; color: var(--text-muted); }
.exec-item-obs { width: 100%; margin-top: 6px; font-size: 0.82rem; }

.progress-bar-wrap {
  width: 100%;
  min-width: 90px;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill { height: 100%; background: var(--brand); border-radius: 4px; transition: width 0.2s ease; }
.progress-bar-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; }

/* ==========================================================================
   MODO ESCURO — mesma paleta de identidade (teal/laranja/vermelho/azul),
   com superfícies escuras e contraste ajustado para telas de farmácia com
   pouca luz. Ativado via [data-theme="dark"] no <html>, alternável e
   persistido em localStorage.
   ========================================================================== */
:root[data-theme="dark"] {
  --brand: #17b3ab;
  --brand-dark: #0d5d63;
  --brand-light: #123037;
  --accent: #f0a63a;
  --danger: #e0685c;
  --success: #35c07c;
  --bg: #0b1518;
  --card-bg: #142228;
  --text: #e7f1f2;
  --text-muted: #93aaae;
  --border: #253c42;
  --shadow: 0 1px 3px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.3);
}
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .field textarea { background: #0f1c21; color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .btn-secondary { background: #233841; color: var(--text); }
:root[data-theme="dark"] .heatmap-table th, :root[data-theme="dark"] .heatmap-table td { border-color: var(--border); }
:root[data-theme="dark"] .heatmap-cell { color: #eaf6f7; }

.btn-ghost-dark {
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 0.78rem;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.btn-ghost-dark:hover { background: rgba(255,255,255,0.18); }

/* ==========================================================================
   DASHBOARD — LAYOUT DENSO SEM ROLAGEM (otimizado para monitores de
   desktop ≥ 1280px de largura / 720px de altura). O conteúdo de cada aba
   ocupa exatamente o espaço vertical disponível, distribuído entre
   KPIs → linhas de gráficos/tabelas, usando flexbox com frações (flex-grow)
   em vez de alturas fixas em pixels. Em telas pequenas a rolagem volta a
   ficar disponível (ver media query no final deste bloco).
   ========================================================================== */
.main.no-scroll { overflow: hidden; padding: 14px 24px 12px; display: flex; flex-direction: column; }

#page-dashboard { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#page-dashboard.hidden { display: none; }
#page-dashboard .page-header { margin-bottom: 8px; flex: 0 0 auto; }
#page-dashboard .page-header h2 { font-size: 1.12rem; }
#page-dashboard .page-header .desc { font-size: 0.74rem; }

.dash-filtros-card { padding: 10px 14px; margin-bottom: 8px; flex: 0 0 auto; }
.dash-filtros-card .filters-row { gap: 8px; margin-bottom: 0; }
.dash-filtros-card .field { margin-bottom: 0; min-width: 116px; }
.dash-filtros-card .field label { font-size: 0.66rem; margin-bottom: 2px; }
.dash-filtros-card .field input, .dash-filtros-card .field select { padding: 6px 8px; font-size: 0.78rem; }
.dash-filtros-card .btn { padding: 7px 12px; font-size: 0.78rem; }

.dash-tabs { margin-bottom: 8px; flex: 0 0 auto; }
.dash-tab { padding: 6px 14px; font-size: 0.8rem; }

#dash-tab-content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* KPIs compactos com sparkline de tendência embutida */
#dash-tab-content .kpi-grid {
  flex: 0 0 auto;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
#dash-tab-content .kpi-card { padding: 8px 12px 6px; }
#dash-tab-content .kpi-card .kpi-label { font-size: 0.6rem; min-height: 2.1em; }
#dash-tab-content .kpi-card .kpi-value { font-size: 1.18rem; margin-top: 2px; }
#dash-tab-content .kpi-card .kpi-variacao { font-size: 0.58rem; margin-top: 2px; }
.kpi-spark { display: block; width: 100%; height: 20px; margin-top: 3px; }

/* Corpo de cada aba: pilha de linhas flexíveis, cada uma com N cartões
   lado a lado — a proporção de altura de cada linha é definida por
   flex-grow (heightFr) no HTML gerado por dashRowHtml(). */
.dash-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.dash-row { display: flex; gap: 8px; min-height: 0; }
.dash-row > * { flex: 1; min-width: 0; min-height: 0; }

#dash-tab-content .card {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  margin-bottom: 0;
}
#dash-tab-content .chart-card-header { margin-bottom: 4px; flex: 0 0 auto; }
#dash-tab-content .chart-card-header h3 { font-size: 0.74rem; line-height: 1.2; }
#dash-tab-content .chart-clickable { flex: 1; min-height: 0; position: relative; }
#dash-tab-content .chart-clickable canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
#dash-tab-content .table-wrap { flex: 1; min-height: 0; overflow-y: auto; max-height: none; font-size: 0.7rem; }
#dash-tab-content .table-wrap.heatmap-wrap { overflow-x: auto; }
#dash-tab-content .data-table th, #dash-tab-content .data-table td { padding: 4px 6px; white-space: nowrap; }
#dash-tab-content .toolbar { flex: 0 0 auto; display: flex; gap: 6px; }
#dash-tab-content .toolbar input, #dash-tab-content .toolbar select { padding: 4px 6px; font-size: 0.72rem; }
#dash-tab-content .empty-state { font-size: 0.72rem; }
#dash-tab-content .card-nota { font-size: 0.6rem; color: var(--text-muted); flex: 0 0 auto; margin-top: 2px; }

/* Badges de status de rastreamento (aba Dispensações) */
.badge.status-preparo { background: #e6eef5; color: #0b3d5c; }
.badge.status-pronto { background: #fdeecb; color: #a8631a; }
.badge.status-retirado { background: #dff3ea; color: #1e8a4c; }
:root[data-theme="dark"] .badge.status-preparo { background: #16324a; color: #bcd6ec; }
:root[data-theme="dark"] .badge.status-pronto { background: #4a3414; color: #f4cf94; }
:root[data-theme="dark"] .badge.status-retirado { background: #123a29; color: #a8ecc9; }

@media (max-height: 720px), (max-width: 1100px) {
  .main.no-scroll { overflow-y: auto; display: block; }
  #page-dashboard { height: auto; }
  #dash-tab-content { overflow: visible; }
  #dash-tab-content .dash-row { flex-wrap: wrap; }
  #dash-tab-content .dash-row > * { flex: 1 1 320px; min-height: 220px; }
  #dash-tab-content .table-wrap { max-height: 320px; }
}

/* ==========================================================================
   POLIMENTO DO APP — controles, tabelas e cabeçalhos.
   Tudo escopado em #app-shell / #modal-root: a tela de login não é afetada.
   ========================================================================== */

/* Campos com o mesmo raio dos cartões internos e fonte do sistema */
#app-shell .field input, #app-shell .field select, #app-shell .field textarea,
#modal-root .field input, #modal-root .field select, #modal-root .field textarea {
  border-radius: 10px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Barras de busca/filtro (fora de .field) seguem o mesmo desenho dos campos */
#app-shell .toolbar input,
#app-shell .toolbar select {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#app-shell .toolbar input[type=search] { min-width: 240px; }
#app-shell .toolbar input:focus,
#app-shell .toolbar select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
:root[data-theme="dark"] #app-shell .toolbar input,
:root[data-theme="dark"] #app-shell .toolbar select { background: #0f1c21; color-scheme: dark; }
:root[data-theme="dark"] #app-shell .field input,
:root[data-theme="dark"] #app-shell .field select,
:root[data-theme="dark"] #modal-root .field input,
:root[data-theme="dark"] #modal-root .field select { color-scheme: dark; }

/* Cabeçalho das tabelas legível no modo escuro */
:root[data-theme="dark"] table.data-table th { background: #16343b; color: #a6e0dc; }
:root[data-theme="dark"] table.data-table tbody tr:hover { background: #18292f; }
table.data-table tbody tr { transition: background 0.12s ease; }

/* Espaço para o sino fixo não cobrir os botões do cabeçalho da página */
@media (min-width: 821px) {
  .page-header { padding-right: 60px; }
}
@media (max-width: 820px) {
  .sidebar { padding-right: 64px; }
  .notif-bell { top: 12px; right: 12px; }
}

/* ==========================================================================
   TELA INICIAL — atalhos em cards para cada módulo
   ========================================================================== */
.inicio-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  padding: 28px 30px;
  margin: 0 60px 24px 0;
  border-radius: var(--radius-lg);
  background: #05363c url("login-bg.svg") center / cover no-repeat;
  color: #fff;
  box-shadow: 0 18px 40px rgba(5, 54, 60, 0.22);
}
.inicio-data {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: rgba(234, 246, 247, 0.78);
  margin-bottom: 6px;
}
.inicio-hero h2 { margin: 0; font-size: 1.7rem; letter-spacing: 0.2px; }
.inicio-hero .desc { margin: 6px 0 0; color: rgba(234, 246, 247, 0.85); font-size: 0.95rem; }

.inicio-resumo { display: flex; gap: 10px; flex-wrap: wrap; }
.inicio-resumo-item {
  display: flex;
  flex-direction: column;
  min-width: 112px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.inicio-resumo-valor { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.inicio-resumo-rotulo { font-size: 0.74rem; color: rgba(234, 246, 247, 0.8); margin-top: 2px; }

.inicio-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-right: 60px;
}
@media (max-width: 1180px) { .inicio-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.inicio-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.inicio-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
  box-shadow: 0 10px 24px rgba(14, 124, 134, 0.16);
}
.inicio-card:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.inicio-card:active { transform: translateY(0); }
.inicio-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 14px;
  background: var(--brand-light);
  font-size: 1.4rem;
  transition: background 0.15s ease;
}
.inicio-card:hover .inicio-card-icon { background: rgba(240, 166, 58, 0.22); }
.inicio-card-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.inicio-card-text strong { font-size: 1rem; }
.inicio-card-text small { font-size: 0.82rem; color: var(--text-muted); line-height: 1.35; }
.inicio-card-arrow {
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: transform 0.15s ease, color 0.15s ease;
}
.inicio-card:hover .inicio-card-arrow { color: var(--brand); transform: translateX(3px); }

:root[data-theme="dark"] .inicio-card-icon { background: rgba(23, 179, 171, 0.16); }
:root[data-theme="dark"] .inicio-card:hover { box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4); }

@media (max-width: 820px) {
  .inicio-hero { margin-right: 0; padding: 22px 20px; }
  .inicio-hero h2 { font-size: 1.4rem; }
  .inicio-resumo { width: 100%; gap: 8px; }
  .inicio-resumo-item { min-width: 0; flex: 1; padding: 10px 10px; }
  .inicio-resumo-valor { font-size: 1.35rem; }
  .inicio-resumo-rotulo { font-size: 0.68rem; }
  .inicio-grid { grid-template-columns: 1fr; margin-right: 0; }
}
/* Início sem barra lateral: conteúdo centralizado + topo com conta e saída */
#app-shell.pagina-inicio .sidebar { display: none; }
#app-shell.pagina-inicio .main { margin-left: 0; }
#page-inicio { max-width: 1180px; margin: 0 auto; }
#app-shell.pagina-inicio .inicio-hero { margin-right: 0; }
#app-shell.pagina-inicio .inicio-grid { margin-right: 0; }

.inicio-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-right: 60px; /* espaço do sino de notificações fixo */
  margin-bottom: 18px;
  min-height: 42px;
}
/* Tela larga: o sino fica fora da coluna centralizada, sem risco de sobrepor */
@media (min-width: 1340px) { .inicio-topo { padding-right: 0; } }
.inicio-marca { display: flex; align-items: center; gap: 10px; }
.inicio-marca img { display: block; width: 36px; height: 36px; }
.inicio-marca-texto { display: flex; flex-direction: column; line-height: 1.15; }
.inicio-marca-texto strong { font-size: 1.05rem; color: var(--text); }
.inicio-marca-texto span { font-size: 0.74rem; color: var(--text-muted); }
.inicio-conta { display: flex; align-items: center; gap: 10px; }
.inicio-usuario { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; min-width: 0; }
.inicio-usuario-email { font-size: 0.85rem; color: var(--text); overflow-wrap: anywhere; }
.inicio-usuario-papel { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.inicio-btn-tema {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.inicio-btn-tema:hover { border-color: var(--brand); }
.inicio-btn-tema:focus-visible, .inicio-btn-sair:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
#app-shell .inicio-btn-sair {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  font-weight: 600;
  color: var(--danger);
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: none;
  white-space: nowrap;
}
#app-shell .inicio-btn-sair:hover { border-color: var(--danger); background: rgba(220, 53, 69, 0.08); }

@media (max-width: 820px) {
  #app-shell.pagina-inicio { flex-direction: column; }
  .inicio-topo { padding-right: 56px; }
  .inicio-usuario { display: none; }
  .inicio-btn-sair { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .inicio-card, .inicio-card-arrow, .inicio-card-icon { transition: none; }
  .inicio-card:hover { transform: none; }
}
