/* Tema compartilhado — Claro (atual), Escuro, Alto contraste e Automático. */
html[data-theme-resolved="dark"] {
  color-scheme: dark;
  --primary: #86a7ff;
  --primary-dark: #dbe5ff;
  --accent: #66d7b4;
  --accent-dark: #7ce1c2;
  --ink: #eef3ff;
  --muted: #bac4d8;
  --line: #3b465b;
  --surface: #202838;
  --bg: #141a24;
  --danger: #ff8c82;
  --shadow: 0 2px 12px rgba(0,0,0,.28);
  --shadow-lg: 0 16px 38px rgba(0,0,0,.42);
  --theme-panel: #1b2230;
  --theme-field: #141c29;
  --theme-hover: #283247;
  --theme-topbar: #203b8f;
}

html[data-theme-resolved="contrast"] {
  color-scheme: dark;
  --primary: #00e5ff;
  --primary-dark: #ffffff;
  --accent: #fff200;
  --accent-dark: #fff200;
  --ink: #ffffff;
  --muted: #ffffff;
  --line: #ffffff;
  --surface: #000000;
  --bg: #000000;
  --danger: #ff7b72;
  --shadow: none;
  --shadow-lg: none;
  --theme-panel: #000000;
  --theme-field: #000000;
  --theme-hover: #151515;
  --theme-topbar: #000000;
}

html[data-theme-resolved="dark"] body,
html[data-theme-resolved="contrast"] body { background: var(--bg) !important; color: var(--ink) !important; }

