:root {
    /* Dark Trading Palette — Binance Pro */
    --binance-bg: #0b0e11;
    --binance-bg-secondary: #181a20;
    --binance-bg-tertiary: #1e2329;
    --binance-border: #2b3139;
    --binance-text-primary: #eaecef;
    --binance-text-secondary: #848e9c;
    --binance-green: #0ecb81;
    --binance-red: #f6465d;
    --binance-yellow: #fcd535;
    --binance-hover: rgba(255, 255, 255, 0.04);

    /* Layout Constants */
    --header-height: 48px;
    --ticker-height: 56px;
}

body.binance-theme {
    background-color: var(--binance-bg);
    color: var(--binance-text-primary);
    font-family: 'Inter', sans-serif;
    margin: 0;
    overflow: hidden;
}

.binance-layout {
    display: grid;
    grid-template-areas:
        "header header header"
        "ticker ticker ticker"
        "book chart form"
        "book tabs form";
    grid-template-columns: 320px 1fr 320px;
    grid-template-rows: var(--header-height) var(--ticker-height) 1fr 300px;
    height: 100vh;
}

/* ─── Header ─── */
.dashboard-header {
    grid-area: header;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--binance-bg-secondary);
    border-bottom: 1px solid var(--binance-border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
    font-size: 1.25rem;
    color: var(--binance-yellow);
}

.header-left h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--binance-text-primary);
    letter-spacing: -0.01em;
    margin: 0;
}

.header-left h1 span {
    color: var(--binance-yellow);
}

/* Header Navigation */
.header-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: 8px;
}

.header-nav .nav-link {
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--binance-text-secondary);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.02em;
}

.header-nav .nav-link:hover {
    color: var(--binance-text-primary);
    background-color: var(--binance-hover);
}

