/* ═══════════════════════════════════════════════════════════════
   Merlin — application shell (builds on the Proxima design tokens
   defined in app.css)
   ═══════════════════════════════════════════════════════════════ */
.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 18px 14px;
    overflow-y: auto;
    gap: 4px;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 18px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-logo { width: 36px; height: 36px; flex-shrink: 0; }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand-title { font: 600 17px 'Inter', system-ui, sans-serif; letter-spacing: -0.015em; color: var(--text-primary); }
.sidebar-brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.04em; text-transform: uppercase; }

.nav-section-label {
    font: 600 10.5px 'Inter', system-ui, sans-serif;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 14px 10px 6px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font: 500 13.5px 'Inter', system-ui, sans-serif;
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
    border: 1px solid transparent;
}
.nav-link:hover { background: var(--bg-glass-hover); color: var(--text-primary); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-glow); }
.nav-link-icon { display: inline-flex; flex-shrink: 0; }
.nav-link-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link-count {
    font: 600 11px 'Inter', system-ui, sans-serif;
    min-width: 20px;
    text-align: center;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}
.nav-link.active .nav-link-count { background: var(--accent); color: #fff; }

.sidebar-spacer { flex: 1; }

/* ─── Main column ─── */
.app-main { display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }

.app-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 60px;
    flex-shrink: 0;
    padding: 0 26px;
    background: rgba(var(--bg-primary-rgb), 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.app-topbar-title { font: 600 16px 'Inter', system-ui, sans-serif; letter-spacing: -0.015em; color: var(--text-primary); }
.app-topbar-spacer { flex: 1; }

.app-content { flex: 1; overflow-y: auto; padding: 28px 32px 64px; }
.app-content-inner { max-width: 1080px; margin: 0 auto; }

/* ─── Persona switcher ─── */
.persona-switch { position: relative; }
.persona-trigger {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 5px 12px 5px 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
}
.persona-trigger:hover { border-color: var(--text-secondary); }
.persona-trigger-text { display: flex; flex-direction: column; line-height: 1.2; text-align: left; }
.persona-trigger-name { font: 600 12.5px 'Inter', system-ui, sans-serif; color: var(--text-primary); }
.persona-trigger-role { font-size: 10.5px; color: var(--text-muted); }
.persona-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 200;
    width: 280px;
    padding: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 28px rgba(0,0,0,0.16), 0 2px 6px rgba(0,0,0,0.06);
    animation: custom-dropdown-in 0.14s ease-out;
}
.persona-menu-label {
    font: 600 10.5px 'Inter', system-ui, sans-serif;
    letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted); padding: 8px 10px 4px;
}
.persona-option {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 10px; background: transparent; border: none;
    border-radius: var(--radius-sm); cursor: pointer; text-align: left;
    transition: background-color 0.12s ease;
}
.persona-option:hover { background: var(--bg-glass-hover); }
.persona-option.selected { background: var(--accent-soft); }
.persona-option-text { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.persona-option-name { font: 600 13px 'Inter', system-ui, sans-serif; color: var(--text-primary); }
.persona-option-role { font-size: 11.5px; color: var(--text-muted); }
.persona-option-check { color: var(--accent); flex-shrink: 0; }

/* ─── Page header ─── */
/* FocusOnNavigate puts tabindex="-1" on the h1 and focuses it after each
   navigation; that programmatic focus should not draw a ring. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible { outline: none; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.page-head-text { flex: 1; min-width: 0; }
.page-head h1 { font: 600 26px/1.2 'Inter', system-ui, sans-serif; letter-spacing: -0.02em; color: var(--text-primary); margin: 0; }
.page-head-sub { font-size: 13.5px; color: var(--text-secondary); margin-top: 4px; }
.page-head-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* ─── Stat cards ─── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}
.stat-card-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-card-label svg { color: var(--text-muted); }
.stat-card-value { font: 600 30px 'Inter', system-ui, sans-serif; letter-spacing: -0.02em; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.stat-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── Toolbar (filters above lists) ─── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-spacer { flex: 1; }
.search-box { position: relative; flex: 1; max-width: 320px; min-width: 180px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-box .input { padding-left: 34px; }

/* ─── Status / priority pills (semantic colours) ─── */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: var(--radius-full);
    font: 600 10.5px 'Inter', system-ui, sans-serif;
    letter-spacing: 0.04em; text-transform: uppercase; line-height: 1.7;
    white-space: nowrap;
}
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-new       { color: #2563eb; background: rgba(37, 99, 235, 0.12); }
.pill-open      { color: #0d9488; background: rgba(13, 148, 136, 0.14); }
.pill-pending   { color: #b45309; background: rgba(245, 158, 11, 0.16); }
.pill-escalated { color: #b91c1c; background: rgba(239, 68, 68, 0.14); }
.pill-resolved  { color: #15803d; background: rgba(34, 197, 94, 0.15); }
.pill-closed    { color: var(--text-secondary); background: var(--bg-tertiary); }
.pill-backlog   { color: var(--text-secondary); background: var(--bg-tertiary); }
.pill-todo      { color: #2563eb; background: rgba(37, 99, 235, 0.12); }
.pill-progress  { color: #7c3aed; background: rgba(124, 58, 237, 0.14); }
.pill-review    { color: #b45309; background: rgba(245, 158, 11, 0.16); }
.pill-done      { color: #15803d; background: rgba(34, 197, 94, 0.15); }
[data-theme="dark"] .pill-new       { color: #93c5fd; }
[data-theme="dark"] .pill-open      { color: #5eead4; }
[data-theme="dark"] .pill-pending   { color: #fbbf24; }
[data-theme="dark"] .pill-escalated { color: #fca5a5; }
[data-theme="dark"] .pill-resolved  { color: #86efac; }
[data-theme="dark"] .pill-todo      { color: #93c5fd; }
[data-theme="dark"] .pill-progress  { color: #c4b5fd; }
[data-theme="dark"] .pill-review    { color: #fbbf24; }
[data-theme="dark"] .pill-done      { color: #86efac; }

.prio { display: inline-flex; align-items: center; gap: 6px; font: 500 12.5px 'Inter', system-ui, sans-serif; color: var(--text-secondary); }
.prio-icon { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.prio-low      .prio-icon { background: #94a3b8; }
.prio-medium   .prio-icon { background: #2563eb; }
.prio-high     .prio-icon { background: #f59e0b; }
.prio-critical .prio-icon { background: #ef4444; }

/* ─── Conversation thread ─── */
.thread { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 12px; }
.msg-body-wrap { flex: 1; min-width: 0; }
.msg-bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.msg.is-agent .msg-bubble { background: var(--accent-soft); border-color: var(--accent-glow); }
.msg.is-system .msg-bubble { background: var(--bg-tertiary); border-style: dashed; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.msg-author { font: 600 13px 'Inter', system-ui, sans-serif; color: var(--text-primary); }
.msg-role { font-size: 11px; color: var(--text-muted); }
.msg-time { font-size: 11.5px; color: var(--text-muted); margin-left: auto; }
.msg-text { font-size: 13.5px; line-height: 1.6; color: var(--text-primary); white-space: pre-wrap; word-break: break-word; }

/* ─── Attachments ─── */
.description-card .msg-text { white-space: pre-wrap; word-break: break-word; }
.attach { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-attach { position: relative; overflow: hidden; cursor: pointer; }
.btn-attach input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.attach-error { font-size: 12px; color: #b91c1c; }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.attach-chip {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-full); padding: 4px 6px 4px 10px;
    font-size: 12.5px; color: var(--text-primary); text-decoration: none;
    max-width: 100%;
}
.attach-chip-link { transition: var(--transition); }
.attach-chip-link:hover { border-color: var(--accent); color: var(--accent); }
.attach-chip-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attach-chip-size { font-size: 11px; color: var(--text-muted); }
.attach-chip-remove {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border: none; border-radius: var(--radius-full);
    background: var(--bg-tertiary); color: var(--text-secondary); cursor: pointer; padding: 0;
}
.attach-chip-remove:hover { background: var(--accent-soft); color: var(--accent); }

/* ─── Two-column detail layout ─── */
.detail-grid { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.detail-aside { display: flex; flex-direction: column; gap: 16px; }
.meta-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; }
.meta-card h3 { margin-top: 0; }
.meta-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-subtle); }
.meta-row:last-child { border-bottom: none; }
.meta-row-label { font-size: 12.5px; color: var(--text-secondary); }
.meta-row-value { font: 500 13px 'Inter', system-ui, sans-serif; color: var(--text-primary); text-align: right; }

@media (max-width: 1000px) {
    .detail-grid { grid-template-columns: 1fr; }
}

/* ─── Kanban board ─── */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; align-items: start; }
.board-col { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 12px; min-height: 120px; transition: background-color 0.15s ease, border-color 0.15s ease; }
.board-col.drag-over { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-glow); }
.board-card { cursor: grab; }
.board-card[draggable="true"]:active { cursor: grabbing; }
.board-card.dragging { opacity: 0.45; }
.board-col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.board-col-title { font: 600 12px 'Inter', system-ui, sans-serif; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); }
.board-col-count { font: 600 11px 'Inter', system-ui, sans-serif; color: var(--text-muted); background: var(--bg-elevated); padding: 1px 7px; border-radius: var(--radius-full); }
.board-cards { display: flex; flex-direction: column; gap: 10px; }
.board-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 13px; cursor: pointer; transition: var(--transition); }
.board-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.board-card-title { font: 500 13.5px 'Inter', system-ui, sans-serif; color: var(--text-primary); line-height: 1.4; margin-bottom: 8px; }
.board-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.board-card-id { font: 500 11px 'JetBrains Mono', monospace; color: var(--text-muted); }
@media (max-width: 900px) { .board { grid-template-columns: 1fr 1fr; } }

/* ─── Dropdown: compact variant for inline / meta-row selects ─── */
.custom-dropdown.is-compact { width: auto; min-width: 150px; }
.custom-dropdown.is-compact .custom-dropdown-trigger { padding: 6px 10px; font-size: 13px; }
.custom-dropdown.is-compact .custom-dropdown-item { padding: 7px 10px; font-size: 13px; }

/* Lists must not clip dropdown menus that open within a row. Keep rounded corners by
   rounding the first/last rows instead of relying on overflow:hidden. */
.list { overflow: visible; }
.list-item:first-child { border-top-left-radius: var(--radius-md); border-top-right-radius: var(--radius-md); }
.list-item:last-child { border-bottom-left-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }

/* ─── Misc helpers ─── */
.row { display: flex; align-items: center; }
.row-gap { gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; }
.stack-sm { gap: 8px; } .stack-md { gap: 16px; } .stack-lg { gap: 24px; }
.muted { color: var(--text-muted); }
.id-mono { font: 500 12px 'JetBrains Mono', monospace; color: var(--text-muted); }
.section-title { font: 600 14px 'Inter', system-ui, sans-serif; color: var(--text-primary); margin: 0 0 12px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.w-full { width: 100%; }

/* Mobile: collapse sidebar */
@media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .app-content { padding: 20px 16px 48px; }
}

/* ─── Blazor framework error UI ─── */
#blazor-error-ui {
    color-scheme: light dark;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    bottom: 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.8rem 1.4rem 0.8rem 1rem;
    position: fixed;
    width: 100%;
    z-index: 1100;
    color: var(--text-primary);
    font-size: 13.5px;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.9rem;
    top: 0.6rem;
}
.blazor-error-boundary {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    color: #b91c1c;
}
