/* ===========================
   Index Page — Dashboard Styles
   =========================== */

/* --- Page container --- */
.dashboard {
    max-width: 1400px;
    margin: 40px auto 0;
    padding: var(--space-md);
}

/* --- Top Bar --- */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    z-index: 1000;
    justify-content: space-between;
}

#connectionContainer {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.update-timer {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-family: 'SF Mono', 'Menlo', monospace;
    min-width: 40px;
}

/* --- Scroll Controls --- */
.scroll-controls {
    flex: 1;
    display: flex;
    height: 100%;
    margin-left: var(--space-md);
    border-left: 1px solid var(--border-color);
}

.scroll-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.scroll-btn:hover {
    background: var(--bg-card-hover);
    color: var(--color-blue);
}

.scroll-btn:active {
    background: var(--border-color);
}

.scroll-up {
    border-right: 1px solid var(--border-color);
}


/* --- Account Info Section --- */
.account-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.account-card {
    padding: var(--space-md);
}

.account-card .stat-value {
    font-size: var(--font-size-xl);
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.combined-balance-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
}

.combined-balance-card .balance-side {
    display: flex;
    flex-direction: column;
}

.combined-balance-card .right-side {
    align-items: flex-end;
    text-align: right;
}

.combined-balance-card .stat-value {
    font-size: var(--font-size-lg);
}

.combined-balance-card .right-side .stat-value {
    justify-content: flex-end;
}

/* Margin percentage badge */
.margin-badge {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-blue);
    background: var(--color-protected-bg);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* --- Health Bar/Strips Section --- */
.health-bar {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
    width: 100%;
}

.health-strip {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-xs);
    padding: 10px 16px;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    border: 1px solid transparent;
    transition: var(--transition-fast);
    text-decoration: none;
    cursor: pointer;
}

.health-strip:hover {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.position-health-bar {
    margin-top: calc(-1 * var(--space-sm));
}

.position-health-bar .health-strip {
    flex-direction: column;
    gap: 0px;
    padding: 3px 12px;
    font-size: var(--font-size-xs);
    text-align: center;
}

.position-health-bar .health-strip span,
.position-health-bar .health-strip strong {
    display: block;
    width: 100%;
    text-align: center;
}

/* Good State */
.health-good {
    background: rgba(76, 175, 80, 0.08);
    border-color: rgba(76, 175, 80, 0.2);
    color: #2E7D32;
}

[data-theme="dark"] .health-good {
    background: rgba(76, 175, 80, 0.12);
    border-color: rgba(76, 175, 80, 0.3);
    color: #81C784;
}

/* Warning/Average State */
.health-warning {
    background: rgba(255, 152, 0, 0.08);
    border-color: rgba(255, 152, 0, 0.2);
    color: #E65100;
}

[data-theme="dark"] .health-warning {
    background: rgba(255, 152, 0, 0.12);
    border-color: rgba(255, 152, 0, 0.3);
    color: #FFB74D;
}

/* Bad/Critical State */
.health-critical {
    background: rgba(244, 67, 54, 0.08);
    border-color: rgba(244, 67, 54, 0.2);
    color: #C62828;
}

[data-theme="dark"] .health-critical {
    background: rgba(244, 67, 54, 0.12);
    border-color: rgba(244, 67, 54, 0.3);
    color: #E57373;
}

/* Unknown/No Data State */
.health-nodata {
    background: rgba(128, 128, 128, 0.08);
    border-color: rgba(128, 128, 128, 0.2);
    color: var(--text-muted);
}

[data-theme="dark"] .health-nodata {
    background: rgba(128, 128, 128, 0.12);
    border-color: rgba(128, 128, 128, 0.3);
    color: var(--text-muted);
}

/* --- Session Progress Bar --- */
.session-card {
    padding: var(--space-md);
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.session-title {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
}

.session-date {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.session-start-date {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: var(--font-weight-normal);
    margin-left: var(--space-xs);
}

.session-progress-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.session-progress-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.session-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.session-section-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.session-section-change {
    font-size: var(--font-size-xs);
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: var(--font-weight-bold);
}

.session-labels {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    font-family: 'SF Mono', 'Menlo', monospace;
}

.session-label-start {
    color: var(--text-muted);
}

.session-label-current {
    font-weight: 800;
    font-size: var(--font-size-lg);
    color: var(--text-primary);
    letter-spacing: 0.5px;
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.4);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-normal);
}

[data-theme="dark"] .session-label-current {
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.85);
    text-shadow: 0px 0px 8px rgba(33, 150, 243, 0.5),
    0px 3px 8px rgba(0, 0, 0, 0.7);
}