.header-nav .nav-link.active {
    color: var(--binance-yellow);
    background-color: rgba(252, 213, 53, 0.12);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ─── Ticker Bar (Premium — matches Spot) ─── */
.binance-ticker-bar {
    grid-area: ticker;
    background: #181a20;
    border-bottom: 1px solid var(--binance-border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    font-size: 12px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.binance-ticker-bar::-webkit-scrollbar {
    display: none;
}

.ticker-item.main-ticker {
    display: flex;
    align-items: center;
    gap: 14px;
    border-right: 1px solid var(--binance-border);
    padding-right: 20px;
    flex-shrink: 0;
}

.ticker-pair {
    font-size: 20px;
    font-weight: 700;
    color: var(--binance-text-primary);
    letter-spacing: -0.01em;
}

.ticker-price {
    font-size: 20px;
    font-weight: 700;
    font-family: 'Roboto Mono', monospace;
    color: var(--binance-green);
    transition: color 0.3s ease;
}

.ticker-price.up {
    color: var(--binance-green);
}

.ticker-price.down {
    color: var(--binance-red);
}

.ticker-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex-shrink: 0;
}

.stat-label {
    color: var(--binance-text-secondary);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.stat-value {
    font-weight: 600;
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    color: var(--binance-text-primary);
}

.stat-value.muted {
    color: var(--binance-text-secondary);
}

.funding-countdown {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ─── Order Book (Left) ─── */
.binance-book {
    grid-area: book;
    background: var(--binance-bg-secondary);
    border-right: 1px solid var(--binance-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.book-tabs {
    display: flex;
    height: 36px;
    border-bottom: 1px solid var(--binance-border);
}

.book-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--binance-text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.book-tab.active {
    color: #fff;
    font-weight: 600;
    border-bottom-color: var(--binance-yellow);
}

.book-tab:hover:not(.active) {
    color: var(--binance-text-primary);
}

.book-tab-content {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.book-tab-content.active {
    display: flex;
}

.order-book-header,
.trades-header-row {
    padding: 8px 12px;
    font-size: 11px;
    color: var(--binance-text-secondary);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border-bottom: 1px solid var(--binance-border);
}

.text-right {
    text-align: right;
}

.order-book-spread {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--binance-border);
    border-bottom: 1px solid var(--binance-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.spread-price {
    font-size: 16px;
    font-weight: 600;
    font-family: 'Roboto Mono', monospace;
}

.spread-pct {
    font-size: 11px;
    color: var(--binance-text-secondary);
}

.trades-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

/* ─── Chart (Center) ─── */
.binance-chart {
    grid-area: chart;
    background: var(--binance-bg-secondary);
    border-bottom: 1px solid var(--binance-border);
    display: flex;
    flex-direction: column;
}

.chart-toolbar {
    padding: 8px 12px;
    display: flex;
    gap: 12px;
    height: 40px;
    align-items: center;
    background: var(--binance-bg-secondary);
    border-bottom: 1px solid var(--binance-border);
}

.chart-spacer {
    flex: 1;
}

.chart-canvas {
    height: calc(100% - 40px);
}

/* ─── Tabs (Positions/Orders) ─── */
.binance-tabs {
    grid-area: tabs;
    background: var(--binance-bg-secondary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.binance-tabs .order-tabs {
    height: 40px;
    display: flex;
    border-bottom: 1px solid var(--binance-border);
    align-items: stretch;
}

.binance-tabs .order-tab {
    padding: 0 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--binance-text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.binance-tabs .order-tab.active {
    color: var(--binance-yellow);
    border-bottom-color: var(--binance-yellow);
    font-weight: 600;
}

.binance-tabs .order-tab:hover:not(.active) {
    color: var(--binance-text-primary);
}

.tab-spacer {
    flex: 1;
}

.tab-actions {
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.btn-cancel-all {
    font-size: 11px;
    padding: 4px 10px;
    background: rgba(246, 70, 93, 0.1);
    color: var(--binance-red);
    border: 1px solid var(--binance-red);
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-cancel-all:hover {
    background: rgba(246, 70, 93, 0.2);
}

.tab-content-container {
    height: calc(100% - 40px);
    overflow-y: auto;
}

.positions-table,
.orders-table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}

.positions-table thead,
.orders-table thead {
    position: sticky;
    top: 0;
    background: var(--binance-bg-secondary);
    text-align: left;
    color: var(--binance-text-secondary);
}

.positions-table th,
.orders-table th {
    padding: 8px 10px;
    font-weight: 500;
}

.positions-table td,
.orders-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--binance-border);
}

.no-positions td,
.no-orders td {
    padding: 40px !important;
    text-align: center;
    color: var(--binance-text-secondary);
}

/* ─── Market Selector (Right Column Top) ─── */
.market-selector {
    display: flex;
    flex-direction: column;
    height: 350px;
    /* Reduced height to fit form below */
    border-bottom: 1px solid var(--binance-border);
    background-color: var(--binance-bg-secondary);
}

.market-selector-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--binance-border);
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background-color: var(--binance-bg-tertiary);
    border-radius: 4px;
    padding: 6px 10px;
}

.search-box i {
    color: var(--binance-text-secondary);
    font-size: 12px;
    margin-right: 8px;
}

.search-box input {
    background: none;
    border: none;
    color: var(--binance-text-primary);
    font-size: 12px;
    width: 100%;
    outline: none;
}

.market-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--binance-border) transparent;
}

.market-list::-webkit-scrollbar {
    width: 4px;
}

.market-list::-webkit-scrollbar-track {
    background: transparent;
}

.market-list::-webkit-scrollbar-thumb {
    background-color: var(--binance-border);
    border-radius: 4px;
}

/* Market Items */
.market-item {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.market-item:hover,
.market-item.active {
    background-color: var(--binance-bg-tertiary);
}

.market-item .favorite-btn {
    background: none;
    border: none;
    color: var(--binance-text-secondary);
    font-size: 12px;
    margin-right: 8px;
    cursor: pointer;
    padding: 0;
}

.market-item .favorite-btn i.fas {
    color: var(--binance-yellow);
}

.market-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    border-radius: 50%;
    background-color: var(--binance-bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.market-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.market-icon-fallback {
    font-size: 10px;
    font-weight: 700;
    color: var(--binance-text-secondary);
}

.market-name {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--binance-text-primary);
}

.market-changeB {
    font-family: 'Roboto Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-align: right;
    min-width: 54px;
}

.market-changeB.positive {
    background: rgba(14, 203, 129, 0.1);
    color: var(--binance-green);
}

.market-changeB.negative {
    background: rgba(246, 70, 93, 0.1);
    color: var(--binance-red);
}

/* ─── Order Form (Right — Premium, matches Spot) ─── */
.binance-form {
    grid-area: form;
    background: var(--binance-bg-secondary);
    border-left: 1px solid var(--binance-border);
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

.binance-form .trading-forms-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    background-color: var(--binance-bg-secondary);
}

/* Form Tabs */
.binance-form .form-tabs {
    display: flex;
    padding: 0;
    border-bottom: 1px solid var(--binance-border);
}

.binance-form .form-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    color: var(--binance-text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.binance-form .form-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: transparent;
    border-radius: 2px 2px 0 0;
    transition: all 0.2s ease;
}

.binance-form .form-tab[data-form-tab="buy"]:hover {
    color: var(--binance-green);
    background: rgba(14, 203, 129, 0.04);
}

.binance-form .form-tab[data-form-tab="sell"]:hover {
    color: var(--binance-red);
    background: rgba(246, 70, 93, 0.04);
}

.binance-form .form-tab[data-form-tab="buy"].active {
    color: var(--binance-green);
    background: rgba(14, 203, 129, 0.06);
}

.binance-form .form-tab[data-form-tab="buy"].active::after {
    background: var(--binance-green);
    left: 10%;
    right: 10%;
}

.binance-form .form-tab[data-form-tab="sell"].active {
    color: var(--binance-red);
    background: rgba(246, 70, 93, 0.06);
}

.binance-form .form-tab[data-form-tab="sell"].active::after {
    background: var(--binance-red);
    left: 10%;
    right: 10%;
}

/* Form Container */
.binance-form .trading-form-container {
    display: none;
    flex-direction: column;
    background-color: var(--binance-bg-secondary);
    padding: 14px;
    overflow-y: auto;
}

.binance-form .trading-form-container.active {
    display: flex;
}

.binance-form .form-body {
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.binance-form .balance-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--binance-text-secondary);
    margin-bottom: 10px;
    padding: 6px 8px;
    background-color: var(--binance-bg-tertiary);
    border-radius: 4px;
}

.binance-form .balance-display .value {
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
    color: var(--binance-text-primary);
}

.binance-form .balance-display .currency {
    font-weight: 600;
    color: var(--binance-text-secondary);
    margin-left: 4px;
}

.binance-form .input-field {
    background-color: var(--binance-bg-tertiary);
    border-radius: 4px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}

.binance-form .input-field:hover {
    border-color: var(--binance-border);
}

.binance-form .input-field:focus-within {
    border-color: var(--binance-yellow);
    box-shadow: 0 0 0 2px rgba(252, 213, 53, 0.1);
}

.binance-form .field-label {
    font-size: 11px;
    color: var(--binance-text-secondary);
    width: 48px;
    flex-shrink: 0;
    font-weight: 500;
}

.binance-form .input-field input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--binance-text-primary);
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Roboto Mono', monospace;
    outline: none;
    width: 0;
    min-width: 0;
}

.binance-form .input-field input::placeholder {
    color: var(--binance-text-secondary);
}

/* Hide number input spinners */
.binance-form .input-field input[type="number"]::-webkit-outer-spin-button,
.binance-form .input-field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.binance-form .input-field input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.binance-form .field-suffix {
    font-size: 11px;
    color: var(--binance-text-secondary);
    margin-left: 6px;
    width: 40px;
    text-align: right;
    font-weight: 600;
    flex-shrink: 0;
}

.binance-form .leverage-selector {
    margin-bottom: 16px;
    padding-top: 4px;
}

.binance-form .leverage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.binance-form .leverage-label {
    font-size: 12px;
    color: var(--binance-text-secondary);
    font-weight: 500;
}

.binance-form .leverage-value-box {
    display: flex;
    align-items: center;
    background: var(--binance-bg-tertiary);
    border: 1px solid var(--binance-border);
    border-radius: 4px;
    padding: 2px 8px;
    transition: all 0.2s;
}

.binance-form .leverage-value-box:focus-within {
    border-color: var(--binance-yellow);
}

.binance-form .leverage-input {
    width: 30px;
    background: transparent;
    border: none;
    color: var(--binance-text-primary);
    font-size: 13px;
    font-weight: 600;
    font-family: 'Roboto Mono', monospace;
    text-align: right;
    outline: none;
    padding: 0;
}

.binance-form .leverage-input::-webkit-outer-spin-button,
.binance-form .leverage-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.binance-form .leverage-suffix {
    color: var(--binance-text-primary);
    font-size: 13px;
    font-weight: 600;
    margin-left: 2px;
}

.binance-form .range-slider-container {
    position: relative;
    height: 24px;
    display: flex;
    align-items: center;
    margin: 0 4px;
}

.binance-form .slider-track-bg {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--binance-bg-tertiary);
    border-radius: 2px;
    z-index: 1;
}

.binance-form .slider-track-fill {
    position: absolute;
    left: 0;
    height: 4px;
    background: var(--binance-yellow);
    border-radius: 2px;
    z-index: 2;
    pointer-events: none;
}

.binance-form .styled-slider {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    position: relative;
    z-index: 3;
    outline: none;
    margin: 0;
}

.binance-form .styled-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border: 4px solid var(--binance-yellow);
    border-radius: 50%;
    cursor: grab;
    transition: transform 0.1s;
}

.binance-form .styled-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.binance-form .styled-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
}

.binance-form .leverage-markers {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    padding: 0 4px;
}

.binance-form .leverage-markers span {
    font-size: 10px;
    color: var(--binance-text-secondary);
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.binance-form .leverage-markers span:hover {
    color: var(--binance-text-primary);
}

.binance-form .leverage-markers span::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--binance-border);
    border-radius: 50%;
    z-index: 0;
}

