/*
 * GLOBAL THEME ENGINE — RST GSM
 * ------------------------------------------------------------------
 * Regras GLOBAIS e de baixo risco que consomem as variáveis --theme-*
 * definidas dinamicamente por includes/helpers/theme_engine.php
 * (renderGlobalThemeStyleBlock).
 *
 * Este arquivo NÃO sobrescreve nenhum sistema de design existente
 * (--uds-*, --ads-*, --auth-*) — essas pontes já ficam no <style> inline
 * gerado pelo PHP. Aqui ficam apenas:
 *   1) o "background ambiente" global (gradients leves, sem imagens);
 *   2) baseline para elementos genéricos usando :where() (especificidade
 *      zero — qualquer outra regra existente sempre vence, então isto
 *      nunca quebra nada que já tenha estilo);
 *   3) classes utilitárias opcionais citadas no pedido (.card, .modal,
 *      .alert, .badge, .pagination, .tabs) para quem ainda não usa um
 *      design system específico;
 *   4) toques globais de identidade (seleção de texto, foco, scrollbar).
 *
 * Performance: só gradients/CSS variables, sem imagens pesadas, sem JS.
 */

/* ===================================================================
   1) BACKGROUND AMBIENTE GLOBAL
   =================================================================== */
body {
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-color: var(--theme-bg, #f6f7fb);
    background-image:
        radial-gradient(1100px 620px at 10% -10%, color-mix(in srgb, var(--theme-primary, #6366f1) 16%, transparent), transparent 60%),
        radial-gradient(900px 560px at 110% 0%, color-mix(in srgb, var(--theme-accent, #8b5cf6) 14%, transparent), transparent 62%),
        radial-gradient(1000px 680px at 50% 115%, color-mix(in srgb, var(--theme-secondary, #6366f1) 10%, transparent), transparent 65%);
    background-repeat: no-repeat;
    transition: background-color 0.25s ease;
}

/* Grid extremamente sutil, só no modo escuro (assinatura "SaaS premium"). */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0;
    background-image:
        linear-gradient(color-mix(in srgb, var(--theme-primary, #38bdf8) 6%, transparent) 1px, transparent 1px),
        linear-gradient(90deg, color-mix(in srgb, var(--theme-primary, #38bdf8) 6%, transparent) 1px, transparent 1px);
    background-size: 42px 42px, 42px 42px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 40%, transparent 90%);
    -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 40%, transparent 90%);
}

.dark body::after {
    opacity: 1;
}

/* ===================================================================
   2) IDENTIDADE GLOBAL: seleção, foco, scrollbar
   =================================================================== */
::selection {
    background: color-mix(in srgb, var(--theme-primary, #6366f1) 55%, transparent);
    color: #fff;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid color-mix(in srgb, var(--theme-primary, #6366f1) 70%, transparent);
    outline-offset: 2px;
}

/* ===================================================================
   3) BASELINE GENÉRICO (especificidade zero — nunca sobrescreve nada
      que já tenha classe/estilo próprio; serve só de fallback coerente)
   =================================================================== */
:where(button:not([class])),
:where(input[type="submit"]:not([class])),
:where(input[type="button"]:not([class])) {
    background: var(--theme-primary, #6366f1);
    color: #fff;
    border: 1px solid transparent;
    border-radius: 0.6rem;
    padding: 0.55rem 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}
:where(button:not([class])):hover,
:where(input[type="submit"]:not([class])):hover,
:where(input[type="button"]:not([class])):hover {
    background: var(--theme-primary-hover, #4f46e5);
}

:where(input:not([class]), select:not([class]), textarea:not([class])) {
    background: var(--theme-surface, #fff);
    color: var(--theme-text, #0f172a);
    border: 1px solid var(--theme-border, #e2e8f0);
    border-radius: 0.55rem;
    padding: 0.5rem 0.75rem;
}

:where(table:not([class])) {
    border-collapse: collapse;
    width: 100%;
    background: var(--theme-surface, #fff);
    color: var(--theme-text, #0f172a);
}
:where(table:not([class])) :where(th, td) {
    border-bottom: 1px solid var(--theme-border, #e2e8f0);
    padding: 0.6rem 0.75rem;
    text-align: left;
}
:where(table:not([class])) :where(tbody tr:hover) {
    background: var(--theme-surface-hover, #f8fafc);
}

/* ===================================================================
   4) CLASSES UTILITÁRIAS OPCIONAIS (opt-in) — item 10 do pedido
   =================================================================== */
.theme-card {
    background: var(--theme-card, #fff);
    border: 1px solid var(--theme-border, #e2e8f0);
    border-radius: 1rem;
    box-shadow: var(--theme-shadow, 0 10px 25px rgba(15, 23, 42, 0.08));
    color: var(--theme-text, #0f172a);
}

.theme-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: color-mix(in srgb, var(--theme-primary, #6366f1) 14%, transparent);
    color: var(--theme-primary, #6366f1);
}
.theme-badge--success { background: color-mix(in srgb, var(--theme-success, #10b981) 16%, transparent); color: var(--theme-success, #10b981); }
.theme-badge--warning { background: color-mix(in srgb, var(--theme-warning, #f59e0b) 16%, transparent); color: var(--theme-warning, #f59e0b); }
.theme-badge--danger { background: color-mix(in srgb, var(--theme-danger, #ef4444) 16%, transparent); color: var(--theme-danger, #ef4444); }
.theme-badge--info { background: color-mix(in srgb, var(--theme-info, #3b82f6) 16%, transparent); color: var(--theme-info, #3b82f6); }

.theme-alert {
    display: flex;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--theme-border, #e2e8f0);
    background: var(--theme-surface-hover, #f8fafc);
    color: var(--theme-text, #0f172a);
}

.theme-modal-backdrop {
    background: rgba(0, 0, 0, 0.6);
}
.theme-modal {
    background: var(--theme-surface, #fff);
    border: 1px solid var(--theme-border, #e2e8f0);
    border-radius: 1rem;
    box-shadow: var(--theme-shadow, 0 20px 45px rgba(0, 0, 0, 0.25));
    color: var(--theme-text, #0f172a);
}

.theme-pagination a,
.theme-pagination button {
    border: 1px solid var(--theme-border, #e2e8f0);
    background: var(--theme-surface, #fff);
    color: var(--theme-text, #0f172a);
    border-radius: 0.5rem;
    padding: 0.35rem 0.7rem;
}
.theme-pagination a.active,
.theme-pagination button.active {
    background: var(--theme-primary, #6366f1);
    border-color: var(--theme-primary, #6366f1);
    color: #fff;
}

.theme-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--theme-border, #e2e8f0);
}
.theme-tabs a,
.theme-tabs button {
    padding: 0.6rem 1rem;
    color: var(--theme-text-muted, #64748b);
    border-bottom: 2px solid transparent;
}
.theme-tabs a.active,
.theme-tabs button.active {
    color: var(--theme-primary, #6366f1);
    border-bottom-color: var(--theme-primary, #6366f1);
}

/* ===================================================================
   5) SERVICES GRID — imagens (Tailwind preflight height:auto colapsa)
   =================================================================== */
.svc-grid-group .aspect-square,
.svc-grid-group .svc-card-thumb {
    position: relative !important;
    width: 100% !important;
    aspect-ratio: 1 / 1;
    min-height: 72px;
}
.svc-grid-group .aspect-square > img,
.svc-grid-group .svc-card-thumb__img,
.svc-grid-group .svc-card-thumb > img {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Lista com grupos: thumbs fixas — NÃO usar height:100% solto (colapsa img) */
.svc-list-group .w-12.h-12 {
    position: relative;
    flex-shrink: 0;
}
.svc-list-group .w-12.h-12 > img {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    object-fit: contain !important;
    display: block !important;
}

/* Navbar / shell: reforço de identidade nos hovers e ícones ativos */
.uds-nav a:hover,
.uds-nav button:hover,
.uds-sidebar a:hover,
.uds-sidebar .active,
.uds-nav__link.is-active,
.uds-nav__item.is-active {
    color: var(--theme-primary, #4f46e5);
}
.uds-btn--primary,
.btn-primary.uds-compat,
.uds-nav__cta {
    background: var(--theme-gradient, linear-gradient(135deg, #4f46e5, #4338ca)) !important;
    color: #fff !important;
    border-color: transparent !important;
}

/* ===================================================================
   6) PERFORMANCE / ACESSIBILIDADE
   =================================================================== */
@media (prefers-reduced-motion: reduce) {
    body::before,
    body::after {
        transition: none !important;
    }
}

/* ===================================================================
   7) PONTE TAILWIND ÍNDIGO/VIOLETA/ROXO → TEMA
      Classes antigas (bg-indigo-600, from-indigo to-purple) passam a
      usar --theme-*. !important vence o CSS gerado pelo CDN.
   =================================================================== */
.bg-indigo-500, .bg-indigo-600, .bg-indigo-700,
.bg-violet-500, .bg-violet-600, .bg-violet-700,
.bg-purple-600, .bg-purple-700 {
    background-color: var(--theme-primary) !important;
}
.hover\:bg-indigo-600:hover, .hover\:bg-indigo-700:hover,
.hover\:bg-violet-600:hover, .hover\:bg-violet-700:hover,
.hover\:bg-purple-700:hover {
    background-color: var(--theme-primary-hover) !important;
}
.bg-indigo-50, .bg-indigo-100, .bg-violet-50, .bg-violet-100, .bg-purple-50, .bg-purple-100 {
    background-color: color-mix(in srgb, var(--theme-primary) 12%, transparent) !important;
}
.dark .dark\:bg-indigo-900, .dark .dark\:bg-indigo-950,
.dark .dark\:bg-violet-900, .dark .dark\:bg-purple-900 {
    background-color: color-mix(in srgb, var(--theme-primary) 22%, var(--theme-surface, #111827)) !important;
}

.text-indigo-500, .text-indigo-600, .text-indigo-700,
.text-violet-500, .text-violet-600, .text-violet-700,
.text-purple-600, .text-purple-700,
.hover\:text-indigo-500:hover, .hover\:text-indigo-600:hover, .hover\:text-indigo-700:hover,
.hover\:text-violet-400:hover {
    color: var(--theme-primary) !important;
}
.dark .dark\:text-indigo-300, .dark .dark\:text-indigo-400,
.dark .dark\:text-violet-300, .dark .dark\:text-violet-400,
.dark .dark\:text-purple-300 {
    color: var(--theme-accent) !important;
}
.text-indigo-100, .text-indigo-200, .dark\:text-indigo-100, .dark\:text-indigo-200 {
    color: color-mix(in srgb, white 82%, var(--theme-primary)) !important;
}

.border-indigo-200, .border-indigo-300, .border-indigo-400, .border-indigo-500, .border-indigo-600,
.border-violet-200, .hover\:border-indigo-300:hover, .hover\:border-indigo-400:hover,
.hover\:border-indigo-600:hover, .focus\:border-indigo-500:focus {
    border-color: var(--theme-primary) !important;
}
.dark .dark\:border-indigo-600, .dark .dark\:border-indigo-700, .dark .dark\:border-indigo-800,
.dark .dark\:hover\:border-indigo-600:hover {
    border-color: color-mix(in srgb, var(--theme-primary) 45%, transparent) !important;
}

.focus\:ring-indigo-500:focus {
    --tw-ring-color: var(--theme-primary);
}

.from-indigo-400, .from-indigo-500, .from-indigo-600, .from-indigo-700,
.from-violet-500, .from-violet-600, .from-purple-500, .from-purple-600 {
    --tw-gradient-from: var(--theme-primary) !important;
    --tw-gradient-to: rgb(var(--theme-primary-rgb) / 0) !important;
    --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
}
.via-purple-500, .via-indigo-500, .via-violet-500 {
    --tw-gradient-to: rgb(var(--theme-secondary-rgb) / 0) !important;
    --tw-gradient-stops: var(--tw-gradient-from), var(--theme-secondary), var(--tw-gradient-to) !important;
}
.to-purple-400, .to-purple-500, .to-purple-600, .to-purple-700,
.to-indigo-500, .to-indigo-600, .to-violet-500, .to-violet-600, .to-pink-500 {
    --tw-gradient-to: var(--theme-secondary) !important;
}
.hover\:from-indigo-700:hover, .hover\:from-indigo-600:hover {
    --tw-gradient-from: var(--theme-primary-hover) !important;
}
.hover\:to-purple-700:hover, .hover\:to-indigo-700:hover {
    --tw-gradient-to: var(--theme-primary-hover) !important;
}

.bg-gradient-to-r.from-indigo-600.to-purple-600,
.bg-gradient-to-r.from-indigo-500.to-purple-500,
.bg-gradient-to-r.from-indigo-600.to-purple-600.hover\:from-indigo-700:hover,
.bg-gradient-to-r.from-blue-600.to-indigo-600 {
    background-image: var(--theme-gradient) !important;
}
.bg-gradient-to-br.from-indigo-50.to-purple-50,
.bg-gradient-to-br.from-indigo-50.to-violet-50,
.from-indigo-50, .to-indigo-50, .to-purple-50, .to-violet-50 {
    background-color: color-mix(in srgb, var(--theme-primary) 10%, var(--theme-surface, #fff));
}

.ring-indigo-500, .focus\:ring-indigo-500:focus {
    --tw-ring-color: var(--theme-primary) !important;
}

/* ===================================================================
   5) HOME PÚBLICA + CATÁLOGO — fundo/texto seguem o tema (não cinza fixo)
   =================================================================== */
html.gs-themed-public,
html.gs-themed-public body {
    background-color: var(--theme-bg, #f6f7fb);
    color: var(--theme-text, #1e293b);
}

.gs-home,
.gs-public-main {
    background-color: var(--theme-bg, #f6f7fb) !important;
    color: var(--theme-text, #1e293b);
}

.gs-home h1, .gs-home h2, .gs-home h3,
.gs-public-main h1, .gs-public-main h2 {
    color: var(--theme-heading, inherit);
}

.gs-home .gs-theme-fill,
.gs-home .gs-theme-fill h2,
.gs-home .gs-section-pill,
.gs-home .gs-section-pill h2,
.gs-home .cta-premium,
.gs-home .cta-premium h2,
.gs-home .cta-premium p {
    color: var(--theme-on-primary, #fff) !important;
}

.gs-home .cta-premium a {
    color: var(--theme-primary) !important;
}

.gs-home .text-gray-600,
.gs-home .text-gray-500,
.gs-home .text-gray-400,
.gs-home .dark\:text-gray-400 {
    color: var(--theme-text-muted) !important;
}

.gs-theme-fill,
.gs-section-pill {
    background: var(--theme-gradient) !important;
    color: var(--theme-on-primary, #fff) !important;
}

.gs-theme-chip {
    background: rgb(var(--theme-primary-rgb) / 0.1) !important;
    color: var(--theme-primary) !important;
    border-color: rgb(var(--theme-primary-rgb) / 0.35) !important;
}

.gs-hero-dots {
    background: rgb(var(--theme-primary-rgb) / 0.38) !important;
    border: 1px solid rgb(var(--theme-primary-rgb) / 0.28) !important;
}

/* Cabeçalho de grupo (grid + lista): contraste estável em todos os temas */
.svc-group-head {
    background: var(--theme-gradient) !important;
    color: var(--theme-on-primary, #fff);
}
.svc-group-head__title,
.svc-group-head__desc {
    color: var(--theme-on-primary, #fff) !important;
}
.svc-group-head__desc {
    opacity: 0.82;
}
.svc-group-head__icon {
    background: var(--theme-on-primary, #fff) !important;
    color: var(--theme-primary) !important;
}
.svc-group-head__icon svg,
.svc-group-head__icon i {
    color: inherit !important;
}
.svc-group-head__count {
    background: var(--theme-on-primary, #fff) !important;
    color: var(--theme-primary) !important;
}

.svc-login-banner {
    background: rgb(var(--theme-primary-rgb) / 0.08) !important;
    border-color: rgb(var(--theme-primary-rgb) / 0.22) !important;
}

.svc-grid-group,
#svcGroupsWrap {
    background: var(--theme-card) !important;
    border-color: var(--theme-border) !important;
}

.gs-public-main .text-gray-600,
.gs-public-main .text-gray-500,
.gs-public-main .text-gray-400 {
    color: var(--theme-text-muted) !important;
}