.session-label-current.val-positive {
    color: var(--color-green);
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.4);
    text-shadow: 0 2px 4px rgba(76, 175, 80, 0.2);
}

[data-theme="dark"] .session-label-current.val-positive {
    color: var(--color-green-light);
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.85);
    text-shadow: 0px 0px 10px rgba(129, 199, 132, 0.5),
    0px 3px 8px rgba(0, 0, 0, 0.7);
}

.session-label-target {
    color: var(--text-muted);
    font-weight: var(--font-weight-medium);
}

@media (max-width: 768px) {
    .session-label-target {
        font-size: var(--font-size-xs);
    }

    .session-meta {
        font-size: 10px; /* Slightly smaller for mobile to ensure it fits */
        gap: var(--space-xs);
    }
}

.session-progress-track {
    width: 100%;
    height: 10px;
    background: var(--border-color);
    border-radius: 5px;
    overflow: hidden;
}

.session-progress-bar {
    height: 100%;
    border-radius: 5px;
    transition: width 1s ease-out;
    min-width: 2px;
}

.session-meta {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* --- Postponed Window Card --- */
.postponed-card {
    padding: var(--space-md);
    background: var(--color-protected-bg);
    border-color: var(--color-blue);
    border-left: 4px solid var(--color-blue);
}

.postponed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.postponed-title {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-lg);
    color: var(--color-blue);
}

.postponed-timer {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    font-family: 'SF Mono', 'Menlo', monospace;
    color: var(--text-primary);
    background: var(--bg-header);
    padding: 2px 10px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.postponed-message {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* --- Summary Stats --- */
.summary-row {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.summary-card {
    flex: 1;
    min-width: 200px;
    padding: var(--space-md);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: var(--space-xs) 0;
    font-size: var(--font-size-sm);
}

.summary-item-label {
    color: var(--text-secondary);
}

.summary-item-value {
    font-weight: var(--font-weight-semibold);
    font-family: 'SF Mono', 'Menlo', monospace;
}

/* Stats header with total count */
.stats-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.stats-total {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    font-family: 'SF Mono', 'Menlo', monospace;
    color: var(--text-primary);
}

.stats-total-label {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* Positive/Negative ratio bar */
.pnl-ratio-bar {
    display: flex;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: var(--space-sm);
    background: var(--border-color);
    gap: 1px;
}

.pnl-ratio-pos {
    background: var(--color-green);
    border-radius: 3px 0 0 3px;
    transition: width var(--transition-normal);
}

.pnl-ratio-neg {
    background: var(--color-negative);
    border-radius: 0 3px 3px 0;
    transition: width var(--transition-normal);
}

/* Divider between sections */
.summary-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-xs) 0;
}

/* Risk metrics — secondary card below table */
.risk-metrics-card {
    margin-top: var(--space-md);
    opacity: 0.7;
    padding: var(--space-sm) var(--space-md);
}

/* --- Positions Table (Desktop) --- */
.positions-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.positions-table th {
    background: var(--bg-header);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.positions-table td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    font-size: var(--font-size-sm);
}

.positions-table tbody tr {
    transition: background var(--transition-fast);
}

.positions-table tbody tr:hover {
    outline: 1px solid var(--color-blue);
    outline-offset: -1px;
    background: transparent;
}

.positions-table tbody tr:last-child td {
    border-bottom: none;
}

/* Row highlights */
.positions-table tr.row-protected {
    background: var(--row-protected);
}

.positions-table tr.row-profit {
    background: var(--row-profit);
}

/* Thick bottom border line for the top 3 biggest positions */
.positions-table tr.top-position-health-good td,
.position-card.top-position-health-good {
    border-bottom: 3px solid #2E7D32 !important;
}

[data-theme="dark"] .positions-table tr.top-position-health-good td,
[data-theme="dark"] .position-card.top-position-health-good {
    border-bottom: 3px solid #81C784 !important;
}

.positions-table tr.top-position-health-warning td,
.position-card.top-position-health-warning {
    border-bottom: 3px solid #E65100 !important;
}

[data-theme="dark"] .positions-table tr.top-position-health-warning td,
[data-theme="dark"] .position-card.top-position-health-warning {
    border-bottom: 3px solid #FFB74D !important;
}

.positions-table tr.top-position-health-critical td,
.position-card.top-position-health-critical {
    border-bottom: 3px solid #C62828 !important;
}

[data-theme="dark"] .positions-table tr.top-position-health-critical td,
[data-theme="dark"] .position-card.top-position-health-critical {
    border-bottom: 3px solid #E57373 !important;
}

/* Flash highlight animation for scrolled positions */
@keyframes highlight-flash-animation {
    0% {
        outline: 3px solid var(--color-blue);
        outline-offset: -3px;
    }
    100% {
        outline: 0px solid transparent;
        outline-offset: -3px;
    }
}

.highlight-flash {
    animation: highlight-flash-animation 1.5s ease-out;
}

.table-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-xl) 0;
}

