/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
    color-scheme: light;
    --bg: radial-gradient(circle at top left, #f6efe6 0%, #eadbc4 48%, #dfcfb6 100%);
    --surface: rgba(255, 251, 245, 0.92);
    --surface-alt: rgba(249, 241, 229, 0.92);
    --ink: #1d1c18;
    --muted: #6e675b;
    --line: rgba(29, 28, 24, 0.12);
    --accent: #1e6f61;
    --accent-2: #b85d34;
    --danger: #8f2f2f;
    --ok: #2a7a44;
    --warn: #966600;
    --shadow: 0 24px 60px rgba(76, 59, 33, 0.14);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

/* ── Shell / layout ──────────────────────────────────────────────────────── */
.shell {
    max-width: 1380px;
    margin: 0 auto;
    padding: 28px 18px 42px;
}

.hero, .toolbar {
    display: grid;
    gap: 18px;
    grid-template-columns: 1.4fr 1fr;
    margin-bottom: 20px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.hero-copy, .hero-stats, .toolbar-panel, .table-panel, .empty {
    padding: 22px;
}

/* ── Typography ──────────────────────────────────────────────────────────── */
h1, h2 { margin: 0 0 10px; font-family: "Space Grotesk", "IBM Plex Sans", sans-serif; }
h1 { font-size: clamp(2.2rem, 5vw, 4.3rem); line-height: 0.92; letter-spacing: -0.05em; }
h2 { font-size: 1.15rem; }
p { margin: 0; color: var(--muted); }
.note { color: var(--muted); font-size: 0.9rem; }

/* ── Stats grid ──────────────────────────────────────────────────────────── */
.hero-stats {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
}
.stat-label {
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.74rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.stat-value { font-size: 1.7rem; font-weight: 800; }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar-panel {
    display: grid;
    gap: 14px;
    align-content: start;
}
.toolbar-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    border: 0;
    border-radius: 999px;
    padding: 11px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    color: white;
    background: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn.secondary { background: var(--accent-2); }
.btn.danger    { background: var(--danger); }
.btn.subtle    { background: #7a786f; }
.small-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.small-actions .btn { padding: 8px 12px; font-size: 0.86rem; }

/* ── Flash messages ──────────────────────────────────────────────────────── */
.flash {
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(30, 111, 97, 0.12);
    border: 1px solid rgba(30, 111, 97, 0.22);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
form.inline { display: inline; }
form.stack, .stack { display: grid; gap: 10px; }

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    font: inherit;
    background: white;
}
textarea { min-height: 86px; resize: vertical; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1080px; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
tr:hover td { background: rgba(255, 255, 255, 0.45); }
.mono { font-family: "IBM Plex Mono", monospace; font-size: 0.84rem; word-break: break-word; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    background: rgba(110, 103, 91, 0.13);
    margin-right: 6px;
    margin-bottom: 6px;
}
.success   { color: var(--ok);     background: rgba(42, 122, 68, 0.12); }
.failed    { color: var(--danger); background: rgba(143, 47, 47, 0.12); }
.skipped   { color: var(--warn);   background: rgba(150, 102, 0, 0.12); }
.invalid   { color: var(--danger); background: rgba(143, 47, 47, 0.12); }
.valid     { color: var(--ok);     background: rgba(42, 122, 68, 0.12); }
.exists-yes { color: var(--ok);     background: rgba(42, 122, 68, 0.12); }
.exists-no  { color: var(--danger); background: rgba(143, 47, 47, 0.12); }
.unknown    { color: var(--muted);  background: rgba(150, 150, 150, 0.12); animation: fade-pulse 1s ease-in-out infinite; }

@keyframes fade-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Pager ───────────────────────────────────────────────────────────────── */
.pager { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.pager .btn { padding: 8px 12px; }
.empty { text-align: center; }

/* ── Search bar ──────────────────────────────────────────────────────────── */
.search-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}
.search-row input[type=text] {
    flex: 1;
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 0.95rem;
}

/* ── Loader overlay ──────────────────────────────────────────────────────── */
.loader-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.22);
    z-index: 999;
    align-items: center;
    justify-content: center;
}
body.loading .loader-overlay { display: flex; }

.spinner {
    width: 56px;
    height: 56px;
    border: 5px solid rgba(255, 255, 255, 0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px 24px;
    overflow-y: auto;
}
.modal-backdrop.open { display: flex; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 26px;
    max-width: 700px;
    width: 100%;
    display: grid;
    gap: 14px;
}
.modal-box h3 { margin: 0; font-size: 1.1rem; }

.modal-prompt-box {
    background: #f4f0ea;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
    cursor: text;
    user-select: all;
    max-height: 160px;
    overflow-y: auto;
}
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Group visual hierarchy ──────────────────────────────────────────────── */
.group-row-open > td:first-child { border-left: 4px solid var(--accent); }
.group-row-open > td { background: rgba(30, 111, 97, 0.06); }

.child-row > td {
    background: rgba(30, 111, 97, 0.04);
    border-bottom-color: rgba(30, 111, 97, 0.1);
}
.child-row > td:first-child {
    padding-left: 32px;
    border-left: 4px solid var(--accent);
    position: relative;
}
.child-row > td:first-child::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(30, 111, 97, 0.22);
}
.child-row:hover > td { background: rgba(30, 111, 97, 0.09); }

.toggle-icon {
    display: inline-block;
    transition: transform 0.2s;
    font-style: normal;
}
.toggle-icon.open { transform: rotate(90deg); }

/* ── Edit page extras ────────────────────────────────────────────────────── */
/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    padding: 12px 0 14px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    white-space: nowrap;
}
.btn-group {
    display: flex;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--line);
}
.btn-tog {
    border: 0;
    background: white;
    padding: 7px 14px;
    font: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--muted);
    transition: background 0.12s, color 0.12s;
}
.btn-tog:not(:first-child) { border-left: 1px solid var(--line); }
.btn-tog:hover  { background: var(--surface-alt); color: var(--ink); }
.btn-tog.active { background: var(--accent); color: white; }
.confidence-range { display: flex; align-items: center; gap: 8px; }
input[type=range] {
    width: 120px;
    accent-color: var(--accent);
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
}
/* ── Confidence badge ────────────────────────────────────────────────────── */
.conf-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 800;
}
.conf-high { background: rgba(42, 122, 68, 0.14);  color: var(--ok); }
.conf-mid  { background: rgba(150, 102, 0, 0.14);  color: var(--warn); }
.conf-low  { background: rgba(143, 47, 47, 0.14);  color: var(--danger); }
/* ── Name / path cell helpers ────────────────────────────────────────────── */
.name-cell { font-size: 0.86rem; word-break: break-all; max-width: 280px; }
.path-cell { font-size: 0.78rem; color: var(--muted); word-break: break-all; max-width: 320px; }
.note-muted { color: #a09a92; font-size: 0.78rem; font-style: italic; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }
label { display: grid; gap: 6px; font-weight: 600; }
.meta { margin-bottom: 16px; color: var(--muted); }
/* ── Process Tracker ──────────────────────────────────────────────────────── */
.processes-panel {
    padding: 22px;
}

.processes-panel h2 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
}

.process-item {
    padding: 12px 16px;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.process-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.process-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--ink);
}

.process-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(42, 122, 68, 0.1);
    color: var(--ok);
    font-weight: 600;
    animation: pulse 2s infinite;
}

.process-status.running::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--ok);
    border-radius: 50%;
    animation: blink 1.5s infinite;
}

.process-details {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--muted);
}

.process-time, .process-pid {
    font-family: "IBM Plex Mono", monospace;
}

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

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.3; }
}
/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1040px) {
    .hero, .toolbar { grid-template-columns: 1fr; }
    .hero-stats, .toolbar-grid { grid-template-columns: 1fr 1fr; }
    .filter-bar { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 720px) {
    .shell { padding: 16px 10px 28px; }
    .hero-copy, .hero-stats, .toolbar-panel, .table-panel { padding: 16px; }
    .hero-stats, .toolbar-grid { grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr; }
}
