/**
 * Theme Switcher - SISTEMA RINCONADA V1
 * Selector flotante de tema (Normal / Oscuro / Claro)
 * 
 * Prioridad de tema:
 *   1. localStorage('rinconada_theme')
 *   2. Tema por defecto de Empresa (inyectado por PHP)
 *   3. Fallback: normal
 *
 * Las variables --company-primary, --company-secondary, --company-accent
 * se inyectan desde PHP en cada vista.
 */

/* ============================================================
   MODO DARK — Paleta oscura premium fija
   ============================================================ */
body[data-theme="dark"] {
    --primary-bg: #1b0863;
    --primary-bg-dark: #0a032c;
    --primary-bg-light: #280aa1;
    --accent-color: #fccd21;
    --accent-hover: #fccd21cc;
    --text-light: #ffffff;
    --text-muted: #b0b5da;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    --toast-bg: rgba(10, 3, 44, 0.85);
    --toast-text: #ffffff;
    --toast-border: rgba(255, 255, 255, 0.1);
    --toast-success: #10b981;
    --toast-error: #ef4444;
    --toast-info: #3b82f6;
    --input-bg: rgba(255, 255, 255, 0.04);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-text: #ffffff;
    --input-placeholder: rgba(255, 255, 255, 0.3);
    --table-header-bg: rgba(255, 255, 255, 0.03);
    --table-row-hover: rgba(255, 255, 255, 0.03);
    --table-border: rgba(255, 255, 255, 0.05);
    background: radial-gradient(circle at 50% 50%, #280aa1 0%, #0a032c 100%) !important;
    color: #ffffff !important;
}

body[data-theme="dark"] .circle-1 {
    background: #1b0863;
    opacity: 0.5;
}

body[data-theme="dark"] .circle-2 {
    background: #fccd21;
    opacity: 0.15;
}

body[data-theme="dark"] .circle-3 {
    background: #a10a74;
    opacity: 0.15;
}

/* ============================================================
   MODO LIGHT — Paleta clara corporativa fija
   ============================================================ */
body[data-theme="light"] {
    --primary-bg: #f5f6fa;
    --primary-bg-dark: #eef0f8;
    --primary-bg-light: #e4e7f5;
    --accent-color: #fccd21;
    --accent-hover: #e0b41b;
    --text-light: #1e1b4b;
    --text-muted: #4f46e5;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(79, 70, 229, 0.15);
    --glass-shadow: rgba(79, 70, 229, 0.08);
    --toast-bg: rgba(255, 255, 255, 0.95);
    --toast-text: #1a1a2e;
    --toast-border: rgba(0, 0, 0, 0.15);
    --toast-success: #059669;
    --toast-error: #dc2626;
    --toast-info: #2563eb;
    --input-bg: rgba(255, 255, 255, 0.85);
    --input-border: rgba(79, 70, 229, 0.2);
    --input-text: #1e1b4b;
    --input-placeholder: rgba(30, 27, 75, 0.4);
    --table-header-bg: rgba(79, 70, 229, 0.06);
    --table-row-hover: rgba(79, 70, 229, 0.04);
    --table-border: rgba(79, 70, 229, 0.1);
    background: radial-gradient(circle at 50% 50%, #e4e7f5 0%, #eef0f8 100%) !important;
    color: #1e1b4b !important;
}

body[data-theme="light"] .circle-1 {
    background: #cbd5e1;
    opacity: 0.4;
}

body[data-theme="light"] .circle-2 {
    background: #fccd21;
    opacity: 0.15;
}

body[data-theme="light"] .circle-3 {
    background: #e9d5ff;
    opacity: 0.35;
}

/* === Light: Header / Nav === */
body[data-theme="light"] .header-nav {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(79, 70, 229, 0.15);
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.06);
}

body[data-theme="light"] .brand-icon {
    color: #4f46e5;
}

body[data-theme="light"] .brand-title h1 {
    color: #1e1b4b;
}

body[data-theme="light"] .brand-title span {
    color: #4f46e5;
}

body[data-theme="light"] .user-name {
    color: #1e1b4b;
}

body[data-theme="light"] .user-role {
    color: #b45309;
}

body[data-theme="light"] .btn-admin {
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(79, 70, 229, 0.2);
    color: #4f46e5;
}

body[data-theme="light"] .btn-admin:hover {
    background: rgba(79, 70, 229, 0.15);
    color: #4f46e5;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.1);
}

body[data-theme="light"] .btn-logout {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #b91c1c;
}

body[data-theme="light"] .btn-logout:hover {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.3);
    color: #b91c1c;
}

