/* =====================================================
   GLOBAL
   ===================================================== */

:root {
    --chart-min-height: 420px;
    --s2-bottom-height: 188px;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
    font-family: Arial, sans-serif;
    color: #000000;
}

* {
    box-sizing: border-box;
}

.dashboard {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
}

.hidden {
    display: none !important;
}


/* =====================================================
   TOP PANEL
   ===================================================== */

.top-panel {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-bottom: 1px solid #d8d8d8;
    background: #ffffff;
}

.tf-btn {
    min-width: 40px;
    height: 22px;
    padding: 0 9px;
    border: 1px solid #000000;
    border-radius: 999px;
    background: #ffffff;
    color: #000000;
    font-size: 10px;
    line-height: 20px;
    font-weight: 700;
    cursor: pointer;
    margin: 0;
}

.tf-btn.active {
    background: #000000;
    color: #ffffff;
}

.sym-btn {
    min-width: 44px;
}


/* =====================================================
   TITLE
   ===================================================== */

.chart-title {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 18px;
    font-weight: 800;
    line-height: 1.1;
    background: #ffffff;
}


/* =====================================================
   CHART AREA
   ===================================================== */

.chart-container {
    flex: 1 0 var(--chart-min-height);
    min-height: var(--chart-min-height);
    position: relative;
    border-top: 1px solid #000000;
    background: #ffffff;
    overflow: hidden;
}

.chart {
    width: 100%;
    height: 100%;
}


/* =====================================================
   CANDLE TOOLTIP
   ===================================================== */

#main-tooltip {
    position: absolute;
    z-index: 1000;
    display: none;
    min-width: 112px;
    padding: 5px 7px;
    background: rgba(17, 24, 39, 0.94);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 5px;
    font-family: Arial, sans-serif;
    font-size: 10px;
    line-height: 1.25;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}

#main-tooltip .tooltip-time {
    margin-bottom: 3px;
    font-size: 10px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
}

#main-tooltip .tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    white-space: nowrap;
}

#main-tooltip .tooltip-row span {
    color: #b8bec8;
    font-weight: 400;
}

#main-tooltip .tooltip-row b {
    color: #ffffff;
    font-weight: 700;
}


/* =====================================================
   S2 BOTTOM AREA
   ===================================================== */

.s2-bottom-grid {
    flex: 0 0 var(--s2-bottom-height);
    height: var(--s2-bottom-height);
    min-height: var(--s2-bottom-height);
    max-height: var(--s2-bottom-height);
    display: grid;
    grid-template-columns: 1.25fr 0.85fr;
    gap: 10px;
    padding: 8px 12px 10px 12px;
    background: #ffffff;
    overflow: hidden;
}

.s2-card {
    height: 100%;
    min-height: 0;
    padding: 8px 10px;
    border: 1px solid #111111;
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.s2-card-title {
    margin-bottom: 6px;
    color: #000000;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.1;
}


/* =====================================================
   PREDICTION BLOCK
   ===================================================== */

.prediction-card {
    min-height: 0;
}

.prediction-layout {
    display: grid;
    grid-template-columns: 1.35fr 0.75fr;
    gap: 10px;
    height: calc(100% - 19px);
    min-height: 0;
}

.prediction-window {
    min-height: 0;
    overflow: auto;
}

.prediction-subtitle {
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #000000;
}

.prediction-metrics {
    min-height: 0;
    padding-left: 10px;
    border-left: 1px solid #e5e7eb;
    overflow: hidden;
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.metric-item {
    padding: 6px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
}

.metric-item span {
    display: block;
    color: #6b7280;
    font-size: 11px;
    line-height: 1.1;
}

.metric-item b {
    display: block;
    margin-top: 2px;
    color: #000000;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.1;
}


/* =====================================================
   MODELS TABLE CARD
   ===================================================== */

.trade-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.models-table-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
}

.models-table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #ffffff;
}

.primary-model-row {
    background: rgba(0, 120, 255, 0.08);
    font-weight: 800;
}

#model-predictions-body td {
    white-space: nowrap;
}


/* =====================================================
   TABLES
   ===================================================== */

.s2-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    line-height: 1.2;
}

.s2-table th,
.s2-table td {
    padding: 3px 5px;
    border-bottom: 1px solid #e5e7eb;
    text-align: right;
    white-space: nowrap;
}

.s2-table th:first-child,
.s2-table td:first-child {
    text-align: left;
}

.s2-table th {
    color: #555555;
    font-weight: 700;
}

.positions-table th,
.positions-table td {
    padding: 3px 4px;
    font-size: 11px;
}


/* =====================================================
   DECISION COLORS
   ===================================================== */

#ml-decision {
    font-weight: 800;
}

.ml-decision-long {
    color: #00a651 !important;
}

.ml-decision-short {
    color: #ff1744 !important;
}

.ml-decision-hold {
    color: #555555 !important;
}


/* =====================================================
   MOBILE DASHBOARD
   ===================================================== */

