:root {
    /* NEXUS AI THEME */
    --bg-global: #050810;
    /* Deep Space Blue */
    --bg-panel: #0d121d;
    /* Darker Blue-Grey */
    --bg-header: #0d121d;
    --bg-hover: #1e2636;

    --text-primary: #f0f4f8;
    --text-secondary: #8b9bb4;
    --text-disabled: #4a5568;

    --up: #00f3ff;
    /* Neon Cyan for Up/Buy */
    --down: #ff0055;
    /* Neon Pink/Red for Down/Sell */
    --accent: #F0B90B;
    /* Gold for Branding */
    --accent-hover: #ffd700;

    --border: #1e2636;
    --border-light: #2d3748;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --glow: 0 0 10px rgba(0, 243, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-global);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* SCROLLBAR */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-global);
}

::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* --- HEADER --- */
header {
    height: 64px;
    background: rgba(13, 18, 29, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.5px;
    text-decoration: none;
    cursor: pointer;
    font-family: 'Space Grotesk', sans-serif;
    /* Tech feel */
}

.brand svg {
    fill: var(--accent);
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 0 5px rgba(240, 185, 11, 0.5));
}

.nav-btn {
    text-decoration: none;
    color: #8b9bb4;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: 0.2s;
}

.nav-btn:hover {
    color: #f0b90b;
    background: rgba(240, 185, 11, 0.1);
    border-color: rgba(240, 185, 11, 0.2);
}

.nav-links {
    display: flex;
    gap: 20px;
    font-size: 14px;
    font-weight: 500;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 4px;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.nav-links a:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-links a.active {
    color: var(--accent);
    background: rgba(240, 185, 11, 0.1);
}

.nav-links a.highlight {
    color: var(--up);
}

/* For "New" or special items */

.nav-mobile-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
}

/* --- TICKER BAR --- */
.ticker-bar {
    height: 40px;
    background: var(--bg-global);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 32px;
    overflow-x: auto;
    white-space: nowrap;
}

.ticker-bar::-webkit-scrollbar {
    display: none;
}

.ticker-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ticker-label {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
}

.ticker-val {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: 12px;
}

.val-up {
    color: var(--up);
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.3);
}

/* Neon Glow */
.val-down {
    color: var(--down);
}

/* --- LAYOUT GRID --- */
.workspace {
    flex: 1;
    display: grid;
    /* Desktop: Markets | OrderBook | Chart | Trade */
    grid-template-columns: 260px 280px 1fr 340px;
    grid-template-rows: 1fr 300px;
    gap: 6px;
    padding: 6px;
    background: var(--bg-global);
    height: calc(100vh - 104px);
    min-height: 700px;
}

.panel {
    background: var(--bg-panel);
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-sm);
}

/* --- COMMON UI ELEMENTS --- */
.panel-head {
    height: 36px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}

.panel-head input {
    background: var(--bg-global);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    outline: none;
    font-size: 11px;
    width: 140px;
    transition: all 0.2s;
}

.panel-head input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(240, 185, 11, 0.1);
}

/* --- MARKETS LIST --- */
.market-list {
    flex: 1;
    overflow-y: auto;
    font-size: 12px;
}

.market-header {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    padding: 8px 16px;
    color: var(--text-disabled);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.market-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    padding: 10px 16px;
    cursor: pointer;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    transition: background 0.1s;
}

.market-row:hover {
    background: var(--bg-hover);
}

.market-row.active {
    background: rgba(240, 185, 11, 0.05);
    border-left: 3px solid var(--accent);
}

.m-pair {
    color: var(--text-primary);
    font-weight: 600;
    font-family: 'IBM Plex Mono', monospace;
}

.m-price,
.m-change {
    text-align: right;
    font-family: 'IBM Plex Mono', monospace;
}

/* --- ORDER BOOK --- */
.orderbook-grid {
    display: grid;
    grid-template-rows: 24px 1fr 40px 1fr;
    height: 100%;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
}

.ob-header {
    display: flex;
    padding: 0 12px;
    color: var(--text-disabled);
    font-size: 10px;
    text-transform: uppercase;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
}

