/* ===== VARIABLES ===== */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-hover: #243049;
    --border: #2a3550;
    --text-primary: #e2e8f0;
    --text-secondary: #8994a7;
    --text-muted: #5a6478;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #10b981;
    --green-bg: rgba(16, 185, 129, 0.1);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.1);
    --orange: #f59e0b;
    --purple: #8b5cf6;
    --sidebar-width: 220px;
    --topbar-height: 56px;
    --radius: 8px;
    --radius-sm: 4px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
}
#sidebar.collapsed { transform: translateX(-100%); }
.logo {
    padding: 1.2rem 1.4rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 1.4rem; color: var(--accent); }
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.5px; }
.nav-links { list-style: none; padding: 0.8rem 0; flex: 1; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 1.4rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.93rem;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-link.active {
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
    border-right: 3px solid var(--accent);
}
.nav-icon { font-size: 1rem; width: 1.4rem; text-align: center; }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); }
.paper-badge {
    background: rgba(245, 158, 11, 0.15);
    color: var(--orange);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 1px;
}

/* ===== MAIN ===== */
#main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: margin-left 0.3s;
}
#main-content.expanded { margin-left: 0; }

/* ===== TOPBAR ===== */
#topbar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 1.5rem; }
#page-title { font-size: 1.1rem; font-weight: 600; }
.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.3rem;
}
.icon-btn:hover { color: var(--text-primary); }
.market-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-secondary); }
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
}
.status-dot.open { background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.clock { font-family: 'Courier New', monospace; font-size: 0.9rem; color: var(--text-secondary); }

/* ===== PAGES ===== */
.page { display: none; padding: 1.5rem; }
.page.active { display: block; }

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.card-header h3 { font-size: 0.95rem; font-weight: 600; }

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.summary-card { text-align: center; }
.card-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 1.6rem; font-weight: 700; }
.card-change { font-size: 0.85rem; margin-top: 0.2rem; }
.card-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ===== GRIDS ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.trading-layout { grid-template-columns: 380px 1fr; }

/* ===== CHART ===== */
.chart-container { height: 320px; position: relative; }
.chart-container-sm { height: 200px; position: relative; }
.chart-card { grid-column: 1 / -1; }
.chart-timeframe { display: flex; gap: 0.3rem; }
.tf-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
}
.tf-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== TABLE ===== */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: 0.7rem 0.8rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 0.7rem 0.8rem;
    font-size: 0.88rem;
    border-bottom: 1px solid rgba(42, 53, 80, 0.5);
}
.data-table tbody tr:hover { background: var(--bg-hover); }

/* ===== COLORS ===== */
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ===== INDICES ===== */
.indices-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.index-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}
.index-name { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.index-value { font-size: 0.88rem; font-weight: 600; }
.index-change { font-size: 0.8rem; font-weight: 600; }

/* ===== BUTTONS ===== */
.btn {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.btn:hover { background: var(--border); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-full { width: 100%; padding: 0.7rem; font-size: 0.95rem; font-weight: 600; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-group { display: flex; gap: 0.3rem; }
.toggle-btn { flex: 1; text-align: center; }
.toggle-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== FORMS ===== */
.order-form { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.form-row { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
input, select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

/* ===== ORDER PREVIEW ===== */
.order-preview {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 0.8rem;
}
.preview-line {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.88rem;
}

/* ===== POSITIONS LIST ===== */
.positions-list { display: flex; flex-direction: column; gap: 0.5rem; }
.position-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0.8rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}
.position-item.long { border-left-color: var(--green); }
.position-item.short { border-left-color: var(--red); }
.position-item.bond { border-left-color: var(--purple); }
.position-info { display: flex; flex-direction: column; gap: 0.15rem; }
.position-symbol { font-weight: 700; font-size: 0.95rem; }
.position-detail { font-size: 0.78rem; color: var(--text-secondary); }
.position-pnl { text-align: right; }
.position-pnl-value { font-weight: 700; font-size: 0.95rem; }
.position-pnl-pct { font-size: 0.78rem; }

/* ===== SEARCH ===== */
.search-bar { display: flex; gap: 0.5rem; }
.search-bar input { flex: 1; }
.symbol-info { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.symbol-price { font-size: 2rem; font-weight: 700; }
.symbol-change { font-size: 1.1rem; font-weight: 600; }
.symbol-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
}

/* ===== MOVERS ===== */
.movers-list { display: flex; flex-direction: column; gap: 0.4rem; }
.mover-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.7rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.mover-item:hover { background: var(--bg-hover); }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(42, 53, 80, 0.5);
}
.stat-label { color: var(--text-secondary); font-size: 0.85rem; }
.stat-value { font-weight: 700; font-size: 0.95rem; }

/* ===== WATCHLIST ===== */
.watchlist-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}
.watchlist-item:hover { background: var(--bg-hover); }
.wl-remove { cursor: pointer; color: var(--text-muted); }
.wl-remove:hover { color: var(--red); }

/* ===== ALERTS ===== */
.alert-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0.8rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--orange);
}
.alert-item.triggered { border-left-color: var(--green); opacity: 0.7; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    min-width: 350px;
    max-width: 500px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.modal-close { font-size: 1rem; }

/* ===== NOTIFICATIONS ===== */
.notifications {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.notification {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 1.2rem;
    font-size: 0.88rem;
    animation: slideIn 0.3s ease;
    max-width: 350px;
    border-left: 3px solid var(--accent);
}
.notification.success { border-left-color: var(--green); }
.notification.error { border-left-color: var(--red); }
.notification.warning { border-left-color: var(--orange); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-size: 0.9rem;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .trading-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    #main-content { margin-left: 0; }
    .summary-cards { grid-template-columns: 1fr 1fr; }
    .indices-grid { grid-template-columns: 1fr; }
}
