/* ============================================
   Dashboard Layout
   ============================================ */
.dashboard-container { padding: 2rem 0; min-height: calc(100vh - 80px); }

.dashboard-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 2rem; flex-wrap: wrap; gap: 1.25rem;
}
.dashboard-title   { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 700; margin-bottom: 0.25rem; }
.dashboard-subtitle { color: var(--color-text-muted); font-size: 0.95rem; }

.dashboard-controls { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.control-select {
    padding: 0.6rem 1rem;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    color: var(--color-text);
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 40px;
    -webkit-appearance: none;
}
.control-select:focus { outline: none; border-color: var(--color-primary); }

.timeframe-toggle {
    display: flex;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    overflow: hidden;
}
.timeframe-btn {
    padding: 0.5rem 0.85rem;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 38px;
}
.timeframe-btn:hover { background: rgba(139,92,246,0.1); color: var(--color-text); }
.timeframe-btn.active { background: var(--color-primary); color: white; }

/* ============================================
   Stats Grid
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    padding: 1.25rem;
}
.stat-label { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.5rem; font-weight: 500; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.5rem; }
.stat-change {
    display: inline-block; font-size: 0.85rem; font-weight: 600;
    padding: 0.25rem 0.5rem; border-radius: 0.25rem;
}
.stat-change.positive { background: rgba(16,185,129,0.1); color: var(--color-success); }
.stat-change.negative { background: rgba(239,68,68,0.1);  color: var(--color-danger); }
.stat-badge {
    display: inline-block; font-size: 0.75rem; font-weight: 600;
    padding: 0.2rem 0.6rem;
    background: rgba(139,92,246,0.1); border: 1px solid var(--color-primary);
    border-radius: 1rem; color: var(--color-primary);
}

/* ============================================
   Content Grid — TV chart left, Historical Match right
   ============================================ */
.content-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 1.5rem; }

.chart-panel {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 12px;
    overflow: hidden;
}
/* TradingView container height */
#tvWidgetContainer { height: 520px !important; }

.insights-panel, .alerts-panel {
    grid-column: span 1;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 1rem;
    overflow: hidden;
}

.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    gap: 0.75rem;
}
.panel-title { font-size: 1.1rem; font-weight: 600; }
.panel-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.icon-btn {
    padding: 0.45rem;
    background: transparent; border: 1px solid var(--color-border);
    border-radius: 0.375rem; color: var(--color-text-muted);
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
    min-width: 34px; min-height: 34px;
}
.icon-btn:hover { background: var(--color-bg-secondary); border-color: var(--color-primary); color: var(--color-primary); }
.icon-btn svg { width: 16px; height: 16px; }
.btn-sm { padding: 0.45rem 0.875rem; font-size: 0.82rem; min-height: 34px; }

/* ============================================
   Chart Container
   ============================================ */
.chart-container { padding: 0; height: 380px; position: relative; overflow: hidden; }
.chart-container canvas { max-width: 100%; max-height: 100%; }
.chart-container > div { width: 100% !important; height: 100% !important; }

/* ============================================
   Insights Panel
   ============================================ */
.insights-content { padding: 1.25rem; max-height: 400px; overflow-y: auto; }
.insight-item {
    display: flex; gap: 1rem; padding: 1rem;
    background: var(--color-bg-secondary); border: 1px solid var(--color-border);
    border-radius: 0.5rem; margin-bottom: 0.875rem;
}
.insight-item:last-child { margin-bottom: 0; }
.insight-icon {
    flex-shrink: 0; width: 2.25rem; height: 2.25rem;
    display: flex; align-items: center; justify-content: center;
    background: rgba(139,92,246,0.1); border-radius: 0.5rem;
}
.insight-icon svg { width: 1.25rem; height: 1.25rem; color: var(--color-primary); }
.insight-text { flex: 1; font-size: 0.9rem; line-height: 1.6; color: var(--color-text-muted); }
.insight-text strong { color: var(--color-text); }