.ob-rows {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ob-rows.asks {
    justify-content: flex-end;
}

.ob-row {
    display: flex;
    justify-content: space-between;
    padding: 1px 12px;
    cursor: pointer;
    position: relative;
    z-index: 1;
    height: 18px;
    align-items: center;
}

.ob-row:hover {
    background: var(--bg-hover);
}

.ob-bg {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    opacity: 0.1;
    z-index: -1;
    transition: width 0.1s;
}

.price {
    font-weight: 500;
}

.price.ask {
    color: var(--down);
}

.price.bid {
    color: var(--up);
}

.qty {
    color: var(--text-secondary);
    opacity: 0.8;
}

.current-price {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--up);
    gap: 10px;
    background: rgba(0, 243, 255, 0.05);
}

/* --- CHART --- */
.chart-container {
    width: 100%;
    height: 100%;
    position: relative;
    background: var(--bg-panel);
}

/* --- TRADE FORM --- */
.trade-form-wrapper {
    padding: 16px;
}

.form-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-global);
    padding: 4px;
    border-radius: 4px;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--text-primary);
    background: var(--bg-hover);
    box-shadow: var(--shadow-sm);
}

.input-box {
    background: var(--bg-global);
    border: 1px solid var(--border);
    border-radius: 4px;
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    margin-bottom: 12px;
    transition: border 0.2s;
}

.input-box:focus-within {
    border-color: var(--accent);
}

.input-label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
}

.input-field {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    text-align: right;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    font-family: 'IBM Plex Mono', monospace;
}

.input-suffix {
    color: var(--text-disabled);
    font-size: 12px;
    margin-left: 8px;
    font-weight: 500;
}

.slider {
    height: 4px;
    background: var(--border);
    margin: 24px 0;
    position: relative;
    border-radius: 2px;
}

.slider-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--bg-panel);
    position: absolute;
    top: -4px;
    cursor: pointer;
    transition: 0.1s;
    box-shadow: 0 0 0 2px var(--border);
}

.slider-thumb:hover {
    transform: scale(1.2);
    border-color: var(--accent);
    background: var(--accent);
}

.btn-trade {
    width: 100%;
    height: 44px;
    border-radius: 4px;
    border: none;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: 0.2s;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.btn-trade.buy {
    background: linear-gradient(135deg, #0ecb81 0%, #00995e 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(14, 203, 129, 0.2);
}

.btn-trade.sell {
    background: linear-gradient(135deg, #f6465d 0%, #c9253d 100%);
    color: white;
    margin-top: 12px;
    box-shadow: 0 4px 12px rgba(246, 70, 93, 0.2);
}

.btn-trade:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-trade:active {
    transform: scale(0.98);
}

/* --- BUTTONS --- */
.btn-outline {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    border: none;
    color: #000;
    padding: 8px 20px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 0 10px rgba(240, 185, 11, 0.3);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

/* --- HISTORY TABLE --- */
.history-panel {
    grid-column: 2 / span 2;
}

.table-container {
    width: 100%;
    overflow-y: auto;
    height: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

th {
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    color: var(--text-secondary);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    z-index: 10;
}

td {
    padding: 8px 16px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    font-family: 'IBM Plex Mono', monospace;
}

tr:hover td {
    background: var(--bg-hover);
}

/* --- RESPONSIVE / MOBILE --- */
@media (max-width: 1200px) {
    .workspace {
        grid-template-columns: 240px 1fr 300px;
        /* Hide Markets on medium screens */
    }

    .market-list,
    .panel:nth-child(1) {
        display: none;
    }

    .workspace {
        grid-template-columns: 280px 1fr 320px;
    }
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        display: flex;
        flex-direction: column;
        height: auto;
        overflow-y: visible;
        min-height: auto;
    }

    .panel {
        min-height: 400px;
        margin-bottom: 6px;
    }

    .trade-form-wrapper {
        padding: 16px;
    }

    .history-panel {
        grid-column: auto;
        height: 300px;
    }

    header {
        padding: 0 16px;
        height: 56px;
    }

    .nav-links {
        display: none;
    }

    .nav-mobile-btn {
        display: block;
    }

    .ticker-bar {
        display: none;
    }

    .header-right .btn-outline,
    .header-right .btn-primary {
        display: none;
    }

    /* Hide auth buttons on mobile */
}

/* --- MODAL --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

.modal.open {
    display: flex;
    animation: fadeIn 0.2s;
}

.modal-box {
    background: var(--bg-panel);
    width: 400px;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}