.binance-form .total-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    margin-bottom: 12px;
    padding: 6px 8px;
    background-color: var(--binance-bg-tertiary);
    border-radius: 4px;
    font-weight: 500;
}

.binance-form .total-display .value {
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    color: var(--binance-text-primary);
}

.binance-form .btn-execute {
    width: 100%;
    padding: 10px;
    border-radius: 4px;
    border: none;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.binance-form .btn-execute.buy {
    background: linear-gradient(135deg, #0ecb81 0%, #0b9e65 100%);
    color: #000;
    box-shadow: 0 2px 8px rgba(14, 203, 129, 0.15);
}

.binance-form .btn-execute.sell {
    background: linear-gradient(135deg, #f6465d 0%, #c9364a 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(246, 70, 93, 0.15);
}

.binance-form .btn-execute:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

.binance-form .btn-execute.buy:hover {
    box-shadow: 0 4px 16px rgba(14, 203, 129, 0.35);
}

.binance-form .btn-execute.sell:hover {
    box-shadow: 0 4px 16px rgba(246, 70, 93, 0.35);
}

.binance-form .btn-execute:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

/* ─── Utilities ─── */
.text-up {
    color: var(--binance-green);
}

.text-down {
    color: var(--binance-red);
}

.bg-up {
    background-color: var(--binance-green);
}

.bg-down {
    background-color: var(--binance-red);
}

.desktop-only {
    /* Visible by default, hidden on mobile via media query below */
    display: flex;
}

/* ─── Interval Buttons (Chart) ─── */
.binance-chart .interval-btn {
    padding: 4px 8px;
    font-size: 12px;
    background: transparent;
    border: none;
    color: var(--binance-text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-weight: 500;
    transition: all 0.15s ease;
}

.binance-chart .interval-btn:hover {
    background: var(--binance-bg-tertiary);
    color: var(--binance-text-primary);
}

.binance-chart .interval-btn.active {
    background: var(--binance-yellow);
    color: #000;
    font-weight: 600;
}

.binance-chart .chart-action-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: transparent;
    border: 1px solid var(--binance-border);
    color: var(--binance-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 12px;
}

.binance-chart .chart-action-btn:hover {
    background: var(--binance-bg-tertiary);
    color: var(--binance-text-primary);
}

/* ─── Mobile Nav ─── */
.mobile-nav {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-nav {
        display: flex;
    }
}