/* Tema do portal. Os estilos claros permanecem na folha original. */
html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #eaf2f8;
  --muted: #aabfce;
  --line: #34485e;
  --canvas: #0b1220;
  --panel: #152235;
  --surface: #1c2d43;
  --surface-hover: #263d57;
  --primary: #67d9e5;
  --primary-hover: #48c3d2;
  --sidebar: #081a2e;
  --success: #80d8ac;
  --warning: #f1c674;
  --danger: #ff919a;
  background: var(--canvas);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .login-page,
html[data-theme="dark"] .login-access {
  background: var(--canvas);
  color: var(--ink);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.theme-toggle:hover { border-color: var(--primary); background: var(--canvas); }
.theme-toggle [data-theme-icon] { font-size: 16px; line-height: 1; }
.login-theme-control { position: absolute; top: 20px; right: 24px; z-index: 2; }
html[data-theme="dark"] .theme-toggle { background: var(--surface); }
html[data-theme="dark"] .theme-toggle:hover { background: var(--surface-hover); }

/* Estrutura e superfícies comuns */
html[data-theme="dark"] :is(
  .topbar, .panel, .metric-card, .modal, .settings-card, .client-card,
  .download-card, .integration-card, .onboarding-steps article,
  .ticket-catalog-form, .ticket-catalog-results-card, .module-card,
  .network-summary-card, .device-metric-card, .device-combined-metric-card
) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(
  .panel-heading, .table-toolbar, .modal-actions, .user-client-access-tools,
  .ticket-dialog .modal-actions, .client-dialog .modal-actions,
  .device-context-dialog .modal-actions
) {
  background: var(--panel);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.metric-card strong, .cell-title, .client-card h3,
  .client-hierarchy-title, .settings-card-heading h2, .device-information-item dd,
  .device-combined-metric-card > h4, .network-summary-card strong,
  .installation-code-field label, .assistant-answer, .project-summary-card strong) {
  color: var(--ink);
}
html[data-theme="dark"] :is(.topbar-label, .topbar-divider, .table-total,
  .cell-subtitle, .field-help, .device-chart-legend, .device-combined-legend,
  .device-process-history-note, .project-timeline-range) {
  color: var(--muted);
}
html[data-theme="dark"] :is(.field label, .field-label,
  .client-list-scope, .knowledge-upload-form label,
  .financial-page label, .vault-layout label,
  .module-form label, .module-filter-bar label) {
  color: #d3e2ed;
}
html[data-theme="dark"] :is(.field .optional, .field-help,
  .module-history-changes span, .device-information-item dt,
  .settings-card p, .client-list-toolbar .muted) {
  color: var(--muted);
}
html[data-theme="dark"] .sidebar { background: var(--sidebar); }
html[data-theme="dark"] :is(.settings-card:hover, .download-card:hover,
  .integration-card:hover, .onboarding-steps article:hover) {
  background: var(--surface);
}

/* Entradas, botões e menus */
html[data-theme="dark"] :is(
  input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
  select, textarea, .search-field input, .user-client-access details,
  .user-actions-trigger, .module-actions-menu > summary,
  .device-metric-indicators summary, .mfa-choice
) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(input, textarea)::placeholder { color: #9bafbe; }
html[data-theme="dark"] :is(input[readonly], input:disabled, select:disabled,
  textarea:disabled, .recurring-readonly-field input) {
  background: #1a293b;
  color: var(--muted);
}
html[data-theme="dark"] :is(
  .button-secondary, .button-subtle, .icon-button, .row-button,
  .logout-button, .user-actions-menu-items .row-button,
  .wget-data-table-tools .wget-data-table-pagination button
) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.button-secondary, .button-subtle, .icon-button,
  .row-button, .user-actions-trigger, .user-actions-menu-items .row-button):hover {
  background: var(--surface-hover);
  color: var(--ink);
}
html[data-theme="dark"] .button-primary { color: #092230; }
html[data-theme="dark"] :is(.button-danger, .row-button-danger,
  .module-actions-menu-item.is-danger) {
  background: #4c2833;
  color: #ffc5c9;
  border-color: #925362;
}
html[data-theme="dark"] :is(.button-danger, .row-button-danger,
  .module-actions-menu-item.is-danger):hover {
  background: #63353f;
  color: #ffe0e3;
}
html[data-theme="dark"] :is(.text-link, .device-name-link, .device-cve-link,
  .auth-links a, .mfa-secret a, .mfa-resend button) {
  color: var(--primary);
}
html[data-theme="dark"] :is(.user-client-access summary,
  .user-client-option, .module-actions-menu-item,
  .device-metric-indicator-option) { color: var(--ink); }
html[data-theme="dark"] :is(.user-client-option:hover,
  .module-actions-menu-item:hover) { background: var(--surface-hover); }
html[data-theme="dark"] :is(.user-actions-menu-items, .module-actions-menu-items,
  .wget-data-table-tools > details > div) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

/* Tabelas e filtros */
html[data-theme="dark"] :is(table, table.wget-data-table) {
  background: var(--panel);
  color: var(--ink);
}
html[data-theme="dark"] :is(th, table.wget-data-table th,
  table.wget-data-table.wget-data-table-header-filters th,
  .project-report-table th) {
  background: #253c55;
  color: #f1f7fc;
  border-color: var(--line);
}
html[data-theme="dark"] :is(td, table.wget-data-table td) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(tbody tr:hover td,
  #ticket-clients-mount table.clients-hierarchy-table tr[data-hierarchy-depth]:not([data-hierarchy-depth="0"]):hover td) {
  background: var(--surface-hover);
}
html[data-theme="dark"] #ticket-clients-mount table.clients-hierarchy-table tr[data-hierarchy-depth]:not([data-hierarchy-depth="0"]) td {
  background: var(--surface);
}
html[data-theme="dark"] :is(
  .wget-data-table-tools > details summary,
  .wget-data-table-tools .wget-data-table-pagination button,
  .wget-data-table-sort-button,
  table.wget-data-table.wget-data-table-header-filters details.wget-data-table-header-filter summary,
  table.wget-data-table.wget-data-table-header-filters details.wget-data-table-header-filter button,
  .wget-multiselect-trigger, .wget-multiselect-popover,
  .wget-multiselect-search, .wget-multiselect-footer .wget-multiselect-cancel
) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.wget-multiselect-trigger:hover,
  .wget-multiselect-option:hover, label.wget-multiselect-select-all:hover,
  .wget-multiselect-footer .wget-multiselect-cancel:hover) {
  background: var(--surface-hover);
  color: var(--ink);
}
html[data-theme="dark"] .wget-multiselect-footer { border-color: var(--line); }
html[data-theme="dark"] table.wget-data-table.wget-data-table-header-filters details.wget-data-table-header-filter[open] > div,
html[data-theme="dark"] .wget-multiselect-popover,
html[data-theme="dark"] .wget-multiselect-options {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] table.wget-data-table.wget-data-table-header-filters details.wget-data-table-header-filter.is-active summary {
  background: #176b75;
  color: #f2fcff;
}
html[data-theme="dark"] .wget-data-table-tools > .wget-data-table-description {
  color: var(--muted);
}
html[data-theme="dark"] .wget-data-table-tools .wget-data-table-pagination button:disabled {
  color: var(--muted);
}

