<?php
require_once __DIR__ . '/theme-init.php';

header('Content-Type: text/css; charset=UTF-8');

$base      = $themePalette['base'];
$secondary = $themePalette['secondary'];
$light     = $themePalette['light'];
$dark      = $themePalette['dark'];
$cor1      = $themePalette['cor1'];
$cor2      = $themePalette['cor2'];
$bgcor     = $themePalette['bgcor']     ?? '#ffffff';
$navbarcor = $themePalette['navbarcor'] ?? '#ffffff';
$fontprimary = $themePalette['fontprimary'] ?? '#6c757d';
$fontsecondary = $themePalette['fontsecondary'] ?? '#091e3e';
$fonthighlight = $themePalette['fonthighlight'] ?? '#06a3da';
[$baseR, $baseG, $baseB] = hexToRgb($base);
[$secondaryR, $secondaryG, $secondaryB] = hexToRgb($secondary);
[$darkR, $darkG, $darkB] = hexToRgb($dark);
?>
:root {
    /* Brand Colors */
    --color-primary: <?= $base ?>;
    --color-primary-hover: <?= $secondary ?>;
    
    /* Backgrounds */
    --color-bg-base: <?= $bgcor ?>;
    --color-bg-surface: #ffffff;
    --color-bg-surface-alt: <?= $light ?>;
    --color-bg-navbar: <?= $navbarcor ?>;
    
    /* UI Typography */
    --color-text-heading: <?= $fontsecondary ?>;
    --color-text-body: <?= $fontprimary ?>;
    --color-text-link: <?= $fonthighlight ?>;
    --color-text-inverse: <?= $cor1 ?>;
    
    /* Semantics */
    --color-success: #10B981;
    --color-danger:  #EF4444;
    --color-warning: #F59E0B;

    /* Legacy Variables (Compatibility) */
    --primary:   var(--color-primary);
    --secondary: var(--color-primary-hover);
    --light:     var(--color-bg-surface-alt);
    --dark:      <?= $dark ?>;
    --cor1:      var(--color-text-inverse);
    --cor2:      <?= $cor2 ?>;
    --bgcor:     var(--color-bg-base);
    --navbarcor: var(--color-bg-navbar);
    --font-primary: var(--color-text-body);
    --font-secondary: var(--color-text-heading);
    --font-highlight: var(--color-text-link);
    --bs-primary:   var(--color-primary);
    --bs-secondary: var(--color-primary-hover);
    --bs-light:     var(--color-bg-surface-alt);
    --bs-dark:      var(--dark);

    --theme-panel-bg:     rgba(255, 255, 255, 0.95);
    --theme-panel-border: rgba(9, 30, 62, 0.12);
}

body {
    background-color: var(--bgcor) !important;
}

/* Navbar (cabeçalho) — NÃO afeta o topbar .bg-light */
nav.navbar {
    background-color: var(--navbarcor) !important;
}

body a,
a {
    color: var(--primary);
}

a:hover {
    color: var(--secondary);
}

.text-primary {
    color: var(--primary) !important;
}

.text-secondary {
    color: var(--secondary) !important;
}

.bg-primary {
    background-color: var(--primary) !important;
}

.bg-secondary {
    background-color: var(--secondary) !important;
}

.bg-light {
    background-color: var(--light) !important;
}

.bg-dark {
    background-color: var(--dark) !important;
}

.border-primary {
    border-color: var(--primary) !important;
}

.border-secondary {
    border-color: var(--secondary) !important;
}

