/**
 * Tema do Hub de Ferramentas Carmelitas
 * Tokens semânticos + remap de utilitários Tailwind no modo escuro.
 * O modo claro permanece nas classes existentes (sem substituição).
 */

.hub-theme-control {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.hub-theme-control__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #4b5563;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.hub-theme-control__select {
    min-height: 2.75rem;
    min-width: 7.5rem;
    padding: 0.375rem 1.75rem 0.375rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background-color: #fff;
    color: #111827;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    cursor: pointer;
    appearance: auto;
}

.hub-theme-control__select:hover {
    border-color: #9ca3af;
}

.hub-theme-control__select:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-color: #2563eb;
}

@media (max-width: 640px) {
    .hub-theme-control__label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

html[data-theme="light"] {
    color-scheme: light;
    --hub-bg-page: #f9fafb;
    --hub-bg-surface: #ffffff;
    --hub-bg-muted: #f3f4f6;
    --hub-bg-elevated: #e5e7eb;
    --hub-text-primary: #111827;
    --hub-text-secondary: #4b5563;
    --hub-text-muted: #6b7280;
    --hub-text-placeholder: #9ca3af;
    --hub-border: #e5e7eb;
    --hub-border-strong: #d1d5db;
    --hub-link: #2563eb;
    --hub-focus: #2563eb;
    --hub-input-bg: #ffffff;
    --hub-overlay: rgba(15, 23, 42, 0.5);
    --hub-success-bg: #d1fae5;
    --hub-success-fg: #065f46;
    --hub-warning-bg: #fef3c7;
    --hub-warning-fg: #92400e;
    --hub-error-bg: #fee2e2;
    --hub-error-fg: #991b1b;
    --hub-info-bg: #eff6ff;
    --hub-info-fg: #1e40af;
    --hub-chart-bg: #ffffff;
    --hub-chart-fg: #333333;
    --hub-chart-muted: #666666;
    --hub-chart-grid: #f0f0f0;
    --hub-chart-axis: #dddddd;
    --hub-theme-color: #f9fafb;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --hub-bg-page: #0f172a;
    --hub-bg-surface: #1e293b;
    --hub-bg-muted: #243044;
    --hub-bg-elevated: #334155;
    --hub-text-primary: #f1f5f9;
    --hub-text-secondary: #cbd5e1;
    --hub-text-muted: #94a3b8;
    --hub-text-placeholder: #94a3b8;
    --hub-border: #334155;
    --hub-border-strong: #475569;
    --hub-link: #93c5fd;
    --hub-focus: #60a5fa;
    --hub-input-bg: #1e293b;
    --hub-overlay: rgba(2, 6, 23, 0.72);
    --hub-success-bg: rgba(16, 185, 129, 0.18);
    --hub-success-fg: #6ee7b7;
    --hub-warning-bg: rgba(245, 158, 11, 0.18);
    --hub-warning-fg: #fcd34d;
    --hub-error-bg: rgba(239, 68, 68, 0.18);
    --hub-error-fg: #fca5a5;
    --hub-info-bg: rgba(59, 130, 246, 0.18);
    --hub-info-fg: #bfdbfe;
    --hub-chart-bg: #1e293b;
    --hub-chart-fg: #e2e8f0;
    --hub-chart-muted: #94a3b8;
    --hub-chart-grid: #334155;
    --hub-chart-axis: #475569;
    --hub-theme-color: #0f172a;
}

html[data-theme="dark"] body {
    background-color: var(--hub-bg-page);
    color: var(--hub-text-primary);
}

html[data-theme="dark"] header {
    background-color: var(--hub-bg-surface) !important;
    border-bottom-color: var(--hub-border) !important;
}

html[data-theme="dark"] footer {
    background-color: var(--hub-bg-surface);
    border-top-color: var(--hub-border);
}

html[data-theme="dark"] .hub-theme-control__label {
    color: var(--hub-text-muted);
}

html[data-theme="dark"] .hub-theme-control__select {
    background-color: var(--hub-input-bg);
    color: var(--hub-text-primary);
    border-color: var(--hub-border-strong);
}

.hub-logo--dark {
    display: none;
}

html[data-theme="dark"] .hub-logo--light {
    display: none;
}

html[data-theme="dark"] .hub-logo--dark {
    display: inline;
}

/* --- Utilitários Tailwind: superfícies --- */
html[data-theme="dark"] .bg-white { background-color: var(--hub-bg-surface) !important; }
html[data-theme="dark"] .bg-gray-50,
html[data-theme="dark"] .bg-slate-50 { background-color: var(--hub-bg-page) !important; }
html[data-theme="dark"] .bg-gray-100,
html[data-theme="dark"] .bg-slate-100 { background-color: var(--hub-bg-muted) !important; }
html[data-theme="dark"] .bg-gray-200,
html[data-theme="dark"] .bg-slate-200 { background-color: var(--hub-bg-elevated) !important; }
html[data-theme="dark"] .bg-gray-300 { background-color: var(--hub-border-strong) !important; }

html[data-theme="dark"] .hover\:bg-gray-50:hover,
html[data-theme="dark"] .hover\:bg-slate-50:hover { background-color: var(--hub-bg-muted) !important; }
html[data-theme="dark"] .hover\:bg-gray-100:hover { background-color: var(--hub-bg-elevated) !important; }
html[data-theme="dark"] .hover\:bg-gray-200:hover,
html[data-theme="dark"] .hover\:bg-gray-300:hover { background-color: #475569 !important; }
html[data-theme="dark"] .hover\:bg-white:hover { background-color: var(--hub-bg-muted) !important; }

html[data-theme="dark"] .even\:bg-gray-50:nth-child(even),
html[data-theme="dark"] .even\:bg-gray-100:nth-child(even) { background-color: var(--hub-bg-muted) !important; }

/* Tinted states */
html[data-theme="dark"] .bg-blue-50,
html[data-theme="dark"] .bg-indigo-50,
html[data-theme="dark"] .bg-sky-50,
html[data-theme="dark"] .bg-cyan-50 { background-color: var(--hub-info-bg) !important; }
html[data-theme="dark"] .bg-blue-100 { background-color: rgba(59, 130, 246, 0.28) !important; }
html[data-theme="dark"] .bg-red-50,
html[data-theme="dark"] .bg-rose-50,
html[data-theme="dark"] .bg-pink-50 { background-color: var(--hub-error-bg) !important; }
html[data-theme="dark"] .bg-red-100 { background-color: rgba(239, 68, 68, 0.28) !important; }
html[data-theme="dark"] .bg-green-50,
html[data-theme="dark"] .bg-emerald-50,
html[data-theme="dark"] .bg-teal-50 { background-color: var(--hub-success-bg) !important; }
html[data-theme="dark"] .bg-green-100 { background-color: rgba(16, 185, 129, 0.28) !important; }
html[data-theme="dark"] .bg-yellow-50,
html[data-theme="dark"] .bg-amber-50,
html[data-theme="dark"] .bg-orange-50 { background-color: var(--hub-warning-bg) !important; }
html[data-theme="dark"] .bg-yellow-100,
html[data-theme="dark"] .bg-amber-100 { background-color: rgba(245, 158, 11, 0.28) !important; }
html[data-theme="dark"] .bg-purple-50,
html[data-theme="dark"] .bg-violet-50,
html[data-theme="dark"] .bg-fuchsia-50 { background-color: rgba(139, 92, 246, 0.18) !important; }

html[data-theme="dark"] .hover\:bg-blue-50:hover { background-color: var(--hub-info-bg) !important; }

/* --- Texto --- */
html[data-theme="dark"] .text-gray-900,
html[data-theme="dark"] .text-slate-900,
html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-slate-800 { color: var(--hub-text-primary) !important; }
html[data-theme="dark"] .text-gray-700,
html[data-theme="dark"] .text-slate-700 { color: var(--hub-text-secondary) !important; }
html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-slate-600 { color: var(--hub-text-secondary) !important; }
html[data-theme="dark"] .text-gray-500,
html[data-theme="dark"] .text-slate-500,
html[data-theme="dark"] .text-gray-400,
html[data-theme="dark"] .text-slate-400 { color: var(--hub-text-muted) !important; }

html[data-theme="dark"] .hover\:text-gray-900:hover { color: var(--hub-text-primary) !important; }
html[data-theme="dark"] .hover\:text-gray-700:hover { color: var(--hub-text-secondary) !important; }

html[data-theme="dark"] .text-blue-600,
html[data-theme="dark"] .text-blue-700,
html[data-theme="dark"] .text-blue-800,
html[data-theme="dark"] .hover\:text-blue-600:hover,
html[data-theme="dark"] .hover\:text-blue-700:hover { color: var(--hub-link) !important; }
html[data-theme="dark"] .text-blue-900 { color: #dbeafe !important; }
html[data-theme="dark"] .text-indigo-600,
html[data-theme="dark"] .text-indigo-700,
html[data-theme="dark"] .text-indigo-800 { color: #c4b5fd !important; }

html[data-theme="dark"] .text-red-500,
html[data-theme="dark"] .text-red-600,
html[data-theme="dark"] .text-red-700,
html[data-theme="dark"] .text-red-800,
html[data-theme="dark"] .text-red-900 { color: var(--hub-error-fg) !important; }
html[data-theme="dark"] .text-green-600,
html[data-theme="dark"] .text-green-700,
html[data-theme="dark"] .text-green-800,
html[data-theme="dark"] .text-green-900,
html[data-theme="dark"] .text-emerald-700 { color: var(--hub-success-fg) !important; }
html[data-theme="dark"] .text-yellow-700,
html[data-theme="dark"] .text-yellow-800,
html[data-theme="dark"] .text-yellow-900,
html[data-theme="dark"] .text-amber-700,
html[data-theme="dark"] .text-amber-800,
html[data-theme="dark"] .text-amber-900,
html[data-theme="dark"] .text-amber-950,
html[data-theme="dark"] .text-orange-700 { color: var(--hub-warning-fg) !important; }
html[data-theme="dark"] .text-purple-700,
html[data-theme="dark"] .text-purple-800 { color: #d8b4fe !important; }

/* --- Bordas --- */
html[data-theme="dark"] .border-gray-100,
html[data-theme="dark"] .border-gray-200,
html[data-theme="dark"] .border-slate-200 { border-color: var(--hub-border) !important; }
html[data-theme="dark"] .border-gray-300,
html[data-theme="dark"] .border-slate-300 { border-color: var(--hub-border-strong) !important; }
html[data-theme="dark"] .border-gray-400 { border-color: #64748b !important; }
html[data-theme="dark"] .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: var(--hub-border) !important; }

html[data-theme="dark"] .border-blue-100,
html[data-theme="dark"] .border-blue-200 { border-color: rgba(96, 165, 250, 0.35) !important; }
html[data-theme="dark"] .border-red-200,
html[data-theme="dark"] .border-red-100 { border-color: rgba(248, 113, 113, 0.35) !important; }
html[data-theme="dark"] .border-green-200,
html[data-theme="dark"] .border-emerald-200 { border-color: rgba(52, 211, 153, 0.35) !important; }
html[data-theme="dark"] .border-yellow-200,
html[data-theme="dark"] .border-amber-100,
html[data-theme="dark"] .border-amber-200 { border-color: rgba(251, 191, 36, 0.35) !important; }
html[data-theme="dark"] .border-purple-200 { border-color: rgba(167, 139, 250, 0.35) !important; }

/* --- Formulários --- */
html[data-theme="dark"] input:not([type="submit"]):not([type="button"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]):not([type="color"]):not([type="image"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background-color: var(--hub-input-bg);
    color: var(--hub-text-primary);
    border-color: var(--hub-border-strong);
    caret-color: var(--hub-text-primary);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: var(--hub-text-placeholder);
    opacity: 1;
}

html[data-theme="dark"] input:disabled,
html[data-theme="dark"] select:disabled,
html[data-theme="dark"] textarea:disabled {
    opacity: 0.65;
    color: var(--hub-text-muted);
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus {
    border-color: var(--hub-focus);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25);
}

html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus,
html[data-theme="dark"] textarea:-webkit-autofill,
html[data-theme="dark"] select:-webkit-autofill {
    -webkit-text-fill-color: var(--hub-text-primary);
    caret-color: var(--hub-text-primary);
    box-shadow: 0 0 0 1000px var(--hub-input-bg) inset;
    transition: background-color 9999s ease-out;
}

html[data-theme="dark"] ::selection {
    background: #1d4ed8;
    color: #f8fafc;
}

/* --- Hub / wizard / busca --- */
html[data-theme="dark"] .tool-card {
    background-color: var(--hub-bg-surface);
    border-color: var(--hub-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .tool-card-title { color: var(--hub-text-primary); }
html[data-theme="dark"] .tool-card-description { color: var(--hub-text-secondary); }
html[data-theme="dark"] .tool-card-footer { border-top-color: var(--hub-border); }

html[data-theme="dark"] .badge-free { background-color: var(--hub-success-bg); color: var(--hub-success-fg); }
html[data-theme="dark"] .badge-eta { background-color: var(--hub-info-bg); color: var(--hub-info-fg); }
html[data-theme="dark"] .badge-hot { background-color: var(--hub-warning-bg); color: var(--hub-warning-fg); }
html[data-theme="dark"] .badge-category { background-color: var(--hub-bg-muted); color: var(--hub-text-secondary); }
html[data-theme="dark"] .badge-popular { background-color: rgba(139, 92, 246, 0.22); color: #e9d5ff; }

html[data-theme="dark"] .eta-pill { color: var(--hub-text-muted); }

html[data-theme="dark"] .wizard-step,
html[data-theme="dark"] .wizard-option,
html[data-theme="dark"] .tool-search-chip,
html[data-theme="dark"] .tool-search-suggestion-chip {
    background-color: var(--hub-bg-surface);
    border-color: var(--hub-border-strong);
    color: var(--hub-text-secondary);
}

html[data-theme="dark"] .wizard-step:hover,
html[data-theme="dark"] .wizard-option:hover,
html[data-theme="dark"] .tool-search-chip:hover,
html[data-theme="dark"] .tool-search-suggestion-chip:hover {
    border-color: var(--hub-focus);
    color: var(--hub-link);
}

html[data-theme="dark"] .wizard-option.selected {
    background-color: var(--hub-info-bg);
    border-color: var(--hub-focus);
}

html[data-theme="dark"] .wizard-progress,
html[data-theme="dark"] .tool-search-count,
html[data-theme="dark"] .tool-search-toggle { color: var(--hub-text-secondary); }

html[data-theme="dark"] .tool-search-input {
    background-color: var(--hub-input-bg);
    color: var(--hub-text-primary);
    border-color: var(--hub-border-strong);
}

html[data-theme="dark"] .tool-search-clear { color: var(--hub-text-muted); }
html[data-theme="dark"] .tool-search-clear:hover {
    color: var(--hub-text-primary);
    background-color: var(--hub-bg-muted);
}

html[data-theme="dark"] .tool-search-empty {
    background-color: var(--hub-bg-muted);
    border-color: var(--hub-border);
}

html[data-theme="dark"] .tool-search-empty-title { color: var(--hub-text-primary); }
html[data-theme="dark"] .tool-search-empty-text { color: var(--hub-text-secondary); }

html[data-theme="dark"] .tool-mark {
    background: #854d0e;
    color: #fde68a;
}

html[data-theme="dark"] .step-number {
    background-color: var(--hub-bg-elevated);
    color: var(--hub-text-muted);
}

html[data-theme="dark"] .step-label { color: var(--hub-text-muted); }
html[data-theme="dark"] .step-line { background-color: var(--hub-border); }

html[data-theme="dark"] .result-panel-light { background: var(--hub-bg-muted); }

html[data-theme="dark"] .spinner {
    border-color: var(--hub-bg-elevated);
    border-top-color: var(--hub-focus);
}

html[data-theme="dark"] .cal-selected {
    border-color: var(--hub-focus) !important;
    background-color: var(--hub-info-bg) !important;
}

/* Adblock */
html[data-theme="dark"] .adblock-guard-card {
    background: var(--hub-bg-surface);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .adblock-guard-title { color: var(--hub-text-primary); }
html[data-theme="dark"] .adblock-guard-text,
html[data-theme="dark"] .adblock-guard-hint { color: var(--hub-text-secondary); }
html[data-theme="dark"] .adblock-guard-icon {
    background: var(--hub-warning-bg);
    color: var(--hub-warning-fg);
}
html[data-theme="dark"] .adblock-guard-btn-secondary {
    background: var(--hub-bg-elevated);
    color: var(--hub-text-primary);
}
html[data-theme="dark"] .adblock-guard-btn-secondary:hover {
    background: #475569;
    color: var(--hub-text-primary);
}

/* IRPF MEI (folha própria) */
html[data-theme="dark"] .irpf-page-container .card {
    background: var(--hub-bg-surface);
    border-color: var(--hub-border);
}
html[data-theme="dark"] .irpf-page-container label { color: var(--hub-text-primary); }
html[data-theme="dark"] .irpf-page-container input,
html[data-theme="dark"] .irpf-page-container select {
    background: var(--hub-input-bg);
    color: var(--hub-text-primary);
    border-color: var(--hub-border-strong);
}
html[data-theme="dark"] .irpf-page-container .btn-secondary {
    background: var(--hub-info-bg);
    color: var(--hub-info-fg);
}
html[data-theme="dark"] .irpf-page-container .special-conditions {
    border-color: var(--hub-border);
}

html[data-theme="dark"] .bar-label { color: var(--hub-text-muted); }
html[data-theme="dark"] .bar-value { color: var(--hub-text-primary); }

html[data-theme="dark"] .reforma-tabela-hint { color: var(--hub-text-muted); }
html[data-theme="dark"] .reforma-accordion[open] summary { border-bottom-color: var(--hub-border); }
html[data-theme="dark"] .reforma-row-2026 { background-color: var(--hub-warning-bg); }

/* Código / pre */
html[data-theme="dark"] pre,
html[data-theme="dark"] code {
    background-color: var(--hub-bg-muted);
    color: var(--hub-text-primary);
}

/* Foco visível extra no controle de tema */
html[data-theme="dark"] .hub-theme-control__select:focus {
    outline-color: var(--hub-focus);
    border-color: var(--hub-focus);
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    .hub-theme-control__select {
        transition: none;
    }
}

@media (forced-colors: active) {
    html[data-theme="dark"] {
        --hub-bg-page: Canvas;
        --hub-bg-surface: Canvas;
        --hub-bg-muted: Canvas;
        --hub-bg-elevated: Canvas;
        --hub-text-primary: CanvasText;
        --hub-text-secondary: CanvasText;
        --hub-text-muted: GrayText;
        --hub-border: ButtonBorder;
        --hub-border-strong: ButtonBorder;
        --hub-input-bg: Field;
        --hub-link: LinkText;
    }
}

/* Impressão: fundo claro, sem seletor de tema */
@media print {
    html,
    html[data-theme="dark"],
    html[data-theme="light"] {
        color-scheme: light !important;
        --hub-bg-page: #ffffff;
        --hub-bg-surface: #ffffff;
        --hub-bg-muted: #f3f4f6;
        --hub-bg-elevated: #e5e7eb;
        --hub-text-primary: #111827;
        --hub-text-secondary: #374151;
        --hub-text-muted: #4b5563;
        --hub-border: #d1d5db;
        --hub-border-strong: #9ca3af;
        --hub-input-bg: #ffffff;
        --hub-chart-bg: #ffffff;
        --hub-chart-fg: #111827;
        --hub-chart-muted: #4b5563;
        --hub-chart-grid: #e5e7eb;
        --hub-chart-axis: #d1d5db;
    }

    html[data-theme="dark"] body,
    body {
        background: #fff !important;
        color: #111 !important;
    }

    .hub-theme-control,
    #hub-theme-select {
        display: none !important;
    }

    html[data-theme="dark"] .hub-logo--light {
        display: inline !important;
    }

    .hub-logo--dark,
    html[data-theme="dark"] .hub-logo--dark {
        display: none !important;
    }
}
