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

:root {
    --ink: #0a0a0f;
    --paper: #fafaf8;
    --accent: #3d5afe;
    --accent-hover: #304ffe;
    --accent-glow: rgba(61, 90, 254, 0.12);
    --accent-light: rgba(61, 90, 254, 0.06);
    --dim: #6b6b7b;
    --border: #e2e2e6;
    --surface: #f2f2f0;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'DM Sans', sans-serif;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-family: 'Space Grotesk', sans-serif;
    line-height: 1.15;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: white;
    color: var(--ink);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface); }

.btn-ghost {
    background: transparent;
    color: var(--dim);
    border-color: transparent;
}
.btn-ghost:hover { color: var(--ink); background: var(--surface); }

.btn-danger {
    background: white;
    color: var(--error);
    border-color: var(--border);
}
.btn-danger:hover { background: var(--error-bg); border-color: var(--error); }

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-full { width: 100%; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 6px;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.92rem;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--ink);
    transition: border-color 0.15s ease;
    outline: none;
}
.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
    padding: 24px;
}
.auth-container {
    width: 100%;
    max-width: 400px;
}
.auth-logo {
    display: block;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
    color: var(--ink);
    text-decoration: none;
    text-align: center;
    margin-bottom: 32px;
}
.auth-logo span { color: var(--accent); }
.auth-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
}
.auth-card h2 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}
.auth-subtitle {
    font-size: 0.88rem;
    color: var(--dim);
    margin-bottom: 24px;
}
.auth-error {
    font-size: 0.85rem;
    color: var(--error);
    margin-bottom: 12px;
    min-height: 20px;
}
.auth-toggle {
    text-align: center;
    font-size: 0.85rem;
    color: var(--dim);
    margin-top: 20px;
}
.auth-toggle a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.auth-toggle a:hover { text-decoration: underline; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
    min-height: 100vh;
}
.app-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.app-nav-left { display: flex; align-items: center; gap: 32px; }
.app-nav-right { display: flex; align-items: center; gap: 16px; }
.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.03em;
    color: var(--ink);
    text-decoration: none;
}
.logo span { color: var(--accent); }
.user-email {
    font-size: 0.82rem;
    color: var(--dim);
}

.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px 60px;
}

/* ============================================================
   DASHBOARD
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}
.page-header h1 {
    font-size: 1.6rem;
    letter-spacing: -0.02em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}
.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
}
.stat-card .stat-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}
.stat-card .stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--ink);
}

/* ============================================================
   PROCESS LIST
   ============================================================ */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.process-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.process-row {
    display: grid;
    grid-template-columns: 1fr 120px 100px 140px 100px;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    color: inherit;
}
.process-row:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-glow);
}
.process-name {
    font-weight: 500;
    font-size: 0.92rem;
}
.process-desc {
    font-size: 0.8rem;
    color: var(--dim);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.process-meta {
    font-size: 0.8rem;
    color: var(--dim);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 100px;
}
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-draft { background: var(--surface); color: var(--dim); }
.badge-paused { background: var(--warning-bg); color: var(--warning); }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-failed { background: var(--error-bg); color: var(--error); }
.badge-running { background: var(--accent-glow); color: var(--accent); }
.badge-skipped { background: var(--surface); color: var(--dim); }
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    background: white;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
    opacity: 0.6;
}
.empty-state h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.empty-state p {
    font-size: 0.9rem;
    color: var(--dim);
    max-width: 400px;
    margin: 0 auto 24px;
}

/* ============================================================
   NEW PROCESS BUILDER
   ============================================================ */
.builder-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 24px;
}
.builder-card h2 {
    font-size: 1.2rem;
    margin-bottom: 4px;
}
.builder-card .subtitle {
    font-size: 0.88rem;
    color: var(--dim);
    margin-bottom: 24px;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.suggestion-chip {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--dim);
    cursor: pointer;
    transition: all 0.15s ease;
}
.suggestion-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

/* Parsed Steps Preview */
.parsed-preview {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}
.parsed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.parsed-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}
.parsed-info {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}
.parsed-info-item {
    font-size: 0.82rem;
    color: var(--dim);
}
.parsed-info-item strong {
    color: var(--ink);
}

.step-pipeline {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 24px;
}
.step-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    position: relative;
}
.step-number {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--accent);
    color: white;
    border-radius: 50%;
}
.step-content {
    flex: 1;
}
.step-label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}
.step-description {
    font-size: 0.82rem;
    color: var(--dim);
    line-height: 1.5;
}
.step-action-tag {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 2px 8px;
    border-radius: 4px;
    margin-top: 6px;
    display: inline-block;
}

.step-connector {
    width: 2px;
    height: 12px;
    background: var(--border);
    margin-left: 33px;
}

.parsed-actions {
    display: flex;
    gap: 12px;
}

/* ============================================================
   PROCESS DETAIL
   ============================================================ */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}
.detail-header h1 {
    font-size: 1.5rem;
    letter-spacing: -0.02em;
}
.detail-meta {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--dim);
}
.detail-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.detail-section {
    margin-bottom: 32px;
}
.detail-section h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.detail-description {
    font-size: 0.92rem;
    color: var(--dim);
    line-height: 1.7;
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
}

/* Run History */
.run-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.run-row {
    display: grid;
    grid-template-columns: 80px 120px 1fr 120px;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}
.run-row:hover { border-color: var(--accent); }
.run-id {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--dim);
}
.run-time {
    font-size: 0.82rem;
    color: var(--dim);
}

/* Run Detail Modal */
.run-detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}
.run-detail-modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 32px;
}
.run-detail-modal h3 {
    font-size: 1.1rem;
    margin-bottom: 20px;
}
.run-step-result {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.run-step-status {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.7rem;
}
.run-step-status.completed { background: var(--success-bg); color: var(--success); }
.run-step-status.failed { background: var(--error-bg); color: var(--error); }
.run-step-status.skipped { background: var(--surface); color: var(--dim); border: 1px solid var(--border); }
.run-step-info { flex: 1; }
.run-step-info .step-label { font-size: 0.85rem; }
.run-step-output {
    font-family: 'Space Grotesk', monospace;
    font-size: 0.75rem;
    color: var(--dim);
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    margin-top: 6px;
    border: 1px solid var(--border);
    overflow-x: auto;
    white-space: pre-wrap;
}

/* ============================================================
   LOADING & ANIMATIONS
   ============================================================ */
.loading-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-bar {
    height: 3px;
    background: var(--accent-glow);
    position: relative;
    border-radius: 2px;
    overflow: hidden;
    margin: 16px 0;
}
.loading-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -50%;
    width: 50%;
    height: 100%;
    background: var(--accent);
    animation: loadbar 1s ease-in-out infinite;
}
@keyframes loadbar {
    0% { left: -50%; }
    100% { left: 100%; }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   BACK LINK
   ============================================================ */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--dim);
    text-decoration: none;
    margin-bottom: 20px;
    cursor: pointer;
}
.back-link:hover { color: var(--accent); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .process-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .detail-header {
        flex-direction: column;
        gap: 16px;
    }
    .run-row {
        grid-template-columns: 1fr 1fr;
    }
    .app-nav {
        flex-direction: column;
        gap: 12px;
    }
    .parsed-actions {
        flex-direction: column;
    }
}
