:root {
    --bg: #eef2f6;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #687586;
    --line: #d9e1ea;
    --accent: #0f9f7a;
    --danger: #d64a4a;
}

* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 100%;
    overflow-x: hidden;
}
.shell { width: calc(100% - 28px); max-width: 1180px; margin: 0 auto; padding: 24px 0 36px; overflow-x: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-weight: 700; font-size: 13px; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 32px; }
h2 { font-size: 18px; }
.status { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; }
.status span { width: 10px; height: 10px; border-radius: 50%; background: #aab4c0; display: inline-block; }
.status.live span { background: var(--accent); box-shadow: 0 0 0 5px rgba(15,159,122,.12); }
.market, .panel, .metrics article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
.market { height: 540px; overflow: hidden; margin-bottom: 16px; }
.tradingview-widget-container,
.tradingview-widget-container__widget,
.tradingview-widget-container iframe {
    width: 100%;
    height: 100%;
    display: block;
}
.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.metrics article { padding: 16px; min-width: 0; }
.metrics span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metrics strong { display: block; font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-positive { color: #1f6fd1; }
.metric-negative { color: var(--danger); }
.stack { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
.panel { padding: 16px; min-width: 0; max-width: 100%; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; color: var(--muted); }
.panel-head h2 { color: var(--text); }
#accountLabel { min-width: 0; overflow-wrap: anywhere; }
.chart-panel { min-height: 360px; overflow: hidden; }
.chart-box { position: relative; width: 100%; max-width: 100%; height: 290px; overflow: hidden; }
.chart-box canvas { width: 100% !important; max-width: 100%; height: 100% !important; }
.table-controls { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.table-controls label { color: var(--muted); }
.table-controls select {
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 0 28px 0 10px;
}
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.profit { color: var(--accent); font-weight: 700; }
.loss { color: var(--danger); font-weight: 700; }
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 14px;
    color: var(--muted);
    font-size: 13px;
}
.pagination div { display: flex; align-items: center; gap: 8px; }
.pagination button {
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    padding: 0 12px;
}
.pagination button:disabled { color: #aab4c0; cursor: not-allowed; background: #f5f7fa; }
.pagination strong { color: var(--text); font-weight: 700; }

@media (max-width: 1024px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
    .market { height: 360px; }
    .chart-panel { min-height: 330px; }
    .chart-box { height: 260px; }
    .table-wrap { overflow-x: visible; }
    .responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table td { display: block; width: 100%; }
    .responsive-table thead { display: none; }
    .responsive-table tbody tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 10px;
        overflow: hidden;
        background: #fff;
    }
    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 16px;
        border-bottom: 1px solid var(--line);
        white-space: normal;
        text-align: right;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .responsive-table td:last-child { border-bottom: 0; }
    .responsive-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 700;
        text-align: left;
        text-transform: uppercase;
        font-size: 12px;
        flex: 0 0 42%;
    }
    .responsive-table td[colspan] { display: block; text-align: left; }
    .responsive-table td[colspan]::before { content: ""; display: none; }
}

@media (max-width: 520px) {
    .shell { width: min(100% - 18px, 1180px); padding-top: 14px; }
    h1 { font-size: 26px; }
    .metrics { grid-template-columns: 1fr; }
    .metrics strong { font-size: 22px; }
    .panel-head, .pagination { align-items: flex-start; flex-direction: column; }
    .panel { padding: 12px; }
    .chart-panel { min-height: 300px; }
    .chart-box { height: 230px; }
}

/* Mobile-first table rendering. Desktop table layout is restored below. */
.responsive-table,
.responsive-table thead,
.responsive-table tbody,
.responsive-table tr,
.responsive-table td {
    display: block;
    width: 100%;
}
.responsive-table thead { display: none; }
.responsive-table tbody tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
    background: #fff;
}
.responsive-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    border-bottom: 1px solid var(--line);
    white-space: normal;
    text-align: right;
    overflow-wrap: anywhere;
}
.responsive-table td:last-child { border-bottom: 0; }
.responsive-table td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    color: var(--muted);
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
    font-size: 12px;
}
.responsive-table td[colspan] {
    display: block;
    text-align: left;
}
.responsive-table td[colspan]::before {
    content: "";
    display: none;
}

@media (min-width: 1025px) {
    .responsive-table {
        display: table;
        width: 100%;
        border-collapse: collapse;
    }
    .responsive-table thead { display: table-header-group; }
    .responsive-table tbody { display: table-row-group; }
    .responsive-table tr { display: table-row; width: auto; border: 0; margin: 0; background: transparent; }
    .responsive-table th,
    .responsive-table td {
        display: table-cell;
        width: auto;
        border-bottom: 1px solid var(--line);
        white-space: nowrap;
        text-align: left;
    }
    .responsive-table td::before { content: none; display: none; }
}

/* Trading records are easier to scan as tables, even on mobile. */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.responsive-table {
    display: table;
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}
.responsive-table thead { display: table-header-group; }
.responsive-table tbody { display: table-row-group; }
.responsive-table tr {
    display: table-row;
    width: auto;
    border: 0;
    margin: 0;
    background: transparent;
}
.responsive-table th,
.responsive-table td {
    display: table-cell;
    width: auto;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    text-align: left;
}
.responsive-table td::before {
    content: none;
    display: none;
}
