* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 12px;
    color: #222;
    background: #fff;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea, table {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ── Controls ────────────────────────────────────────────────────────────── */

#controls {
    border-bottom: 1px solid #bbb;
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

#controls label {
    color: #555;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#controls select {
    border: 1px solid #bbb;
    padding: 3px 6px;
    background: #fff;
}

#exchange-label {
    font-size: 12px;
    color: #555;
}

#last-updated {
    margin-left: auto;
    font-size: 11px;
    color: #777;
    font-variant-numeric: tabular-nums;
}

#sync-btn {
    font-size: 11px;
    padding: 3px 12px;
    border: 1px solid #bbb;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

#sync-btn:hover { background: #f0f0f0; }
#sync-btn:disabled { color: #999; cursor: wait; }
#sync-btn.syncing { color: #999; }

/* ── Chart tooltip ───────────────────────────────────────────────────────── */

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: #fff;
    border: 1px solid #888;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    z-index: 10;
    white-space: nowrap;
    display: none;
}

.chart-tooltip .tooltip-time {
    color: #666;
    font-size: 10px;
    margin-bottom: 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid #eee;
}

.chart-tooltip .tooltip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.5;
}

.chart-tooltip .tooltip-swatch {
    width: 8px;
    height: 2px;
    display: inline-block;
}

.chart-tooltip .tooltip-label {
    color: #555;
    margin-right: auto;
}

.chart-tooltip .tooltip-value {
    font-weight: 600;
    color: #111;
}

.chart-body {
    position: relative;
}

/* ── KPI ribbon ──────────────────────────────────────────────────────────── */

#kpi-ribbon {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 24px;
    padding: 8px 20px;
    border-bottom: 1px solid #ccc;
    background: #fafafa;
}

.kpi {
    display: grid;
    grid-template-columns: max-content 1fr;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.kpi-label {
    font-size: 11px;
    color: #666;
}

.kpi-value {
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.kpi-sub {
    font-size: 10px;
    color: #999;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
    #kpi-ribbon {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 4px 20px;
    }
    .kpi {
        grid-template-columns: 1fr auto;
    }
}

#risk-ribbon {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 24px;
    padding: 8px 20px;
    border-bottom: 1px solid #ccc;
    background: #fafafa;
}

#risk-ribbon:empty {
    display: none;
}

/* ── Chart grid ──────────────────────────────────────────────────────────── */

#chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.chart-cell {
    padding: 10px 16px;
    border-bottom: 1px solid #ddd;
    border-right: 1px solid #ddd;
    min-height: 280px;
    overflow: hidden;
}

.chart-cell:nth-child(2n) {
    border-right: none;
}

/* ── Calendar ────────────────────────────────────────────────────────────── */

#cell-calendar {
    display: flex;
    flex-direction: column;
}

#calendar-month {
    font-size: 11px;
    color: #555;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#calendar-total {
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding-left: 8px;
    border-left: 1px solid #ddd;
}

.cal-nav {
    background: #fff;
    border: 1px solid #bbb;
    cursor: pointer;
    padding: 0 6px;
    font-size: 13px;
    line-height: 1.4;
    color: #555;
}

.cal-nav:hover {
    background: #f0f0f0;
}

#cal-prev {
    margin-left: auto;
}

#calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: auto repeat(6, 1fr);
    gap: 1px;
    background: #fff;
    flex: 1 1 auto;
    min-height: 0;
}

#calendar:not(:empty) {
    background: #ddd;
    border: 1px solid #ddd;
}

.cal-dow {
    background: #f5f5f5;
    padding: 3px 4px;
    text-align: center;
    font-weight: 700;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-size: 9px;
}

