/* ============================================================================
   SISTEMA CENTRALIZADO DE TEMAS E PERSONALIZAÇÃO VISUAL POR USUÁRIO (AdvApp)
   Temas integrados: LIGHT (padrão) · BLACK · PINK · CUSTOM (por usuário)
   ============================================================================ */

html[data-theme="black"] {
    color-scheme: dark;

    /* A. Geral e Superfícies */
    --theme-bg-app: #090909;
    --theme-bg-surface: #111111;
    --theme-bg-surface-2: #191919;
    --theme-bg-surface-3: #222222;
    --theme-border: #292929;
    --theme-border-strong: #3A3A3A;
    --theme-divider: #1F1F1F;
    --theme-overlay: #050505;

    /* B. Sidebar / Menu Lateral */
    --theme-sb-bg: #0B0B0B;
    --theme-sb-surface: #141414;
    --theme-sb-text: #D4D4D8;
    --theme-sb-text-muted: #8E8E98;
    --theme-sb-hover-bg: #1A1A1A;
    --theme-sb-active-bg: #1E1A13;
    --theme-sb-active-text: #D4AF6A;
    --theme-sb-icon: #9A9AA3;
    --theme-sb-border: #222222;

    /* C. Cabeçalho e Subheaders */
    --theme-header-bg: #101010;
    --theme-header-text: #F5F5F5;
    --theme-header-border: #262626;

    /* D. Tipografia */
    --theme-text-primary: #F5F5F5;
    --theme-text-secondary: #C4C4CC;
    --theme-text-muted: #8A8A94;
    --theme-link: #C6A56B;
    --theme-link-hover: #DFC086;

    /* E. Botões e Destaque */
    --theme-accent: #C6A56B;
    --theme-accent-hover: #B49257;
    --theme-accent-text: #0B0B0B;
    --theme-btn-sec-bg: #1D1D1D;
    --theme-btn-sec-text: #E5E5EA;
    --theme-btn-sec-border: #333333;
    --theme-btn-sec-hover: #282828;

    /* F. Status Semânticos */
    --theme-success: #22C55E;
    --theme-success-soft: #102819;
    --theme-warning: #EAB308;
    --theme-warning-soft: #2B220B;
    --theme-danger: #EF4444;
    --theme-danger-soft: #2D1215;
    --theme-info: #60A5FA;
    --theme-info-soft: #132035;

    /* G. Formulários */
    --theme-input-bg: #141414;
    --theme-input-text: #F5F5F5;
    --theme-input-border: #323232;
    --theme-input-focus: #C6A56B;
    --theme-input-placeholder: #71717A;
    --theme-label: #D4D4D8;

    /* H. Tabelas */
    --theme-table-header-bg: #171717;
    --theme-table-header-text: #B4B4BD;
    --theme-table-row-bg: #111111;
    --theme-table-row-alt: #151515;
    --theme-table-row-hover: #1D1C19;
    --theme-table-border: #252525;

    /* I. Cards & Modais */
    --theme-card-bg: #141414;
    --theme-card-border: #292929;
    --theme-card-header-bg: #1A1A1A;
    --theme-modal-bg: #121212;
    --theme-modal-header-bg: #181818;
    --theme-modal-footer-bg: #161616;

    /* J. Elementos Adicionais */
    --theme-tooltip-bg: #232326;
    --theme-tooltip-text: #F5F5F5;
    --theme-scrollbar-track: #0E0E0E;
    --theme-scrollbar-thumb: #303030;
    --theme-progress-track: #242424;
    --theme-progress-fill: #C6A56B;
}

