/* ═══════════════════════════════════════════════════════════════════
   TradeMate VN — Stock Detail CSS
   4-col header (Info | Trading | Fund | Tech) + 2 tabs
   ═══════════════════════════════════════════════════════════════════ */

/* ── Back Row ───────────────────────────────────────────────── */
.sd-back-row { margin-bottom: var(--space-sm); }

/* ── Star (Watchlist) ───────────────────────────────────────── */
.sd-star {
    background: none; border: none; cursor: pointer;
    font-size: 18px; color: var(--color-text-muted);
    transition: color 0.2s; padding: 8px; vertical-align: middle;
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.sd-star:hover, .sd-star.active { color: var(--color-neutral); }

/* ═══ 4-COLUMN HEADER ════════════════════════════════════════ */
.sd-header-grid {
    display: grid;
    grid-template-columns: 1fr 1.1fr 1.4fr 1.4fr;
    gap: 0;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    overflow: hidden;
}

.sd-col {
    padding: var(--space-sm) var(--space-sm);
    min-width: 0;
    border-left: 1px solid var(--color-border);
}
.sd-col:first-child { border-left: none; }

/* Column title bar */
.sd-col-title {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-xs);
    padding-bottom: 3px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Column footer (period, trend) */
.sd-col-footer {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    margin-top: 2px;
    text-align: right;
}

/* ── Col 1: Identity ──────────────────────────────────────── */
.sd-col-identity {
    position: relative;
}
.sd-col-identity > .sd-star {
    position: absolute;
    top: var(--space-xs);
    right: var(--space-xs);
    font-size: 20px;
    z-index: 1;
}
.sd-col-identity .sd-id-top {
    padding-right: 26px;
}
.sd-col-identity .sd-symbol {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-primary);
}
.sd-col-identity .sd-name {
    display: block;
    font-size: 0.65rem;
    color: var(--color-text-secondary);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sd-col-identity .sd-meta-sector {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    margin-bottom: 2px;
}
.sd-col-identity .sd-price-line {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    margin: 2px 0 var(--space-xs);
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--color-border);
}
.sd-col-identity .sd-price {
    font-size: var(--font-size-xl);
    font-weight: 700;
}
.sd-col-identity .sd-change {
    font-size: var(--font-size-xs);
    font-weight: 600;
}
.sd-col-identity .sd-meta {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}

/* ── Col 2: Trading — Signal badge ───────────────────────── */
.sd-signal-badge {
    display: inline-block;
    font-size: var(--font-size-xs);
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
}
.sd-signal--buy  { background: rgba(16,185,129,0.15); color: var(--color-positive); }
.sd-signal--sell { background: rgba(239,68,68,0.15); color: var(--color-negative); }
.sd-signal--watch { background: rgba(245,158,11,0.15); color: var(--color-neutral); }
.sd-signal-bias {
    font-weight: 400; font-size: 0.6rem; opacity: 0.8; text-transform: none;
}

/* Level pills compact */
.sd-levels {
    display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px;
}
.sd-levels .tm-level-pill {
    font-size: 0.6rem; padding: 1px 4px;
}

/* ═══ KEY-VALUE ROWS ═════════════════════════════════════════ */
.sd-kv {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1px 0;
    font-size: var(--font-size-xs);
    line-height: 1.55;
}
.sd-kv-label {
    color: var(--color-text-muted);
    white-space: nowrap;
    margin-right: 4px;
    flex-shrink: 0;
}
.sd-kv-value {
    font-weight: 600;
    text-align: right;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sd-kv-value.positive { color: var(--color-positive); }
.sd-kv-value.negative { color: var(--color-negative); }

/* ═══ 2-COL MINI GRID (12 metrics → 6 rows) ═════════════════ */
.sd-kv-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 var(--space-sm);
}

/* ═══ OHLCV CHART ════════════════════════════════════════════ */
.sd-chart-wrapper {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-md);
    position: relative;
}
.sd-chart-in-tab {
    border: none; border-radius: 0; margin-bottom: 0;
}
.sd-chart-header {
    display: flex; align-items: center;
    gap: var(--space-md); flex-wrap: wrap;
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--color-border);
}
.sd-chart-legend { display: flex; gap: var(--space-md); }
.sd-legend-item {
    display: inline-flex; align-items: center;
    gap: 4px; font-size: 11px; color: var(--color-text-muted);
}
.sd-legend-dot {
    width: 12px; height: 3px; border-radius: 2px; display: inline-block;
}
.sd-chart-area { height: 280px; }

