/* Tema global do painel. Cores de status continuam sob responsabilidade dos modulos. */
:root,
[data-theme="dark"] {
    --theme-bg-page: #0f1115;
    --theme-bg-header: #121418;
    --theme-bg-secondary: #111827;
    --theme-bg-card: #18202c;
    --theme-bg-card-secondary: #222b38;
    --theme-text-primary: #f8fafc;
    --theme-text-secondary: #d1d9e6;
    --theme-text-muted: #aebacd;
    --theme-border-primary: #334155;
    --theme-border-secondary: #263244;
    --theme-accent: #20c8ff;
    --theme-accent-hover: #52d6ff;
    --theme-input-bg: #111827;
    --theme-input-text: #f8fafc;
    --theme-shadow: rgba(0, 0, 0, .42);
    --theme-surface-1: #111827;
    --theme-surface-2: #161e2a;
    --theme-surface-3: #1f2937;
    --theme-surface-hover: #263244;
    --theme-text-inverse: #111827;
    --theme-text-on-dark: #f8fafc;
    --theme-text-on-dark-muted: #dbeafe;
    --theme-input-placeholder: #aebacd;
    --theme-input-border: #475569;
    --theme-disabled-bg: #1e293b;
    --theme-disabled-text: #aebacd;
    --theme-disabled-border: #475569;
    --theme-divider: #263244;
    --theme-button-bg: #161e2a;
    --theme-button-text: #f8fafc;
    --theme-button-border: #475569;
    --theme-button-hover: #263244;
    --theme-modal-bg: #111827;
    --theme-dropdown-bg: #111827;
    --theme-success-bg: #123524;
    --theme-success-text: #bbf7d0;
    --theme-success-border: #287a4c;
    --theme-warning-bg: #3b2a0b;
    --theme-warning-text: #fde68a;
    --theme-warning-border: #8a6417;
    --theme-danger-bg: #3f1724;
    --theme-danger-text: #fecdd3;
    --theme-danger-border: #8b3045;
    --theme-info-bg: #102f45;
    --theme-info-text: #bae6fd;
    --theme-info-border: #246487;
    color-scheme: dark;
}

[data-theme="light"] {
    --theme-bg-page: #f3f6f9;
    --theme-bg-header: #ffffff;
    --theme-bg-secondary: #f8fafc;
    --theme-bg-card: #ffffff;
    --theme-bg-card-secondary: #eef2f6;
    --theme-text-primary: #111827;
    --theme-text-secondary: #334155;
    --theme-text-muted: #52657a;
    --theme-border-primary: #cbd5e1;
    --theme-border-secondary: #d7e0ea;
    --theme-accent: #0077b6;
    --theme-accent-hover: #005f91;
    --theme-input-bg: #ffffff;
    --theme-input-text: #111827;
    --theme-shadow: rgba(15, 23, 42, .14);
    --theme-surface-1: #ffffff;
    --theme-surface-2: #f8fafc;
    --theme-surface-3: #eef2f6;
    --theme-surface-hover: #e8eef5;
    --theme-text-inverse: #ffffff;
    --theme-text-on-dark: #ffffff;
    --theme-text-on-dark-muted: #dbeafe;
    --theme-input-placeholder: #64748b;
    --theme-input-border: #b8c5d3;
    --theme-disabled-bg: #f1f5f9;
    --theme-disabled-text: #52657a;
    --theme-disabled-border: #94a3b8;
    --theme-divider: #d8e0e8;
    --theme-button-bg: #ffffff;
    --theme-button-text: #334155;
    --theme-button-border: #94a3b8;
    --theme-button-hover: #e8eef5;
    --theme-modal-bg: #ffffff;
    --theme-dropdown-bg: #ffffff;
    --theme-success-bg: #f0fdf4;
    --theme-success-text: #166534;
    --theme-success-border: #86efac;
    --theme-warning-bg: #fffbeb;
    --theme-warning-text: #92400e;
    --theme-warning-border: #fcd34d;
    --theme-danger-bg: #fef2f2;
    --theme-danger-text: #991b1b;
    --theme-danger-border: #fca5a5;
    --theme-info-bg: #eff6ff;
    --theme-info-text: #1e40af;
    --theme-info-border: #93c5fd;
    color-scheme: light;
}

html,
body {
    background-color: var(--theme-bg-page);
    color: var(--theme-text-primary);
}

body,
button,
input,
select,
textarea {
    transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}

/* Contraste minimo global, inclusive em templates com CSS inline. */
[data-theme="dark"] body {
    color: var(--theme-text-primary);
}

[data-theme="dark"] .card .tempo,
[data-theme="dark"] .card small.tempo,
[data-theme="dark"] .card small.tempo-total,
[data-theme="dark"] .tempo,
[data-theme="dark"] .muted {
    color: var(--theme-text-secondary);
}