:root,
html[data-theme="light"] {
    color-scheme: light;

    --theme-bg-app: #F7F8FA;
    --theme-bg-surface: #FFFFFF;
    --theme-bg-surface-2: #F1F3F5;
    --theme-bg-surface-3: #E5E7EB;
    --theme-border: #E5E7EB;
    --theme-border-strong: #CBD5E1;
    --theme-divider: #F3F4F6;
    --theme-overlay: #0F172A;

    --theme-sb-bg: #FFFFFF;
    --theme-sb-surface: #F8FAFC;
    --theme-sb-text: #374151;
    --theme-sb-text-muted: #6B7280;
    --theme-sb-hover-bg: #F1F5F9;
    --theme-sb-active-bg: #EEF2F6;
    --theme-sb-active-text: #111827;
    --theme-sb-icon: #64748B;
    --theme-sb-border: #E5E7EB;

    --theme-header-bg: #FFFFFF;
    --theme-header-text: #111827;
    --theme-header-border: #E5E7EB;

    --theme-text-primary: #202124;
    --theme-text-secondary: #4B5563;
    --theme-text-muted: #6B7280;
    --theme-link: #475569;
    --theme-link-hover: #1E293B;

    --theme-accent: #64748B;
    --theme-accent-hover: #475569;
    --theme-accent-text: #FFFFFF;
    --theme-btn-sec-bg: #F3F4F6;
    --theme-btn-sec-text: #374151;
    --theme-btn-sec-border: #D1D5DB;
    --theme-btn-sec-hover: #E5E7EB;

    --theme-success: #15803D;
    --theme-success-soft: #ECFDF5;
    --theme-warning: #B45309;
    --theme-warning-soft: #FFFBEB;
    --theme-danger: #B91C1C;
    --theme-danger-soft: #FEF2F2;
    --theme-info: #2563EB;
    --theme-info-soft: #EFF6FF;

    --theme-input-bg: #FFFFFF;
    --theme-input-text: #202124;
    --theme-input-border: #D1D5DB;
    --theme-input-focus: #64748B;
    --theme-input-placeholder: #9CA3AF;
    --theme-label: #4B5563;

    --theme-table-header-bg: #F9FAFB;
    --theme-table-header-text: #6B7280;
    --theme-table-row-bg: #FFFFFF;
    --theme-table-row-alt: #FAFAFA;
    --theme-table-row-hover: #F3F4F6;
    --theme-table-border: #E5E7EB;

    --theme-card-bg: #FFFFFF;
    --theme-card-border: #E5E7EB;
    --theme-card-header-bg: #F9FAFB;
    --theme-modal-bg: #FFFFFF;
    --theme-modal-header-bg: #F8F9FA;
    --theme-modal-footer-bg: #F8FAFC;

    --theme-tooltip-bg: #1F2937;
    --theme-tooltip-text: #FFFFFF;
    --theme-scrollbar-track: #F3F4F6;
    --theme-scrollbar-thumb: #CBD5E1;
    --theme-progress-track: #E5E7EB;
    --theme-progress-fill: #64748B;
}

