/*
 * Tema claro/escuro (ver assets/js/theme.js).
 *
 * As cores vêm do Design System (assets/css/design-system.css): lá ficam os
 * tokens --ds-* dos dois temas e os componentes. Este arquivo só mantém:
 *  - as variáveis legadas --theme-* e --dk-* (usadas nos <style> das páginas),
 *    agora apontando para os tokens do DS;
 *  - ajustes do tema escuro para bibliotecas/telas que o DS não cobre.
 * Tudo fica dentro de @media screen: na impressão vale sempre o tema claro.
 */
@media screen {
:root {
  color-scheme: light;
  --theme-page: var(--ds-bg, #FAF6F8);
  --theme-surface: var(--ds-surface, #ffffff);
  --theme-surface-raised: var(--ds-surface-elevated, #ffffff);
  --theme-surface-muted: var(--ds-surface-2, #F4EEF1);
  --theme-text: var(--ds-fg, #2B1B24);
  --theme-text-strong: var(--ds-fg-strong, #1F1219);
  --theme-text-muted: var(--ds-muted, #6B5862);
  --theme-border: var(--ds-border, #ECE2E8);
  --theme-hover: var(--ds-surface-2, #F4EEF1);
  --theme-input: var(--ds-input, #ffffff);
  --theme-shadow: var(--ds-shadow-md);
  --theme-accent: var(--ds-primary, #C92F69);
}

html[data-theme="dark"] {
  color-scheme: dark;

  /*
   * Variáveis --dk-* de mistura: existem SOMENTE no tema escuro.
   * As páginas escrevem color-mix(in srgb, <cor> var(--dk-ink, 100%), var(--dk-ink-base, <cor>)):
   * no claro vale a cor original; no escuro ela é clareada/escurecida para manter contraste.
   */
  --dk-surface-2: var(--ds-surface-2);
  /* Tons pastel (fundo de ícones, selos): % da cor original misturada ao fundo escuro */
  --dk-mix: 18%;
  /* Textos/ícones saturados: clareados para manter contraste */
  --dk-ink: 58%;
  --dk-ink-base: #ffffff;
}

/* Durante a troca de tema, nada anima (evita o "degradê" desencontrado entre elementos). */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: none !important;
}

/* Botão de alternar tema (cores no design-system.css) */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  margin: 0 10px;
  padding: 6px 12px;
  border: 1px solid var(--theme-border);
  border-radius: 999px;
  background: var(--theme-surface);
  color: var(--theme-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--ds-ring, rgba(224, 71, 129, 0.55));
  outline-offset: 2px;
}

.theme-toggle .material-icons {
  font-size: 19px;
  color: var(--theme-accent);
}

.theme-toggle-float {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
}

@media (max-width: 575px) {
  .theme-toggle {
    gap: 0;
    width: 38px;
    min-width: 38px;
    padding: 6px;
    margin: 0 5px;
  }

  .theme-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .theme-toggle-float {
    top: 10px;
    right: 10px;
  }
}

/* ---------------------------------------------------------------------------
 * Tema escuro: textos do Material que têm cor fixa (#3C4858, #999…)
 * ------------------------------------------------------------------------- */
html[data-theme="dark"] body,
html[data-theme="dark"] .main-panel,
html[data-theme="dark"] .content {
  background-color: var(--theme-page) !important;
  color: var(--theme-text);
}

html[data-theme="dark"] .main-panel .content h1,
html[data-theme="dark"] .main-panel .content h2,
html[data-theme="dark"] .main-panel .content h3,
html[data-theme="dark"] .main-panel .content h4,
html[data-theme="dark"] .main-panel .content h5,
html[data-theme="dark"] .main-panel .content label,
html[data-theme="dark"] .main-panel .content p,
html[data-theme="dark"] .main-panel .content th,
html[data-theme="dark"] .main-panel .content td,
html[data-theme="dark"] .main-panel .content .form-check-label,
html[data-theme="dark"] .main-panel .content .custom-control-label {
  /* Sem !important: cores semânticas (.text-success, .text-danger…) e as das páginas continuam valendo. */
  color: var(--theme-text);
}

html[data-theme="dark"] .main-panel .content a:not([class]) {
  color: var(--ds-primary);
}

html[data-theme="dark"] .close {
  color: var(--theme-text);
  text-shadow: none;
}

html[data-theme="dark"] select option {
  background-color: var(--theme-surface-raised);
  color: var(--theme-text);
}

/* Inputs fora do .form-control (páginas com campos próprios) */
html[data-theme="dark"] select:not(.form-control),
html[data-theme="dark"] textarea:not(.form-control),
html[data-theme="dark"] input:not(.form-control):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="file"]) {
  background-color: var(--theme-input);
  color: var(--theme-text);
  border-color: var(--ds-input-border);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--ds-subtle);
  opacity: 1;
}

/* Autocompletar do Chrome pinta o input de amarelo-claro. */
html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--theme-text-strong);
  -webkit-box-shadow: 0 0 0 1000px var(--theme-input) inset !important;
  caret-color: var(--theme-text-strong);
}

/* DataTables / tabelas com fundo branco fixo */
html[data-theme="dark"] .dataTables_wrapper,
html[data-theme="dark"] .dt-container {
  background-color: transparent !important;
  color: var(--theme-text);
}

html[data-theme="dark"] table.dataTable tbody tr,
html[data-theme="dark"] .table tbody tr {
  background-color: transparent;
}

/* ---------------------------------------------------------------------------
 * ApexCharts / Chart.js
 * ------------------------------------------------------------------------- */
html[data-theme="dark"] .apexcharts-text,
html[data-theme="dark"] .apexcharts-text tspan,
html[data-theme="dark"] .apexcharts-title-text,
html[data-theme="dark"] .apexcharts-subtitle-text,
html[data-theme="dark"] .apexcharts-datalabel-label,
html[data-theme="dark"] .apexcharts-datalabel-value {
  fill: var(--theme-text) !important;
}

html[data-theme="dark"] .apexcharts-legend-text {
  color: var(--theme-text) !important;
}

html[data-theme="dark"] .apexcharts-gridline,
html[data-theme="dark"] .apexcharts-grid line,
html[data-theme="dark"] .apexcharts-xaxis-tick,
html[data-theme="dark"] .apexcharts-yaxis line,
html[data-theme="dark"] .apexcharts-xaxis line {
  stroke: var(--theme-border) !important;
}

html[data-theme="dark"] .apexcharts-pie-area,
html[data-theme="dark"] .apexcharts-bar-area {
  stroke: var(--theme-surface);
}

html[data-theme="dark"] .apexcharts-menu,
html[data-theme="dark"] .apexcharts-tooltip.apexcharts-theme-light,
html[data-theme="dark"] .apexcharts-xaxistooltip {
  background: var(--theme-surface-raised) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

html[data-theme="dark"] .apexcharts-tooltip.apexcharts-theme-light .apexcharts-tooltip-title {
  background: var(--theme-surface-muted) !important;
  border-color: var(--theme-border) !important;
}

html[data-theme="dark"] .apexcharts-toolbar {
  background: transparent !important;
}

html[data-theme="dark"] .apexcharts-menu-item:hover {
  background: var(--theme-hover) !important;
}

html[data-theme="dark"] .apexcharts-toolbar svg,
html[data-theme="dark"] .apexcharts-menu-icon svg {
  fill: var(--theme-text-muted) !important;
}

/* Chart.js desenha em <canvas>: só o contêiner pode ser ajustado por CSS. */
html[data-theme="dark"] canvas {
  color-scheme: dark;
}

/* ---------------------------------------------------------------------------
 * FullCalendar (fundos brancos fixos do tema "unthemed")
 * ------------------------------------------------------------------------- */
html[data-theme="dark"] .fc-view-container,
html[data-theme="dark"] .fc-view,
html[data-theme="dark"] .fc-unthemed .fc-content,
html[data-theme="dark"] .fc-unthemed .fc-popover,
html[data-theme="dark"] .fc-unthemed td,
html[data-theme="dark"] .fc-unthemed .fc-list-view,
html[data-theme="dark"] .fc-unthemed .fc-list-heading td,
html[data-theme="dark"] .fc-unthemed .fc-list-item:hover td,
html[data-theme="dark"] .fc-unthemed .fc-divider,
html[data-theme="dark"] .fc-unthemed .fc-list-empty {
  background-color: var(--theme-surface);
  color: var(--theme-text);
}

html[data-theme="dark"] .fc-unthemed td.fc-today {
  background: var(--ds-primary-soft);
}

html[data-theme="dark"] .fc-unthemed .fc-list-item a {
  color: var(--theme-text-muted) !important;
}

/* ---------------------------------------------------------------------------
 * Páginas públicas (sem o layout do sistema)
 * ------------------------------------------------------------------------- */
html[data-theme="dark"] body.public-theme-page p,
html[data-theme="dark"] body.public-theme-page h1,
html[data-theme="dark"] body.public-theme-page h2,
html[data-theme="dark"] body.public-theme-page h3,
html[data-theme="dark"] body.public-theme-page h4,
html[data-theme="dark"] body.public-theme-page h5,
html[data-theme="dark"] body.public-theme-page h6 {
  color: var(--theme-text) !important;
}

html[data-theme="dark"] body.login-page .card-login {
  background: var(--ds-surface) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text);
}

html[data-theme="dark"] body.login-page .card-login .card-header,
html[data-theme="dark"] body.login-page .card-login .card-body {
  background-color: transparent !important;
  color: var(--theme-text);
}

/* Painel de chamada (TV da recepção) */
html[data-theme="dark"] body.call-panel {
  --tinta: var(--ds-fg);
  --suave: var(--ds-muted);
  background: linear-gradient(135deg, var(--ds-bg) 0%, var(--ds-surface) 60%, var(--ds-surface-2) 100%) !important;
  color: var(--theme-text);
}

html[data-theme="dark"] body.call-panel .hero,
html[data-theme="dark"] body.call-panel .tabela-card {
  background: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
}

html[data-theme="dark"] body.call-panel .paciente {
  color: var(--ds-primary-ink);
}

html[data-theme="dark"] body.call-panel .divisor,
html[data-theme="dark"] body.call-panel .historico h2::after {
  background: linear-gradient(90deg, transparent, var(--ds-border-strong), transparent);
}

html[data-theme="dark"] body.call-panel thead th {
  background: var(--theme-surface-raised) !important;
  color: var(--ds-primary-ink);
}

html[data-theme="dark"] body.call-panel tbody td {
  color: var(--theme-text);
  border-color: var(--theme-border);
}

html[data-theme="dark"] body.call-panel tbody tr:nth-child(even) td {
  background: var(--ds-surface-2);
}

html[data-theme="dark"] body.call-panel tbody tr.nova td {
  background: var(--ds-primary-soft-2) !important;
}

/* Barras de rolagem e seleção */
html[data-theme="dark"] {
  scrollbar-color: var(--ds-border-strong) var(--theme-page);
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle {
    transition: none;
  }
}
}

@media print {
  .theme-toggle {
    display: none !important;
  }
}