/* ═══ SUB-PANELS (RSI, MCDX) ════════════════════════════ */
.sd-sub-panel {
    border-top: 1px solid var(--color-border);
}
.sd-sub-panel-label {
    display: flex;
    gap: var(--space-md);
    padding: 2px var(--space-md);
    font-size: 10px;
    color: var(--color-text-muted);
}
.sd-sub-chart-area { width: 100%; }
.sd-sub-chart-rsi { height: 100px; }
.sd-sub-chart-mcdx { height: 120px; }
.sd-chart-tooltip {
    display: none; position: absolute;
    top: 36px; left: var(--space-md);
    gap: var(--space-md); font-size: 11px;
    color: var(--color-text-secondary);
    z-index: 5; pointer-events: none; flex-wrap: wrap;
}
.sd-chart-tooltip .positive { color: var(--color-positive); }
.sd-chart-tooltip .negative { color: var(--color-negative); }

/* ═══ OVERRIDES ══════════════════════════════════════════════ */
.tm-stat-chip-value.positive { color: var(--color-positive); }
.tm-stat-chip-value.negative { color: var(--color-negative); }

/* ═══════════════════════════════════════════════════════════════════
   STOCK LIST — Heatmap-style Grid Tiles
   ═══════════════════════════════════════════════════════════════════ */
.sl-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.sl-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-xs);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    min-height: 52px;
    gap: 2px;
}
.sl-tile:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 5;
}

.sl-tile-symbol {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
}
.sl-tile-change {
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
}
.sl-tile-change.positive { color: var(--color-positive); }
.sl-tile-change.negative { color: var(--color-negative); }

/* Color backgrounds */
.sl-tile--pos {
    background: linear-gradient(135deg, rgba(16,185,129,0.08), rgba(16,185,129,0.03));
    border-color: rgba(16,185,129,0.25);
}
.sl-tile--strong-pos {
    background: linear-gradient(135deg, rgba(16,185,129,0.18), rgba(16,185,129,0.08));
    border-color: rgba(16,185,129,0.4);
}
.sl-tile--neg {
    background: linear-gradient(135deg, rgba(239,68,68,0.08), rgba(239,68,68,0.03));
    border-color: rgba(239,68,68,0.25);
}
.sl-tile--strong-neg {
    background: linear-gradient(135deg, rgba(239,68,68,0.18), rgba(239,68,68,0.08));
    border-color: rgba(239,68,68,0.4);
}

/* ═══ STOCK LIST HEADER ══════════════════════════════════════ */
.sl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}
.sl-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}
.sl-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.sl-count-badge {
    font-size: var(--font-size-sm);
    font-weight: 400;
    color: var(--color-text-muted);
}
.sl-style-badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: 12px;
    white-space: nowrap;
}
.sl-filter-input {
    max-width: 180px;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
}
.sl-sort-select {
    max-width: 170px;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
}

/* ═══ GROUP SUMMARY PILLS ═══════════════════════════════════ */
.sl-group-summary {
    display: flex;
    gap: 6px;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}
.sl-group-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--color-bg-card);
    border: 1px solid var(--pill-color, var(--color-border));
    border-radius: 16px;
    cursor: pointer;
    transition: opacity 0.2s;
    font-size: var(--font-size-xs);
}
.sl-group-pill:hover { opacity: 0.8; }
.sl-group-pill--dim { opacity: 0.4; }
.sl-group-pill-icon { font-size: 0.7rem; }
.sl-group-pill-label {
    color: var(--color-text-secondary);
    font-weight: 500;
}
.sl-group-pill-count {
    font-weight: 700;
    color: var(--color-text);
    background: var(--color-bg-secondary);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.6rem;
}

/* ═══ GROUP SECTIONS ════════════════════════════════════════ */
.sl-group {
    margin-bottom: var(--space-md);
}
.sl-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    margin-bottom: var(--space-xs);
    border-left: 3px solid var(--group-color, var(--color-border));
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: color-mix(in srgb, var(--group-color, var(--color-border)) 6%, transparent);
}
.sl-group-header-icon { font-size: 0.75rem; }
.sl-group-header-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
}
.sl-group-header-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-left: auto;
}

/* ═══ SCORED TILE (enriched) ════════════════════════════════ */
.sl-tile--scored {
    min-height: 58px;
    padding: 5px var(--space-xs) 4px;
    gap: 1px;
}
.sl-tile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 2px;
}
.sl-tile-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 2px;
}
.sl-tile-score {
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--color-text-muted);
    background: var(--color-bg-secondary);
    padding: 0 3px;
    border-radius: 3px;
    line-height: 1.4;
}
.sl-tile-metric {
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    line-height: 1;
    white-space: nowrap;
}
.sl-tile-signal-label {
    font-size: 0.5rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    padding: 1px 4px;
    border-radius: 3px;
    flex-shrink: 0;
}
.sl-tile-signal-label--buy {
    color: var(--color-positive);
    background: rgba(16, 185, 129, 0.15);
}
.sl-tile-signal-label--sell {
    color: var(--color-negative);
    background: rgba(239, 68, 68, 0.15);
}
.sl-tile-signal-label--watch {
    color: var(--color-neutral);
    background: rgba(245, 158, 11, 0.12);
}

