/* ===== CLOUD RISE SISTEMA DE TEMAS Y COMPONENTES UNIFICADOS ===== */
:root,
[data-theme="dark"],
body.cr-dark-theme {
    --cr-bg-dark: #0a0c13;
    --cr-panel-bg: #121622;
    --cr-card-bg: #181d2e;
    --cr-card-hover: #1f253a;
    --cr-border: #262e45;
    --cr-primary: #7928ca;
    --cr-accent: #ff007f;
    --cr-cyan: #00f2fe;
    --cr-text: #ffffff;
    --cr-text-muted: #ffffff;
    --cr-subtext: #e2e8f0;
    --cr-input-bg: #0f121b;
    --cr-modal-bg: #121622;
    --cr-shadow: rgba(0, 0, 0, 0.6);
    --cr-toolbar-bg: rgba(18, 22, 34, 0.85);
    --cr-viewport-bg: #080a0f;
    --cr-item-box-bg: #111420;
    color-scheme: dark;
}

[data-theme="light"],
body.cr-light-theme {
    --cr-bg-dark: #f0f2f5;
    --cr-panel-bg: #ffffff;
    --cr-card-bg: #ffffff;
    --cr-card-hover: #f1f5f9;
    --cr-border: #cbd5e1;
    --cr-primary: #7928ca;
    --cr-accent: #ff007f;
    --cr-cyan: #0284c7;
    --cr-text: #0f172a;
    --cr-text-muted: #1e293b;
    --cr-subtext: #334155;
    --cr-input-bg: #f8fafc;
    --cr-modal-bg: #ffffff;
    --cr-shadow: rgba(0, 0, 0, 0.1);
    --cr-toolbar-bg: rgba(255, 255, 255, 0.9);
    --cr-viewport-bg: #e2e8f0;
    --cr-item-box-bg: #f1f5f9;
    color-scheme: light;
}

/* Reglas globales de contraste para textos pequeños y text-muted */
:root:not([data-theme="light"]) small,
:root:not([data-theme="light"]) .text-muted,
:root:not([data-theme="light"]) .text-secondary,
[data-theme="dark"] small,
[data-theme="dark"] .text-muted,
[data-theme="dark"] .text-secondary,
body.cr-dark-theme small,
body.cr-dark-theme .text-muted,
body.cr-dark-theme .text-secondary {
    color: #ffffff !important;
}

[data-theme="light"] small,
[data-theme="light"] .text-muted,
[data-theme="light"] .text-secondary,
body.cr-light-theme small,
body.cr-light-theme .text-muted,
body.cr-light-theme .text-secondary {
    color: #1e293b !important;
}

/* Form checks y labels */
:root:not([data-theme="light"]) .form-check-label,
[data-theme="dark"] .form-check-label,
body.cr-dark-theme .form-check-label {
    color: #ffffff !important;
}
[data-theme="light"] .form-check-label,
body.cr-light-theme .form-check-label {
    color: #1e293b !important;
}

/* Botones outline en modo claro */
[data-theme="light"] .btn-outline-light,
body.cr-light-theme .btn-outline-light {
    color: #1e293b !important;
    border-color: #cbd5e1 !important;
    background-color: #f8fafc !important;
}
[data-theme="light"] .btn-outline-light:hover,
body.cr-light-theme .btn-outline-light:hover {
    background-color: #e2e8f0 !important;
    color: #0f172a !important;
}
[data-theme="light"] .btn-outline-secondary,
body.cr-light-theme .btn-outline-secondary {
    color: #334155 !important;
    border-color: #cbd5e1 !important;
}

/* Compatibilidad con selects y options */
select, .form-select-custom, .form-control-custom, .form-select, .form-control {
    background-color: var(--cr-input-bg) !important;
    color: var(--cr-text) !important;
    border-color: var(--cr-border) !important;
}
option {
    background-color: var(--cr-card-bg) !important;
    color: var(--cr-text) !important;
}

/* Compatibilidad con clases bootstrap bg-light y bordes en tema oscuro */
:root:not([data-theme="light"]) .bg-light,
[data-theme="dark"] .bg-light,
body.cr-dark-theme .bg-light {
    background-color: var(--cr-panel-bg) !important;
    border-color: var(--cr-border) !important;
    color: var(--cr-text) !important;
}

:root:not([data-theme="light"]) .border-bottom,
:root:not([data-theme="light"]) .border-top,
:root:not([data-theme="light"]) .border,
[data-theme="dark"] .border-bottom,
[data-theme="dark"] .border-top,
[data-theme="dark"] .border,
body.cr-dark-theme .border-bottom,
body.cr-dark-theme .border-top,
body.cr-dark-theme .border {
    border-color: var(--cr-border) !important;
}

:root:not([data-theme="light"]) .modal-content,
[data-theme="dark"] .modal-content,
body.cr-dark-theme .modal-content {
    background-color: var(--cr-card-bg) !important;
    color: var(--cr-text) !important;
    border: 1px solid var(--cr-border) !important;
}

[data-theme="light"] .screen-badge-info,
body.cr-light-theme .screen-badge-info {
    background: rgba(255, 255, 255, 0.88) !important;
    color: #1e293b !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
}