.cal-day {
    background: #fff;
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

.cal-day.empty {
    background: #fafafa;
}

.cal-day .cal-date {
    font-size: 10px;
    color: #888;
    font-weight: 700;
}

.cal-day .cal-pnl {
    font-size: 10px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.cal-day.positive { background: #e7f5ea; }
.cal-day.positive .cal-pnl { color: #1a6f2a; }
.cal-day.negative { background: #fbeaea; }
.cal-day.negative .cal-pnl { color: #9b1c1c; }
.cal-day.today { outline: 2px solid #1a56db; outline-offset: -2px; z-index: 1; }

.chart-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.chart-header h3 {
    font-size: 11px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.chart-header select {
    font-size: 11px;
    border: 1px solid #bbb;
    padding: 2px 4px;
    background: #fff;
}

.expand-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #ccc;
    padding: 2px 4px;
}

.expand-btn:hover {
    color: #666;
}

body.has-expanded {
    overflow: hidden;
}

.chart-cell.expanded {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    background: #fff;
    border: none;
    padding: 16px 32px 24px;
    min-height: unset;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chart-cell.expanded .chart-header {
    flex: 0 0 auto;
    margin-bottom: 12px;
}

.chart-cell.expanded .chart-body {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
}

/* ── Stats section ───────────────────────────────────────────────────────── */

#stats-section {
    padding: 14px 24px 24px;
    overflow-x: auto;
}

#stats-section h3 {
    font-size: 11px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */

table {
    border-collapse: collapse;
    font-size: 12px;
}

#stats-table {
    width: auto;
}

th {
    text-align: left;
    padding: 5px 10px 5px 6px;
    border-bottom: 1px solid #888;
    font-weight: 700;
    font-size: 11px;
    color: #444;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th:hover { background: #f8f8f8; }
th.num { text-align: right; }

th .sort-arrow {
    font-size: 9px;
    margin-left: 2px;
    color: #ccc;
}

th.sorted .sort-arrow { color: #222; }

td {
    padding: 4px 10px 4px 6px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
}

td.num { text-align: right; }
td.label-cell { color: #666; font-size: 11px; }

tr.totals-row { font-weight: 600; }
tr.totals-row td {
    border-top: 1px solid #999;
    border-bottom: 1px solid #999;
}

.positive { color: #227a2b; }
.negative { color: #b91c1c; }
.neutral { color: #888; }

/* ── uPlot ───────────────────────────────────────────────────────────────── */

.uplot { font-family: inherit; }

.uplot .u-legend {
    font-family: inherit;
    font-size: 11px;
    padding: 4px 0 0;
    color: #444;
}

.uplot .u-legend .u-marker {
    width: 10px;
    height: 10px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

.sparkline {
    display: block;
    width: 80px;
    height: 20px;
}

@media (max-width: 900px) {
    #chart-grid { grid-template-columns: 1fr; }
    .chart-cell { border-right: none; }
    #kpi-ribbon { flex-wrap: wrap; }
    .kpi { flex-basis: 50%; border-bottom: 1px solid #e0e0e0; }
}

/* ── Top navigation ─────────────────────────────────────────────────────── */

#topnav {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #bbb;
    background: #fafafa;
}

#topnav a {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    text-decoration: none;
    padding: 10px 20px;
    border-bottom: 2px solid transparent;
    transition: color 0.1s;
}

#topnav a:hover {
    color: #333;
}

#topnav a.active {
    color: #222;
    border-bottom-color: #222;
    background: #fff;
}

/* ── Market page ────────────────────────────────────────────────────────── */

#market-chart-section {
    padding: 14px 20px;
    border-bottom: 1px solid #ddd;
}

#market-chart,
#compare-chart {
    min-height: 380px;
    overflow: visible;
}

#market-chart-section .chart-header select {
    font-size: 12px;
    border: 1px solid #bbb;
    padding: 3px 6px;
    background: #fff;
}

#position-builder {
    padding: 14px 20px;
    border-bottom: 1px solid #ddd;
}

#position-builder h3 {
    font-size: 11px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

#builder-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 10px;
}

#builder-summary {
    display: flex;
    gap: 20px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

#builder-summary .builder-kpi {
    display: flex;
    gap: 4px;
}

#builder-summary .builder-kpi-label {
    color: #666;
    font-size: 11px;
}

#builder-summary .builder-kpi-value {
    font-weight: 700;
}

#builder-table {
    width: auto;
}

#builder-table input {
    width: 90px;
    font-size: 12px;
    font-family: inherit;
    border: 1px solid #bbb;
    padding: 2px 6px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

#builder-table input:focus {
    outline: none;
    border-color: #888;
}

#builder-table .remove-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 14px;
    padding: 2px 6px;
}

#builder-table .remove-btn:hover {
    color: #333;
}

#market-table-section {
    padding: 14px 20px 24px;
    overflow-x: auto;
}

#market-table-section h3 {
    font-size: 11px;
    font-weight: 700;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.market-table {
    width: 100%;
}

.market-table tbody tr {
    cursor: pointer;
}

.market-table tbody tr:hover {
    background: #f8f8f8;
}

#compare-section {
    padding: 14px 20px;
    border-bottom: 1px solid #ddd;
}

.combobox-wrap {
    position: relative;
    display: inline-block;
}

.combobox-wrap input {
    font-size: 12px;
    border: 1px solid #bbb;
    padding: 4px 8px;
    background: #fff;
    width: 160px;
}

.combobox-wrap input:focus {
    outline: none;
    border-color: #888;
}

.combobox-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 160px;
    max-height: 300px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    border: 1px solid #bbb;
    border-top: none;
    z-index: 100;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.combobox-item {
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
}

.combobox-item:hover {
    background: #f0f0f0;
}

.compare-label {
    font-size: 11px;
    color: #555;
    display: flex;
    align-items: center;
    gap: 4px;
}

.compare-label input {
    font-size: 11px;
    border: 1px solid #bbb;
    padding: 3px 6px;
    background: #fff;
}

#compare-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.compare-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border: 1px solid #bbb;
    background: #f5f5f5;
    cursor: default;
}

.compare-tag .tag-remove {
    cursor: pointer;
    color: #999;
    font-size: 13px;
    line-height: 1;
}

.compare-tag .tag-remove:hover {
    color: #333;
}