html[data-theme="pink"] {
    color-scheme: light;

    --theme-bg-app: #FFF5F8;
    --theme-bg-surface: #FFFFFF;
    --theme-bg-surface-2: #FFF0F5;
    --theme-bg-surface-3: #FCE7F0;
    --theme-border: #F5D0E0;
    --theme-border-strong: #ECBCD1;
    --theme-divider: #FCE7F0;
    --theme-overlay: #3B1E2E;

    --theme-sb-bg: #FCE7F0;
    --theme-sb-surface: #FDEEF4;
    --theme-sb-text: #573B4B;
    --theme-sb-text-muted: #967A89;
    --theme-sb-hover-bg: #FAD7E5;
    --theme-sb-active-bg: #F8C9DC;
    --theme-sb-active-text: #9D2F5E;
    --theme-sb-icon: #9E607A;
    --theme-sb-border: #F3C6D9;

    --theme-header-bg: #FFF9FB;
    --theme-header-text: #573B4B;
    --theme-header-border: #F5D0E0;

    --theme-text-primary: #573B4B;
    --theme-text-secondary: #7A5A6A;
    --theme-text-muted: #967A89;
    --theme-link: #C44D80;
    --theme-link-hover: #9D2F5E;

    --theme-accent: #E88BAF;
    --theme-accent-hover: #D96F99;
    --theme-accent-text: #FFFFFF;
    --theme-btn-sec-bg: #FCE7F0;
    --theme-btn-sec-text: #573B4B;
    --theme-btn-sec-border: #F5D0E0;
    --theme-btn-sec-hover: #FAD7E5;

    --theme-success: #3D9A72;
    --theme-success-soft: #EAF8F2;
    --theme-warning: #D98A3A;
    --theme-warning-soft: #FFF6EA;
    --theme-danger: #D9537A;
    --theme-danger-soft: #FFEBF0;
    --theme-info: #8B7AE0;
    --theme-info-soft: #F2EFFE;

    --theme-input-bg: #FFFFFF;
    --theme-input-text: #573B4B;
    --theme-input-border: #F0C3D7;
    --theme-input-focus: #E88BAF;
    --theme-input-placeholder: #B698A7;
    --theme-label: #6E4B5D;

    --theme-table-header-bg: #FCEEF4;
    --theme-table-header-text: #825E71;
    --theme-table-row-bg: #FFFFFF;
    --theme-table-row-alt: #FFF9FB;
    --theme-table-row-hover: #FCE7F0;
    --theme-table-border: #F6DCE7;

    --theme-card-bg: #FFFFFF;
    --theme-card-border: #F5D0E0;
    --theme-card-header-bg: #FCEEF4;
    --theme-modal-bg: #FFFFFF;
    --theme-modal-header-bg: #FCEEF4;
    --theme-modal-footer-bg: #FFF5F9;

    --theme-tooltip-bg: #573B4B;
    --theme-tooltip-text: #FFF5F8;
    --theme-scrollbar-track: #FFF0F5;
    --theme-scrollbar-thumb: #EAB7CE;
    --theme-progress-track: #FCE7F0;
    --theme-progress-fill: #E88BAF;
}

/* Mapeamento Dinâmico dos Aliases Globais e Variáveis da Sidebar */
:root,
html[data-theme] {
    --bg-app: var(--theme-bg-app);
    --bg-surface: var(--theme-bg-surface);
    --bg-surface-2: var(--theme-bg-surface-2);
    --bg-sidebar: var(--theme-sb-bg);
    --text-primary: var(--theme-text-primary);
    --text-color: var(--theme-text-primary);
    --text-secondary: var(--theme-text-secondary);
    --text-muted: var(--theme-text-muted);
    --border-color: var(--theme-border);
    --accent-color: var(--theme-accent);
    --accent-hover: var(--theme-accent-hover);
    --sb-bg-primary: var(--theme-sb-bg);
    --sb-bg-secondary: var(--theme-sb-surface);
    --sb-bg-elevated: var(--theme-bg-surface-2);
    --sb-bg-hover: var(--theme-sb-hover-bg);
    --sb-bg-active: var(--theme-sb-active-bg);
    --sb-border-subtle: var(--theme-sb-border);
    --sb-border-strong: var(--theme-border-strong);
    --sb-text-primary: var(--theme-sb-text);
    --sb-text-secondary: var(--theme-sb-text-muted);
    --sb-text-muted: var(--theme-sb-icon);
    --sb-accent: var(--theme-sb-active-text);
    --sb-accent-soft: color-mix(in srgb, var(--theme-sb-active-text) 14%, transparent);
    --sb-accent-border: color-mix(in srgb, var(--theme-sb-active-text) 32%, transparent);
}

