/* Reset y Variables Base */
:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-emerald: #10b981;
    --accent-emerald-dark: rgba(16, 185, 129, 0.15);
    --accent-rose: #f43f5e;
    --font-family: 'Inter', -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

/* Efecto Premium de Fondo Dinámico Glassmorphism */
.glass-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
                radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.1), transparent 25%);
    z-index: -1;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Encabezado */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.topbar h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.topbar h1 span {
    color: var(--accent-blue);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.dot.online {
    background-color: var(--accent-emerald);
    box-shadow: 0 0 10px var(--accent-emerald);
}

.dot.offline {
    background-color: var(--accent-rose);
    box-shadow: 0 0 10px var(--accent-rose);
}

/* Botones Premium */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.btn-primary {
    background-color: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-primary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-accent {
    background-color: var(--accent-blue);
    color: white;
    width: 100%;
    margin-top: 1rem;
}

.btn-accent:hover {
    background-color: var(--accent-blue-hover);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* Sistema de Grid: 2 columnas ([Config + Credenciales] | [Gráfico + Monitor Alertas]) */
.dashboard-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.config-panel      { grid-column: 1 / 2; grid-row: 1; }
.credentials-panel { grid-column: 1 / 2; grid-row: 2; margin-top: 0; }

.chart-panel {
    grid-column: 2 / 3;
    grid-row: 1;
    display: flex;
    flex-direction: column;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-legend {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.chart-container {
    width: 100%;
    height: 420px;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.alerts-panel {
    grid-column: 2 / 3;
    grid-row: 2;
    min-height: 400px;
}

/* Tarjetas Vidrio Congelado */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.panel h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* Controles de Formulario limpios */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group select,
.form-group input {
    width: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem;
    border-radius: 6px;
    font-family: var(--font-family);
    transition: border-color 0.2s ease;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* Panel Mágico de Permisos */

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.credential-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.credential-item:last-child {
    border-bottom: none;
}

.cred-info h3 {
    font-size: 0.9rem;
    font-weight: 500;
}

.cred-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

/* Panel Asíncrono de Avisos de Inversión */

.alerts-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 700px;
    overflow-y: auto;
}

.alert-card {
    background-color: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.alert-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
}

.alert-header {
    padding: 1rem 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background-color: rgba(0, 0, 0, 0.2);
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #94a3b8;
}

.signal-badge {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.confidence-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #cbd5e1;
}

.badge {
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.badge-buy {
    background-color: var(--accent-emerald-dark);
    color: #34d399;
}

.timestamp {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.alert-body {
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.math-analysis h4,
.ai-analysis h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1.2rem;
}

.stat-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.stat-box:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

.stat-value.text-emerald { color: #34d399; }
.stat-value.text-rose { color: #fb7185; }
.stat-value.text-blue { color: #60a5fa; }

.ratios {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8rem;
    padding-top: 1rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.ai-text-content {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #e2e8f0;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
}

.ai-error-box {
    background: rgba(244, 63, 94, 0.08);
    border-left: 4px solid var(--accent-rose);
    color: #fda4af;
    font-family: monospace;
    font-size: 0.85rem;
}

.ai-analysis {
    padding-top: 1.2rem;
    border-top: 1px solid var(--border-color);
}

/* Anatomía de la Vela */
.candle-anatomy {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.candle-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}

.candle-stat {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.candle-stat:last-child {
    border-bottom: none;
}

.candle-stat .label { color: var(--text-secondary); }
.candle-stat .val { font-family: monospace; font-weight: 500; }

/* Cajitas de Niveles */
.trading-boxes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin: 1.2rem 0;
}

.box {
    padding: 0.8rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.3rem;
}

.box-blue { background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3); color: #60a5fa; }
.box-green { background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.3); color: #34d399; }
.box-orange { background: rgba(249, 115, 22, 0.1); border: 1px solid rgba(249, 115, 22, 0.3); color: #fb923c; }

.box-label { font-size: 0.7rem; text-transform: uppercase; font-weight: 600; }
.box-price { font-size: 1rem; font-weight: 700; font-family: monospace; }

/* Scrollbar Personalizado */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ---- Botón de Análisis Principal ---- */
.analyze-section {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.2rem;
}

.btn-analyze {
    background: linear-gradient(135deg, #1d4ed8, #0891b2);
    color: white;
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem;
    border-radius: 10px;
    transition: opacity 0.2s ease, transform 0.15s ease;
}
.btn-analyze:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-analyze:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Badge resultado del análisis */
.analysis-badge {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    text-align: center;
    display: none;
}
.analysis-badge.buy  { background: rgba(16,185,129,0.15); color: #34d399; display: block; }
.analysis-badge.sell { background: rgba(244,63,94,0.15);  color: #fb7185; display: block; }
.analysis-badge.hold { background: rgba(234,179,8,0.15);  color: #facc15; display: block; }
.analysis-badge.error { background: rgba(100,100,100,0.15); color: var(--text-secondary); display: block; }

/* ---- Encabezado panel alertas ---- */
.alerts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.alerts-header h2 { margin-bottom: 0; }
.btn-sm { padding: 0.3rem 0.8rem; font-size: 0.8rem; }

.no-alerts {
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 3rem 1rem;
    line-height: 1.7;
}

/* ---- Tarjetas por tipo de señal ---- */
.buy-alert  { border-color: #00ff88 !important; background-color: rgba(0, 255, 136, 0.05) !important; }
.sell-alert { border-color: #fb7185 !important; background-color: rgba(244, 63, 94, 0.05) !important; }
.hold-alert { border-color: #facc15 !important; background-color: rgba(234, 179, 8, 0.05) !important; }

.vibrant-signal {
    color: #00ff88;
    text-shadow: 0 0 15px rgba(0, 255, 136, 0.5);
    font-weight: 800;
}

.sell-alert .vibrant-signal {
    color: #fb7185;
    text-shadow: 0 0 15px rgba(251, 113, 133, 0.5);
}
.hold-alert { border-color: rgba(250,204,21,0.25)  !important; background-color: rgba(234,179,8,0.04) !important; }

.badge-buy  { background: rgba(16,185,129,0.15);  color: #34d399; }
.badge-sell { background: rgba(244,63,94,0.15);   color: #fb7185; }
.badge-hold { background: rgba(234,179,8,0.15);   color: #facc15; }

/* Código inline */
code {
    background: rgba(255,255,255,0.07);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    color: #93c5fd;
}

/* Estado credencial */
.cred-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Ratios responsivos */
.ratios { flex-wrap: wrap; gap: 0.8rem 1.5rem; }

/* ---- Modal de guía de credenciales ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }

.modal-box {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    max-width: 480px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}
.modal-box h3 { font-size: 1.1rem; font-weight: 600; }
#modal-body ol { padding-left: 1.3rem; line-height: 2.2; color: var(--text-secondary); font-size: 0.9rem; }
#modal-body a { color: var(--accent-blue); }
.modal-box .btn-accent { margin-top: 0; }

/* ---- Responsivo ---- */
@media (max-width: 1100px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }
    .config-panel      { grid-column: 1 / 2; grid-row: 1; }
    .credentials-panel { grid-column: 2 / 3; grid-row: 1; }
    .alerts-panel      { grid-column: 1 / 3; grid-row: 2; }
}
/* Cuadrícula V2 (6 campos) */
.v2-grid {
    grid-template-columns: repeat(3, 1fr) !important;
}

@media (max-width: 600px) {
    .v2-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 640px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .config-panel, .credentials-panel, .alerts-panel { grid-column: 1; grid-row: auto; }
    .topbar { flex-direction: column; gap: 1rem; align-items: flex-start; }
    .ratios { flex-direction: column; gap: 0.4rem; }
}
/* ---- Sentimiento Macro económico ---- */
.macro-section {
    padding: 1.2rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 1rem;
}

.macro-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.macro-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
}

.macro-item {
    background: rgba(15, 23, 42, 0.5);
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    text-align: center;
    transition: all 0.3s ease;
}

.macro-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: help;
}

.macro-val {
    font-size: 0.95rem;
    font-weight: 700;
    font-family: monospace;
}

.macro-val small {
    font-size: 0.7rem;
    opacity: 0.8;
}

.macro-impact {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

/* Colores de Impacto */
.macro-item.bullish {
    border-color: rgba(244, 63, 94, 0.3);
    box-shadow: inset 0 0 10px rgba(244, 63, 94, 0.05);
}
.macro-item.bullish .macro-impact { color: #fb7185; background: rgba(244, 63, 94, 0.1); }
.macro-item.bullish .macro-val { color: #fb7185; }

.macro-item.bearish {
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: inset 0 0 10px rgba(16, 185, 129, 0.05);
}
.macro-item.bearish .macro-impact { color: #34d399; background: rgba(16, 185, 129, 0.1); }
.macro-item.bearish .macro-val { color: #34d399; }

.macro-item.neutral {
    border-color: rgba(255, 255, 255, 0.1);
}
.macro-item.neutral .macro-impact { color: var(--text-secondary); background: rgba(255, 255, 255, 0.05); }

@media (max-width: 500px) {
    .macro-grid { grid-template-columns: 1fr; }
}
