/* ================================================================
   MCX Terminal Pro - Styles
   ================================================================ */

:root {
    --bg-body: #131722;
    --bg-panel: #1e222d;
    --bg-hover: #2a2e39;
    --bg-input: #16181e;
    --border: #363a45;
    --text-main: #d1d4dc;
    --text-muted: #787b86;
    --accent: #2962ff;
    --accent-hover: #1e53e4;
    --up: #26a69a;
    --down: #ef5350;
    --radius: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
body { background: var(--bg-body); color: var(--text-main); height: 100vh; display: flex; overflow: hidden; }

/* ---- App Layout ---- */
.app-layout { display: flex; width: 100%; height: 100%; }

/* ---- Left Sidebar (Indicators + Watchlist) ---- */
.sidebar {
    width: 240px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar.collapsed { width: 0; border-right: none; opacity: 0; pointer-events: none; }

.sidebar-header {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    font-weight: bold;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.sidebar-header .logo-icon { color: var(--accent); font-size: 1.1rem; }

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}
.sidebar-tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.sidebar-tab:hover { color: var(--text-main); }
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-panel { flex: 1; overflow-y: auto; display: none; }
.sidebar-panel.active { display: block; }

/* Indicator buttons */
.sidebar-content { padding: 8px; }
.section-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 10px 5px 5px;
}
.ind-btn {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    padding: 7px 10px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    font-size: 0.82rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}
.ind-btn:hover { background: var(--bg-hover); }
.ind-btn.active { background: rgba(41, 98, 255, 0.15); border-color: var(--accent); }
.ind-btn .btn-status { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.ind-btn.active .btn-status { background: var(--accent); }

/* Watchlist */
.watchlist-list { padding: 5px 8px; }
.watchlist-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.watchlist-item:hover { background: var(--bg-hover); }
.watchlist-item.active { background: rgba(41, 98, 255, 0.12); border-color: rgba(41, 98, 255, 0.3); }
.watchlist-item .wl-name { font-size: 0.82rem; font-weight: 500; }
.watchlist-item .wl-price { font-family: monospace; font-size: 0.8rem; text-align: right; }
.watchlist-item .wl-change { font-size: 0.7rem; }
.watchlist-item .wl-change.up { color: var(--up); }
.watchlist-item .wl-change.down { color: var(--down); }

.watchlist-add {
    margin: 8px;
    padding: 7px;
    width: calc(100% - 16px);
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    text-align: center;
    transition: all 0.2s;
}
.watchlist-add:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Main Area ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---- Top Bar ---- */
.top-bar {
    height: 46px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-toggle {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 1.1rem; padding: 4px 6px; border-radius: 4px;
}
.sidebar-toggle:hover { color: var(--text-main); background: var(--bg-hover); }

.symbol-select {
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}
.symbol-select:focus { outline: none; border-color: var(--accent); }

.timeframe-group { display: flex; gap: 2px; }
.tf-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 9px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.15s;
}
.tf-btn:hover { color: var(--text-main); background: var(--bg-hover); }
.tf-btn.active { background: var(--bg-hover); color: var(--text-main); font-weight: 600; }

/* Chart type buttons */
.chart-type-group { display: flex; gap: 2px; margin-left: 5px; }
.ct-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
}
.ct-btn:hover { color: var(--text-main); }
.ct-btn.active { color: var(--accent); border-color: rgba(41, 98, 255, 0.3); }

.top-bar-divider { width: 1px; height: 24px; background: var(--border); }

.price-display { font-family: monospace; font-size: 1rem; font-weight: 600; }
.price-display.up { color: var(--up); }
.price-display.down { color: var(--down); }

.price-change { font-family: monospace; font-size: 0.78rem; }
.price-change.up { color: var(--up); }
.price-change.down { color: var(--down); }

.legend-area {
    margin-left: auto;
    display: flex;
    gap: 12px;
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    white-space: nowrap;
}

.top-bar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.top-bar-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.15s;
}
.top-bar-btn:hover { color: var(--text-main); border-color: var(--text-muted); }

.user-badge {
    background: rgba(41, 98, 255, 0.15);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
}
.user-badge:hover { background: rgba(41, 98, 255, 0.25); }

/* ---- Chart ---- */
.chart-wrapper { flex: 1; position: relative; background: var(--bg-body); }
#chart-container { width: 100%; height: 100%; }