/* Mapeamento Dinâmico do Módulo RBAC (.rbac-shell e Modais RBAC) */
html[data-theme] .rbac-shell,
html[data-theme] .rbac-modal-backdrop {
    --rbac-bg: var(--theme-card-bg);
    --rbac-bg-subtle: var(--theme-bg-surface-2);
    --rbac-bg-muted: var(--theme-bg-surface-3);
    --rbac-border: var(--theme-border);
    --rbac-border-strong: var(--theme-border-strong);
    --rbac-ink: var(--theme-text-primary);
    --rbac-ink-secondary: var(--theme-text-secondary);
    --rbac-ink-muted: var(--theme-text-muted);
    --rbac-accent: var(--theme-accent);
    --rbac-gold: var(--theme-accent);
    --rbac-gold-bg: color-mix(in srgb, var(--theme-accent) 12%, var(--theme-card-bg));
    --rbac-gold-border: color-mix(in srgb, var(--theme-accent) 32%, var(--theme-border));
    --rbac-green: var(--theme-success);
    --rbac-green-bg: var(--theme-success-soft);
    --rbac-green-border: color-mix(in srgb, var(--theme-success) 35%, var(--theme-border));
    --rbac-red: var(--theme-danger);
    --rbac-red-bg: var(--theme-danger-soft);
    --rbac-red-border: color-mix(in srgb, var(--theme-danger) 35%, var(--theme-border));
    --rbac-amber: var(--theme-warning);
    --rbac-amber-bg: var(--theme-warning-soft);
    --rbac-amber-border: color-mix(in srgb, var(--theme-warning) 35%, var(--theme-border));
}

/* ============================================================================
   CONTROLES NATIVOS, TRANSIÇÕES E SCROLLBARS GLOBAIS
   ============================================================================ */

body,
#main-content,
#module-container,
#sidebar,
.modal-content,
.table-container,
.card {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    body,
    #main-content,
    #module-container,
    #sidebar,
    .modal-content,
    .table-container,
    .card {
        transition: none !important;
    }
}

/* Scrollbar global discreta adaptada ao tema */
#main-content,
.modal-content,
.dash-table-scroll,
.timeline-list {
    scrollbar-width: thin;
    scrollbar-color: var(--theme-scrollbar-thumb) var(--theme-scrollbar-track);
}

#main-content::-webkit-scrollbar,
.modal-content::-webkit-scrollbar,
.dash-table-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

#main-content::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track,
.dash-table-scroll::-webkit-scrollbar-track {
    background: var(--theme-scrollbar-track);
}

#main-content::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb,
.dash-table-scroll::-webkit-scrollbar-thumb {
    background: var(--theme-scrollbar-thumb);
    border-radius: 999px;
}

/* Campos de formulário adaptados globalmente */
#app-layout input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]):not([type="range"]),
#app-layout select,
#app-layout textarea,
.modal-overlay input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]):not([type="range"]),
.modal-overlay select,
.modal-overlay textarea {
    background-color: var(--theme-input-bg);
    color: var(--theme-input-text);
    border-color: var(--theme-input-border);
}

#app-layout input::placeholder,
#app-layout textarea::placeholder,
.modal-overlay input::placeholder,
.modal-overlay textarea::placeholder {
    color: var(--theme-input-placeholder);
}

#app-layout input:focus,
#app-layout select:focus,
#app-layout textarea:focus,
.modal-overlay input:focus,
.modal-overlay select:focus,
.modal-overlay textarea:focus {
    outline: none;
    border-color: var(--theme-input-focus);
}

#app-layout select option,
.modal-overlay select option {
    background-color: var(--theme-bg-surface);
    color: var(--theme-text-primary);
}

#app-layout input[type="color"],
.modal-overlay input[type="color"] {
    background-color: var(--theme-input-bg);
    border-color: var(--theme-input-border);
}

/* Tabelas padrão nos módulos */
.table-container {
    background: var(--theme-card-bg);
    border: 1px solid var(--theme-card-border);
    border-radius: 8px;
    overflow: hidden;
}

.table-container table {
    width: 100%;
    border-collapse: collapse;
    background: var(--theme-table-row-bg);
    color: var(--theme-text-primary);
}

.table-container thead tr {
    background: var(--theme-table-header-bg);
    border-bottom: 1px solid var(--theme-table-border);
}

.table-container th {
    color: var(--theme-table-header-text);
}

.table-container tbody tr {
    background: var(--theme-table-row-bg);
    border-bottom: 1px solid var(--theme-table-border);
    transition: background-color 0.15s ease;
}

.table-container tbody tr:nth-child(even) {
    background: var(--theme-table-row-alt);
}

.table-container tbody tr:hover {
    background: var(--theme-table-row-hover);
}

