/* ─── Variables ─── */
:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #263548;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --running: #8b5cf6;
    --running-bg: rgba(139, 92, 246, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ─── Layout ─── */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

/* ─── Header ─── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 32px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header h1 span {
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.scheduler-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.scheduler-info .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot.active {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.dot.paused {
    background: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}

/* ─── Buttons ─── */
.btn {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: var(--bg-card-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── KPI Cards ─── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    transition: border-color 0.15s ease;
}

.kpi-card:hover {
    border-color: var(--primary);
}

.kpi-card .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.kpi-card .value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1;
}

.kpi-card .sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.kpi-card.success .value { color: var(--success); }
.kpi-card.error .value { color: var(--error); }
.kpi-card.primary .value { color: var(--primary); }
.kpi-card.warning .value { color: var(--warning); }

/* ─── Charts ─── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

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

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-muted);
}

.chart-card canvas {
    max-height: 250px;
}

/* ─── Table ─── */
.table-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.table-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

tbody tr {
    transition: background 0.1s ease;
    cursor: pointer;
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

tbody td {
    padding: 12px 16px;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ─── Status badges ─── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.success {
    background: var(--success-bg);
    color: var(--success);
}

.badge.error {
    background: var(--error-bg);
    color: var(--error);
}

.badge.running {
    background: var(--running-bg);
    color: var(--running);
}

.badge .dot-sm {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge.running .dot-sm {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ─── Trigger badge ─── */
.trigger {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ─── Mono numbers ─── */
.mono {
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
}

.modal h3 {
    font-size: 1.1rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal .close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal .close-btn:hover {
    color: var(--text);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.detail-item {
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

.detail-item .label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.detail-item .value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
}

.detail-item.full {
    grid-column: 1 / -1;
}

.error-box {
    margin-top: 16px;
    padding: 12px;
    background: var(--error-bg);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--error);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ─── Empty state ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.9rem;
    margin-top: 8px;
}

/* ─── Tabs ─── */
.tabs-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 4px;
    border: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
}

.tab-content {
    min-height: 200px;
}

.tab-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
    }

    table {
        font-size: 0.8rem;
    }

    thead th, tbody td {
        padding: 8px 10px;
    }
}
