/* ================================================================
   MARKETS PAGE — Light Theme (v5)
   ================================================================ */

body.markets-open { background: #f8fafc !important; }

body.markets-open .app-shell {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    background: #f8fafc !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
}

body.markets-open .markets-page,
.markets-page {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-height: 100svh;
    width: 100%;
}

/* ---- Page header ---- */
.mkt-page-head {
    padding: 18px 28px 14px;
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
}

.mkt-scope-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.mkt-scope-select-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.mkt-scope-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 6px 32px 6px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #f1f5f9;
    color: #0f172a;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}
.mkt-scope-select:hover { border-color: #3b82f6; }
.mkt-scope-select:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
.mkt-scope-caret { position: absolute; right: 10px; pointer-events: none; color: #64748b; }

.mkt-live-stamp { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.mkt-live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #16a34a; box-shadow: 0 0 5px #16a34a;
    animation: mktPulse 2s ease-in-out infinite;
}
.mkt-live-text { color: #64748b; font-size: 0.82rem; }

@keyframes mktPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.mkt-overview-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2rem, 3.2vw, 2.8rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    color: #0f172a;
    margin: 0 0 4px;
    letter-spacing: -0.02em;
}
.mkt-overview-sub { font-size: 0.88rem; color: #64748b; margin: 0; }

/* ---- 4 Metric Cards ---- */
.mkt-metric-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid #e2e8f0;
    background: #ffffff;
}
.mkt-metric-card {
    padding: 18px 22px;
    border-right: 1px solid #e2e8f0;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mkt-metric-card:last-child { border-right: none; }

.mkt-metric-eyebrow {
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: #94a3b8;
    text-transform: uppercase;
}
.mkt-metric-val {
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    font-weight: 700;
    color: #0f172a;
    line-height: 1;
}
.mkt-val-gain { color: #16a34a !important; }
.mkt-val-loss { color: #dc2626 !important; }
.mkt-metric-desc { font-size: 0.78rem; color: #64748b; margin: 0; }

/* Sentiment */
.mkt-sentiment-body { display: flex; align-items: center; gap: 12px; flex: 1; }
.mkt-sentiment-icon svg { color: #dc2626; }
[data-sentiment="bull"] .mkt-sentiment-icon svg { color: #16a34a; }
.mkt-sentiment-text { flex: 1; min-width: 0; }
.mkt-sentiment-spark { margin-left: auto; opacity: 0.9; flex-shrink: 0; }

/* Breadth */
.mkt-breadth-nums { display: flex; align-items: baseline; gap: 12px; }
.mkt-breadth-adv { font-size: clamp(1.3rem, 2vw, 1.8rem); font-weight: 700; color: #16a34a; line-height: 1; }
.mkt-breadth-dec { font-size: clamp(1.3rem, 2vw, 1.8rem); font-weight: 700; color: #dc2626; line-height: 1; }
.mkt-breadth-labels { display: flex; gap: 20px; font-size: 0.74rem; color: #94a3b8; }
.mkt-breadth-bar-wrap { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: #f1f5f9; }
.mkt-breadth-bar-adv { background: #16a34a; height: 100%; transition: width 600ms ease; min-width: 2px; }
.mkt-breadth-bar-dec { background: #dc2626; height: 100%; transition: width 600ms ease; min-width: 2px; }
.mkt-ratio-label { font-size: 0.75rem; color: #64748b; margin: 0; }

/* Top sector */
.mkt-sector-card-inner { display: flex; align-items: center; gap: 12px; flex: 1; }
.mkt-sector-icon-wrap {
    width: 42px; height: 42px; border-radius: 12px;
    background: #eff6ff;
    display: flex; align-items: center; justify-content: center;
    color: #3b82f6; flex-shrink: 0;
}
.mkt-sector-chg { font-size: 1rem; font-weight: 700; margin: 2px 0 3px; }

/* Most active */
.mkt-active-symbol { font-size: clamp(1.2rem, 2vw, 1.7rem); font-weight: 700; color: #0f172a; line-height: 1; display: block; }
.mkt-active-row { display: flex; align-items: baseline; gap: 10px; margin-top: 5px; }
.mkt-active-price { font-size: 0.9rem; color: #475569; font-weight: 500; }
.mkt-active-chg { font-size: 0.9rem; font-weight: 700; }

/* ---- Bottom grid ---- */
.mkt-bottom-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    flex: 1;
    gap: 0;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}
.mkt-panel {
    padding: 22px 24px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border: none;
    margin: 12px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(15,23,42,0.06), 0 0 0 1px #e2e8f0;
}

.mkt-panel-hd { display: flex; align-items: center; gap: 8px; flex-shrink: 0; color: #64748b; }
.mkt-panel-hd svg { color: #94a3b8; }
.mkt-panel-hd-row { justify-content: space-between; }

/* Sector tabs */
.mkt-sector-tabs {
    display: flex; gap: 3px; background: #f1f5f9;
    border-radius: 8px; padding: 3px; width: fit-content;
}
.mkt-sector-tab {
    padding: 5px 13px; border: none; border-radius: 6px;
    background: transparent; color: #64748b;
    font-size: 0.79rem; font-weight: 500; cursor: pointer;
    transition: background 150ms, color 150ms; white-space: nowrap;
}
.mkt-sector-tab.active { background: #ffffff; color: #0f172a; box-shadow: 0 1px 3px rgba(15,23,42,0.08); }

/* Donut + sector list stacked */
.mkt-sector-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    flex: 1;
    overflow: hidden;
}
.mkt-donut-wrap {
    position: relative;
    width: 260px; height: 260px;
    flex-shrink: 0;
}
.mkt-donut { display: block; overflow: visible; }

@keyframes mktSegIn {
    from { opacity: 0; transform: scale(0.2); }
    to   { opacity: 1; transform: scale(1); }
}
.mkt-donut-seg {
    transform-origin: 130px 130px;
    opacity: 0;
    animation: mktSegIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
    animation-delay: var(--seg-delay, 0ms);
}

.mkt-donut-label {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center; pointer-events: none; width: 90px;
}
.mkt-donut-label strong { display: block; font-size: 0.88rem; font-weight: 700; color: #0f172a; line-height: 1.2; }
.mkt-donut-label span { display: block; font-size: 0.7rem; color: #64748b; line-height: 1.4; }
.mkt-donut-label small { display: block; font-size: 0.6rem; color: #94a3b8; margin-top: 2px; }

/* Sector list: 2 columns below donut */
.mkt-sector-list {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 7px 16px; width: 100%;
}
.mkt-sector-row { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
.mkt-sector-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.mkt-sector-name { flex: 1; color: #475569; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mkt-sector-pct { font-weight: 700; color: #0f172a; min-width: 34px; text-align: right; flex-shrink: 0; }
.mkt-sector-chg-val { min-width: 52px; text-align: right; font-weight: 700; font-size: 0.78rem; flex-shrink: 0; }

.mkt-sector-note { font-size: 0.71rem; color: #94a3b8; margin: 0; flex-shrink: 0; }

/* Time tabs */
.mkt-time-tabs {
    display: flex;
    gap: 3px;
    padding: 4px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(226, 232, 240, 0.72));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 18px rgba(15, 23, 42, 0.05);
}
.mkt-time-tab {
    padding: 5px 12px; border: none; border-radius: 7px;
    background: transparent; color: #64748b;
    font-size: 0.77rem; font-weight: 800; cursor: pointer;
    transition: background 150ms, color 150ms, box-shadow 150ms, transform 150ms;
}
.mkt-time-tab:hover { color: #0f172a; transform: translateY(-1px); }
.mkt-time-tab.active {
    background: #ffffff;
    color: #2563eb;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.14), inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

/* Breadth chart */
.mkt-breadth-gauge-card {
    position: relative;
    display: grid;
    grid-template-columns: minmax(210px, 300px) 1fr;
    align-items: center;
    gap: clamp(18px, 3vw, 34px);
    padding: clamp(20px, 3vw, 30px);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    overflow: hidden;
    background:
        radial-gradient(circle at 18% 0%, rgba(16, 185, 129, 0.24), transparent 34%),
        radial-gradient(circle at 93% 18%, rgba(239, 68, 68, 0.18), transparent 30%),
        linear-gradient(135deg, #0b1220 0%, #111827 45%, #1e293b 100%);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    isolation: isolate;
}

.mkt-breadth-gauge-card::before {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: 17px;
    background:
        linear-gradient(115deg, rgba(255, 255, 255, 0.12), transparent 36%),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 72px);
    pointer-events: none;
    z-index: 0;
}

.mkt-breadth-gauge-card::after {
    content: "";
    position: absolute;
    left: 22px;
    right: 22px;
    top: 16px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent);
    opacity: 0.7;
    pointer-events: none;
    z-index: 0;
}

.mkt-gauge-wrap {
    position: relative;
    z-index: 1;
    min-height: 156px;
    filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.26));
}

.mkt-gauge-svg {
    width: 100%;
    height: 156px;
    display: block;
    overflow: visible;
}

.mkt-gauge-track,
.mkt-gauge-adv,
.mkt-gauge-dec {
    fill: none;
    stroke-width: 20;
    stroke-linecap: round;
    path-length: 100;
}

.mkt-gauge-track {
    stroke: rgba(148, 163, 184, 0.22);
}
.mkt-gauge-adv {
    stroke: #18d681;
    stroke-dasharray: 0 100;
    transition: stroke-dasharray 600ms ease;
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.68));
}
.mkt-gauge-dec {
    stroke: #f43f5e;
    stroke-dasharray: 0 100;
    stroke-dashoffset: 0;
    transform: scaleX(-1);
    transform-origin: 110px 112px;
    transition: stroke-dasharray 600ms ease, stroke-dashoffset 600ms ease;
    filter: drop-shadow(0 0 8px rgba(244, 63, 94, 0.62));
}

.mkt-gauge-center {
    position: absolute;
    left: 50%;
    top: 60%;
    transform: translate(-50%, -50%);
    text-align: center;
    min-width: 120px;
    padding: 12px 14px 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.46);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 14px 34px rgba(2, 6, 23, 0.22);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.mkt-gauge-center strong {
    display: block;
    color: #f8fafc;
    font-size: clamp(2rem, 3vw, 2.6rem);
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.03em;
}

.mkt-gauge-center span {
    display: block;
    margin-top: 6px;
    color: #cbd5e1;
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mkt-gauge-counts {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.mkt-gauge-counts div {
    position: relative;
    min-height: 112px;
    padding: 18px 20px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.mkt-gauge-counts div:first-child { color: #22c55e; }
.mkt-gauge-counts div:last-child { color: #f43f5e; }

.mkt-gauge-counts div::before {
    content: "";
    position: absolute;
    inset: auto 18px 14px 18px;
    height: 4px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.8;
    box-shadow: 0 0 18px currentColor;
}

.mkt-gauge-counts span {
    display: block;
    color: #cbd5e1;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.mkt-gauge-counts strong {
    display: block;
    margin-top: 12px;
    font-size: clamp(2rem, 3vw, 2.7rem);
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.04em;
}

.mkt-gauge-green { color: #22c55e; text-shadow: 0 0 24px rgba(34, 197, 94, 0.28); }
.mkt-gauge-red { color: #f43f5e; text-shadow: 0 0 24px rgba(244, 63, 94, 0.25); }

.mkt-breadth-chart-wrap {
    flex: 1;
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 250, 252, 0.84)),
        repeating-linear-gradient(0deg, transparent 0 31px, rgba(148, 163, 184, 0.12) 31px 32px);
    padding: 14px 8px 4px;
    display: flex;
    min-height: 220px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.92);
}
.mkt-breadth-svg { width: 100%; height: 100%; display: block; }

/* Bottom stats */
.mkt-breadth-stats {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    border: none;
    border-radius: 0;
    overflow: visible;
    flex-shrink: 0;
}
.mkt-stat-block {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    border: 1px solid rgba(226, 232, 240, 0.86);
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.05);
}
.mkt-stat-block:last-child { border-right: 1px solid rgba(226, 232, 240, 0.86); }
.mkt-stat-label { font-size: 0.67rem; font-weight: 850; letter-spacing: 0.1em; color: #94a3b8; }
.mkt-adv-label { color: #16a34a; }
.mkt-dec-label { color: #dc2626; }
.mkt-stat-val { font-size: clamp(1rem, 1.8vw, 1.4rem); font-weight: 700; color: #0f172a; line-height: 1; }
.mkt-stat-delta { font-size: 0.73rem; color: #64748b; }
.mkt-adv-delta { color: #16a34a; }
.mkt-dec-delta { color: #dc2626; }

/* ---- Responsive ---- */
@media (max-width: 1000px) {
    .mkt-metric-row { grid-template-columns: repeat(2, 1fr); }
    .mkt-bottom-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .mkt-metric-row { grid-template-columns: 1fr; }
    .mkt-metric-card { border-right: none; border-bottom: 1px solid #e2e8f0; }
    .mkt-page-head { padding: 14px 16px; }
    .mkt-sector-list { grid-template-columns: 1fr; }
    .mkt-breadth-gauge-card,
    .mkt-gauge-counts { grid-template-columns: 1fr; }
}
