:root {
    --bg: #f8f9fa;
    --surface: #fff;
    --border: #e2e5e9;
    --text: #1a1d21;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --running: #2563eb;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, monospace;
    --radius: 8px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111218;
        --surface: #1a1b23;
        --border: #2e3040;
        --text: #e1e3ea;
        --text-muted: #8b8fa3;
        --primary: #4f8ff7;
        --primary-hover: #3b7de8;
        --success: #34d399;
        --danger: #f87171;
        --warning: #fbbf24;
        --running: #4f8ff7;
    }
}

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

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

/* Auth pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.auth-card .subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
}

.form-group input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9375rem;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}

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

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-run {
    background: var(--success);
    color: #fff;
    width: auto;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
}

.btn-run:hover { background: #047857; }
.btn-run:disabled { opacity: 0.6; cursor: not-allowed; }

.form-footer {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

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

.form-footer a:hover { text-decoration: underline; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 1rem;
    display: none;
}

.alert-error {
    background: color-mix(in srgb, var(--danger) 10%, var(--surface));
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--surface));
}

.alert-success {
    background: color-mix(in srgb, var(--success) 10%, var(--surface));
    color: var(--success);
    border: 1px solid color-mix(in srgb, var(--success) 25%, var(--surface));
}

/* Dashboard layout */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-brand {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    text-decoration: none;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.topbar-link {
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

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

.topbar-link.active {
    color: var(--text);
    font-weight: 500;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-user {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    cursor: pointer;
    color: var(--text-muted);
    font-family: var(--font);
}

.btn-logout:hover {
    background: var(--bg);
    color: var(--text);
}

.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Runs table */
.runs-table {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.runs-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.runs-table td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

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

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

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-success { background: color-mix(in srgb, var(--success) 12%, var(--surface)); color: var(--success); }
.status-failed { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.status-running { background: color-mix(in srgb, var(--running) 12%, var(--surface)); color: var(--running); }

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

.status-running .status-dot {
    animation: pulse 1.5s infinite;
}

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

.duration {
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* Run detail / log viewer */
.run-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.run-header .run-title {
    font-weight: 600;
    font-size: 1rem;
}

.run-header .run-meta {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.log-viewer {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: var(--radius);
    padding: 1rem;
    font-family: var(--mono);
    font-size: 0.8125rem;
    line-height: 1.7;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 70vh;
    overflow-y: auto;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.back-link:hover { color: var(--text); }

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}
