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

:root {
    --bg: #1E2A3A;
    --surface: #253545;
    --surface-hover: #2D3F50;
    --border: #364A5C;
    --text: #F7FAFC;
    --text-muted: #A0AEC0;
    --accent: #5BB8C9;
    --accent-hover: #4AA3B4;
    --success: #38A169;
    --error: #E53E3E;
    --warning: #D69E2E;
    --radius: 12px;
    --radius-sm: 8px;
}

html, body { height: 100%; }
body {
    font-family: 'Plus Jakarta Sans', 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* === Layout === */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.app-header {
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    margin-bottom: 2rem;
}

.app-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 720px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    cursor: pointer;
}

.header-brand h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.header-logo { width: 28px; height: 28px; }

.header-auth {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
}

.header-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

/* User menu */
.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    transition: background 150ms, border-color 150ms;
}
.user-menu-toggle:hover { background: var(--surface-hover); border-color: var(--border); }

.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}

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

.user-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
}

.user-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    min-width: 10rem;
    z-index: 100;
    padding: 0.35rem;
}

.user-menu-name {
    display: block;
    padding: 0.4rem 0.6rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: none;
    border: none;
    border-radius: 0.375rem;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 150ms;
}
.user-menu-item:hover { background: var(--surface-hover); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms, color 150ms;
    font-family: inherit;
    color: var(--text);
}
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--surface); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-ghost { background: none; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

/* === Page header === */
.page-header { margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 0.25rem; }
.page-header .subtitle, .upload-page .subtitle { color: var(--text-muted); font-size: 0.9rem; }

/* === Upload page === */
.upload-page { padding: 2rem 0; }

/* Pipeline toolbar — search + type filters */
.pipeline-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 0.6rem 2.2rem 0.6rem 2.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 150ms;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); }
.search-clear {
    position: absolute;
    right: 0.6rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    display: flex;
    align-items: center;
}
.search-clear:hover { color: var(--text); }

.type-filters {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.type-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
    font-family: inherit;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all 150ms;
}
.type-chip:hover { border-color: var(--accent); color: var(--text); }
.type-chip.active {
    background: rgba(91, 184, 201, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}
.chip-svg { flex-shrink: 0; }

.pipeline-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    text-align: center;
}
.empty-state p { font-size: 0.85rem; }

/* Pipeline grid */
.pipeline-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.pipeline-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.pipeline-card {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: border-color 150ms, background 150ms;
    font-family: inherit;
    font-size: inherit;
}

.pipeline-card:hover { border-color: var(--accent); background: var(--surface-hover); }
.pipeline-card.selected { border-color: var(--accent); background: rgba(91, 184, 201, 0.1); box-shadow: 0 0 0 1px var(--accent); }

.pipeline-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}
.pipeline-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pipeline-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    flex-shrink: 0;
}
.pipeline-name { font-weight: 600; font-size: 0.9rem; flex: 1; min-width: 0; }
.pipeline-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }

.pipeline-card-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.pipeline-badges {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}
.input-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    white-space: nowrap;
}

/* Favorite button */
.btn-fav {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: transform 150ms;
    opacity: 0.4;
}
.pipeline-card:hover .btn-fav,
.btn-fav.is-fav { opacity: 1; }
.btn-fav:hover { transform: scale(1.2); }

.group-title-fav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Toolbar layout */
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.view-toggle {
    padding: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Compact list view */
.pipeline-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.pipeline-list .pipeline-group.compact { gap: 0.15rem; }
.pipeline-list .group-title {
    font-size: 0.7rem;
    margin-bottom: 0.15rem;
}

.pipeline-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: border-color 150ms, background 150ms;
    font-family: inherit;
    font-size: inherit;
}
.pipeline-row:hover { border-color: var(--accent); background: var(--surface-hover); }
.pipeline-row-name { font-weight: 500; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipeline-row-right {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    margin-left: auto;
}
.input-badge-sm { font-size: 0.6rem; padding: 0.1rem 0.35rem; }
.btn-fav-sm { padding: 0.15rem; }
.pipeline-row:hover .btn-fav,
.pipeline-row .btn-fav.is-fav { opacity: 1; }

/* Selected pipeline header */
.selected-pipeline-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}
.selected-pipeline-header > .btn { white-space: nowrap; flex-shrink: 0; }
.selected-pipeline-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}
.selected-pipeline-name {
    font-size: 1.1rem;
    font-weight: 600;
}
.selected-pipeline-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Upload section */
.upload-section { display: flex; flex-direction: column; gap: 0.75rem; }