[data-theme="dark"] .card small.tempo-total {
    color: #38c9ff;
}

[data-theme="light"] body,
[data-theme="light"] .page,
[data-theme="light"] .dashboard-page,
[data-theme="light"] .devolucoes-page,
[data-theme="light"] .chat-page,
[data-theme="light"] .pecas-page,
[data-theme="light"] .localizacao-page,
[data-theme="light"] .cliente-localizacao-page,
[data-theme="light"] .consulta-clientes-page,
[data-theme="light"] .atividades-page {
    background: var(--theme-bg-page);
    color: var(--theme-text-primary);
}

[data-theme="light"] header,
[data-theme="light"] .topbar,
[data-theme="light"] .header-clean,
[data-theme="light"] .pecas-topbar,
[data-theme="light"] .dashboard-topbar,
[data-theme="light"] .localizacao-topbar,
[data-theme="light"] .chat-topbar,
    background: var(--theme-bg-header);
    color: var(--theme-text-primary);
    border-color: var(--theme-border-secondary);
    box-shadow: 0 2px 10px var(--theme-shadow);
}

[data-theme="light"] .card,
[data-theme="light"] .panel,
[data-theme="light"] .box,
[data-theme="light"] .glass,
[data-theme="light"] .header-card,
[data-theme="light"] .table-card,
[data-theme="light"] .mes-card,
[data-theme="light"] .calendar,
[data-theme="light"] .summary,
[data-theme="light"] .sum-card,
[data-theme="light"] .saldo-box,
[data-theme="light"] .info-card,
[data-theme="light"] .hero-card,
[data-theme="light"] .form-admin,
[data-theme="light"] .modal-content,
[data-theme="light"] .pecas-card,
[data-theme="light"] .pecas-panel,
[data-theme="light"] .pecas-modal-box,
[data-theme="light"] .pecas-drawer,
[data-theme="light"] .cliente-loc-card,
[data-theme="light"] .atividades-card,
[data-theme="light"] .devolucoes-card,
[data-theme="light"] .devolucoes-report,
    background: var(--theme-bg-card);
    color: var(--theme-text-primary);
    border-color: var(--theme-border-primary);
    box-shadow: 0 8px 24px var(--theme-shadow);
}

[data-theme="light"] .tipo-card,
[data-theme="light"] .filtro,
[data-theme="light"] .filtro-data,
[data-theme="light"] .day,
[data-theme="light"] .chat-box,
[data-theme="light"] .filters,
[data-theme="light"] .empty-state,
[data-theme="light"] .wizard,
[data-theme="light"] .steps,
[data-theme="light"] .info-box,
[data-theme="light"] .checkbox-box,
[data-theme="light"] .mes-head,
[data-theme="light"] .chat-sidebar,
[data-theme="light"] .chat-main,
[data-theme="light"] .chat-header,
[data-theme="light"] .chat-list,
[data-theme="light"] .pecas-hero,
[data-theme="light"] .pecas-toolbar,
[data-theme="light"] .pecas-table-wrap,
[data-theme="light"] .atividades-toolbar,
[data-theme="light"] .atividades-table-wrap,
[data-theme="light"] .localizacao-hero {
    background: var(--theme-surface-2);
    color: var(--theme-text-primary);
    border-color: var(--theme-border-primary);
}

[data-theme="light"] .content,
[data-theme="light"] .panel-body,
[data-theme="light"] .modal-section,
[data-theme="light"] .table-wrap,
[data-theme="light"] .pecas-modal-body,
[data-theme="light"] .pecas-drawer-body,
[data-theme="light"] .chat-conversation-body {
    background-color: var(--theme-bg-card);
    color: var(--theme-text-primary);
    border-color: var(--theme-border-secondary);
}

[data-theme="light"] h1,
[data-theme="light"] h2,
[data-theme="light"] h3,
[data-theme="light"] h4,
[data-theme="light"] h5,
[data-theme="light"] .title,
[data-theme="light"] .panel-title,
[data-theme="light"] .header-card h1 {
    color: var(--theme-text-primary);
}

[data-theme="light"] label,
[data-theme="light"] .subtitle,
[data-theme="light"] .sub,
[data-theme="light"] .muted,
[data-theme="light"] .vazio,
[data-theme="light"] .empty,
[data-theme="light"] .saldo-label,
[data-theme="light"] .info-atualizacao,
[data-theme="light"] .metric-title,
[data-theme="light"] .sum-card .label,
[data-theme="light"] .header-card p,
[data-theme="light"] .panel-title p {
    color: var(--theme-text-secondary);
}

