/* ═══════════════════════════════════════════════════
   Q_fin — Obsidian Terminal
   Premium dark fintech dashboard
   ═══════════════════════════════════════════════════ */

:root {
    --bg-deep:    #06080d;
    --bg:         #0a0e17;
    --bg-card:    #111827;
    --bg-elevated:#1a2332;
    --border:     rgba(255,255,255,0.06);
    --text:       #e8edf5;
    --text-dim:   #7a8599;
    --text-muted: #4a5568;
    --accent:     #00d4aa;
    --accent-dim: rgba(0,212,170,0.12);
    --green:      #00d4aa;
    --green-dim:  rgba(0,212,170,0.15);
    --red:        #ff6b6b;
    --red-dim:    rgba(255,107,107,0.15);
    --blue:       #5b9cf6;
    --blue-dim:   rgba(91,156,246,0.15);
    --purple:     #a78bfa;
    --purple-dim: rgba(167,139,250,0.15);
    --orange:     #f59e0b;
    --orange-dim: rgba(245,158,11,0.15);
    --radius:     14px;
    --radius-sm:  8px;
    --gap:        14px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overscroll-behavior: contain; -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Outfit', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    padding: 0 var(--gap) var(--gap);
    padding-top: calc(66px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overflow-x: hidden;
}

/* Noise overlay */
.noise {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

@media (hover: none) { .noise { display: none; } }

body > *:not(.noise):not(.header):not(.tab-bar):not(.loading-overlay) { position: relative; z-index: 1; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

/* ─── Header ─── */
.header {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: rgba(17, 24, 39, 0.75);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    border-radius: 0 0 16px 16px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 50;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.logo {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 20px;
    letter-spacing: -0.5px;
    color: var(--text);
}

.logo-accent { color: var(--accent); }

.header-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 3px 8px;
    border-radius: 4px;
    animation: pulse-badge 2.5s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.exchange-select {
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237a8599' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.exchange-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── Tab Bar ─── */
.tab-bar {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
    display: flex;
    background: rgba(17, 24, 39, 0.75);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 20px;
    padding: 4px 6px;
    padding-bottom: 4px;
    z-index: 100;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 10px 8px;
    min-height: 50px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 14px;
}

.tab-btn.active { color: var(--accent); background: rgba(0,212,170,0.1); }
.tab-btn:active { transform: scale(0.92); }

.tab-icon { width: 24px; height: 24px; }
.tab-label { font-size: 11px; font-weight: 500; letter-spacing: 0.3px; }

/* ─── Tab Panes ─── */
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 8px;
    animation: cardIn 0.35s ease both;
}

.card:nth-child(1) { animation-delay: 0s; }
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.18s; }
.card:nth-child(5) { animation-delay: 0.24s; }

@keyframes cardIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.card-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* ─── Hero Stat (big number) ─── */
.hero-stat {
    text-align: center;
    padding: 8px 0 4px;
    margin-bottom: 8px;
}

.hero-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--text), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.5px;
}

/* ─── Stats Row ─── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px;
    text-align: center;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.stat-label {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* ─── Chart Container ─── */
.chart-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
}

.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ─── Period Buttons ─── */
.period-buttons {
    display: flex;
    gap: 6px;
    margin-bottom: var(--gap);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border);
}

.period-btn {
    flex: 1;
    padding: 8px 4px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.period-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.period-btn:active { transform: scale(0.96); }

/* ─── Toggle ─── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: var(--gap);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    min-height: 44px;
    cursor: pointer;
}

.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 11px;
    cursor: pointer;
    transition: all 0.25s;
}

.toggle.on {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.25s;
}

.toggle.on::after {
    transform: translateX(18px);
    background: var(--accent);
}

/* ─── Trade Items ─── */
.trade-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s;
}

.trade-item:active { border-color: rgba(255,255,255,0.12); }

.trade-dir {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 3px 7px;
    border-radius: 4px;
    display: inline-block;
}

.trade-dir.long  { background: var(--green-dim); color: var(--green); }
.trade-dir.short { background: var(--red-dim); color: var(--red); }

.trade-pnl {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 14px;
}

.trade-pnl.positive { color: var(--green); }
.trade-pnl.negative { color: var(--red); }

.trade-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Position Card ─── */
.position-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.position-dir {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 15px;
}

.position-entry {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-dim);
}

/* ─── Account Row ─── */
.account-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.account-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

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

.account-label {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
}

.account-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.account-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 500;
}

/* ─── Doughnut Legend ─── */
.doughnut-wrap {
    display: flex;
    align-items: center;
    gap: 20px;
}

.doughnut-chart-box {
    width: 130px; height: 130px;
    flex-shrink: 0;
}

.doughnut-legend {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.legend-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.legend-dot {
    width: 10px; height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.legend-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}

/* ─── Divergence Summary ─── */
.div-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: var(--gap);
}

.div-stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 8px;
    text-align: center;
}

.div-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 600;
}

.div-stat-label {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ─── Loading ─── */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(6,8,13,0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.loading-overlay.hidden { display: none; }

.loader { position: relative; width: 44px; height: 44px; }

.loader-ring {
    position: absolute;
    inset: 0;
    border: 2px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader-ring:nth-child(2) {
    inset: 6px;
    border-top-color: transparent;
    border-right-color: var(--blue);
    animation-duration: 1.5s;
    animation-direction: reverse;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Error / Empty ─── */
.error-box, .empty-box {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.error-box .retry-btn {
    margin-top: 16px;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(0,212,170,0.2);
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 500;
    min-height: 44px;
    transition: all 0.2s;
}

.error-box .retry-btn:active { transform: scale(0.96); }

/* ─── Color Utilities ─── */
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-blue   { color: var(--blue); }
.text-purple { color: var(--purple); }
.text-orange { color: var(--orange); }
.text-dim    { color: var(--text-dim); }
.text-muted  { color: var(--text-muted); }

/* ─── Load More Button ─── */
.load-more-btn {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--text-dim);
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 4px;
}

.load-more-btn:hover { border-color: var(--accent); color: var(--accent); }