/* Prompt field */
.prompt-field { display: flex; flex-direction: column; gap: 0.3rem; }
.prompt-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.prompt-label .text-muted { font-weight: 400; }

.prompt-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.6rem 0.85rem;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 150ms;
}
.prompt-input:focus { outline: none; border-color: var(--accent); }
.prompt-input::placeholder { color: var(--text-muted); opacity: 0.6; }

/* InputParameterForm */
.param-field { display: flex; flex-direction: column; gap: 0.3rem; }
.param-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.param-label .text-muted { font-weight: 400; }
.param-input {
    width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border);
    border-radius: 0.5rem; background: var(--surface); color: var(--text);
    font-size: 0.85rem; font-family: inherit; resize: vertical;
    transition: border-color 0.15s;
}
.param-input:focus { outline: none; border-color: var(--accent); }
.param-input::placeholder { color: var(--text-muted); opacity: 0.6; }
.param-picker { position: relative; }
.param-picker-selected { cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.param-picker-spinner { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%); }
.param-dropdown {
    position: absolute; z-index: 50; top: 100%; left: 0; right: 0;
    max-height: 220px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); margin-top: 0.25rem;
}
.param-dropdown-item {
    padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.85rem;
    transition: background 0.1s;
}
.param-dropdown-item:hover { background: var(--surface-hover, rgba(255,255,255,0.05)); }
.param-dropdown-empty { padding: 0.5rem 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

/* Reprocess bar */
.reprocess-bar {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.drop-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 200ms, background 200ms;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(91, 184, 201, 0.05);
}

.drop-zone input[type="file"] { display: none; }

.drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}
.drop-content svg { opacity: 0.4; }
.drop-content .hint { font-size: 0.78rem; opacity: 0.5; }

/* === Status cards === */
.draft-pending-card {
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.draft-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}

.status-text { display: flex; flex-direction: column; gap: 0.25rem; }
.file-name { color: var(--text-muted); font-size: 0.85rem; }

/* === Processing card with timeline === */
.processing-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.processing-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.processing-header strong { display: block; font-size: 0.95rem; }

.file-badge {
    display: inline-block;
    font-size: 0.78rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.2rem;
}

.steps-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-left: 0.5rem;
}

.timeline-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    position: relative;
}

.timeline-step:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 7px;
    top: calc(50% + 10px);
    bottom: -0.5rem;
    width: 1px;
    background: var(--border);
}

.timeline-step.completed { color: var(--success); }
.timeline-step.completed::before { background: var(--success); opacity: 0.3; }
.timeline-step.processing { color: var(--accent); }
.timeline-step.failed { color: var(--error); }

.timeline-indicator {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.timeline-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
}

.mini-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.timeline-title { flex: 1; }
.timeline-progress { color: var(--text-muted); font-size: 0.75rem; }

/* === Result card === */
.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.result-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.result-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-title h3 { font-size: 0.95rem; font-weight: 600; }

.result-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.result-content {
    padding: 1.5rem;
    max-height: 600px;
    overflow-y: auto;
    line-height: 1.7;
    font-size: 0.9rem;
}

.result-content h1, .result-content h2, .result-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}
.result-content h1:first-child, .result-content h2:first-child { margin-top: 0; }
.result-content h1 { font-size: 1.2rem; }
.result-content h2 { font-size: 1.05rem; color: var(--accent); }
.result-content h3 { font-size: 0.95rem; color: var(--text); }
.result-content ul, .result-content ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.result-content li { margin-bottom: 0.3rem; }
.result-content p { margin-bottom: 0.75rem; }
.result-content strong { color: var(--text); }
.result-content code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}
.result-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-muted);
}
.result-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}
.result-content th, .result-content td {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    text-align: left;
}
.result-content th { background: var(--surface-hover); font-weight: 600; }
.result-content input[type="checkbox"] { margin-right: 0.4rem; }

/* === JSON result rendering === */
.json-section { margin-bottom: 1.25rem; }
.json-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.json-count {
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
}

.json-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.json-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    transition: border-color 150ms;
}
.json-card:hover { border-color: var(--accent); }

.json-field {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.82rem;
    line-height: 1.4;
}
.json-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    min-width: 6.5rem;
    flex-shrink: 0;
}
.json-value { color: var(--text); }

.json-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.json-tag {
    font-size: 0.68rem;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    background: rgba(91, 184, 201, 0.12);
    color: var(--accent);
    white-space: nowrap;
}