[data-theme="light"] .column h3,
[data-theme="light"] .pecas-eyebrow,
[data-theme="light"] .cliente-loc-eyebrow,
[data-theme="light"] .localizacao-eyebrow,
[data-theme="light"] a:not(.btn):not([class*="button"]) {
    color: var(--theme-accent);
}

[data-theme="light"] .card .tempo,
[data-theme="light"] .card small.tempo,
[data-theme="light"] .tempo,
[data-theme="light"] .timer,
[data-theme="light"] [class*="timer"],
[data-theme="light"] [class*="tempo"] {
    color: var(--theme-text-muted);
}

[data-theme="light"] .card small.tempo-total,
[data-theme="light"] .tempo-total,
[data-theme="light"] [class*="tempo-ativo"] {
    color: var(--theme-accent);
}

[data-theme] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
[data-theme] select,
[data-theme] textarea,
[data-theme] option {
    background-color: var(--theme-input-bg);
    color: var(--theme-input-text);
    border-color: var(--theme-border-primary);
}

[data-theme] input::placeholder,
[data-theme] textarea::placeholder {
    color: var(--theme-input-placeholder);
    opacity: 1;
}

[data-theme="light"] input:focus,
[data-theme="light"] select:focus,
[data-theme="light"] textarea:focus {
    border-color: var(--theme-accent);
    outline-color: var(--theme-accent);
    box-shadow: 0 0 0 2px rgba(0, 119, 182, .16);
}

[data-theme="light"] table {
    color: var(--theme-text-primary);
    border-color: var(--theme-border-primary);
}

[data-theme="light"] thead,
[data-theme="light"] th {
    background-color: var(--theme-bg-card-secondary);
    color: var(--theme-text-secondary);
    border-color: var(--theme-border-primary);
}

[data-theme="light"] td,
[data-theme="light"] tr {
    border-color: var(--theme-border-secondary);
}

[data-theme="light"] tbody tr:hover {
    background-color: rgba(0, 119, 182, .07);
}

[data-theme="light"] .menu-dropdown,
[data-theme="light"] .codigo-menu,
[data-theme="light"] [class*="context-menu"],
[data-theme="light"] [class*="popover"] {
    background: var(--theme-bg-card);
    color: var(--theme-text-primary);
    border-color: var(--theme-border-primary);
    box-shadow: 0 18px 40px var(--theme-shadow);
}

[data-theme="light"] .menu-item,
[data-theme="light"] .submenu-toggle,
[data-theme="light"] .codigo-menu button {
    color: var(--theme-text-primary);
}

[data-theme="light"] .menu-item:hover,
[data-theme="light"] .submenu-toggle:hover,
[data-theme="light"] .codigo-menu button:hover {
    background: rgba(0, 119, 182, .1);
    color: var(--theme-accent);
}

[data-theme="light"] .modal {
    color: var(--theme-text-primary);
}

[data-theme="light"] .modal-content {
    background: var(--theme-modal-bg);
    border-color: var(--theme-border-primary);
}

[data-theme="light"] .cbtn.ghost,
[data-theme="light"] .btn.outline,
[data-theme="light"] .btn-top:not(.warning),
[data-theme="light"] button.cancel,
[data-theme="light"] button.ghost {
    background: var(--theme-button-bg);
    color: var(--theme-button-text);
    border-color: var(--theme-button-border);
}

[data-theme="light"] .cbtn.ghost:hover,
[data-theme="light"] .btn.outline:hover,
[data-theme="light"] .btn-top:not(.warning):hover,
[data-theme="light"] button.cancel:hover,
[data-theme="light"] button.ghost:hover {
    background: var(--theme-button-hover);
    color: var(--theme-text-primary);
}

[data-theme="light"] button:disabled,
[data-theme="light"] input:disabled,
[data-theme="light"] select:disabled,
[data-theme="light"] textarea:disabled,
[data-theme="light"] .cbtn:disabled,
[data-theme="light"] .cbtn.disabled {
    background: var(--theme-disabled-bg);
    color: var(--theme-disabled-text);
    border-color: var(--theme-disabled-border);
    opacity: .78;
    box-shadow: none;
}

[data-theme="light"] input:read-only,
[data-theme="light"] textarea:read-only {
    background: var(--theme-surface-2);
    color: var(--theme-text-secondary);
}

[data-theme="dark"] button:disabled,
[data-theme="dark"] input:disabled,
[data-theme="dark"] select:disabled,
[data-theme="dark"] textarea:disabled,
[data-theme="dark"] .cbtn:disabled,
[data-theme="dark"] .cbtn.disabled {
    background: var(--theme-disabled-bg);
    color: var(--theme-disabled-text);
    border-color: var(--theme-disabled-border);
    opacity: .78;
    box-shadow: none;
}

