/* ═══════════════════════════════════════════════════════════
   MISSION CONTROL — Dashboard CSS
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --border: #2a2a3a;
    --border-glow: rgba(99, 102, 241, 0.3);
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --gradient-1: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-2: linear-gradient(135deg, #06b6d4, #3b82f6);
    --gradient-3: linear-gradient(135deg, #f59e0b, #ef4444);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-card: 0 4px 24px rgba(0,0,0,0.3), 0 0 0 1px var(--border);
    --shadow-glow: 0 0 30px var(--accent-glow);
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Background Grid ── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 50% -20%, rgba(99,102,241,0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139,92,246,0.05), transparent);
    pointer-events: none;
    z-index: 0;
}

.grid-bg {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

/* ── Layout ── */
.app { position: relative; z-index: 1; }

.header {
    padding: 40px 48px 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 24px;
}

.header-left h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #fff 0%, #8888a0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.header-left .subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 400;
}

.header-left .subtitle .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 8px;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52,211,153,0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(52,211,153,0); }
}

/* ── Period Tabs ── */
.period-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 4px;
    border: 1px solid var(--border);
}

.period-tab {
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    border: none;
    background: none;
    font-family: inherit;
}

.period-tab:hover { color: var(--text-primary); }

.period-tab.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 12px rgba(99,102,241,0.3);
}

/* ── KPI Cards ── */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    padding: 20px 48px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.kpi-card:hover {
    border-color: var(--border-glow);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.kpi-card .kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: 16px;
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.02em;
    line-height: 1;
}

.kpi-card .kpi-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    filter: blur(50px);
    opacity: 0.08;
    pointer-events: none;
}

.kpi-card:nth-child(1)::after { background: #6366f1; }
.kpi-card:nth-child(2)::after { background: #34d399; }
.kpi-card:nth-child(3)::after { background: #fbbf24; }
.kpi-card:nth-child(4)::after { background: #f87171; }

/* ── Section ── */
.section {
    padding: 20px 48px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title .badge {
    font-size: 0.75rem;
    background: var(--accent-glow);
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}

/* ── Agent Grid ── */
.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.agent-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 28px;
    position: relative;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.agent-card:hover {
    border-color: var(--border-glow);
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
}

.agent-card .glow-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.agent-card:hover .glow-bar { opacity: 1; }

.agent-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.agent-avatar {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    flex-shrink: 0;
    position: relative;
}

.agent-avatar .status-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 3px solid var(--bg-card);
}

.agent-avatar .status-dot.active { background: var(--success); }
.agent-avatar .status-dot.idle { background: var(--warning); }
.agent-avatar .status-dot.offline { background: var(--text-muted); }

.agent-info h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.agent-info .role {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Agent Stats Row ── */
.agent-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.agent-stat {
    text-align: center;
    padding: 12px 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.agent-card:hover .agent-stat { border-color: var(--border); }

.agent-stat .stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.agent-stat .stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 2px;
}

/* ── Projects List ── */
.projects-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.project-tag {
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-weight: 500;
    transition: all 0.3s ease;
}

.project-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Cost Bar ── */
.cost-bar-container {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.cost-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.cost-bar-header .cost-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.cost-bar-header .cost-value {
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.cost-bar {
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.cost-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0;
}

/* ── Charts Section ── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    padding: 20px 48px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 28px;
}

.chart-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 20px;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ── Cost Table ── */
.cost-table {
    width: 100%;
    border-collapse: collapse;
}

.cost-table th {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.cost-table td {
    padding: 12px 12px;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(42,42,58,0.5);
}

.cost-table tr:last-child td { border-bottom: none; }

.cost-table .agent-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cost-table .agent-mini-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.cost-table .cost-amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.cost-table .cost-bar-mini {
    width: 80px;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
}

.cost-table .cost-bar-mini-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s ease;
}

.cost-table .tokens-cell {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ── Provider Badges ── */
.provider-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.provider-badge {
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Loading ── */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.6s ease;
}

.loading-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .charts-row { grid-template-columns: 1fr; }
    .header, .kpi-row, .section, .charts-row { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 768px) {
    .header-left h1 { font-size: 1.6rem; }
    .agents-grid { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

/* ── Animations ── */
.fade-up {
    opacity: 0;
    transform: translateY(24px);
}

.stagger-item {
    opacity: 0;
    transform: translateY(16px);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Footer ── */
.footer {
    text-align: center;
    padding: 40px 48px 32px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}
