/* Night lighting is independent of the classic/v4 layout. Screen only:
   never recolor generated documents or saved rich-text content. */
@media screen {
html[data-color-mode="dark"] {
  color-scheme:dark;
  --night-bg:#101b20;--night-surface:#17272d;--night-raised:#1d3036;--night-field:#122127;
  --night-border:#344a50;--night-text:#e2ede8;--night-muted:#adbfba;--night-accent:#7cdbb5;
  --bg:var(--night-bg)!important;--surface:var(--night-surface)!important;--surface-2:var(--night-raised)!important;
  --border:var(--night-border)!important;--border-soft:#293e45!important;--line:var(--night-border)!important;
  --text:var(--night-text)!important;--text-soft:#c1d1cb!important;--text-muted:var(--night-muted)!important;--text-faint:#9baeb3!important;
  --accent:#65cba3!important;--accent-soft:#1a3b32!important;--accent-hover:#83dfb9!important;--ok:#7cdbb5;--ok-soft:#193b31;--warn:#efc67c;
  --shadow-sm:0 1px 4px #0002;--shadow-md:0 6px 20px #0003;--shadow-lg:0 24px 70px #0008;
  --po-ps-canvas:var(--night-bg);--po-ps-pri1:#186945;--po-ps-pri2:#145638;--po-ps-priSoft:#172d27;--po-ps-priBd:#315447;--po-ps-priText:#89ddb4;
  --po-ps-sec1:#245783;--po-ps-sec2:#1b456a;--po-ps-secSoft:#192a39;--po-ps-secBd:#345069;--po-ps-secText:#9dc8f2;
  --po-ubs-canvas:var(--night-bg);--po-ubs-pri1:#245f96;--po-ubs-pri2:#1d4c78;--po-ubs-priSoft:#192e40;--po-ubs-priBd:#345c78;--po-ubs-priText:#9fcef6;
  --po-ubs-sec1:#14685f;--po-ubs-sec2:#10554f;--po-ubs-secSoft:#18312f;--po-ubs-secBd:#315852;--po-ubs-secText:#86d9c9;
  --po-pediatria-canvas:var(--night-bg);--po-pediatria-pri1:#8a345f;--po-pediatria-pri2:#6e2b51;--po-pediatria-priSoft:#30232f;--po-pediatria-priBd:#624057;--po-pediatria-priText:#f2b1d0;
  --po-pediatria-sec1:#59438a;--po-pediatria-sec2:#493572;--po-pediatria-secSoft:#28243a;--po-pediatria-secBd:#51446b;--po-pediatria-secText:#cbb9f5;
}
html[data-color-mode="dark"][data-app-layout="wide"] body{background:var(--night-bg)!important;color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.app.po-app,.v4m-root,.v4m-main,.po-rx-intro,.app-content,.gaso-view,.calc-view,.ia-view,.pt-view,.rename-view){background:var(--night-bg)!important;color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-sidebar,.po-mobile-menu-bar){background:#142329!important;border-color:var(--night-border)!important;box-shadow:4px 0 24px #0001!important;color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-brand strong,.po-profile-data strong,.po-rx-intro h1,.po-rx-title,#po-mode-heading){color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-brand small,.po-sidebar-label,.po-profile-data small,.po-rx-eyebrow,.po-rx-intro p,.po-mobile-menu-bar>span){color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-sidebar .po-area-nav button{color:#c2d4cb!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-sidebar .po-area-nav button:hover{background:#203d32!important;color:#b1f3d4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-sidebar .po-area-nav button[aria-current="page"]{background:#21674c!important;color:#f2fff8!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-profile,.po-display>summary,.po-icon-button,.po-mobile-menu-bar>button,.po-sidebar-close,.po-support){background:var(--night-raised)!important;color:#bbd3c6!important;border-color:var(--night-border)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-sidebar .po-top-actions{border-color:var(--night-border)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-light-toggle{background:#3b3523!important;color:#f1d58c!important;border-color:#70603e!important;box-shadow:0 0 0 2px #f1d58c0a}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-logout{color:#f5a3a7!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-display-panel,.po-font-control button,.po-history){background:var(--night-raised)!important;color:var(--night-text)!important;border-color:var(--night-border)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-display-panel p{color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-mode-panel{background:linear-gradient(180deg,#16272b,#132328)!important;border-color:#2b4147!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-modedivider>span{background:linear-gradient(90deg,transparent,#365249,transparent)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-mode-options .v4m-mode{background:#1b2d32!important;border-color:#385047!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-mode-options .v4m-mode-on{background:var(--v4-primary-soft)!important;border-color:var(--night-accent)!important;outline-color:var(--night-accent)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-mode>div:last-child>div:first-child{color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-mode-desc{color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-mode:not(.v4m-mode-on) .v4m-mode-ico{background:#273e36!important;color:#a5c6b4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar{background:#101b20f5!important;border-color:#2b4147!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-search-field label{color:#c0d3c8!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar .v4m-searchbox{background:var(--night-field)!important;color:#8fbaaa!important;border-color:#405e54!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar input{color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(input,textarea)::placeholder{color:#9ab0ac!important;opacity:1}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-search-clear{background:#294037!important;color:#cae7d8!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar .v4m-act-atestado{background:#213551!important;border-color:#415b81!important;color:#b4d0ff!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-certificate-icon{color:#b4d0ff!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar .hero-act-exam{background:#1b3034!important;border-color:#3b5554!important;color:#c6e4d4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-toolbar .hero-act-exam>button:last-child{background:#274354!important;color:#b0d4f4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-viewsel>span{color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-viewsel>div{background:#172a2f!important;border-color:#334b50!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-viewsel button:not([aria-pressed="true"]){color:#b9d0c5!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-apres{background:#312735!important;color:#f2b1d0!important;border-color:#7a4f6a!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-list-card,.po-ped-card){background:#1b2d32!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-list-card,.po-ped-card):hover{background:#243c3e!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-open-button{color:#ddece4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-open-button>span:last-child{color:#9ab8aa!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-ped-cid,.po-add-cid){background:#293a45!important;color:#bcd6ec!important;border-color:#42637b!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-list-card>span{background:#263e35!important;color:#b6d9c7!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .v4m-cols>div>div:first-child>span{background:#ffffff12!important;color:#f1faf5!important}
/* Reading and editing surfaces are themed with CSS only; stored HTML stays intact. */
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-dialog,.po-rx-card,.modal,.pt-mbox,.drawer,.history-drawer){background:var(--night-surface)!important;color:var(--night-text)!important;border-color:var(--night-border)!important;box-shadow:var(--shadow-lg)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-topline,.po-rx-actions,.po-rx-footer,.modal-header,.modal-footer,.editor-toolbar){background:#192d32!important;border-color:#344a50!important;color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-topline>span,.modal-title,.modal-eyebrow,.field>span){color:#c7ddd1!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-heading{border-color:#344a50!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-content{background:#101d23!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-content>div{background:#192a30!important;border-color:#3b5657!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-content .editor-area,.po-rx-content .editor-area.editable,.po-rx-content .editor-area.editable:focus){background:transparent!important;color:#dce8e3!important;caret-color:#9fe4c3}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-content .editor-area :is(p,span,div,li,strong,b,h1,h2,h3,h4,td,th){background-color:transparent!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-content .editor-area :is(h1,h2,h3,h4){color:#a0dfc0!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-tab{color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-tab[aria-pressed="true"]{color:#99e3bc!important;border-color:#99e3bc!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-rx-close,.po-rx-actions button[style*="background: rgb(255"],.po-rx-confirm button,.po-rx-metadata button,.po-ped-confirm button){background:#253b40!important;border-color:#47625d!important;color:#dfebe4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-ped-confirm{background:#3e282c!important;color:#f3c3c7!important;border-color:#745059!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-ped-confirm .po-ped-confirm-delete{background:#93404e!important;color:white!important}
html[data-color-mode="dark"][data-app-layout="wide"] body button[title="Apagar prescrição"]{color:#ffacb2!important;opacity:1!important}
/* Common controls and clinical modules share tokens; retain semantic status colors. */
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-app,.modal,.pt-mbox,.drawer,.history-drawer,.po-rx-dialog) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),select,textarea){background:var(--night-field)!important;color:var(--night-text)!important;border-color:#40585f!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-app,.modal,.po-rx-dialog) :is(input,textarea,select,button):focus-visible{outline:2px solid #8adab5!important;outline-offset:2px}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.card,.gaso-card,.calc-card,.ia-search-card,.ia-result-card,.ia-result-farmaco,.ia-result-doenca,.ia-result-caso,.ia-md-content,.pt-form-section,.pt-mbox-body,.ped-result,.ped-med-card,.ped-catalog-item,.pcv2-inputs,.pcv2-meds,.pcv2-med,.form-card,.account-card){background:var(--night-surface)!important;border-color:var(--night-border)!important;color:var(--night-text)!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.modal-body,.ped-calc-body-v2,.ped-catalog-body,.ia-tab-bar,.ped-meds-head,.pcv2-meds-head,.pcv2-med-body){background:var(--night-surface)!important;color:var(--night-text)!important;border-color:var(--night-border)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.modal-sub,.field-label,.form-label,.calc-label,.gaso-label,.pt-lbl,.pcv2-label,.ped-dose-meta,.ped-dose-pres,.ped-catalog-meta){color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.btn-ghost,.btn-secondary,.icon-btn,.editor-toolbar button,.ped-catalog-tab,.ped-filter-btn){background:#22363c!important;color:#c8ddd1!important;border-color:#405a5c!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-app,.modal,.drawer) :is(.section-title,.card-title,.gaso-title,.calc-title,.ia-title,.ped-dose-name){color:#a8dfc3!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.modal-overlay,.po-rx-backdrop){background:#061115bb!important}
html[data-color-mode="dark"][data-app-layout="wide"] body #localbar{background:#561f29!important;border-color:#77323e!important;color:#ffe1e4!important}
html[data-color-mode="dark"][data-app-layout="wide"] body #localbar .localbar-line{background:#561f29!important}
html[data-color-mode="dark"][data-app-layout="wide"] body #localbar :is(button,.localbar-panel){background:#702b38!important;color:#ffe4e8!important;border-color:#934553!important}
/* Paper previews intentionally remain paper-like. Printing uses separate styles. */
html[data-color-mode="dark"][data-app-layout="wide"] body .preview-paper{color-scheme:light;background:white!important;color:#17222a!important;border-color:#d9e1e5!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .preview-paper :is(p,span,div,h1,h2,h3,strong,b){color:inherit}
}
@media screen {
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-form-card,.gaso-section,.gaso-diag,.gaso-ox-card,.gaso-ref-box,.gaso-passo-body,.calc-crit-btn,.calc-result-card,.calc-pending,.calc-ref-table,.calc-note,.gcs-section,.gcs-section-hd,.gcs-opt,.ia-history-item,.ia-hist-body,.ia-doenca-card,.rename-toolbar-wrap,.rename-card,.rename-apres,.rename-apres-hd,.rename-footer,.pt-rc,.pt-lista-card,.pt-lista-hdr,.pt-row-acc,.pt-empty-state,.pt-cal,.pt-cal-dows,.pt-cc-e,.pt-cc-wknd,.pt-mbox,.pt-mbox-ftr,.pt-tog,.pt-sug,.pt-bloco,.pt-bloco-hdr,.pt-bloco-sec-hdr,.pt-cal-popup,.pt-turno-btn,.pt-rel-modal,.pt-rel-hdr,.pt-rel-sidebar,.pt-rel-card,.pt-rel-table,.pt-rel-th,.pt-tpl-item,.pt-lc-item,.pcv2-med-edit){background:var(--night-surface)!important;color:var(--night-text)!important;border-color:var(--night-border)!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-form-card,.gaso-section,.gaso-diag,.calc-view,.gcs-section,.rename-view,.pt-view,.ia-view,.pt-mbox) :is(h1,h2,h3,h4,label,th){color:#c8e0d2!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-form-title,.gaso-optional-title,.gaso-label,.gaso-ref,.calc-crit-text,.calc-ref-title,.gcs-opt-label,.gcs-section-title,.rename-name,.rename-nome,.rename-class,.pt-row-name,.pt-ri-loc,.pt-ri-name,.pt-mbox-title,.pt-mbox-sub,.pt-lista-title,.pt-bloco-title){color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-btn-clear,.ia-copy-btn,.pt-btn-sec,.pt-marr,.pt-tog-btn,.pt-turno-btn,.pt-rel-preset,.pt-scope-btn){background:#243b40!important;color:#c8ddd2!important;border-color:#48615f!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gcs-opt-on,.calc-crit-btn.on,.pt-tog-btn.on,.ia-tab-btn-on){background:#275040!important;color:#d8f6e5!important;border-color:#67b997!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-comp-bad,.gaso-err,.ia-error,.ia-urg-extrema,.pt-ferr,.pt-conflict-box){background:#46272e!important;color:#ffbec7!important;border-color:#84525c!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-comp-warn,.gaso-ox-warn,.calc-result-alert,.ia-urg-alertas,.pt-info-warn){background:#3d3422!important;color:#f7d598!important;border-color:#79653e!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.gaso-comp-ok,.ia-copy-btn-ok){background:#1d3d30!important;color:#a3e2bd!important;border-color:#477d5f!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .ped-badge{background:#432a3b!important;color:#f6b6d4!important}
/* Legacy neutral inline surfaces. Limit this bridge to app UI and exclude paper previews. */
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-app,.modal,.pt-mbox,.drawer) :is([style*="background: rgb(255, 255, 255)"],[style*="background: white"],[style*="background-color: rgb(255, 255, 255)"]):not(.preview-paper,.preview-paper *){background:var(--night-raised)!important;color:var(--night-text)!important;border-color:var(--night-border)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.po-app,.modal,.pt-mbox,.drawer) :is([style*="color: rgb(23, 37, 28)"],[style*="color: rgb(51, 71, 58)"],[style*="color: rgb(95, 115, 103)"],[style*="color: rgb(15, 23, 42)"],[style*="color: rgb(71, 85, 105)"]):not(.preview-paper,.preview-paper *){color:var(--night-text)!important}
}
@media screen {
html[data-color-mode="dark"]{--card:var(--night-surface)!important;--card-bg:var(--night-surface)!important;--ink:var(--night-text)!important;--ink-muted:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-sidebar .po-light-toggle{background:#3b3523!important;color:#f1d58c!important;border-color:#70603e!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.ia-prompt-card,.ia-prompt-area,.ia-prompt-footer,.av-main,.av-wrap,.av-repouso,.av-escolha-card,.av-creditos,.av-panel,.av-card){background:var(--night-surface)!important;color:var(--night-text)!important;border-color:var(--night-border)!important;box-shadow:none!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .av-main :is(h1,h2,h3,strong,p){color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.av-escolha-card small,.av-repouso small,.ia-mode-pill,.ia-tab-btn,.ia-prompt-ico,.rename-classe,.rename-uso-txt,.rename-uso-lbl,.pt-mlbl,.pt-rc-val,.pt-rc-lbl,.pt-cal-dow,.pt-cal-hint,.pt-empty-hint,.pt-bloco-sub){color:var(--night-muted)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.ia-mode-pill.ia-mode-active,.pt-hoje-btn,.pt-bloco-badge-cur){background:#354135!important;color:#c8eccf!important;border-color:#5c7560!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc{background:#192c32!important;border-color:#344a50!important;color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc-e{background:#13232a!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc-today{background:#264739!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc:hover{background:#2a403f!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc-num{color:#d3e5db!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-cc-past .pt-cc-num{color:#96b2a5!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-rc-ico{background:#2a3e43!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.pt-rg .pt-rc-val,.rename-via-badge[style*="color: rgb(22, 163, 74)"]){color:#8ed3ac!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .pt-ro .pt-rc-val{color:#efcc8f!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .rename-via-badge{color:#c4d8ed!important;border-color:#4a626e!important;background:#213641!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .po-rx-content .editor-area :is([style*="color: rgb(0, 0, 0)"],[style*="color: #000"],[style*="color: black"],font[color="black"],font[color="#000000"]){color:inherit!important}
}
@media screen {
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.paciente-prominent,.print-info-row,.opt-line--especial,.preview-wrap,.preview-container,.print-right){background:var(--night-raised)!important;border-color:var(--night-border)!important;color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.paciente-label-big,.preview-label){color:#b7d6c5!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .cab-box--vazio{background:#3b3220!important;border-color:#8c7441!important;color:#f1d49c!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .cab-box--vazio :is(.cab-box-nome,.cab-box-sub){color:#f1d49c!important}
}
@media screen {
html[data-color-mode="dark"][data-app-layout="wide"] body .av-main :is(b,.av-escolha-desc,.av-repouso span){color:var(--night-text)!important}
html[data-color-mode="dark"][data-app-layout="wide"] body :is(.pt-meta-btn,.pt-metas-btn){background:#243b40!important;color:#d6e9df!important;border-color:#47625d!important}
html[data-color-mode="dark"][data-app-layout="wide"] body .modal [style*="background: rgb(239, 246, 255)"]{background:#20374e!important;color:#b8d7fa!important;border-color:#456282!important}
}