/* ============================================
   Alerts Panel
   ============================================ */
.alerts-list { padding: 1.25rem; max-height: 400px; overflow-y: auto; }
.alert-item {
    display: flex; align-items: flex-start; gap: 1rem; padding: 1rem;
    background: var(--color-bg-secondary); border: 1px solid var(--color-border);
    border-radius: 0.5rem; margin-bottom: 0.875rem; flex-wrap: wrap;
}
.alert-item:last-child { margin-bottom: 0; }
.alert-icon {
    flex-shrink: 0; width: 2.25rem; height: 2.25rem;
    display: flex; align-items: center; justify-content: center;
    background: rgba(245,158,11,0.1); border-radius: 0.5rem;
}
.alert-icon svg { width: 1.25rem; height: 1.25rem; color: var(--color-warning); }
.alert-content { flex: 1; min-width: 0; }
.alert-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.25rem; }
.alert-time  { font-size: 0.75rem; color: var(--color-text-muted); }
.alert-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 3rem 1rem; text-align: center;
}
.empty-state svg { width: 3rem; height: 3rem; color: var(--color-text-muted); margin-bottom: 1rem; }
.empty-state p { color: var(--color-text-muted); font-size: 0.9rem; }

/* ── Toolbar (chart controls inside dashboard) ── */
.toolbar {
    display: flex; flex-direction: column; gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: #111113; border: 1px solid #27272a; border-radius: 12px;
    margin-top: 1.25rem;
}
.toolbar-left  { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.toolbar-right {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 0.75rem;
    padding-top: 0.65rem; border-top: 1px solid #1e1e22;
}
#statusDot.live { background: #26c17b; box-shadow: 0 0 6px #26c17b88; }

/* ============================================
   RESPONSIVE — Tablet (max-width: 1400px)
   ============================================ */
@media (max-width: 1400px) {
    .content-grid { grid-template-columns: 3fr 2fr; }
}
@media (max-width: 1100px) {
    .content-grid { grid-template-columns: 1fr; }
    .chart-panel, .insights-panel, .alerts-panel { grid-column: span 1; }
    #tvWidgetContainer { height: 420px !important; }
}

/* ============================================
   RESPONSIVE — Mobile (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    .dashboard-container { padding: 1.25rem 0; }

    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .dashboard-controls {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    /* Symbol search wrapper fills available space */
    #dashSymbolWrapper { flex: 1 1 auto; min-width: 100px; max-width: 100%; }
    #dashSymbolWrapper > div { width: 100% !important; }
    #symbolSearch { width: 100% !important; min-width: 0 !important; box-sizing: border-box; }

    .control-select { width: 100%; }
    .timeframe-toggle { width: 100%; justify-content: stretch; }
    .timeframe-btn { flex: 1; font-size: 0.78rem; padding: 0.45rem 0.5rem; }

    /* Refresh button + auto-refresh side by side */
    #refreshBtn { flex-shrink: 0; padding: 0.5rem 0.75rem; font-size: 0.82rem; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.875rem; }
    .stat-value { font-size: 1.3rem; }

    .chart-container { height: 280px; padding: 0; }

    .panel-header { padding: 1rem; }
    .insights-content, .alerts-list { padding: 1rem; }

    .toolbar { padding: 0.85rem 1rem; }
    .toolbar-right { flex-direction: column; align-items: flex-start; }
}

/* ============================================
   RESPONSIVE — Small Mobile (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.5rem; }
    .chart-container { height: 240px; padding: 0; }

    /* Scroll timeframe pills rather than wrap */
    .timeframe-toggle { overflow-x: auto; flex-wrap: nowrap; }
    .timeframe-btn { flex-shrink: 0; }
}
/* ── Mobile-responsive inline grids (algo scores + indicators) ── */
@media (max-width: 480px) {
  .algo-score-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .indicator-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    font-size: 0.78rem;
  }
  .algo-score-grid > div,
  .indicator-grid > div {
    padding: 4px 2px;
  }
}