/* ============================================================================
   CLASSES UTILITÁRIAS SEMÂNTICAS PARA SUBSTITUIR CORES INLINE
   ============================================================================ */

.theme-surface {
    background: var(--theme-bg-surface);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}

.theme-surface-2 {
    background: var(--theme-bg-surface-2);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}

.theme-card {
    background: var(--theme-card-bg);
    color: var(--theme-text-primary);
    border: 1px solid var(--theme-card-border);
    border-radius: 8px;
}

.theme-modal-backdrop {
    background: color-mix(in srgb, var(--theme-overlay) 55%, transparent);
    backdrop-filter: blur(3px);
}

.theme-modal-panel {
    background: var(--theme-modal-bg);
    color: var(--theme-text-primary);
    border: 1px solid var(--theme-border);
    box-shadow: 0 20px 44px -12px color-mix(in srgb, var(--theme-overlay) 45%, transparent);
}

.theme-modal-header {
    background: var(--theme-modal-header-bg);
    color: var(--theme-header-text);
    border-bottom: 1px solid var(--theme-border);
}

.theme-modal-footer {
    background: var(--theme-modal-footer-bg);
    border-top: 1px solid var(--theme-border);
}

.theme-btn-primary {
    background: color-mix(in srgb, var(--theme-accent) 16%, var(--theme-btn-sec-bg));
    color: var(--theme-text-primary);
    border: 1px solid color-mix(in srgb, var(--theme-accent) 42%, var(--theme-border-strong));
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.16s ease, border-color 0.16s ease;
}

.theme-btn-primary:hover {
    background: color-mix(in srgb, var(--theme-accent) 24%, var(--theme-btn-sec-bg));
    border-color: color-mix(in srgb, var(--theme-accent) 62%, var(--theme-border-strong));
}

.theme-btn-secondary {
    background: var(--theme-btn-sec-bg);
    color: var(--theme-btn-sec-text);
    border: 1px solid var(--theme-btn-sec-border);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.16s ease, border-color 0.16s ease;
}

.theme-btn-secondary:hover {
    background: var(--theme-btn-sec-hover);
    border-color: var(--theme-border-strong);
}

.theme-btn-danger-soft {
    background: transparent;
    color: var(--theme-text-secondary);
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.theme-btn-danger-soft:hover {
    background: var(--theme-danger-soft);
    color: var(--theme-danger);
    border-color: color-mix(in srgb, var(--theme-danger) 35%, var(--theme-border));
}

.theme-btn-info-soft {
    background: color-mix(in srgb, var(--theme-info) 10%, var(--theme-btn-sec-bg));
    color: color-mix(in srgb, var(--theme-info) 78%, var(--theme-text-primary));
    border: 1px solid color-mix(in srgb, var(--theme-info) 30%, var(--theme-border));
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.theme-btn-success-soft {
    background: color-mix(in srgb, var(--theme-success) 10%, var(--theme-btn-sec-bg));
    color: color-mix(in srgb, var(--theme-success) 78%, var(--theme-text-primary));
    border: 1px solid color-mix(in srgb, var(--theme-success) 30%, var(--theme-border));
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.theme-box-success {
    background: var(--theme-success-soft);
    border: 1px solid color-mix(in srgb, var(--theme-success) 32%, var(--theme-border));
    color: var(--theme-text-primary);
}

.theme-box-success-title {
    color: var(--theme-success);
}

.theme-box-info {
    background: var(--theme-info-soft);
    border: 1px solid color-mix(in srgb, var(--theme-info) 32%, var(--theme-border));
    color: var(--theme-text-primary);
}

.theme-box-danger {
    background: var(--theme-danger-soft);
    border: 1px solid color-mix(in srgb, var(--theme-danger) 35%, var(--theme-border));
    color: var(--theme-danger);
}

.theme-box-warning {
    background: var(--theme-warning-soft);
    border: 1px solid color-mix(in srgb, var(--theme-warning) 35%, var(--theme-border));
    color: var(--theme-warning);
}