.json-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.json-badge-high { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.json-badge-medium { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.json-badge-low { background: rgba(34, 197, 94, 0.15); color: #4ade80; }

.json-summary {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.85rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}
.json-summary:last-child { border-bottom: none; }
.json-summary-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}
.json-metric {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

/* === Error card === */
.error-card {
    background: var(--surface);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 2rem;
    color: var(--error);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}
.error-card p { max-width: 500px; }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 960px;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.modal-toolbar h3 { font-size: 0.95rem; font-weight: 600; }

.modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    margin-bottom: 0;
    padding: 2rem;
}

/* === Spinner === */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* === Loading === */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--text-muted);
    font-size: 1rem;
}

/* === Navigation tabs === */
.nav-tabs {
    display: flex;
    gap: 0.25rem;
}

.nav-tab {
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: color 150ms, background 150ms;
}
.nav-tab:hover { color: var(--text); background: var(--surface-hover); }
.nav-tab.active { color: var(--accent); background: rgba(91, 184, 201, 0.1); }

/* === Sessions page === */
.sessions-page { padding: 2rem 0; }

.sessions-heading {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.session-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.session-card {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 150ms;
}
.session-card:hover { background: var(--surface-hover); }

.session-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.session-card-pipeline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    padding: 0.2rem 0.5rem 0.2rem 0.3rem;
    border-radius: 999px;
    background: var(--surface-hover);
}
.session-card-pipeline > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.session-card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-title-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.session-title-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    padding: 0.15rem 0.3rem;
    border-radius: 0.25rem;
    transition: background 150ms;
}
.session-title-text:hover { background: var(--surface-hover); }
.session-title-input {
    font-size: 1.1rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--surface);
    color: var(--text);
    flex: 1;
    max-width: 20rem;
}
.btn-icon { padding: 0.2rem; }

.session-card-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.session-card-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

/* Status badges */
.status-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.status-badge.completed { background: rgba(56, 161, 105, 0.15); color: var(--success); }
.status-badge.failed { background: rgba(229, 62, 62, 0.15); color: var(--error); }
.status-badge.draft { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.status-badge.processing { background: rgba(91, 184, 201, 0.15); color: var(--accent); }
.status-badge.queued { background: rgba(214, 158, 46, 0.15); color: var(--warning); }
.status-badge.uploading { background: rgba(214, 158, 46, 0.15); color: var(--warning); }
.status-badge.created { background: rgba(160, 174, 192, 0.15); color: var(--text-muted); }

/* Session detail */
.session-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.session-detail-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.session-detail-pipeline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pipeline-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.25rem 0.6rem 0.25rem 0.35rem;
    border-radius: 999px;
    background: var(--surface-hover);
}

.session-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.meta-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.meta-value {
    font-size: 0.85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-id {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.72rem;
    opacity: 0.6;
}

.session-params {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.param-tag {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.8rem;
}
.param-tag-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.param-tag-value {
    color: var(--text);
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Action dropdown */
.action-dropdown { position: relative; }
.action-dropdown-backdrop { position: fixed; inset: 0; z-index: 90; }
.action-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.3rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    min-width: 10rem;
    z-index: 100;
    padding: 0.3rem;
}
.action-dropdown-menu.action-dropdown-right { left: auto; right: 0; }
.action-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.45rem 0.65rem;
    background: none;
    border: none;
    border-radius: 0.375rem;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 150ms;
    white-space: nowrap;
}
.action-dropdown-item:hover { background: var(--surface-hover); }
.action-dropdown-item:disabled { opacity: 0.5; cursor: default; }
.action-dropdown-item.action-dropdown-danger { color: var(--error); }
.action-dropdown-item.action-dropdown-danger:hover { background: rgba(229, 62, 62, 0.1); }

.btn-danger { color: var(--error) !important; border-color: var(--error) !important; }
.btn-danger:hover:not(:disabled) { background: rgba(229, 62, 62, 0.1) !important; }

.btn-step-download {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.1rem;
    border-radius: 4px;
    transition: color 150ms;
}
.btn-step-download:hover { color: var(--accent); }

.btn-step-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    transition: background 150ms;
}
.btn-step-link:hover { background: rgba(91, 184, 201, 0.1); }

.step-links {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.modal-sm {
    max-width: 400px;
    padding: 1.5rem;
}

/* Reprocess panel */
.reprocess-panel {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.reprocess-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
}


/* === User menu divider === */
.user-menu-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.25rem 0;
}

/* === Profile page === */
.profile-page { padding-bottom: 2rem; }
.profile-page h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 1.25rem; }

.profile-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(91, 184, 201, 0.15);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    flex-shrink: 0;
    border: 2px solid var(--accent);
}

.profile-info h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 0.1rem; }
.profile-info p { margin-bottom: 0.4rem; }

