/* QuantVision - Financial Quantitative Analysis Platform */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d29;
    --bg-card: #1e2230;
    --bg-hover: #2a2f3e;
    --text-primary: #e8eaed;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-light: #60a5fa;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f59e0b;
    --purple: #8b5cf6;
    --border: #2d3142;
    --radius: 8px;
    --sidebar-width: 220px;
}

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

body {
    font-family: -apple-system, "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.nav-list {
    list-style: none;
    padding: 8px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--bg-hover);
    color: var(--accent-light);
    border-left-color: var(--accent);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

/* Content */
.content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 20px 24px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
}

.page-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Grid */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Mobile bottom nav + responsive layout ===== */
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }

    body { flex-direction: column; }

    /* Sidebar -> bottom nav */
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        border-right: none;
        border-top: 1px solid var(--border);
        z-index: 200;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .sidebar-header { display: none; }
    .nav-list {
        display: flex;
        justify-content: space-around;
        padding: 0;
    }
    .nav-link {
        flex-direction: column;
        gap: 2px;
        padding: 8px 4px;
        font-size: 10px;
        border-left: none;
        border-bottom: 3px solid transparent;
        flex: 1;
        text-align: center;
        justify-content: center;
    }
    .nav-link.active {
        border-bottom-color: var(--accent);
        color: var(--accent-light);
        background: transparent;
    }
    .nav-icon { font-size: 20px; width: auto; }

    /* Content fills above bottom nav */
    .content {
        margin-left: 0;
        padding: 12px 10px 70px;
        flex: 1;
    }

    /* Grids -> single column */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

    /* Metric cards -> 2 columns */
    #index-cards.grid-4,
    #bt-metrics.grid-4 { grid-template-columns: repeat(2, 1fr); }

    /* Chart heights for portrait */
    .chart-container { height: 280px; }
    .chart-container-lg { height: 340px; }
    .chart-container-sm { height: 220px; }

    /* Dashboard widgets stack */
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-grid .widget,
    .dashboard-grid .widget.wide,
    .dashboard-grid .widget.narrow {
        grid-column: span 1;
    }

    /* Controls wrap */
    .control-bar {
        gap: 6px;
        flex-direction: column;
        align-items: stretch;
    }
    .control-bar label { font-size: 12px; }
    .input-field { font-size: 14px; padding: 10px; width: 100% !important; }
    .btn { padding: 10px; font-size: 14px; width: 100%; }

    /* Page header */
    .page-title { font-size: 18px; }
    .page-desc { font-size: 12px; }

    /* Cards */
    .card { padding: 12px; margin-bottom: 10px; }
    .card-title { font-size: 13px; }

    /* Metric values */
    .metric-value { font-size: 20px; }
    .metric-label { font-size: 11px; }

    /* Table: horizontal scroll */
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 6px 8px; }

    /* Widget drag handle hidden on touch */
    .widget-handle { display: none; }
    .widget { padding: 12px; cursor: default; }
}

/* Metric cards */
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    transition: transform 0.2s, border-color 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
}

.metric-change {
    font-size: 12px;
    margin-top: 4px;
}

.positive { color: var(--green); }
.negative { color: var(--red); }

/* Chart container */
.chart-container {
    width: 100%;
    height: 350px;
}

.chart-container-lg {
    width: 100%;
    height: 500px;
}

.chart-container-sm {
    width: 100%;
    height: 260px;
}

/* Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 8px 12px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
    cursor: pointer;
}

/* Controls */
.control-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.input-field {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.input-field:focus {
    border-color: var(--accent);
}

.btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

select.input-field {
    cursor: pointer;
    appearance: auto;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

.loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Draggable widget */
.widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: move;
    transition: box-shadow 0.2s, opacity 0.2s;
}

.widget.dragging {
    opacity: 0.5;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.widget-handle {
    color: var(--text-muted);
    cursor: move;
    font-size: 18px;
}

.widget-close {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    background: none;
    border: none;
}

.widget-close:hover {
    color: var(--red);
}

/* Dashboard grid with drag-drop */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    min-height: 200px;
}

.dashboard-grid .widget {
    grid-column: span 6;
}

.dashboard-grid .widget.wide {
    grid-column: span 12;
}

.dashboard-grid .widget.narrow {
    grid-column: span 4;
}

.drop-placeholder {
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    background: rgba(59, 130, 246, 0.05);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Tooltip */
.tooltip {
    position: relative;
}

.tooltip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 200;
}

/* Tag */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.tag-green { background: rgba(34,197,94,0.15); color: var(--green); }
.tag-red { background: rgba(239,68,68,0.15); color: var(--red); }
.tag-blue { background: rgba(59,130,246,0.15); color: var(--accent-light); }