/* Select2 Bootstrap 5 en Dark Mode y Light Mode */
:root:not([data-theme="light"]) .select2-container--bootstrap-5 .select2-selection,
[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection,
body.cr-dark-theme .select2-container--bootstrap-5 .select2-selection {
    background-color: var(--cr-input-bg) !important;
    border-color: var(--cr-border) !important;
    color: var(--cr-text) !important;
}
:root:not([data-theme="light"]) .select2-container--bootstrap-5 .select2-selection .select2-selection__rendered,
[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection .select2-selection__rendered,
body.cr-dark-theme .select2-container--bootstrap-5 .select2-selection .select2-selection__rendered {
    color: var(--cr-text) !important;
}
:root:not([data-theme="light"]) .select2-dropdown,
[data-theme="dark"] .select2-dropdown,
body.cr-dark-theme .select2-dropdown {
    background-color: var(--cr-card-bg) !important;
    border-color: var(--cr-border) !important;
    color: var(--cr-text) !important;
}
:root:not([data-theme="light"]) .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field,
[data-theme="dark"] .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field,
body.cr-dark-theme .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    background-color: var(--cr-input-bg) !important;
    border-color: var(--cr-border) !important;
    color: var(--cr-text) !important;
}
:root:not([data-theme="light"]) .select2-container--bootstrap-5 .select2-results__option,
[data-theme="dark"] .select2-container--bootstrap-5 .select2-results__option,
body.cr-dark-theme .select2-container--bootstrap-5 .select2-results__option {
    color: var(--cr-text) !important;
}
:root:not([data-theme="light"]) .select2-container--bootstrap-5 .select2-results__option--highlighted,
[data-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted,
body.cr-dark-theme .select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--cr-primary) !important;
    color: #ffffff !important;
}

/* Indicadores de Conexión */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.3s, box-shadow 0.3s;
}
.status-connected {
    background-color: #2ecc71 !important;
    box-shadow: 0 0 8px #2ecc71 !important;
}
.status-disconnected {
    background-color: #ef4444 !important;
    box-shadow: 0 0 6px #ef4444 !important;
}
.status-connecting {
    background-color: #f59e0b !important;
    box-shadow: 0 0 8px #f59e0b !important;
    animation: crPulseConnecting 1.2s infinite ease-in-out;
}

@keyframes crPulseConnecting {
    0%, 100% { opacity: 0.5; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* Botón Conectar (Tuerca) en Navbar */
.btn-connect-header {
    background: linear-gradient(135deg, rgba(121, 40, 202, 0.15), rgba(255, 0, 127, 0.15));
    border: 1px solid var(--cr-border);
    color: var(--cr-text);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s ease;
}
.btn-connect-header:hover {
    border-color: var(--cr-accent);
    background: linear-gradient(135deg, rgba(121, 40, 202, 0.25), rgba(255, 0, 127, 0.25));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 0, 127, 0.2);
}
.btn-connect-header .gear-icon {
    font-size: 1rem;
    transition: transform 0.4s ease;
}
.btn-connect-header:hover .gear-icon {
    transform: rotate(45deg);
}
.btn-connect-header .conn-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    padding-left: 2px;
}

/* Botón Selector de Tema */
.btn-theme-toggle {
    background: var(--cr-card-bg);
    border: 1px solid var(--cr-border);
    color: var(--cr-text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}
.btn-theme-toggle:hover {
    border-color: var(--cr-cyan);
    transform: scale(1.08);
}

/* Modal de Conexiones Unificado */
.cr-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 15px;
}
.cr-modal-backdrop.active {
    display: flex;
    animation: crFadeIn 0.2s ease-out;
}

@keyframes crFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cr-modal-window {
    background: var(--cr-modal-bg);
    border: 1px solid var(--cr-border);
    border-radius: 16px;
    width: 100%;
    max-width: 620px;
    box-shadow: 0 20px 50px var(--cr-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: crPopUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes crPopUp {
    from { transform: scale(0.92) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.cr-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--cr-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}
.cr-modal-header h5 {
    margin: 0;
    font-weight: 800;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--cr-text);
}
.cr-modal-close-btn {
    background: transparent;
    border: none;
    color: var(--cr-text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
}
.cr-modal-close-btn:hover {
    color: var(--cr-text);
    background: rgba(255, 255, 255, 0.1);
}

.cr-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(85vh - 120px);
    overflow-y: auto;
}

.cr-conn-card {
    background: var(--cr-card-bg);
    border: 1px solid var(--cr-border);
    border-radius: 12px;
    padding: 16px;
}
.cr-conn-card-title {
    font-size: 0.9rem;
    font-weight: 800;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--cr-text);
}
.cr-conn-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 700;
}

.cr-form-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--cr-text-muted);
    margin-bottom: 4px;
    display: block;
}
.cr-form-control {
    background: var(--cr-input-bg);
    border: 1px solid var(--cr-border);
    color: var(--cr-text);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    width: 100%;
    outline: none;
    transition: all 0.2s;
}
.cr-form-control:focus {
    border-color: var(--cr-cyan);
    box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2);
}

.cr-modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--cr-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}