/* Unfit toggle */
.sl-unfit-toggle {
    text-align: center;
    padding: var(--space-sm) 0;
}
.sl-unfit-btn {
    font-size: var(--font-size-xs);
    padding: 4px 12px;
    min-height: 44px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.sl-unfit-btn:hover { color: var(--color-text); }

/* ═══ MODAL SCORE SECTION ═══════════════════════════════════ */
.sl-modal-score-section {
    margin-bottom: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-sm);
}
.sl-modal-score-bar {
    height: 6px;
    background: var(--color-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.sl-modal-score-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}
.sl-modal-score-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sl-modal-score-value {
    font-size: var(--font-size-md);
    font-weight: 700;
}
.sl-modal-score-group {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}
.sl-modal-reasons {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
}

/* Modal color classes */
.tm-modal-body .positive { color: var(--color-positive); }
.tm-modal-body .negative { color: var(--color-negative); }

/* Modal info rows */
.sl-modal-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}
.sl-modal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-sm);
}
.sl-modal-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}
.sl-modal-value {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
}

/* ═══ RESPONSIVE ═════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .sd-header-grid { grid-template-columns: 1fr 1fr; }
    .sd-col:nth-child(3) { border-left: none; border-top: 1px solid var(--color-border); }
    .sd-col:nth-child(4) { border-top: 1px solid var(--color-border); }
    .sl-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 600px) {
    .sd-col { padding: var(--space-xs) var(--space-sm); }
    .sd-chart-area { height: 220px; }
    .sd-sub-chart-rsi { height: 80px; }
    .sd-sub-chart-mcdx { height: 80px; }
    .sd-col-identity .sd-price { font-size: var(--font-size-lg); }
    .sd-kv-2col { gap: 0 4px; }
    .sl-grid { grid-template-columns: repeat(4, 1fr); }
    .sl-tile { min-height: 44px; }
    .sl-header { flex-direction: column; align-items: flex-start; }
    .sl-header-right { width: 100%; }
    .sl-filter-input { flex: 1; max-width: none; }
    .sl-sort-select { max-width: 140px; }
    .sl-group-summary { gap: 4px; }
    .sl-group-pill { padding: 3px 8px; font-size: 0.6rem; }
}
@media (max-width: 400px) {
    .sd-header-grid { grid-template-columns: 1fr; }
    .sd-col { border-left: none !important; border-top: 1px solid var(--color-border); }
    .sd-col:first-child { border-top: none; }
    .sl-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 360px) {
    .sl-grid { grid-template-columns: repeat(2, 1fr); }
    .sd-chart-area { height: 180px; }
    .sd-sub-chart-rsi { height: 60px; }
    .sd-sub-chart-mcdx { height: 60px; }
}

/* ═══ LIVE ANALYSIS ══════════════════════════════════════════ */

/* Banner shown when source is db_only */
.sd-live-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-md);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-primary, #6366f1);
    border-radius: var(--radius-md, 8px);
}
.sd-live-banner-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    flex: 1;
}
.sd-live-btn {
    white-space: nowrap;
    padding: 6px 16px;
    min-height: 44px;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: #fff;
    background: var(--color-primary, #6366f1);
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    transition: opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.sd-live-btn:hover { opacity: 0.85; }
.sd-live-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Fullscreen overlay during live analysis */
.sd-live-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}
.sd-live-progress {
    width: 380px;
    max-width: 90vw;
    padding: var(--space-lg) var(--space-xl);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg, 12px);
    text-align: center;
}
.sd-live-progress-title {
    font-size: var(--font-size-md);
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-md);
}
.sd-live-progress-bar {
    height: 8px;
    background: var(--color-bg-secondary, #1e1e2e);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: var(--space-sm);
}
.sd-live-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--color-primary, #6366f1);
    border-radius: 4px;
    transition: width 0.4s ease;
}
.sd-live-progress-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: 4px;
}
.sd-live-progress-time {
    font-size: var(--font-size-xs, 0.7rem);
    color: var(--color-text-muted);
    opacity: 0.7;
}

/* Source badge on header */
.sd-source-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: var(--font-size-xs, 0.65rem);
    font-weight: 600;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}
.sd-source-badge--db {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}
.sd-source-badge--live {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

@media (max-width: 600px) {
    .sd-live-banner {
        flex-direction: column;
        text-align: center;
    }
    .sd-live-progress { padding: var(--space-md); }
}