/* Overlays */
.overlay-center {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center; pointer-events: none; z-index: 100;
}
.spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-msg {
    color: var(--down);
    background: rgba(239, 83, 80, 0.1);
    padding: 10px 20px;
    border-radius: 4px;
    display: none;
}

/* ---- Footer Status ---- */
.footer-status {
    height: 26px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    padding: 0 15px;
    justify-content: space-between;
    flex-shrink: 0;
}
.status-dot {
    width: 6px; height: 6px;
    background: var(--up);
    border-radius: 50%;
    margin-right: 5px;
    display: inline-block;
}
.status-dot.disconnected { background: var(--down); }

.disclaimer {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ---- Right Panel (Trading) ---- */
.right-panel {
    width: 320px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
}
.right-panel.collapsed { width: 0; border-left: none; opacity: 0; pointer-events: none; }

.panel-header {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.panel-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 1.2rem; padding: 0 4px;
}
.panel-close:hover { color: var(--text-main); }

/* Trade form */
.trade-form { padding: 12px 15px; border-bottom: 1px solid var(--border); }
.trade-type-toggle {
    display: flex; gap: 0; margin-bottom: 12px;
    border-radius: 4px; overflow: hidden; border: 1px solid var(--border);
}
.trade-type-btn {
    flex: 1; padding: 8px; border: none;
    font-weight: 600; font-size: 0.85rem;
    cursor: pointer; text-align: center;
    background: var(--bg-body); color: var(--text-muted);
    transition: all 0.15s;
}
.trade-type-btn.buy.active { background: rgba(38, 166, 154, 0.2); color: var(--up); }
.trade-type-btn.sell.active { background: rgba(239, 83, 80, 0.2); color: var(--down); }

.trade-field { margin-bottom: 10px; }
.trade-field label {
    display: block; font-size: 0.72rem;
    color: var(--text-muted); margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: 0.3px;
}
.trade-field input {
    width: 100%; padding: 8px 10px;
    background: var(--bg-body); border: 1px solid var(--border);
    color: var(--text-main); border-radius: 4px;
    font-size: 0.85rem; font-family: monospace;
}
.trade-field input:focus { outline: none; border-color: var(--accent); }

.trade-submit {
    width: 100%; padding: 10px;
    border: none; border-radius: 4px;
    font-weight: 600; font-size: 0.9rem;
    cursor: pointer; transition: opacity 0.15s;
    margin-top: 5px;
}
.trade-submit:hover { opacity: 0.85; }
.trade-submit.buy { background: var(--up); color: #fff; }
.trade-submit.sell { background: var(--down); color: #fff; }

/* Positions & History */
.panel-section { flex: 1; overflow-y: auto; }
.panel-section-tabs { display: flex; border-bottom: 1px solid var(--border); }
.ps-tab {
    flex: 1; padding: 7px; text-align: center;
    font-size: 0.72rem; text-transform: uppercase;
    color: var(--text-muted); cursor: pointer;
    border: none; background: none;
    border-bottom: 2px solid transparent;
}
.ps-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.positions-list, .history-list { display: none; }
.positions-list.active, .history-list.active { display: block; }

.position-card {
    padding: 10px 15px;
    border-bottom: 1px solid rgba(54, 58, 69, 0.5);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px;
    font-size: 0.8rem;
}
.position-card:hover { background: var(--bg-hover); }
.pos-symbol { font-weight: 600; }
.pos-type { font-size: 0.7rem; text-transform: uppercase; }
.pos-type.buy { color: var(--up); }
.pos-type.sell { color: var(--down); }
.pos-details { color: var(--text-muted); font-size: 0.72rem; font-family: monospace; }
.pos-pnl { text-align: right; font-family: monospace; font-weight: 600; }
.pos-pnl.up { color: var(--up); }
.pos-pnl.down { color: var(--down); }
.pos-close-btn {
    background: rgba(239, 83, 80, 0.15);
    color: var(--down);
    border: none; border-radius: 3px;
    padding: 3px 8px; font-size: 0.7rem;
    cursor: pointer; margin-top: 4px;
}
.pos-close-btn:hover { background: rgba(239, 83, 80, 0.3); }

/* Portfolio summary bar */
.portfolio-bar {
    padding: 8px 15px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    background: var(--bg-panel);
    flex-shrink: 0;
}
.portfolio-stat { text-align: center; }
.portfolio-stat .label { color: var(--text-muted); margin-bottom: 2px; }
.portfolio-stat .value { font-family: monospace; font-weight: 600; }

/* ---- Auth Overlay ---- */
.auth-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.auth-overlay.hidden { display: none; }

.auth-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 30px;
    width: 380px;
    max-width: 90vw;
}
.auth-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 5px;
}
.auth-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}
.auth-tabs {
    display: flex; gap: 0;
    margin-bottom: 20px;
    border-radius: 4px; overflow: hidden;
    border: 1px solid var(--border);
}
.auth-tab {
    flex: 1; padding: 8px;
    text-align: center;
    background: var(--bg-body);
    color: var(--text-muted);
    border: none; cursor: pointer;
    font-size: 0.85rem; font-weight: 500;
    transition: all 0.15s;
}
.auth-tab.active { background: var(--accent); color: #fff; }

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-field {
    margin-bottom: 14px;
}
.auth-field label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.auth-field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    font-size: 0.9rem;
}
.auth-field input:focus { outline: none; border-color: var(--accent); }