/* === Light: Sections === */
body[data-theme="light"] .section-title {
    color: #1e1b4b;
    border-left-color: #4f46e5;
}

body[data-theme="light"] .dashboard-footer {
    border-top: 1px solid rgba(79, 70, 229, 0.1);
    color: #4f46e5;
}

/* === Light: Login === */
body[data-theme="light"] .login-container {
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(79, 70, 229, 0.15);
    box-shadow: 0 20px 40px rgba(79, 70, 229, 0.08);
}

body[data-theme="light"] .login-container:hover {
    box-shadow: 0 25px 50px rgba(79, 70, 229, 0.12), 0 0 20px rgba(0, 0, 0, 0.02);
}

body[data-theme="light"] .form-input {
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    color: var(--input-text);
}

body[data-theme="light"] .form-input::placeholder {
    color: var(--input-placeholder);
}

body[data-theme="light"] .form-input:hover {
    background: #ffffff;
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(252, 205, 33, 0.2);
}

body[data-theme="light"] .form-input:focus {
    background: #ffffff;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(252, 205, 33, 0.3);
}

body[data-theme="light"] .alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #b91c1c;
}

body[data-theme="light"] .alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #065f46;
}

body[data-theme="light"] .login-footer {
    border-top: 1px solid rgba(79, 70, 229, 0.1);
}