@media (max-width: 768px) {

    html,
    body {
        height: auto;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .dashboard {
        width: 100%;
        min-height: 100vh;
        height: auto;
    }

    .chart-container {
        flex: 0 0 auto;
        height: 420px;
        min-height: 320px;
    }

    .s2-bottom-grid {
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        max-height: none;
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
        overflow: visible;
    }

    .s2-card {
        height: auto;
        min-height: 0;
    }

    .prediction-layout {
        height: auto;
        grid-template-columns: 1fr;
    }

    .prediction-metrics {
        border-left: none;
        padding-left: 0;
        padding-top: 8px;
        border-top: 1px solid #e5e7eb;
    }

    .prediction-window {
        overflow-x: auto;
    }

    .prediction-window .s2-table {
        min-width: 460px;
    }

    .trade-card {
        max-height: 360px;
    }

    .positions-table {
        min-width: 100%;
    }
}


/* =====================================================
   MODEL STATS PAGE
   /model/<model_key>
   ===================================================== */

html.model-html,
body.model-body {
    width: 100%;
    min-height: 100%;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

body.model-body .dashboard.model-page {
    display: block !important;
    width: 100%;
    min-height: 100vh;
    height: auto !important;
    overflow: visible !important;
    background: #ffffff;
    padding-bottom: 16px;
}


/* ===== MODEL TOP ===== */

.model-top-panel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-bottom: 1px solid #d8d8d8;
    background: #ffffff;
}

.model-back-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.model-title {
    padding: 6px 10px;
    margin: 0;
    font-size: 18px;
    line-height: 1.1;
}


/* ===== MODEL LAYOUT ===== */

.model-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 8px 8px 8px;
}

.model-section {
    margin: 0 8px 8px 8px;
}

.model-summary-grid .model-section {
    margin: 0;
}


/* ===== MODEL PASSPORT / SUMMARY TABLES ===== */

.model-passport-card,
.model-summary-card {
    min-height: 0;
}

.model-inner-scroll {
    max-height: 180px;
    overflow-y: auto;
    overflow-x: hidden;
}

.model-kv-table {
    table-layout: fixed;
    width: 100%;
    font-size: 11px;
}

.model-kv-table th,
.model-kv-table td {
    padding: 3px 5px;
    font-size: 11px;
    line-height: 1.15;
    vertical-align: top;
    border-bottom: 1px solid #e5e7eb;
}

.model-kv-table th {
    color: #555555;
    font-weight: 600;
    background: #ffffff;
}

.model-kv-table th:nth-child(1),
.model-kv-table td:nth-child(1) {
    width: 34%;
    text-align: left !important;
    color: #555555;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-kv-table th:nth-child(2),
.model-kv-table td:nth-child(2) {
    width: 66%;
    text-align: left !important;
    color: #000000;
    font-weight: 400;
    white-space: normal;
    word-break: break-word;
}


/* ===== MODEL CHARTS ===== */

.model-charts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(240px, 1fr));
    gap: 8px;
    margin: 0 8px 8px 8px;
}

.model-chart-card {
    min-height: 140px;
}

.model-mini-chart {
    width: 100%;
    height: 82px;
    position: relative;
}

.model-mini-chart canvas {
    width: 100%;
    height: 82px;
    display: block;
}

.model-bars {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 96px;
    overflow: hidden;
}

.bar-row {
    display: grid;
    grid-template-columns: 88px 1fr 54px;
    gap: 6px;
    align-items: center;
    font-size: 10px;
}

.bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.bar-track {
    height: 7px;
    background: rgba(120, 120, 120, 0.18);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: #777777;
}

.bar-fill.up {
    background: #00a651;
}

.bar-fill.down {
    background: #ff1744;
}

.bar-fill.flat {
    background: #777777;
}

.bar-fill.decision {
    background: #0077cc;
}

.bar-fill.error {
    background: #b000b0;
}

.bar-value {
    text-align: right;
    font-weight: 500;
    font-size: 10px;
}


/* ===== MODEL CSV TABLE ===== */

.model-table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px;
}

.model-download-link {
    min-width: 88px;
    text-align: center;
}

.model-csv-title-link,
.model-link {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.model-csv-title-link:hover,
.model-link:hover {
    opacity: 0.75;
}

.model-table-wrap {
    overflow: auto;
    max-height: 55vh;
}

.model-table-wrap table {
    min-width: 1100px;
}

.model-table-wrap th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #ffffff;
}

.model-table-wrap th,
.model-table-wrap td {
    font-weight: 400;
}


/* ===== MODEL COLORS ===== */

.td-up {
    color: #00a651;
    font-weight: 600;
}

.td-down {
    color: #ff1744;
    font-weight: 600;
}

.td-flat {
    color: #777777;
    font-weight: 500;
}

.td-error {
    color: #b000b0;
    font-weight: 600;
}

.small-note {
    margin-top: 3px;
    font-size: 10px;
    opacity: 0.65;
}


/* ===== MODEL RESPONSIVE ===== */

@media (max-width: 1300px) {
    .model-charts-grid {
        grid-template-columns: repeat(2, minmax(240px, 1fr));
    }
}

@media (max-width: 1000px) {
    .model-summary-grid {
        grid-template-columns: 1fr;
    }

    .model-charts-grid {
        grid-template-columns: 1fr;
    }

    .model-inner-scroll {
        max-height: 170px;
    }
}

@media (max-width: 680px) {
    .model-kv-table th:nth-child(1),
    .model-kv-table td:nth-child(1) {
        width: 42%;
    }

    .model-kv-table th:nth-child(2),
    .model-kv-table td:nth-child(2) {
        width: 58%;
    }

    .bar-row {
        grid-template-columns: 76px 1fr 44px;
    }

    .model-table-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .model-top-panel {
        flex-wrap: wrap;
    }

    .model-nav-actions {
        width: 100%;
        margin-left: 0;
        justify-content: flex-end;
    }
}

.model-nav-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}



.model-nav-counter {
    min-width: 42px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: #555555;
    line-height: 22px;
}

.model-nav-link {
    max-width: 270px;
    min-width: 180px;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}