/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: #1f2937;
    background: #f3f4f6;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    background: #0f172a;
    color: #e2e8f0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: 20px 0;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 12px;
    padding: 0 20px 24px 20px;
    align-items: center;
    border-bottom: 1px solid #1e293b;
    margin-bottom: 16px;
}
.brand-logo {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: white;
    font-size: 14px;
}
.brand-text h1 { font-size: 15px; color: #f8fafc; }
.brand-text p { font-size: 11px; color: #94a3b8; margin-top: 2px; }

.sidebar-nav { display: grid; gap: 4px; padding: 0 12px; }
.nav-item {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 6px;
    color: #cbd5e1;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: #1e293b; color: #f8fafc; text-decoration: none; }
.nav-item.active { background: #2563eb; color: white; }
.nav-icon { font-size: 14px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #1e293b;
    font-size: 12px;
}
.status-indicator { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-idle { background: #64748b; }
.dot-live { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25); }
.dot-error { background: #ef4444; }

/* ===== Main content ===== */
.main-content {
    padding: 28px 32px;
    display: grid;
    gap: 20px;
    align-content: start;
    overflow-x: hidden;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.page-title { font-size: 22px; color: #0f172a; }
.page-subtitle { color: #64748b; font-size: 13px; margin-top: 4px; }
.header-actions { display: flex; gap: 8px; }

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: 10px;
    padding: 20px 22px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
}
.card-live { border-color: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.08); }
.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.card-title { font-size: 16px; color: #0f172a; }
.card-subtitle { color: #64748b; font-size: 13px; margin-top: 4px; }
.card-header-actions { display: flex; gap: 8px; }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.badge-live { background: #d1fae5; color: #065f46; }
.badge-completed { background: #dbeafe; color: #1e40af; }
.badge-aborted { background: #fee2e2; color: #991b1b; }
.badge-running { background: #d1fae5; color: #065f46; }
.pulse-dot {
    width: 6px; height: 6px; background: #10b981; border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.4); }
}

/* ===== Metrics grid ===== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.metric-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    display: grid;
    gap: 4px;
}
.metric-label {
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.metric-value {
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    font-variant-numeric: tabular-nums;
}
.metric-small { font-size: 14px; font-weight: 600; }

/* ===== Split grid (2-col) ===== */
.split-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.panel {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
}
.panel-title {
    font-size: 13px;
    color: #334155;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Forms ===== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-group { display: grid; gap: 6px; }
.form-group.span-2 { grid-column: 1 / -1; }
.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: #334155;
}
.req { color: #ef4444; }
.form-hint { font-size: 11px; color: #64748b; }
.form-hint-link { font-size: 11px; }

input[type="text"],
input[type="number"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    font: inherit;
    color: #1f2937;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
textarea { resize: vertical; }
input[type="file"] { padding: 6px; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 6px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: #334155; border-color: #d1d5db; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* ===== Tables ===== */
.table-scroll { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #1f2937;
    font-variant-numeric: tabular-nums;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table .text-right { text-align: right; }
.empty-row { text-align: center; color: #94a3b8; padding: 20px; font-style: italic; }

/* ===== Toasts ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: grid;
    gap: 8px;
    z-index: 1000;
    max-width: 360px;
}
.toast {
    background: white;
    border-left: 4px solid #2563eb;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    font-size: 13px;
    animation: slideIn 0.25s ease-out;
}
.toast-success { border-left-color: #10b981; }
.toast-error { border-left-color: #ef4444; }
.toast-warn { border-left-color: #f59e0b; }
@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== Detail grid (dl/dt/dd) ===== */
.detail-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px 16px;
    margin: 0;
    align-items: baseline;
}
.detail-grid dt {
    font-weight: 600;
    color: #475569;
    font-size: 13px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
}
.detail-grid dd {
    margin: 0;
    padding: 6px 0;
    font-size: 14px;
    color: #0f172a;
    word-break: break-word;
    border-bottom: 1px solid #f1f5f9;
}
.detail-grid dt:last-of-type,
.detail-grid dd:last-of-type { border-bottom: none; }

/* ===== Modal ===== */
[hidden] { display: none !important; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 16px;
    z-index: 1000;
    overflow-y: auto;
}
.modal {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-lg { max-width: 900px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close {
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #64748b;
    padding: 4px 8px;
}
.modal-close:hover { color: #0f172a; }
.modal-body {
    padding: 20px;
    display: grid;
    gap: 14px;
}
.modal-actions {
    padding: 14px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    background: #f8fafc;
}
.modal .modal-actions { padding: 14px 0 0; border-top: none; background: transparent; }
.modal-body .modal-actions {
    padding: 14px 0 0;
    border-top: 1px solid #e2e8f0;
    margin-top: 6px;
    background: transparent;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.empty-state {
    padding: 32px 20px;
    text-align: center;
    color: #64748b;
    font-size: 14px;
}
.loading {
    padding: 20px;
    text-align: center;
    color: #64748b;
    font-size: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { position: relative; height: auto; grid-template-rows: auto auto auto; }
    .sidebar-nav { grid-auto-flow: column; grid-auto-columns: 1fr; }
    .nav-item { justify-content: center; }
    .main-content { padding: 20px 16px; }
    .form-grid, .split-grid, .form-grid-2 { grid-template-columns: 1fr; }
    .modal-backdrop { padding: 20px 12px; }
}