html[data-theme-resolved="dark"] .topbar,
html[data-theme-resolved="dark"] .app-topbar { background: var(--theme-topbar) !important; }
html[data-theme-resolved="contrast"] .topbar,
html[data-theme-resolved="contrast"] .app-topbar { background:#000 !important; border-bottom:2px solid #fff !important; box-shadow:none !important; }

html[data-theme-resolved="dark"] :is(.submenu,.update-card,.doc-row,.report-frame-wrap,.login-card,.panel-section,.modal,.account-menu,.bell-panel,.bell-item,.useful-link-card,.admin-summary-card,.account-card,.about-card,.adm-card,.adm-tag,.reg-paciente-box,.sessao-card),
html[data-theme-resolved="contrast"] :is(.submenu,.update-card,.doc-row,.report-frame-wrap,.login-card,.panel-section,.modal,.account-menu,.bell-panel,.bell-item,.useful-link-card,.admin-summary-card,.account-card,.about-card,.adm-card,.adm-tag,.reg-paciente-box,.sessao-card) {
  background: var(--theme-panel) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}

html[data-theme-resolved="dark"] :is(input,select,textarea),
html[data-theme-resolved="contrast"] :is(input,select,textarea) {
  background: var(--theme-field) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
html[data-theme-resolved="dark"] :is(input,textarea)::placeholder { color:#8893a8 !important; }
html[data-theme-resolved="contrast"] :is(input,textarea)::placeholder { color:#d0d0d0 !important; }

html[data-theme-resolved="dark"] :is(.btn--outline,.btn--danger),
html[data-theme-resolved="contrast"] :is(.btn--outline,.btn--danger) { background: var(--theme-panel) !important; }

html[data-theme-resolved="dark"] :is(.card__icon,.useful-link-card__icon,.icon-preview),
html[data-theme-resolved="contrast"] :is(.card__icon,.useful-link-card__icon,.icon-preview) { background: var(--theme-hover) !important; }


html[data-theme-resolved="dark"] .btn--accent { background:#167a5d !important; color:#fff !important; }
html[data-theme-resolved="dark"] .btn--accent:hover { background:#105f49 !important; }
html[data-theme-resolved="dark"] .admin-tab.is-active { background:#2f4f9d !important; color:#fff !important; }
html[data-theme-resolved="dark"] .badge--admin { background:#293650 !important; color:#bcd0ff !important; }
html[data-theme-resolved="dark"] .badge--user { background:#252c3b !important; color:#d4dbea !important; }
html[data-theme-resolved="dark"] .badge--inactive { background:#3a2427 !important; color:#ffaaa2 !important; }
html[data-theme-resolved="contrast"] :is(.badge--admin,.badge--user,.badge--inactive) { background:#000 !important; color:#fff !important; border:1px solid #fff !important; }
html[data-theme-resolved="contrast"] .admin-tab.is-active { background:#000 !important; color:#fff200 !important; border:2px solid #fff !important; }
html[data-theme-resolved="dark"] .form-msg.is-error { background:#3a2427 !important; }
html[data-theme-resolved="dark"] .form-msg.is-ok { background:#17352e !important; }
html[data-theme-resolved="contrast"] :is(.form-msg.is-error,.form-msg.is-ok,.notice-box,.reg-aviso) { background:#000 !important; color:#fff !important; border:2px solid #fff !important; }

html[data-theme-resolved="dark"] .notice-box { background:#1c2a3a !important; color:#c9d8eb !important; border-color:#40536b !important; }
html[data-theme-resolved="dark"] .notice-box.is-warning,
html[data-theme-resolved="dark"] .admin-summary-card.is-warning,
html[data-theme-resolved="dark"] .reg-aviso { background:#362f1f !important; color:#ffe3a1 !important; border-color:#7c6835 !important; }
html[data-theme-resolved="dark"] .notice-box.is-error { background:#3a2427 !important; color:#ffc2ba !important; border-color:#77423d !important; }
html[data-theme-resolved="dark"] .admin-summary-card.is-ok { background:#17352e !important; border-color:#356c5d !important; }

html[data-theme-resolved="dark"] :is(.badge--admin,.badge--user,.badge--inactive),
html[data-theme-resolved="contrast"] :is(.badge--admin,.badge--user,.badge--inactive) { border:1px solid currentColor; }

html[data-theme-resolved="dark"] .login-shell { background:var(--bg) !important; }
html[data-theme-resolved="contrast"] .login-shell { background:#000 !important; }

/* O logo (.brand) tem fundo branco fixo para servir de "etiqueta" sobre a
   barra colorida do cabeçalho. Dentro do card de login, em temas escuro e
   alto contraste, isso deixa um retângulo branco destacado — aqui removemos
   só esse fundo, deixando a imagem flutuar sobre o card escuro. O .brand do
   cabeçalho normal não é afetado. */
html[data-theme-resolved="dark"] .login-card .brand { background:transparent !important; }
html[data-theme-resolved="contrast"] .login-card .brand { background:transparent !important; }

/* Logo do login: versão colorida por padrão (tema claro), versão branca
   (com opacidade reduzida no fundo do brasão para preservar estrelas, cruz
   e ornamentos) nos temas escuro e alto contraste. */
.login-card .brand-logo--white { display:none; }
html[data-theme-resolved="dark"] .login-card .brand-logo--color,
html[data-theme-resolved="contrast"] .login-card .brand-logo--color { display:none; }
html[data-theme-resolved="dark"] .login-card .brand-logo--white,
html[data-theme-resolved="contrast"] .login-card .brand-logo--white { display:block; }

/* eMulti: menu lateral também acompanha o tema. */
html[data-theme-resolved="dark"] {
  --side-bg:#19283b;
  --side-ink:#dbe8fb;
  --side-hover:#273b55;
}
html[data-theme-resolved="dark"] .side-nav { border-right-color:#334861 !important; }
html[data-theme-resolved="dark"] .side-nav__item.is-active { background:#315071 !important; color:#fff !important; }
html[data-theme-resolved="contrast"] {
  --side-bg:#000;
  --side-ink:#fff;
  --side-hover:#181818;
}
html[data-theme-resolved="contrast"] .side-nav { border-right:2px solid #fff !important; }
html[data-theme-resolved="contrast"] .side-nav__item { border:1px solid transparent !important; }
html[data-theme-resolved="contrast"] .side-nav__item:hover,
html[data-theme-resolved="contrast"] .side-nav__item.is-active { background:#000 !important; color:#fff200 !important; border-color:#fff !important; }

/* Elementos de páginas com CSS próprio. */
html[data-theme-resolved="dark"] :is(.painel,.paciente,.tabs,.unidade-dropdown,.card),
html[data-theme-resolved="contrast"] :is(.painel,.paciente,.tabs,.unidade-dropdown,.card) { background:var(--theme-panel) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] :is(.upload-box,.xlsx-preview th,.med-row),
html[data-theme-resolved="contrast"] :is(.upload-box,.xlsx-preview th,.med-row) { background:var(--surface) !important; color:var(--ink) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] :is(.xlsx-preview td,.unidade-opcao,.tbl td),
html[data-theme-resolved="contrast"] :is(.xlsx-preview td,.unidade-opcao,.tbl td) { color:var(--ink) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] .tbl tr:nth-child(even) td { background:#1d2635 !important; }
html[data-theme-resolved="contrast"] .tbl tr:nth-child(even) td { background:#000 !important; }

/* Receituário: a interface acompanha o tema, mas a folha permanece branca. */
html[data-theme-resolved="dark"] .sidebar { background:var(--theme-panel) !important; border-color:var(--line) !important; }
html[data-theme-resolved="contrast"] .sidebar { background:#000 !important; border-color:#fff !important; }
html[data-theme-resolved="dark"] .preview { background:var(--bg) !important; }
html[data-theme-resolved="contrast"] .preview { background:#000 !important; }
html[data-theme-resolved="dark"] .a4,
html[data-theme-resolved="contrast"] .a4,
html[data-theme-resolved="dark"] .a4 *,
html[data-theme-resolved="contrast"] .a4 * { color-scheme:light; }
html[data-theme-resolved="dark"] .a4,
html[data-theme-resolved="contrast"] .a4 { background:#fff !important; color:#111 !important; }
html[data-theme-resolved="dark"] .a4 :is(.emitente,.fl,.fv,.prescricao,.ass-label,.ass-val,.via-label),
html[data-theme-resolved="contrast"] .a4 :is(.emitente,.fl,.fv,.prescricao,.ass-label,.ass-val,.via-label) { color:#111 !important; }
html[data-theme-resolved="dark"] .a4 .prescricao,
html[data-theme-resolved="contrast"] .a4 .prescricao { background:#fff !important; }

/* Controles de aparência */
.theme-choice-grid { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:6px 4px 4px; }
.theme-choice-grid button,
.theme-choice-list button { position:relative; }
.theme-choice-grid button.is-active,
.theme-choice-list button.is-active { background:var(--surface) !important; color:var(--primary-dark) !important; box-shadow:inset 0 0 0 1px var(--line); }
.theme-choice__check { margin-left:auto; font-weight:800; min-width:14px; text-align:center; }
.theme-menu-label { padding:7px 10px 4px; color:var(--muted); font-size:11px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; }

html[data-theme-resolved="contrast"] :focus-visible { outline:4px solid #fff200 !important; outline-offset:3px !important; }
html[data-theme-resolved="contrast"] a { text-decoration:underline; text-underline-offset:2px; }
html[data-theme-resolved="contrast"] button,
html[data-theme-resolved="contrast"] input,
html[data-theme-resolved="contrast"] select,
html[data-theme-resolved="contrast"] textarea { border-width:2px !important; }
html[data-theme-resolved="contrast"] :is(.btn--accent,.btn-wpp,.btn-gerar,.btn-print) { background:#fff200 !important; color:#000 !important; border:2px solid #fff !important; }

@media (forced-colors: active) {
  * { forced-color-adjust:auto; }
  :focus-visible { outline:3px solid Highlight !important; }
  .a4, .a4 * { forced-color-adjust:none; }
}

@media print {
  html { color-scheme:light !important; }
  body { background:#fff !important; color:#000 !important; }
  .a4, .a4 * { color-scheme:light !important; }
}

/* Menu de conta/aparência do Portal principal. */
.portal-account-wrap { position:relative; }
.portal-account-button {
  border:0; background:transparent; color:#fff; display:flex; align-items:center; gap:9px;
  padding:6px 9px; border-radius:8px; font-family:inherit; cursor:pointer; max-width:330px;
}
.portal-account-button:hover,
.portal-account-button[aria-expanded="true"] { background:rgba(255,255,255,.12); }
.portal-account-button__name { font-size:13px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.portal-account-button__chevron { font-size:18px; line-height:1; transform:translateY(-1px); }
.portal-account-menu {
  position:absolute; right:0; top:calc(100% + 8px); z-index:260; min-width:250px; padding:7px;
  border-radius:10px; background:#fff; border:1px solid var(--line); box-shadow:var(--shadow-lg); color:var(--ink);
}
.portal-account-menu[hidden] { display:none; }
.portal-account-menu button,
.portal-account-menu a {
  width:100%; border:0; background:transparent; color:var(--ink); display:flex; align-items:center; gap:9px;
  padding:9px 11px; border-radius:7px; font-family:inherit; font-size:13px; font-weight:600; cursor:pointer; text-align:left;
}
.portal-account-menu button:hover,
.portal-account-menu a:hover { background:var(--surface); color:var(--primary-dark); }
.theme-choice-list { display:flex; flex-direction:column; gap:2px; }
html[data-theme-resolved="dark"] .portal-account-menu,
html[data-theme-resolved="contrast"] .portal-account-menu { background:var(--theme-panel); border-color:var(--line); }

@media (max-width:760px) {
  .portal-account-button__name { display:none; }
  .portal-account-button { padding:5px 6px; }
  .portal-account-menu { right:-2px; min-width:235px; }
}

/* Ajustes das ferramentas legadas que possuem CSS próprio na página. */
html[data-theme-resolved="dark"] .layout .painel,
html[data-theme-resolved="contrast"] .layout .painel { background:var(--theme-panel) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] .upload-box p { color:var(--muted) !important; }
html[data-theme-resolved="contrast"] .upload-box p { color:#fff !important; }
html[data-theme-resolved="dark"] .layout .btn-add { color:var(--ink) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] .layout .btn-add:hover { background:var(--theme-hover) !important; }
html[data-theme-resolved="contrast"] .layout .btn-add { color:#fff200 !important; border-color:#fff !important; }
html[data-theme-resolved="dark"] :is(.warn,.badge-notel) { background:#3a301d !important; color:#ffd787 !important; }
html[data-theme-resolved="contrast"] :is(.warn,.badge-notel,.info) { background:#000 !important; color:#fff !important; border:1px solid #fff !important; }
html[data-theme-resolved="dark"] :is(.chip,.tel-badge-multi) { background:#17352e !important; border-color:#356c5d !important; color:#91e9cc !important; }
html[data-theme-resolved="dark"] .col-chip { background:#2c2943 !important; border-color:#625a93 !important; color:#d7d1ff !important; }
html[data-theme-resolved="contrast"] :is(.chip,.tel-badge-multi,.col-chip) { background:#000 !important; border:1px solid #fff !important; color:#fff200 !important; }
html[data-theme-resolved="dark"] code { background:var(--theme-hover) !important; color:var(--ink) !important; }
html[data-theme-resolved="contrast"] code { background:#000 !important; color:#fff200 !important; border:1px solid #fff; }

html[data-theme-resolved="dark"] :is(.unidade-dropdown,.download-item,.btn-gerar-outline) { background:var(--theme-panel) !important; border-color:var(--line) !important; }
html[data-theme-resolved="dark"] :is(.unidade-opcao:hover,.unidade-opcao.destacada,.btn-add:hover,.btn-gerar-outline:hover) { background:var(--theme-hover) !important; }
html[data-theme-resolved="dark"] .unidade-opcao-nova { background:#17352e !important; }
html[data-theme-resolved="dark"] .download-item .dl-nome { color:#b9d1ff !important; }
html[data-theme-resolved="dark"] :is(.aviso.info,.aviso.sucesso,.status-box.sucesso) { background:#263425 !important; color:#d8efc8 !important; border-color:#526a4c !important; }
html[data-theme-resolved="dark"] :is(.aviso.erro,.status-box.erro) { background:#3a2427 !important; color:#ffc2ba !important; border-color:#77423d !important; }
html[data-theme-resolved="contrast"] :is(.unidade-dropdown,.download-item,.btn-gerar-outline,.aviso,.status-box) { background:#000 !important; color:#fff !important; border:2px solid #fff !important; }
html[data-theme-resolved="contrast"] :is(.card-header,.tabs) { background:#000 !important; color:#fff !important; border-color:#fff !important; }
html[data-theme-resolved="contrast"] .tab-btn.active { color:#fff200 !important; border-bottom-color:#fff200 !important; }
html[data-theme-resolved="contrast"] .download-link { background:#fff200 !important; color:#000 !important; border:2px solid #fff !important; }
html[data-theme-resolved="contrast"] .login-bg { display:none !important; }

@media (max-width:1080px) and (min-width:761px) {
  .portal-account-button__name { max-width:130px; }
}

/* Contraste de ações e cabeçalhos em páginas com CSS local. */
html[data-theme-resolved="dark"] :is(.btn-wpp,.btn-gerar) { background:#167a5d !important; color:#fff !important; }
html[data-theme-resolved="dark"] :is(.btn-wpp,.btn-gerar):hover { background:#105f49 !important; }
html[data-theme-resolved="dark"] :is(.card-header,.tbl th,.unidade-opcao .uo-tag,.btn-primario,.download-link),
html[data-theme-resolved="dark"] body > .tabs { background:#294b9b !important; color:#fff !important; }
html[data-theme-resolved="contrast"] :is(.tbl th,.unidade-opcao .uo-tag,.btn-primario,.card-header),
html[data-theme-resolved="contrast"] body > .tabs { background:#000 !important; color:#fff !important; border-color:#fff !important; }
html[data-theme-resolved="dark"] .login-bg canvas { filter:brightness(2.2) saturate(.75); opacity:.62; }


/* ======================================================================
   v2.7 — seletor compacto de aparência no cabeçalho
   ====================================================================== */
.theme-control {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  min-height: 38px;
  border: 1px solid rgba(255,255,255,.48);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
.theme-control:hover,
.theme-control:focus-within { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.72); }
.theme-control__toggle,
.theme-control__menu-button {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-control__toggle {
  gap: 7px;
  padding: 0 9px 0 11px;
  border-radius: 999px 0 0 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.theme-control__menu-button {
  width: 30px;
  border-left: 1px solid rgba(255,255,255,.28);
  border-radius: 0 999px 999px 0;
}
.theme-control__toggle:hover,
.theme-control__menu-button:hover,
.theme-control__menu-button[aria-expanded="true"] { background: rgba(255,255,255,.10); }
.theme-control__icon,
.theme-choice__icon { display:inline-flex; align-items:center; justify-content:center; flex:0 0 auto; }
.theme-control__icon svg { width:18px; height:18px; }
.theme-control__menu-button svg { width:16px; height:16px; transition:transform .16s ease; }
.theme-control__menu-button[aria-expanded="true"] svg { transform:rotate(180deg); }
.theme-control svg,
.theme-choice__icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-control__menu {
  position:absolute;
  right:0;
  top:calc(100% + 8px);
  z-index:280;
  min-width:230px;
  padding:7px;
  border-radius:10px;
  background:#fff;
  border:1px solid var(--line);
  box-shadow:var(--shadow-lg);
  color:var(--ink);
}
.theme-control__menu[hidden] { display:none; }
.theme-control__menu .theme-menu-label { padding:7px 10px 5px; }
.theme-control__menu .theme-choice-list button {
  width:100%;
  border:0;
  background:transparent;
  color:var(--ink);
  display:flex;
  align-items:center;
  gap:9px;
  padding:9px 10px;
  border-radius:7px;
  font-family:inherit;
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  text-align:left;
}
.theme-control__menu .theme-choice-list button:hover { background:var(--surface); color:var(--primary-dark); }
.theme-choice__icon svg { width:17px; height:17px; }
html[data-theme-resolved="dark"] .theme-control__menu { background:var(--theme-panel); color:var(--ink); border-color:var(--line); }
html[data-theme-resolved="dark"] .theme-control__menu .theme-choice-list button { color:var(--ink); }
html[data-theme-resolved="contrast"] .theme-control { background:#000; border:2px solid #fff; color:#fff; }
html[data-theme-resolved="contrast"] .theme-control__menu { background:#000; color:#fff; border:2px solid #fff; box-shadow:none; }
html[data-theme-resolved="contrast"] .theme-control__menu .theme-choice-list button { color:#fff; border:1px solid transparent !important; }
html[data-theme-resolved="contrast"] .theme-control__menu .theme-choice-list button:hover,
html[data-theme-resolved="contrast"] .theme-control__menu .theme-choice-list button.is-active { color:#fff200 !important; border-color:#fff !important; background:#000 !important; }
html[data-theme-resolved="contrast"] .theme-control__menu-button { border-left:2px solid #fff !important; }

@media (max-width:1180px) {
  .theme-control__label { display:none; }
  .theme-control__toggle { padding:0 8px 0 10px; }
}
@media (max-width:760px) {
  .theme-control { min-height:36px; }
  .theme-control__toggle { padding:0 7px 0 9px; }
  .theme-control__menu-button { width:27px; }
  .theme-control__menu { right:-2px; min-width:225px; }
}