.profile-section { margin-bottom: 1.5rem; }
.profile-section h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.profile-details {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.profile-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.profile-detail-row:last-child { border-bottom: none; }

.role-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.role-badge.role-admin {
    background: rgba(91, 184, 201, 0.15);
    color: var(--accent);
    border: 1px solid var(--accent);
}
.role-badge.role-superadmin {
    background: rgba(91, 184, 201, 0.15);
    color: var(--accent);
    border: 1px solid var(--accent);
}
.role-badge.role-member {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.role-badge.role-systemuser {
    background: rgba(214, 158, 46, 0.15);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.quota-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 1rem 0.5rem;
    overflow: hidden;
}
.quota-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.4s ease;
}
.quota-bar-warning { background: var(--warning); }
.quota-bar-danger { background: var(--error); }

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

.message { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; }
.message-error { background: rgba(229, 62, 62, 0.1); border: 1px solid var(--error); color: var(--error); }

/* === Admin page === */
.admin-page { padding-bottom: 2rem; }
.admin-header { margin-bottom: 1.5rem; }
.admin-header h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 0.25rem; }

.admin-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.admin-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 150ms, border-color 150ms;
    margin-bottom: -1px;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-section { margin-bottom: 2rem; }
.admin-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.admin-section-header h3 { font-size: 1.1rem; font-weight: 600; }

.admin-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.admin-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface-hover); }

.user-cell { display: flex; flex-direction: column; gap: 0.1rem; }
.user-cell-name { font-weight: 500; }
.user-cell-email { font-size: 0.8rem; color: var(--text-muted); }

.license-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.license-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.license-card.license-default { border-color: var(--accent); }
.license-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.license-card-header strong { font-size: 1rem; }
.default-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent);
    background: rgba(91, 184, 201, 0.15);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.license-card-body { padding: 0.75rem 1rem; }
.license-section { margin-bottom: 0.75rem; }
.license-section:last-child { margin-bottom: 0; }
.license-section-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}
.license-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
}

/* Admin edit modal */
.modal-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}
.modal-edit-header h3 { font-size: 1rem; font-weight: 600; }
.modal-edit-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}
.modal-edit-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}
.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem;
}
.btn-close:hover { color: var(--text); }

.modal-field { margin-bottom: 0.75rem; }
.modal-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.modal-field select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.825rem;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7f89' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 1.75rem;
}
.modal-field select:focus { outline: none; border-color: var(--accent); }

.loading-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

/* Preview modal */
.preview-modal {
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.preview-content {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Markdown body */
.markdown-body { font-size: 0.88rem; line-height: 1.7; color: var(--text); }
.markdown-body h1 { font-size: 1.4rem; font-weight: 700; margin: 1.5rem 0 0.5rem; }
.markdown-body h2 { font-size: 1.15rem; font-weight: 600; margin: 1.25rem 0 0.4rem; }
.markdown-body h3 { font-size: 1rem; font-weight: 600; margin: 1rem 0 0.3rem; }
.markdown-body p { margin: 0.5rem 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.markdown-body li { margin: 0.2rem 0; }
.markdown-body strong { font-weight: 600; }
.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    padding: 0.3rem 0.8rem;
    margin: 0.5rem 0;
    color: var(--text-muted);
}
.markdown-body code {
    background: rgba(255, 255, 255, 0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.82rem;
}
.markdown-body pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin: 0.5rem 0;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.82rem;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}
.markdown-body th { background: var(--surface); font-weight: 600; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* === Responsive — mobile === */
@media (max-width: 640px) {
    .app-header .container {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .header-title { font-size: 0.95rem; }
    .header-logo { width: 24px; height: 24px; }

    .nav-tabs {
        order: 3;
        width: 100%;
        justify-content: center;
        gap: 0.15rem;
    }
    .nav-tab {
        flex: 1;
        text-align: center;
        padding: 0.45rem 0.5rem;
        font-size: 0.8rem;
    }

    .header-auth { margin-left: auto; }
    .user-name { display: none; }
    .user-menu-toggle { padding: 0.25rem; }

    .container { padding: 0 1rem; }
    .upload-page, .sessions-page { padding: 1rem 0; }

    .selected-pipeline-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .session-detail { padding: 1rem; }
    .session-detail-info h2 { font-size: 0.95rem; }

    .session-card { padding: 0.45rem 0.6rem; }
    .session-card-pipeline { font-size: 0.8rem; }

    .modal-panel { margin: 0.5rem; max-width: calc(100vw - 1rem) !important; }
    .preview-modal { max-height: 95vh; }
    .session-actions { gap: 0.35rem; flex-wrap: wrap; }
    .session-actions .btn { font-size: 0.72rem; padding: 0.3rem 0.5rem; }
}