.btn-primary {
    color: var(--cor1) !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-check:focus + .btn-primary,
.btn-check:checked + .btn-primary {
    color: var(--cor1) !important;
    background-color: var(--secondary) !important;
    border-color: var(--secondary) !important;
    box-shadow: 0 0 0 .25rem rgba(<?= $secondaryR ?>, <?= $secondaryG ?>, <?= $secondaryB ?>, 0.35) !important;
}

.btn-secondary {
    color: var(--cor2) !important;
    background-color: var(--secondary) !important;
    border-color: var(--secondary) !important;
}

.btn-secondary:hover,
.btn-secondary:focus,
.btn-secondary:active,
.btn-check:focus + .btn-secondary,
.btn-check:checked + .btn-secondary {
    color: var(--cor1) !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 .25rem rgba(<?= $baseR ?>, <?= $baseG ?>, <?= $baseB ?>, 0.35) !important;
}

.btn-outline-primary {
    color: var(--primary) !important;
    background-color: transparent !important;
    border-color: var(--primary) !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
    color: var(--cor1) !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.btn-light {
    color: var(--dark) !important;
    background-color: var(--light) !important;
    border-color: var(--light) !important;
}

.btn-dark {
    color: #ffffff !important;
    background-color: var(--dark) !important;
    border-color: var(--dark) !important;
}

.navbar-light .navbar-nav .nav-link:hover,
.navbar-light .navbar-nav .nav-link.active,
.section-title h5,
.team-item .team-text p,
.service-item a.btn,
.spinner-grow.text-primary,
.spinner-grow.text-secondary {
    color: var(--primary) !important;
}

.top-shape::before {
    background: var(--primary) !important;
}

.section-title h5::before {
    background: var(--primary) !important;
}

.section-title h5::after {
    background: var(--secondary) !important;
}

.carousel-caption,
.hero-header,
.bg-appointment,
.bg-testimonial {
    background-color: rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.15) !important;
}

.hero-header {
    background-image: linear-gradient(rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.85), rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.85)), url(../img/carousel-1.jpg) !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
    background-size: cover !important;
}

.bg-appointment {
    background-image: linear-gradient(rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.85), rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.85)), url(../img/carousel-1.jpg) !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
    background-size: cover !important;
}

.appointment-form,
.offer-text,
.testimonial-carousel {
    background: rgba(<?= $baseR ?>, <?= $baseG ?>, <?= $baseB ?>, 0.85) !important;
}

.service-item:hover .bg-light h5,
.service-item:hover .bg-light p {
    color: var(--cor1) !important;
}

#searchModal .modal-content {
    background: rgba(<?= $darkR ?>, <?= $darkG ?>, <?= $darkB ?>, 0.7) !important;
}

body > .container-fluid.text-light.py-4 {
    background: var(--dark) !important;
}

.theme-switcher-nav {
    color: var(--dark);
    white-space: nowrap;
}

.theme-switcher-color {
    width: 42px;
    height: 42px;
    padding: 4px;
    border: 1px solid rgba(9, 30, 62, 0.18);
    border-radius: 10px;
    background: var(--light);
    cursor: pointer;
}

.theme-switcher-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.theme-switcher-color::-webkit-color-swatch {
    border: 0;
    border-radius: 8px;
}

.theme-switcher-color-sm {
    width: 22px;
    height: 22px;
    padding: 1px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
}

.theme-switcher-color-sm::-webkit-color-swatch-wrapper {
    padding: 0;
}

.theme-switcher-color-sm::-webkit-color-swatch {
    border: 0;
    border-radius: 3px;
}

.site-logo-box {
    display: inline-block;
    vertical-align: middle;
}

.site-logo-image {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
}

@media (max-width: 991.98px) {
    .theme-switcher-nav {
        width: 100%;
        margin: 12px 0;
        justify-content: center;
    }
}

/* Utilities semânticos adicionais */
.text-heading {
    color: var(--color-text-heading) !important;
}

.text-body {
    color: var(--color-text-body) !important;
}

.bg-surface {
    background-color: var(--color-bg-surface) !important;
}

.text-inverse {
    color: var(--color-text-inverse) !important;
}

/* Proteção e Estilização Global de Fontes Premium */
body, p, span:not(.navbar-toggler-icon):not(.carousel-control-prev-icon):not(.carousel-control-next-icon):not(.badge), li, td {
    color: var(--color-text-body) !important;
}

h1, h2, h3, h4, h5, h6, .section-title h5, .font-weight-bold, .font-weight-semi-bold {
    color: var(--color-text-heading) !important;
}

a:not(.btn):not(.nav-link):not(.navbar-brand), strong, b, .text-primary {
    color: var(--color-text-link) !important;
}