/* Symbol cell */
.symbol-name {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.symbol-age {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* PnL cell */
.pnl-main {
    font-weight: var(--font-weight-semibold);
    font-family: 'SF Mono', 'Menlo', monospace;
}

.pnl-percent {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Menlo', monospace;
}

.pnl-realised {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 2px;
    font-family: 'SF Mono', 'Menlo', monospace;
}

/* Change cell with averaging highlight */
.change-cell {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: var(--font-weight-medium);
}

.cell-averaging {
    background: rgba(198, 40, 40, 0.12);
    border-radius: 4px;
    padding: 2px 6px;
}

/* Numeric cells */
.num-cell {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: var(--font-size-sm);
    white-space: nowrap;
}

/* Events cell */
.events-cell {
    max-width: 350px;
    min-width: 200px;
}

/* --- Positions Cards (Mobile) --- */
.positions-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.position-card {
    padding: 0;
}

.position-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.position-card-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.position-card-pnl {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-base);
}

.position-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xs) var(--space-md);
    padding: var(--space-sm) var(--space-md);
}

.position-card-item {
    display: flex;
    flex-direction: column;
}

.position-card-item-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.position-card-item-value {
    font-size: var(--font-size-sm);
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: var(--font-weight-medium);
}

.position-card-events {
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border-color);
}

/* Card tint variants */
.position-card.card-protected .position-card-header {
    border-bottom-color: rgba(33, 150, 243, 0.3);
}

.position-card.card-profit .position-card-header {
    border-bottom-color: rgba(76, 175, 80, 0.3);
}

/* --- Loading state --- */
.loading-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--text-muted);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--space-md);
}

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

/* --- Responsive --- */
@media (max-width: 768px) {
    .dashboard {
        padding: var(--space-sm);
    }

    .account-grid {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }

    .combined-balance-card {
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
    }

    .combined-balance-card .stat-value {
        font-size: var(--font-size-base);
    }

    .combined-balance-card .stat-sub {
        font-size: var(--font-size-xs);
    }

    .health-bar {
        flex-direction: row;
        gap: 4px;
    }

    .health-strip {
        padding: 4px 8px;
        font-size: 9px;
    }

    .health-strip span {
        white-space: nowrap;
    }

    .position-health-bar {
        margin-top: calc(-1 * var(--space-xs));
    }

    .position-health-bar .health-strip {
        padding: 2px 4px;
        gap: 0px;
        font-size: 8px;
    }

    .summary-row {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .summary-card {
        min-width: unset;
    }

    .positions-table-wrap {
        display: none;
    }

    .positions-cards {
        display: flex;
    }

    .footer {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (min-width: 769px) {
    .positions-cards {
        display: none;
    }
}

/* --- Bottom Status Bar --- */
.bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--bg-header);
    border-top: 1px solid var(--border-color);
    margin-top: var(--space-xl);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.app-started-info {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-family: 'SF Mono', 'Menlo', monospace;
}

#appStartedTime {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

/* --- Coin Trend History --- */
.coin-history-row {
    margin-top: var(--space-md);
}

.coin-history-card {
    border-top: 3px solid var(--color-blue);
}

.state-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

.badge-up {
    background: rgba(76, 175, 80, 0.15);
    color: var(--color-green);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.badge-down {
    background: rgba(244, 67, 54, 0.15);
    color: var(--color-negative);
    border: 1px solid rgba(244, 67, 54, 0.3);
}

.badge-nope {
    background: var(--bg-header);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.arrow {
    margin: 0 4px;
    color: var(--text-muted);
    font-weight: normal;
}
