/* ── Reset & base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e2e8f0;
    --border-subtle: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --info: #0ea5e9;
    --info-light: #f0f9ff;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", monospace;
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Nav ─────────────────────────────────────────────────────────────── */
.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
    background: rgba(255,255,255,0.9);
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 4px; }
.nav-brand {
    font-weight: 700; font-size: 15px; color: var(--text);
    text-decoration: none; margin-right: 16px;
    letter-spacing: -0.01em;
}
.nav-link {
    font-size: 13px; color: var(--text-secondary); text-decoration: none;
    padding: 6px 10px; border-radius: 6px; font-weight: 500;
    transition: all var(--transition);
}
.nav-link:hover { color: var(--text); background: var(--bg); }
.nav-link.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.nav-user {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-secondary); font-weight: 500;
}
.avatar { width: 26px; height: 26px; border-radius: 50%; }

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

/* ── Page header ─────────────────────────────────────────────────────── */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
.page-header h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.back-link {
    font-size: 13px; color: var(--text-muted); text-decoration: none;
    display: inline-flex; align-items: center; gap: 4px; margin-bottom: 4px;
    font-weight: 500; transition: color var(--transition);
}
.back-link:hover { color: var(--primary); }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
    background: var(--bg); color: var(--text-muted);
}
.badge-agent { background: var(--primary-light); color: var(--primary); }
.badge-pending { background: var(--warning-light); color: #b45309; }
.badge-running { background: var(--info-light); color: #0369a1; }
.badge-completed { background: var(--success-light); color: #047857; }
.badge-failed { background: var(--danger-light); color: var(--danger); }
.badge-timing { background: var(--bg); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.badge-count { background: var(--bg); color: var(--text-muted); }

/* ── Filters ─────────────────────────────────────────────────────────── */
.filters { margin-bottom: 16px; }
.filter-form { display: flex; gap: 8px; }
.filter-form select {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; font-weight: 500; background: var(--surface); cursor: pointer;
    color: var(--text-secondary); transition: border-color var(--transition);
    font-family: inherit;
}
.filter-form select:hover { border-color: #94a3b8; }
.filter-form select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }

/* ── Trace table ─────────────────────────────────────────────────────── */
.trace-table {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
    border: 1px solid var(--border);
}
.trace-table th {
    text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600;
    color: var(--text-muted); background: var(--surface); border-bottom: 1px solid var(--border);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.trace-table td {
    padding: 10px 16px; font-size: 13px; border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
.trace-table tbody tr:last-child td { border-bottom: none; }
.trace-row { cursor: pointer; transition: background var(--transition); }
.trace-row:hover { background: #f8faff; }
.trace-row--disabled { cursor: default; opacity: 0.6; }
.trace-row--disabled:hover { background: inherit; }
.nowrap { white-space: nowrap; }
.prompt-preview {
    max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text);
}
.mono { font-family: var(--font-mono); font-size: 12px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 48px; font-size: 14px; }

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 16px; margin-top: 20px;
}
.page-info { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border-radius: 6px;
    font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    transition: all var(--transition); font-family: inherit;
}
.btn:hover { background: var(--bg); border-color: #cbd5e1; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
    box-shadow: 0 1px 2px rgba(99,102,241,0.2);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* ── Trace detail: meta grid ─────────────────────────────────────────── */
.trace-meta {
    background: var(--surface); border-radius: var(--radius-lg);
    border: 1px solid var(--border); padding: 20px; margin-bottom: 24px;
}
.meta-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label {
    font-size: 11px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
}
.meta-value { font-size: 14px; font-weight: 500; color: var(--text); }

/* ── Sections ────────────────────────────────────────────────────────── */
.section { margin-bottom: 24px; }
.section h2 {
    font-size: 14px; font-weight: 700; margin-bottom: 12px;
    text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary);
}

/* ── Code blocks ─────────────────────────────────────────────────────── */
.code-block {
    background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: var(--radius);
    font-family: var(--font-mono); font-size: 13px;
    overflow-x: auto; white-space: pre-wrap; word-break: break-word;
    line-height: 1.6; max-height: 400px; overflow-y: auto;
    border: 1px solid #1e293b;
}
.code-sm { font-size: 12px; max-height: 250px; }
.code-error { border-left: 3px solid var(--danger); }

/* ── Mermaid ─────────────────────────────────────────────────────────── */
.mermaid-container {
    background: var(--surface); padding: 32px; border-radius: var(--radius-lg);
    border: 1px solid var(--border); overflow-x: auto;
    display: flex; justify-content: center;
}
.mermaid-container .mermaid { text-align: center; }
.legend {
    display: flex; gap: 20px; margin-top: 12px; flex-wrap: wrap;
    padding: 0 4px;
}
.legend-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-muted); font-weight: 500;
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ── Span cards ──────────────────────────────────────────────────────── */
.span-card {
    background: var(--surface); border-radius: var(--radius-lg);
    border: 1px solid var(--border); margin-bottom: 8px;
    border-left: 3px solid var(--info);
    overflow: hidden;
}
.span-error { border-left-color: var(--danger); }
.span-header {
    padding: 12px 16px; cursor: pointer; display: flex; align-items: center;
    gap: 10px; font-size: 14px; font-weight: 600;
    transition: background var(--transition);
}
.span-header:hover { background: var(--bg); }
.span-header::marker { color: var(--text-muted); }
.span-name { flex: 1; }
.span-body { padding: 0 16px 16px; }
.span-section { margin-top: 12px; }
.span-section h4 {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}

/* ── Tool cards ──────────────────────────────────────────────────────── */
.tool-card {
    background: var(--bg); border-radius: var(--radius);
    margin-bottom: 6px; border-left: 3px solid #cbd5e1;
    overflow: hidden;
}
.tool-error { border-left-color: var(--danger); }
.tool-header {
    padding: 8px 12px; cursor: pointer; display: flex; align-items: center;
    gap: 8px; font-size: 13px; font-weight: 600;
    transition: background var(--transition);
}
.tool-header:hover { background: #e2e8f0; }
.tool-name { flex: 1; font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }
.tool-body { padding: 0 12px 12px; }
.tool-section { margin-top: 8px; }
.tool-section h5 {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px;
}

/* ── Agent cards ─────────────────────────────────────────────────────── */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.agent-card {
    background: var(--surface); border-radius: var(--radius-lg);
    border: 1px solid var(--border); padding: 20px;
    transition: box-shadow var(--transition);
}
.agent-card:hover { box-shadow: var(--shadow-md); }
.agent-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 2px; letter-spacing: -0.01em; }
.agent-slug { color: var(--text-muted); margin-bottom: 8px; font-size: 13px; }
.agent-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; line-height: 1.5; }
.agent-stats { display: flex; gap: 16px; margin-bottom: 14px; }
.stat { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* ── Login page ──────────────────────────────────────────────────────── */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--bg);
}
.login-card {
    background: var(--surface); padding: 48px; border-radius: var(--radius-lg);
    border: 1px solid var(--border); text-align: center;
    max-width: 400px; width: 100%;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; font-weight: 700; letter-spacing: -0.02em; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.btn-login { display: block; width: 100%; padding: 12px; font-size: 14px; }
.error {
    color: #b91c1c; font-size: 13px; margin-bottom: 16px;
    padding: 10px 12px; background: var(--danger-light);
    border-radius: var(--radius); border: 1px solid #fecaca;
}