/* === Light: Admin Tables === */
body[data-theme="light"] .btn-nav {
    background: rgba(79, 70, 229, 0.06);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .btn-nav:hover {
    background: rgba(79, 70, 229, 0.12);
    border-color: var(--accent-color);
    color: #4f46e5;
}

body[data-theme="light"] th {
    background: var(--table-header-bg);
    border-bottom: 1.5px solid var(--table-border);
    color: #4f46e5;
}

body[data-theme="light"] td {
    color: #1e1b4b;
    border-bottom: 1px solid var(--table-border);
}

body[data-theme="light"] tr:hover td {
    background: var(--table-row-hover);
}

body[data-theme="light"] .tab-btn {
    background: rgba(79, 70, 229, 0.06);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .tab-btn:hover {
    background: rgba(79, 70, 229, 0.12);
    color: #1e1b4b;
}

body[data-theme="light"] .tab-btn.active {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #ffffff;
}

body[data-theme="light"] .form-control {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
}

body[data-theme="light"] .form-control:focus {
    border-color: var(--accent-color);
    background: #ffffff;
    box-shadow: 0 0 8px rgba(252, 205, 33, 0.2);
}

body[data-theme="light"] select.form-control option {
    background: #ffffff;
    color: #1e1b4b;
}

body[data-theme="light"] .search-input {
    background: rgba(255, 255, 255, 0.9) !important;
    border: 1.5px solid rgba(79, 70, 229, 0.3) !important;
    color: #1e1b4b !important;
}

body[data-theme="light"] .search-input::placeholder {
    color: rgba(30, 27, 75, 0.5) !important;
}

body[data-theme="light"] .search-input:focus {
    border-color: #4f46e5 !important;
    background: #ffffff !important;
    box-shadow: 0 0 10px rgba(79, 70, 229, 0.2) !important;
}

/* === Light: Modals === */
body[data-theme="light"] .modal-content {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(79, 70, 229, 0.15);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
}

body[data-theme="light"] .modal-header {
    border-bottom: 1px solid rgba(79, 70, 229, 0.1);
}

body[data-theme="light"] .modal-header h2 {
    color: #1e1b4b;
}

body[data-theme="light"] .modal-body {
    color: #1e1b4b;
}

/* === Light: Switches === */
body[data-theme="light"] .switch-wrapper {
    background: rgba(79, 70, 229, 0.04);
    border: 1px solid rgba(79, 70, 229, 0.1);
}

body[data-theme="light"] .switch-wrapper:hover {
    background: rgba(79, 70, 229, 0.08);
}

body[data-theme="light"] .switch-label {
    color: #1e1b4b;
}

body[data-theme="light"] .slider {
    background-color: #cbd5e1;
}

body[data-theme="light"] .slider:before {
    background-color: #ffffff;
}

body[data-theme="light"] .btn-submit-form {
    color: #0a032c;
}

/* === Light: Pagination === */
body[data-theme="light"] .page-btn {
    background: rgba(79, 70, 229, 0.06);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .page-btn:hover:not(:disabled) {
    background: rgba(79, 70, 229, 0.15);
    color: #1e1b4b;
}

body[data-theme="light"] .page-btn:disabled {
    opacity: 0.4;
}

body[data-theme="light"] .limit-select {
    background: rgba(79, 70, 229, 0.06);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .limit-select option {
    background: #ffffff;
    color: #1e1b4b;
}

/* === Light: Glass Buttons === */
body[data-theme="light"] .btn-glass {
    background: rgba(79, 70, 229, 0.06);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .btn-glass:hover:not(.btn-accent) {
    background: rgba(79, 70, 229, 0.12);
    color: #1e1b4b;
}

body[data-theme="light"] .btn-glass.btn-accent {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #0a032c;
}

body[data-theme="light"] .btn-glass.btn-accent:hover {
    filter: brightness(1.1);
}

body[data-theme="light"] .btn-action {
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}

body[data-theme="light"] .btn-action:hover {
    background: rgba(79, 70, 229, 0.18);
    color: #1e1b4b;
}

body[data-theme="light"] .badge-role {
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.2);
    color: #4f46e5;
}

/* === Light: Toast === */
body[data-theme="light"] .toast {
    background: var(--toast-bg);
    border: 1px solid var(--toast-border);
    color: var(--toast-text);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

body[data-theme="light"] .toast-success-border {
    border-left: 4px solid var(--toast-success);
}

body[data-theme="light"] .toast-error-border {
    border-left: 4px solid var(--toast-error);
}

/* === Dark: Toast === */
body[data-theme="dark"] .toast {
    background: var(--toast-bg);
    border: 1px solid var(--toast-border);
    color: var(--toast-text);
}

/* === Dark: Header / Nav (hereda defaults oscuros) === */
body[data-theme="dark"] .header-nav {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

/* ============================================================
   SELECTOR FLOTANTE DE TEMA — Widget UI
   ============================================================ */
.theme-switcher-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 8px;
    font-family: 'Outfit', sans-serif;
}

.theme-switcher-fab .ts-trigger {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    background: rgba(27, 8, 99, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: #fccd21;
    padding: 0;
    outline: none;
}

.theme-switcher-fab .ts-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
    border-color: rgba(252, 205, 33, 0.4);
}

.theme-switcher-fab .ts-trigger:active {
    transform: scale(0.95);
}

/* Adaptación del FAB en modo claro */
body[data-theme="light"] .theme-switcher-fab .ts-trigger {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(79, 70, 229, 0.2);
    color: #4f46e5;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.15);
}

body[data-theme="light"] .theme-switcher-fab .ts-trigger:hover {
    border-color: rgba(79, 70, 229, 0.4);
    box-shadow: 0 6px 28px rgba(79, 70, 229, 0.2);
}

/* Panel desplegable */
.theme-switcher-fab .ts-panel {
    background: rgba(10, 3, 44, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    gap: 4px;
    min-width: 170px;
    transform: translateY(10px);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                opacity 0.2s ease;
}

.theme-switcher-fab .ts-panel.open {
    display: flex;
    transform: translateY(0);
    opacity: 1;
}

.theme-switcher-fab .ts-panel-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #b0b5da;
    padding: 6px 12px 4px;
    font-weight: 600;
    user-select: none;
}

.theme-switcher-fab .ts-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
    width: 100%;
    text-align: left;
}

.theme-switcher-fab .ts-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.theme-switcher-fab .ts-option.active {
    background: rgba(252, 205, 33, 0.15);
    color: #fccd21;
    font-weight: 600;
}

.theme-switcher-fab .ts-option .ts-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.theme-switcher-fab .ts-option .ts-check {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s;
    color: #fccd21;
}

.theme-switcher-fab .ts-option.active .ts-check {
    opacity: 1;
}

/* Adaptación del panel en modo claro */
body[data-theme="light"] .theme-switcher-fab .ts-panel {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(79, 70, 229, 0.15);
    box-shadow: 0 12px 40px rgba(79, 70, 229, 0.15);
}

body[data-theme="light"] .theme-switcher-fab .ts-panel-title {
    color: #4f46e5;
}

body[data-theme="light"] .theme-switcher-fab .ts-option {
    color: #1e1b4b;
}

body[data-theme="light"] .theme-switcher-fab .ts-option:hover {
    background: rgba(79, 70, 229, 0.06);
}

body[data-theme="light"] .theme-switcher-fab .ts-option.active {
    background: rgba(79, 70, 229, 0.1);
    color: #4f46e5;
}

body[data-theme="light"] .theme-switcher-fab .ts-option .ts-check {
    color: #4f46e5;
}

/* Responsividad del FAB */
@media (max-width: 480px) {
    .theme-switcher-fab {
        bottom: 16px;
        left: 16px;
    }

    .theme-switcher-fab .ts-trigger {
        width: 40px;
        height: 40px;
    }

    .theme-switcher-fab .ts-panel {
        min-width: 155px;
    }
}