/* Atendimento, módulos e cadastros */
html[data-theme="dark"] :is(.ticket-catalog-form, .settings-scope,
  .assistant-scope, .assistant-summary, .client-hierarchy-kind,
  .module-placeholder-icon, .secret-output) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(#ticket-history .ticket-history-entry--company,
  #ticket-history .ticket-history-entry--customer,
  #ticket-history .ticket-history-entry--system,
  .module-history-event, .project-annotation) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] #ticket-history .ticket-history-entry--customer {
  background: #1c3947;
  border-color: #356b76;
}
html[data-theme="dark"] :is(.badge, .badge-muted) {
  background: #2b3d50;
  color: #d3e2ed;
}
html[data-theme="dark"] .badge-success { background: #1a4739; color: #a7ebc4; }
html[data-theme="dark"] .badge-warning { background: #513d20; color: #f9d78f; }
html[data-theme="dark"] .badge-danger { background: #542c36; color: #ffb7bb; }
html[data-theme="dark"] .badge-info { background: #1c4055; color: #a4e1f2; }
html[data-theme="dark"] :is(.notice-success, .toast) {
  background: #173f34;
  color: #b4ebcd;
  border-color: #3b8064;
}
html[data-theme="dark"] :is(.notice-danger, .toast-error, .form-error) {
  background: #4c2833;
  color: #ffc5c9;
  border-color: #925362;
}

/* Projetos, recorrência e gestão */
html[data-theme="dark"] :is(
  .project-general-section, .project-planner, .project-summary-card,
  .project-task-card, .project-task-editor-screen, .project-task-summary,
  .project-annotation-composer, .project-annotation-save-first,
  .project-timeline, .project-timeline-chart, .project-gantt-calendar,
  .project-gantt-month, .project-gantt-day, .recurring-form-section,
  .recurring-weekday-option, .recurring-tag-option, .recurring-readonly-field,
  .automation-rule-section, .automation-rule-row
) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(
  .project-general-section-heading, .project-planner-heading,
  .project-task-editor-header, .project-timeline-header,
  .project-gantt-weekdays, .recurring-form-section-heading,
  .recurring-weekday-options, .recurring-tag-options,
  .recurring-schedule-grid [data-field-key="active"],
  .recurring-editor-dialog > h2, .project-editor-dialog > h2,
  .recurring-editor-form > .module-editor-actions
) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.project-general-section-heading h3,
  .project-planner-heading h3, .project-task-editor-header h4,
  .recurring-form-section-heading h3, .project-annotations-heading h3,
  .project-gantt-day-number, .project-gantt-month h4,
  .project-annotation-content, .project-annotation-meta strong) {
  color: var(--ink);
}
html[data-theme="dark"] :is(.project-gantt-day.is-outside,
  .project-gantt-day.is-weekend) { background: #17263a; }
html[data-theme="dark"] :is(.financial-kpi-card, .vacation-calendar,
  .vacation-calendar-day, .financial-records-panel) {
  border-color: var(--line);
}
html[data-theme="dark"] .financial-kpi-card.financial-kpi-healthy {
  background: #173829;
  border-color: #3b8064;
}
html[data-theme="dark"] .financial-kpi-card.financial-kpi-warning {
  background: #3a301a;
  border-color: #9b793a;
}
html[data-theme="dark"] .financial-kpi-card.financial-kpi-exceeded {
  background: #44272e;
  border-color: #925362;
}
html[data-theme="dark"] .financial-kpi-card.financial-kpi-information {
  background: #1b364a;
  border-color: #45738f;
}
html[data-theme="dark"] .financial-kpi-card strong { color: var(--ink); }
html[data-theme="dark"] .financial-kpi-card .financial-kpi-label,
html[data-theme="dark"] .financial-kpi-card > p { color: var(--muted); }
html[data-theme="dark"] .financial-kpi-healthy .financial-kpi-status {
  background: #265441;
  color: #c2f0d4;
}
html[data-theme="dark"] .financial-kpi-warning .financial-kpi-status {
  background: #604d27;
  color: #ffecb8;
}
html[data-theme="dark"] .financial-kpi-exceeded .financial-kpi-status {
  background: #673942;
  color: #ffd6da;
}
html[data-theme="dark"] .financial-kpi-information .financial-kpi-status {
  background: #28506a;
  color: #d1eeff;
}

/* Inventário, dispositivos, gráficos e Secret */
html[data-theme="dark"] :is(.device-context-dialog, .device-information-item,
  .device-detail-table, .device-metric-card, .device-combined-metric-card,
  .network-summary-card, .network-topology-canvas, .inventory-map-panel,
  .inventory-map-toolbar, .inventory-map-equipment-bar, .inventory-map-viewport,
  .inventory-map-logical-viewport, .knowledge-tree, .vault-layout,
  .vault-table-card, .vault-detail-row) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.device-combined-chart, .metric-chart-background) {
  background: var(--surface);
  fill: var(--surface);
  border-color: var(--line);
}
html[data-theme="dark"] .metric-chart-grid { stroke: #40566c; }
html[data-theme="dark"] .metric-chart-axis { stroke: #9eb6c6; }
html[data-theme="dark"] :is(.metric-chart-label, .metric-network-scale,
  .metric-threshold-label) { fill: #c7dbe7; }
html[data-theme="dark"] :is(.device-tab-button[aria-selected="true"],
  .knowledge-tree-node, .vault-copy-value, .vault-eye-button,
  .vault-detail-row strong, .vault-totp-code) { color: var(--ink); }
html[data-theme="dark"] .knowledge-tree-node.is-selected { background: var(--surface-hover); }
html[data-theme="dark"] :is(.vault-copy-value, .vault-eye-button,
  .vault-secret-display, .vault-inline-value) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.vault-copy-value, .vault-eye-button):hover,
html[data-theme="dark"] .vault-eye-button.is-active {
  background: var(--surface-hover);
  color: var(--primary);
}
html[data-theme="dark"] :is(.inventory-map-panel, #inventory-map-canvas) {
  --brand-border: var(--line);
  --brand-white: var(--panel);
  --brand-navy1: var(--ink);
  --brand-navy2: #76dce8;
  --brand-navy4: #4fb4d8;
  --brand-paleyellow: #59451e;
}

/* Superfícies usadas pelos submenus. Algumas ainda usam cores claras fixas. */
html[data-theme="dark"] :is(
  .tenant-toolbar, .financial-employees-summary,
  .financial-table-totals > div, .knowledge-tree-pane,
  .knowledge-upload-form, .knowledge-file-panel .table-wrap,
  .ai-report-history article, .project-summary-grid,
  .automation-simulation-result, .m365-mail-test-panel,
  .device-context-navigation, .device-context-footer,
  .device-disk-summary-row, .device-metric-indicator-options,
  .device-process-history-note, .vacation-calendar,
  .vacation-calendar-weekdays, .inventory-map-floor-plan-controls,
  .settings-compact-module > .client-list-toolbar,
  .settings-compact-module > .settings-module-list,
  .ticket-catalog-modern .ticket-catalog-form,
  .ticket-catalog-modern .ticket-catalog-results-card,
  .assistant-chat-panel, .assistant-chat-answer,
  .device-vulnerability-card, .vault-totp-result,
  .vault-detail-row, .vault-secret-row
) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] .financial-page .module-list-wrapper > .wget-data-table-tools,
html[data-theme="dark"] .financial-employees-summary,
html[data-theme="dark"] .knowledge-tree-pane,
html[data-theme="dark"] .knowledge-upload-form {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(
  .knowledge-tree-pane .knowledge-pane-heading h3,
  .knowledge-content-pane .knowledge-folder-toolbar h3,
  .financial-employees-summary-heading h3,
  .financial-suppliers-panel .module-list-wrapper,
  .financial-page .wget-data-table-tools > label,
  .tenant-toolbar label, .settings-page-intro h2
) { color: var(--ink); }
html[data-theme="dark"] :is(
  .knowledge-tree-toggle, .knowledge-folder-toolbar .eyebrow,
  .financial-employees-summary-heading p,
  .settings-page-intro p, .settings-card-caption,
  .assistant-scope p, .assistant-summary-list dt,
  .assistant-evidence-meta, .assistant-limitations-list
) { color: var(--muted); }
html[data-theme="dark"] :is(
  .assistant-summary-list dd, .assistant-evidence-item strong,
  .module-history > h3, .module-history-event-header strong,
  .network-summary-label, .vault-password-history summary
) { color: var(--ink); }
html[data-theme="dark"] :is(
  .knowledge-tree-node:hover, .knowledge-tree-node.is-selected,
  .assistant-chat-user, .assistant-chat-answer,
  .alert-overview-link:hover, .module-actions-menu[open] > summary,
  .module-actions-menu-item:hover, .user-actions-menu[open] .user-actions-trigger
) { background: var(--surface-hover); color: var(--ink); }
html[data-theme="dark"] :is(
  .knowledge-tree-count, .module-actions-menu-item,
  .vault-protected-value, .project-gantt-legend-item i,
  .vacation-calendar-employee.status-planned
) { background: var(--surface); color: var(--muted); }
html[data-theme="dark"] .knowledge-tree-list .knowledge-tree-list {
  border-color: var(--line);
}
html[data-theme="dark"] .knowledge-tree-count {
  background: var(--surface-hover);
  color: var(--ink);
}
html[data-theme="dark"] .knowledge-tree-node.is-selected {
  background: #205368;
  color: #e4f9ff;
}
html[data-theme="dark"] :is(.sidebar-collapse,
  .wget-data-table-sort-button) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(
  .module-editor-dialog, .module-actions-dialog,
  .knowledge-dialog, .delete-device-dialog
) { background: var(--panel); color: var(--ink); }
html[data-theme="dark"] :is(
  .module-editor-dialog > h2, .module-actions-dialog > h2,
  .knowledge-dialog-heading, .module-history-event-header,
  .financial-table-totals
) { border-color: var(--line); }
html[data-theme="dark"] :is(
  .wget-data-table-tools > .page-info,
  .wget-data-table-tools > p[role="status"],
  .wget-data-table-tools > label,
  .module-list-wrapper > .field-label
) { color: var(--ink); }
html[data-theme="dark"] .wget-data-table-tools > .wget-data-table-description {
  color: var(--muted);
}
html[data-theme="dark"] :is(
  #knowledge-files-table, #project-documents-table,
  #vault-credentials-table, #module-table-licenses,
  #subclient-users-grid, #module-table-recurring_calls
).wget-data-table-header-filters tbody tr:not([hidden]) {
  background: var(--panel);
  color: var(--ink);
}
html[data-theme="dark"] :is(
  .knowledge-file-manager, .knowledge-content-pane,
  .financial-page .module-list-wrapper,
  .vault-layout, .assistant-result-content
) { color: var(--ink); }

/* Calendários e Gantt preservam as distinções de status no tema escuro. */
html[data-theme="dark"] :is(.project-gantt-day, .project-gantt-month,
  .project-gantt-calendar, .vacation-calendar-month, .vacation-calendar-day) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.project-gantt-day.is-outside,
  .project-gantt-day.is-weekend, .vacation-calendar-day.is-outside) {
  background: #121e2d;
  color: var(--muted);
}
html[data-theme="dark"] :is(.project-gantt-day.has-tasks,
  .vacation-calendar-day.has-vacation) { background: #1b3b48; }
html[data-theme="dark"] .vacation-calendar-day.has-planned { background: #263748; }
html[data-theme="dark"] .vacation-calendar-day.has-approved { background: #1b4536; }
html[data-theme="dark"] .vacation-calendar-day.has-in-progress { background: #4b3d21; }
html[data-theme="dark"] .vacation-calendar-day.has-holiday { background: #482c37; }
html[data-theme="dark"] :is(.project-gantt-event.status-todo,
  .project-timeline-bar.status-todo) { background: #334a60; color: var(--ink); }
html[data-theme="dark"] .project-gantt-event.status-doing {
  background: #604b25;
  color: #fff0c9;
}
html[data-theme="dark"] .project-gantt-event.is-critical {
  background: #63353d;
  color: #ffe0e4;
}

/* Avisos e controles que têm variantes claras codificadas diretamente. */
html[data-theme="dark"] :is(.notice-warning, .device-update-notice) {
  background: #41351d;
  color: #f6dc9d;
  border-color: #92713a;
}
html[data-theme="dark"] :is(.delete-device-warning,
  .device-metric-communication) {
  background: #452932;
  color: #ffd0d4;
  border-color: #9b5a67;
}
html[data-theme="dark"] :is(.inline-notice, .m365-mail-security,
  .mfa-secret) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] .mfa-qr img { background: #fff; }
html[data-theme="dark"] #inventory-map-canvas {
  --comment-bg-color: #59451e;
  --text-color: var(--ink);
}

/* Rótulos SVG da planta física usam cores fixas no tema claro. */
html[data-theme="dark"] #inventory-map-canvas .inventory-map-node rect { fill: var(--surface); stroke: var(--primary); }
html[data-theme="dark"] #inventory-map-canvas .inventory-map-node text { fill: var(--ink); font-weight: 700; }
html[data-theme="dark"] #inventory-map-canvas .inventory-map-node.is-selected rect { fill: var(--primary); }
html[data-theme="dark"] #inventory-map-canvas .inventory-map-node.is-selected text { fill: #092230; }
html[data-theme="dark"] #inventory-map-canvas .inventory-map-note text { fill: #fff2cc; font-weight: 600; }
html[data-theme="dark"] #inventory-map-canvas .inventory-map-edge text {
  fill: var(--ink);
  stroke: #0b1220;
  stroke-width: 3px;
  stroke-linejoin: round;
  paint-order: stroke fill;
}
html[data-theme="dark"] #inventory-map-canvas .inventory-map-edge > path:not(.inventory-map-hit) { stroke: var(--primary); }
html[data-theme="dark"] .inventory-map-toolbar button.button-primary { background-color: var(--primary); color: #092230; }
html[data-theme="dark"] .inventory-map-floor-plan-name { color: var(--muted); }

/* Campos de texto e rodapé do chamado no tema escuro. */
html[data-theme="dark"] .ticket-dialog .ticket-reply-editor {
  background-color: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  caret-color: var(--ink);
}
html[data-theme="dark"] .ticket-dialog .ticket-final-actions {
  background-color: var(--panel);
  border-color: var(--line);
}

@media (max-width: 680px) {
  .topbar .theme-toggle { width: 34px; padding: 5px; }
  .topbar .theme-toggle [data-theme-label] { display: none; }
  .login-theme-control { top: 14px; right: 14px; }
}
