/* APEX Control Room — Dark theme for MEV operations */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2332;
    --bg-card-hover: #1e2a3a;
    --border: #2d3748;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #10b981;
    --red: #ef4444;
    --yellow: #f59e0b;
    --orange: #f97316;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --sidebar-width: 220px;
    --topbar-height: 52px;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* — Sidebar — */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.logo {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 20px;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 2px;
}

.logo-sub {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    width: 100%;
}

.nav-links {
    list-style: none;
    padding: 8px 0;
    flex: 1;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
}

.nav-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

.ws-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
}

.ws-indicator.connected .ws-dot {
    background: var(--green);
}

.ws-indicator.connected {
    color: var(--green);
}

/* — Main content — */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#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 24px;
    flex-shrink: 0;
}

#topbar-left h1 {
    font-size: 16px;
    font-weight: 600;
}

#topbar-right {
    display: flex;
    gap: 20px;
}

.topbar-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 14px;
    font-family: var(--font-mono);
    font-weight: 600;
}

#page-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* — Cards — */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

/* — Grid layouts — */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 16px;
}

/* — Stats — */
.metric-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
}

.metric-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.metric-value {
    font-size: 22px;
    font-family: var(--font-mono);
    font-weight: 700;
}

.metric-unit {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 4px;
}

.metric-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-family: var(--font-mono);
}

/* — Color modifiers — */
.text-green {
    color: var(--green);
}

.text-red {
    color: var(--red);
}

.text-yellow {
    color: var(--yellow);
}

.text-cyan {
    color: var(--cyan);
}

.text-purple {
    color: var(--purple);
}

.text-accent {
    color: var(--accent);
}

/* — Tables — */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(45, 55, 72, 0.5);
    font-family: var(--font-mono);
    font-size: 12px;
}

.data-table tr:hover td {
    background: var(--bg-card-hover);
}

/* — Latency bar — */
.latency-bar-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.latency-stage {
    font-size: 11px;
    color: var(--text-secondary);
    width: 100px;
    text-align: right;
}

.latency-bar-track {
    flex: 1;
    height: 24px;
    background: rgba(45, 55, 72, 0.4);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.latency-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: white;
    min-width: 40px;
}

.latency-bar-fill.fast {
    background: var(--green);
}

.latency-bar-fill.medium {
    background: var(--yellow);
}

.latency-bar-fill.slow {
    background: var(--red);
}

/* — Badges — */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-green {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
}

.badge-red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

.badge-yellow {
    background: rgba(245, 158, 11, 0.15);
    color: var(--yellow);
}

.badge-blue {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

/* — Buttons — */
.btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: var(--red);
    border-color: var(--red);
    color: white;
}

/* — Forms — */
.input {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    font-family: var(--font-mono);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
}

/* — Service status — */
.service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(45, 55, 72, 0.4);
}

.service-name {
    font-size: 13px;
    font-weight: 500;
}

.service-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.service-latency {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
}

/* — Pipeline waterfall — */
.waterfall {
    position: relative;
    padding: 20px 0;
}

.waterfall-stage {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.waterfall-label {
    width: 120px;
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
    padding-right: 12px;
}

.waterfall-bar {
    height: 28px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    min-width: 60px;
    transition: width 0.5s ease;
}

/* — Empty state — */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

/* — JSON viewer — */
.json-viewer {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
}

/* — Scrollbar — */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* — Alert rows — */
.alert-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(45, 55, 72, 0.4);
    border-left: 3px solid transparent;
}

.alert-row.p0 {
    border-left-color: var(--red);
}

.alert-row.p1 {
    border-left-color: var(--orange);
}

.alert-row.p2 {
    border-left-color: var(--yellow);
}

.alert-row.p3 {
    border-left-color: var(--text-muted);
}

/* — Responsive — */
@media (max-width: 1200px) {
    .grid-4 {
        grid-template-columns: 1fr 1fr;
    }

    .grid-3 {
        grid-template-columns: 1fr 1fr;
    }
}

/* — Alert severity rows — */
.alert-critical { border-left-color: var(--red); }
.alert-high { border-left-color: var(--orange); }
.alert-warning { border-left-color: var(--yellow); }
.alert-info { border-left-color: var(--text-muted); }

.badge-orange { background: rgba(249,115,22,0.15); color: var(--orange); }

.text-orange { color: var(--orange); }

/* — accent color aliases used in config/system pages — */
:root {
    --accent-green: var(--green);
    --accent-red: var(--red);
    --accent-yellow: var(--yellow);
    --accent-orange: var(--orange);
    --accent-blue: var(--accent);
}

.btn-sm { padding: 2px 8px; font-size: 10px; }