.auth-submit {
    width: 100%;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 5px;
    transition: background 0.15s;
}
.auth-submit:hover { background: var(--accent-hover); }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
    color: var(--down);
    font-size: 0.8rem;
    margin-top: 10px;
    min-height: 20px;
}
.auth-error:empty { display: none; }

/* ---- Indicator Config Popup ---- */
.indicator-popup {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 15px;
    z-index: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 200px;
    display: none;
}
.indicator-popup.visible { display: block; }
.indicator-popup h4 { font-size: 0.82rem; margin-bottom: 10px; font-weight: 600; }
.indicator-popup label { font-size: 0.72rem; color: var(--text-muted); display: block; margin-bottom: 3px; }
.indicator-popup input {
    width: 100%; padding: 5px 8px;
    background: var(--bg-body); border: 1px solid var(--border);
    color: var(--text-main); border-radius: 3px;
    font-size: 0.8rem; margin-bottom: 8px;
}
.indicator-popup .popup-actions { display: flex; gap: 5px; margin-top: 5px; }
.indicator-popup .popup-btn {
    flex: 1; padding: 5px; border: none; border-radius: 3px;
    font-size: 0.78rem; cursor: pointer;
}
.indicator-popup .popup-apply { background: var(--accent); color: #fff; }
.indicator-popup .popup-cancel { background: var(--bg-hover); color: var(--text-main); }

/* ---- Add Commodity Modal ---- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: none; align-items: center; justify-content: center;
    z-index: 600;
}
.modal-overlay.visible { display: flex; }
.modal-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    width: 300px;
}
.modal-card h3 { font-size: 0.95rem; margin-bottom: 12px; }
.modal-item {
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex; justify-content: space-between;
}
.modal-item:hover { background: var(--bg-hover); }
.modal-item .mi-unit { color: var(--text-muted); font-size: 0.75rem; }
.modal-close {
    margin-top: 12px; width: 100%; padding: 8px;
    background: var(--bg-hover); border: none; border-radius: 4px;
    color: var(--text-muted); cursor: pointer; font-size: 0.82rem;
}

/* ---- Keyboard Shortcuts Overlay ---- */
.shortcuts-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    display: none; align-items: center; justify-content: center;
    z-index: 700;
}
.shortcuts-overlay.visible { display: flex; }
.shortcuts-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 360px;
}
.shortcuts-card h3 { font-size: 1rem; margin-bottom: 15px; }
.shortcut-row {
    display: flex; justify-content: space-between;
    padding: 5px 0; font-size: 0.82rem;
}
.shortcut-key {
    background: var(--bg-body);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.78rem;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .right-panel { width: 280px; }
    .legend-area { display: none; }
}

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }

    .sidebar {
        width: 100% !important;
        height: auto;
        max-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        transition: max-height 0.3s ease;
    }
    .sidebar.mobile-open { max-height: 50vh; overflow-y: auto; opacity: 1; pointer-events: auto; }
    .sidebar.collapsed { max-height: 0; }

    .right-panel {
        position: fixed;
        right: 0; top: 0; bottom: 0;
        width: 300px !important;
        z-index: 400;
        box-shadow: -4px 0 20px rgba(0,0,0,0.5);
    }
    .right-panel.collapsed { width: 0 !important; }

    .top-bar { gap: 6px; padding: 0 8px; flex-wrap: nowrap; overflow-x: auto; }
    .timeframe-group { flex-shrink: 0; }
    .chart-type-group { display: none; }
    .top-bar-divider { display: none; }

    .footer-status { font-size: 0.65rem; }
    .disclaimer { display: none; }
}
