/* --- CONFIGURACIÓN DE VARIABLES Y TEMAS --- */
:root {
    /* Tema Oscuro (Predeterminado para Trading) */
    --bg-body: #0b0e11;
    --glass-bg: rgba(30, 34, 45, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-main: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --success: #34d399;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    --input-bg: rgba(255, 255, 255, 0.05);
    /* <select> cerrado y opciones del desplegable (donde el navegador lo permite) */
    --select-bg: #1e293b;
    --select-color: #f1f5f9;
    --select-option-bg: #1e293b;
    --select-option-color: #f1f5f9;
    --select-border: rgba(255, 255, 255, 0.16);
    color-scheme: dark;
}

html[data-theme="light"] {
    /* Tema Claro */
    --bg-body: #f0f2f5;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.05);
    --text-main: #1a1d23;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --success: #10b981;
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --input-bg: rgba(0, 0, 0, 0.03);
    --select-bg: #ffffff;
    --select-color: #0f172a;
    --select-option-bg: #ffffff;
    --select-option-color: #0f172a;
    --select-border: rgba(15, 23, 42, 0.2);
    color-scheme: light;
}

/* --- RESET BÁSICO --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
}

body {
    background: var(--bg-body);
    color: var(--text-main);
    transition: background 0.3s ease, color 0.3s ease;
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    min-height: 100svh;
}
/* Móvil/tablet: min-height 100*vh hace el documento más alto que la ventana *visible* (barra del
   navegador); los toques a “pestañas / menú / +” van al propio HTML. !important anula <style>
   incrustados y hojas posteriores salvo excepciones (login-standalone). */
/* padding-bottom: env() suele ser 0 en Android con botones de sistema; 3rem ≈ 48px evita que el
   documento ocupe la zona de atrás / inicio / recientes. Usar con viewport-fit=cover en la página. */
@media (max-width: 1400px) {
    html {
        min-height: 0 !important;
        height: auto !important;
    }
    body:not(.login-standalone) {
        min-height: 0 !important;
        min-height: auto !important;
        height: auto !important;
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px), 3rem) !important;
    }
    body.login-standalone {
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px), 2.5rem) !important;
    }
}

/* --- SELECT / DESPLEGABLES (toda la web que enlaza este CSS) --- */
select {
    background-color: var(--select-bg);
    color: var(--select-color);
    border: 1px solid var(--select-border);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    font: inherit;
    line-height: 1.35;
    cursor: pointer;
    max-width: 100%;
    box-sizing: border-box;
}

select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

select option,
select optgroup {
    background-color: var(--select-option-bg);
    color: var(--select-option-color);
}

/* --- NAVEGACIÓN (TOP NAV) --- */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
}

.logo {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--accent);
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* --- ELEMENTOS DE INTERFAZ (BOTONES E INPUTS) --- */
.icon-btn {
    background: var(--glass-bg);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    font-size: 0.9rem;
}

.icon-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.logout-link {
    text-decoration: none;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-weight: bold;
    transition: 0.2s;
}

.logout-link:hover {
    background: #ef4444;
    color: white;
}

/* --- CONTENEDOR PRINCIPAL --- */
.container {
    max-width: 1100px;
    margin: 100px auto 40px;
    padding: 0 20px;
}

.welcome {
    margin-bottom: 2.5rem;
}

.badge.online {
    color: var(--success);
    font-weight: 800;
    background: rgba(52, 211, 153, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
}

/* --- GRID DE TARJETAS (ESTADÍSTICAS / INVERSIONES) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card p {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-card h3 {
    font-size: 2rem;
    font-weight: 800;
    margin: 8px 0;
}

/* --- SLIDERS (RSI) --- */
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: rgba(100, 116, 139, 0.2);
    outline: none;
    margin: 15px 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 3px solid var(--bg-body);
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

/* --- PANEL DE CONFIGURACIÓN Y MODALES --- */
.config-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    margin-top: 20px;
}

/* --- RESPONSIVE --- */
@media (max-width: 600px) {
    .container { margin-top: 80px; }
    .top-nav { padding: 0.8rem 1rem; }
    .stat-card h3 { font-size: 1.5rem; }
}

/* --- Dashboard (solo admin): conmutador ES/EN --- */
.dash-admin-lang {
    flex-shrink: 0;
}
.dash-admin-lang-form {
    display: inline-flex;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, 0.38);
    border-radius: 8px;
    overflow: hidden;
    vertical-align: middle;
}
.dash-admin-lang-btn {
    margin: 0;
    padding: 6px 12px;
    font-weight: 700;
    font-size: 0.78rem;
    cursor: pointer;
    border: none;
    background: rgba(148, 163, 184, 0.18);
    color: #cbd5e1;
}
.dash-admin-lang-btn:hover {
    background: rgba(59, 130, 246, 0.28);
    color: #fff;
}
.dash-admin-lang-btn.is-active {
    background: var(--accent, #3b82f6);
    color: #fff;
}

/* --- Marca global: logo SVG --- */
.top-nav-brand-cluster {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.logo-interarea {
    display: block;
    flex-shrink: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: pulse-glow 3s infinite ease-in-out;
    filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.3));
}
@keyframes pulse-glow {
    0% {
        filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.4));
    }
    50% {
        filter: drop-shadow(0 0 8px rgba(6, 182, 212, 0.6));
    }
    100% {
        filter: drop-shadow(0 0 2px rgba(59, 130, 246, 0.4));
    }
}
.logo-interarea:hover {
    transform: scale(1.08) translateY(-2px);
    filter: drop-shadow(0 0 12px rgba(59, 130, 246, 0.8))
        drop-shadow(0 0 20px rgba(6, 182, 212, 0.4));
}

/* --- Subpáginas: “Menú” (admin) / vuelta a dashboard (cliente) bajo la safe area móvil --- */
/* Mín. ~3 mm bajo reloj si env=0; con notch env() domina. */
.admin-subpage-top,
.dash-back-nav {
    box-sizing: border-box;
    margin: 0;
    position: relative;
    z-index: 2;
    padding: max(3mm, calc(4px + env(safe-area-inset-top, 0px)))
        max(0px, env(safe-area-inset-right, 0px)) 6px
        max(0px, env(safe-area-inset-left, 0px));
}
.dash-back-nav {
    display: block;
    margin-bottom: 4px;
}
.dash-back-nav .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.14);
    color: #e2e8f0;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
}
.dash-back-nav .btn-ghost:hover {
    filter: brightness(1.08);
}

/* Admin subpáginas: mismo aspecto botón que en dashboard cliente */
.admin-subpage-top .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.14);
    color: #e2e8f0;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    box-sizing: border-box;
}
.admin-subpage-top button.btn-ghost {
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
}
.admin-subpage-top .btn-ghost:hover {
    filter: brightness(1.08);
}

/* Admin: Correo/Insights: siempre una sola fila, sin bajar a segunda línea */
.admin-subpage-top.ia-comm-topbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    min-width: 0;
    padding-top: max(3mm, calc(4px + env(safe-area-inset-top, 0px)));
    padding-bottom: 10px;
}
.admin-subpage-top.ia-comm-topbar .btn-ghost {
    flex: 0 0 auto;
    white-space: nowrap;
    font-size: max(0.8rem, 12px);
}
/* Una sola fila: en anchos mínimos se puede desplazar ligeramente en horizontal. */
@media (max-width: 360px) {
    .admin-subpage-top.ia-comm-topbar {
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .admin-subpage-top.ia-comm-topbar::-webkit-scrollbar {
        display: none;
    }
}