[data-theme="light"] .alert.error,
[data-theme="light"] .alert.danger,
[data-theme="light"] .error-message,
[data-theme="light"] [role="alert"].error {
    background: var(--theme-danger-bg);
    color: var(--theme-danger-text);
    border-color: var(--theme-danger-border);
}

[data-theme="light"] .erro,
[data-theme="light"] .alert-error,
[data-theme="light"] .message.error,
[data-theme="light"] .pecas-message.error,
[data-theme="light"] .cliente-loc-message.error {
    background: var(--theme-danger-bg);
    color: var(--theme-danger-text);
    border-color: var(--theme-danger-border);
}

[data-theme="light"] .alert.success,
[data-theme="light"] .success-message {
    background: var(--theme-success-bg);
    color: var(--theme-success-text);
    border-color: var(--theme-success-border);
}

[data-theme="light"] .alert-success,
[data-theme="light"] .message.success,
[data-theme="light"] .pecas-message.success,
[data-theme="light"] .cliente-loc-message.success {
    background: var(--theme-success-bg);
    color: var(--theme-success-text);
    border-color: var(--theme-success-border);
}

[data-theme="light"] .alert.warning,
[data-theme="light"] .warning-message {
    background: var(--theme-warning-bg);
    color: var(--theme-warning-text);
    border-color: var(--theme-warning-border);
}

[data-theme="light"] .alert-warning,
[data-theme="light"] .message.warning {
    background: var(--theme-warning-bg);
    color: var(--theme-warning-text);
    border-color: var(--theme-warning-border);
}

[data-theme="light"] .alert.info,
[data-theme="light"] .info-message {
    background: var(--theme-info-bg);
    color: var(--theme-info-text);
    border-color: var(--theme-info-border);
}

[data-theme="light"] .alert-info,
[data-theme="light"] .message.info,
[data-theme="light"] .pecas-message.info,
[data-theme="light"] .cliente-loc-message.info {
    background: var(--theme-info-bg);
    color: var(--theme-info-text);
    border-color: var(--theme-info-border);
}

[data-theme="dark"] .alert.error,
[data-theme="dark"] .alert.danger,
[data-theme="dark"] .error-message {
    background: var(--theme-danger-bg);
    color: var(--theme-danger-text);
    border-color: var(--theme-danger-border);
}

[data-theme="dark"] .alert.success,
[data-theme="dark"] .success-message {
    background: var(--theme-success-bg);
    color: var(--theme-success-text);
    border-color: var(--theme-success-border);
}

[data-theme="dark"] .alert.warning,
[data-theme="dark"] .warning-message {
    background: var(--theme-warning-bg);
    color: var(--theme-warning-text);
    border-color: var(--theme-warning-border);
}

[data-theme="dark"] .alert.info,
[data-theme="dark"] .info-message {
    background: var(--theme-info-bg);
    color: var(--theme-info-text);
    border-color: var(--theme-info-border);
}

::selection {
    background: var(--theme-accent);
    color: var(--theme-text-inverse);
}

button svg,
a svg {
    fill: currentColor;
    stroke: currentColor;
}

[data-theme="light"] * {
    scrollbar-color: #94a3b8 #e7edf3;
}

[data-theme="light"] *::-webkit-scrollbar-track {
    background: #e7edf3;
}

[data-theme="light"] *::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-color: #e7edf3;
}

.purchase-notification-toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 12000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    width: min(390px, calc(100vw - 32px));
    pointer-events: none;
}

.purchase-notification-toast {
    position: relative;
    display: grid;
    gap: 7px;
    padding: 16px;
    border: 1px solid var(--theme-border-primary);
    border-radius: 12px;
    background: var(--theme-bg-card);
    color: var(--theme-text-primary);
    box-shadow: 0 16px 36px var(--theme-shadow);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: auto;
    cursor: pointer;
}

.purchase-notification-toast.visible { opacity: 1; transform: translateY(0); }
.purchase-notification-toast.leaving { opacity: 0; transform: translateX(16px); }
.purchase-notification-title { padding-right: 24px; font-size: .96rem; }
.purchase-notification-body { color: var(--theme-text-secondary); white-space: pre-line; line-height: 1.4; }
.purchase-notification-toast small { color: var(--theme-text-muted); }

.purchase-notification-close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: 0;
    background: transparent;
    color: var(--theme-text-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

.purchase-notification-open {
    justify-self: end;
    padding: 5px 0;
    border: 0;
    background: transparent;
    color: var(--theme-accent);
    font-weight: 700;
    cursor: pointer;
}

@media (max-width: 560px) {
    .purchase-notification-toasts {
        right: 16px;
        bottom: 16px;
    }
}
