:root,
[data-theme="amber"] {
    /* Token secondari usati da componenti che non seguono il sistema principale */
    --surface-2: #1a1a28;
    --border:    rgba(255, 255, 255, 0.10);
    --text-1:    #e8e7e3;
    --text-2:    #a8a79f;

    --bg: #0a0a0b;
    --panel: rgba(19, 19, 22, 0.88);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text: #f5f5f2;
    --muted: #a8a79f;
    --accent: #ff8a1d;
    --accent-soft: rgba(255, 138, 29, 0.14);
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --sidebar-width: 280px;
    --bg-tint: rgba(255, 138, 29, 0.18);
    --sidebar-bg: rgba(8, 8, 10, 0.82);
    --mobile-sidebar-bg: rgba(8, 8, 10, 0.74);
    --mobile-overlay-bg: rgba(0, 0, 0, 0.46);
    --input-bg: rgba(0, 0, 0, 0.24);
    --nav-link: #dad9d1;
    --checkbox-bg: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] {
    /* Token secondari — light overrides */
    --surface-2: #ffffff;
    --border:    rgba(0, 0, 0, 0.10);
    --text-1:    #1a1918;
    --text-2:    #72716a;

    --bg: #f5f3ee;
    --panel: rgba(255, 255, 255, 0.92);
    --line: rgba(0, 0, 0, 0.08);
    --line-strong: rgba(0, 0, 0, 0.14);
    --text: #1a1918;
    --muted: #72716a;
    --accent: #ff7300;
    --accent-soft: rgba(255, 115, 0, 0.12);
    --shadow: 0 12px 48px rgba(0, 0, 0, 0.1);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --sidebar-width: 280px;
    --bg-tint: rgba(232, 116, 20, 0.1);
    --sidebar-bg: rgba(238, 235, 229, 0.98);
    --mobile-sidebar-bg: rgba(248, 246, 241, 0.78);
    --mobile-overlay-bg: rgba(26, 25, 24, 0.26);
    --input-bg: rgba(0, 0, 0, 0.05);
    --nav-link: #3a3a38;
    --checkbox-bg: rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    overflow-x: hidden; /* prevent horizontal scroll on all devices */
    background:
        radial-gradient(circle at top left, var(--bg-tint), transparent 26%),
        var(--bg);
    color: var(--text);
    font-family: "Instrument Sans", sans-serif;
}

body,
#app {
    min-height: 100dvh;
}

a {
    color: inherit;
    text-decoration: none;
}

button, input, textarea, select {
    font: inherit;
}

/* ── Custom checkboxes ── */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--line-strong);
    border-radius: 5px;
    background: var(--checkbox-bg);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: background 140ms ease, border-color 140ms ease;
    vertical-align: middle;
}

input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 5px;
    width: 5px;
    height: 9px;
    border: 2px solid #111;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

h1, h2, h3, strong {
    font-family: "Sora", sans-serif;
}

h1, h2, h3, p {
    margin-top: 0;
}

.shell-backdrop {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(140deg, var(--bg-tint), transparent 30%);
}

.app-shell {
    position: relative;
    height: 100dvh;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    overflow: hidden;
}

.shell-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px 22px;
    border-right: 1px solid var(--line);
    background: var(--sidebar-bg);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 28px;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
    transition: width 0.22s ease, min-width 0.22s ease, padding 0.22s ease;
}

/* ── Desktop collapsed (icon-only) ──────────────── */
.shell-sidebar.is-collapsed {
    width: 64px;
    min-width: 64px;
    padding: 20px 10px 28px;
    overflow: hidden;
}

/* In collapsed mode hide the brand lockup and centre the toggle button */
.shell-sidebar.is-collapsed .sidebar-header-row {
    justify-content: center;
    margin-bottom: 12px;
}

.shell-sidebar.is-collapsed .brand-lockup {
    display: none;
}

.shell-sidebar.is-collapsed .btn-sidebar-collapse {
    width: 40px;
    height: 40px;
}

.shell-sidebar.is-collapsed .brand-lockup > span:last-child,
.shell-sidebar.is-collapsed .sidebar-label,
.shell-sidebar.is-collapsed .sidebar-label--btn,
.shell-sidebar.is-collapsed .nav-link__text,
.shell-sidebar.is-collapsed .user-summary__name,
.shell-sidebar.is-collapsed .user-summary__meta {
    display: none;
}

.shell-sidebar.is-collapsed .brand-lockup {
    justify-content: center;
}

.shell-sidebar.is-collapsed .nav-link {
    padding: 12px;
    justify-content: center;
    transform: none !important;
}

.shell-sidebar.is-collapsed .btn-sidebar-collapse i {
    transform: rotate(180deg);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-lockup strong {
    display: block;
    font-size: 1rem;
}

.brand-lockup small,
.user-summary__meta,
.meta-inline,
.stack-item span,
.citation-card span,
.chunk-card small,
.panel__lead {
    display: block;
    color: var(--muted);
    font-size: 0.92rem;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(255,115,0,0.08);
    flex-shrink: 0;
}

.brand-mark img {
    width: 34px;
    height: 34px;
}

.sidebar-nav {
    display: grid;
    gap: 24px;
}

.sidebar-group {
    display: grid;
    gap: 8px;
}

.sidebar-label,
.eyebrow,
.section-caption {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.72rem;
    color: var(--muted);
}

.sidebar-label--btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}

.sidebar-label--btn:hover {
    background: var(--bg-tint);
}

.sidebar-chevron {
    font-size: 0.6rem;
    color: var(--muted);
    transition: transform 0.2s ease;
}

.sidebar-chevron.is-collapsed {
    transform: rotate(-90deg);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    color: var(--nav-link);
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
    white-space: nowrap;
}

/* Collapse toggle button inside sidebar */
.btn-sidebar-collapse {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.btn-sidebar-collapse:hover {
    background: var(--bg-tint);
    color: var(--text);
}

.sidebar-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-link:hover,
.nav-link.is-active {
    background: var(--accent-soft);
    color: white;
    transform: translateX(4px);
}

.sidebar-foot {
    margin-top: auto;
}

.user-summary {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--panel);
}

.user-summary__name {
    display: block;
    font-weight: 700;
}

.shell-main {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
}

.shell-header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 32px;
    background: rgba(10, 10, 11, 0.9);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.route-heading {
    font-size: 1.3rem;
    font-family: "Sora", sans-serif;
}

.shell-actions,
.toolbar-actions,
.hero-block__actions,
.toggle-row,
.table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.session-pill,
.tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    color: #ecebe4;
}

.shell-content {
    padding: 4px 32px 40px;
}

.section-toolbar,
.hero-block,
.panel,
.metric-panel,
.provider-card,
.center-stage__panel {
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.section-toolbar,
.hero-block {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 18px;
    border-radius: var(--radius-xl);
    padding: 24px 28px;
    margin-bottom: 22px;
}

.hero-block h1 {
    max-width: 22ch;
    font-size: clamp(1.4rem, 2.4vw, 1.9rem);
    margin-bottom: 8px;
    line-height: 1.25;
}

.section-toolbar h1,
.panel .panel__header h1,
.panel .panel__header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.section-toolbar h1 {
    font-size: 1.25rem;
    margin-bottom: 6px;
}

.metric-grid,
.workspace-grid,
.document-layout,
.document-stage,
.form-grid,
.chunk-grid {
    display: grid;
    gap: 18px;
}

.metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 18px;
}

.metric-panel {
    border-radius: 22px;
    padding: 18px 20px;
}

.metric-panel span,
.metric-panel small {
    display: block;
}

.metric-panel strong {
    display: block;
    margin: 10px 0 6px;
    font-size: 2.2rem;
}

.workspace-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
    border-radius: var(--radius-xl);
    padding: 24px;
    min-width: 0;
}

.page-actions-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.page-actions-bar__stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.panel--sidebar {
    position: sticky;
    top: 100px;
    align-self: start;
}

.panel__header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.stack-list,
.form-stack,
.provider-stack,
.citation-list {
    display: grid;
    gap: 12px;
}

.stack-item,
.citation-card,
.chunk-card {
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
}

.stack-item strong,
.citation-card strong,
.chunk-card strong {
    display: block;
    margin-bottom: 6px;
}

.stack-item__preview {
    margin-top: 10px;
    color: #eceae2;
    line-height: 1.55;
}

.stack-item__preview p {
    margin: 0;
}

.stack-item--button,
.tree-file,
.tab-button,
.button {
    cursor: pointer;
}

.stack-item--button {
    text-align: left;
    color: inherit;
    background: rgba(255, 255, 255, 0.02);
}

.stack-item--button.is-active,
.stack-item:hover,
.citation-card:hover,
.tree-file:hover,
.tree-file.is-active,
.provider-card:hover {
    border-color: rgba(255, 138, 29, 0.45);
    background: rgba(255, 138, 29, 0.08);
}

.docs-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.toolbar-actions--grow {
    flex: 1;
    min-width: 0;
}

.tab-strip--inline {
    margin-bottom: 0;
    flex-shrink: 0;
}

.panel__count {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 0 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
}

.document-layout {
    grid-template-columns: 320px minmax(0, 1fr);
}

.document-stage {
    grid-template-columns: 280px minmax(0, 1fr);
}

.panel--sidebar .tree-root {
    padding-top: 4px;
}

.tree-root {
    display: grid;
    gap: 8px;
}

.tree-folder summary {
    list-style: none;
    cursor: pointer;
    padding: 6px 0;
    color: #f1efe8;
}

.tree-folder summary::-webkit-details-marker {
    display: none;
}

.tree-branch {
    display: grid;
    gap: 8px;
    padding-left: 14px;
    border-left: 1px solid var(--line);
    margin-left: 6px;
}

.tree-file {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
    color: inherit;
    padding: 10px 12px;
    border-radius: 14px;
    text-align: left;
}

.document-html {
    line-height: 1.7;
    color: var(--text);
}

.document-html h1,
.document-html h2,
.document-html h3 {
    margin: 1.2rem 0 0.6rem;
}

.version-history {
    display: grid;
    gap: 14px;
}

.version-list {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.version-card {
    display: grid;
    gap: 8px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
}

.version-card span,
.version-card code {
    color: var(--muted);
    font-size: 0.92rem;
}

.chunk-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
    display: grid;
    gap: 8px;
}

.field--full {
    grid-column: 1 / -1;
}

.input {
    width: 100%;
    padding: 13px 14px;
    border-radius: 14px;
    border: 1px solid var(--line-strong);
    background: var(--input-bg);
    color: var(--text);
}

.input:focus {
    outline: none;
    border-color: rgba(255, 138, 29, 0.65);
    box-shadow: 0 0 0 3px rgba(255, 138, 29, 0.14);
}

.input--invalid {
    border-color: rgba(255, 111, 97, 0.6);
}

.input--compact {
    min-width: 180px;
}

.input--textarea {
    min-height: 140px;
    resize: vertical;
}

.input--xl {
    min-height: 190px;
}

.input--otp {
    letter-spacing: 0.3em;
    font-size: 1.2rem;
}

.button {
    padding: 12px 18px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: linear-gradient(145deg, var(--accent), #ffb158);
    color: #121212;
    font-weight: 800;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.button--secondary {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    border-color: var(--line-strong);
}

.button--secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.button--ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--line);
}

.button--ghost:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.button--outline {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

.button--outline:hover {
    background: rgba(255, 138, 29, 0.1);
}

.button--primary {
    background: linear-gradient(145deg, var(--accent), #ffb158);
    color: #121212;
    font-weight: 800;
}

.button--tiny {
    padding: 8px 10px;
    font-size: 0.84rem;
}

/* Same height as .input--sm (6px+line-height+6px) */
.button--sm {
    padding: 7px 14px;
    font-size: 0.88rem;
    border-radius: 10px;
}

.auth-submit {
    justify-content: center;
    min-height: 48px;
}

.auth-submit__spinner {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 2px solid rgba(18, 18, 18, 0.26);
    border-top-color: #121212;
    animation: bb-spin 0.75s linear infinite;
}

.auth-progress {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 138, 29, 0.24);
    background: rgba(255, 138, 29, 0.09);
    color: var(--text);
    font-size: 0.9rem;
}

.auth-progress small {
    color: var(--muted);
    line-height: 1.35;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 1rem;
    transition: background 150ms ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.06);
}

.notice {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    margin: 0 0 18px;
}

.notice--success {
    background: rgba(56, 201, 140, 0.12);
}

.notice--warning {
    background: rgba(255, 187, 69, 0.12);
}

.notice--danger {
    background: rgba(255, 111, 97, 0.12);
}

.notice--neutral {
    background: rgba(255, 255, 255, 0.04);
}

.tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.code-panel,
.result-panel {
    padding: 18px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--line);
    white-space: pre-wrap;
    line-height: 1.65;
}

.toggle-line {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #e9e6de;
}

.divider {
    height: 1px;
    background: var(--line);
    margin: 22px 0;
}

.table-wrap {
    overflow-x: auto;
}

.workspace-grid--account {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mcp-connect {
    margin-top: 18px;
}

.mcp-connect__header {
    align-items: flex-start;
}

.mcp-connect__header h2 {
    margin-bottom: 8px;
}

.mcp-connect__grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr 1fr;
    gap: 14px;
    margin: 16px 0;
}

.mcp-provider-card {
    display: grid;
    gap: 12px;
    align-content: start;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.025);
}

.mcp-provider-card--primary {
    background: linear-gradient(145deg, rgba(255, 138, 29, 0.12), rgba(255, 255, 255, 0.025));
    border-color: rgba(255, 138, 29, 0.28);
}

.mcp-provider-card__icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: var(--accent);
    background: rgba(255, 138, 29, 0.11);
}

.mcp-provider-card h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.mcp-provider-card p,
.mcp-provider-card li,
.mcp-token-row small,
.empty-inline,
.mcp-advanced summary,
.mcp-code-grid span {
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.55;
}

.mcp-provider-card ol {
    margin: 0;
    padding-left: 18px;
}

.mcp-token-result {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    border: 1px solid rgba(56, 201, 140, 0.24);
    border-radius: 16px;
    padding: 14px;
    background: rgba(56, 201, 140, 0.08);
    margin: 14px 0;
}

.mcp-token-result code {
    display: block;
    color: var(--text);
    word-break: break-all;
    margin-top: 4px;
}

.mcp-advanced {
    margin: 10px 0 18px;
}

.mcp-advanced summary {
    cursor: pointer;
}

.mcp-code-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 12px;
    margin-top: 10px;
}

.mcp-code-grid pre {
    margin: 6px 0 0;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--text);
    font-size: 0.8rem;
}

.mcp-token-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.mcp-token-list__header,
.mcp-token-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.mcp-token-list__header h3 {
    margin: 0;
    font-size: 1rem;
}

.mcp-token-row {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
}

.mcp-token-row strong,
.mcp-token-row small {
    display: block;
}

.mcp-token-row.is-revoked {
    opacity: 0.62;
}

.empty-inline {
    border: 1px dashed var(--line);
    border-radius: 14px;
    padding: 14px;
}

.status-pill--muted {
    color: var(--muted);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.04);
}

.user-admin-list {
    display: grid;
    gap: 14px;
}

.user-admin-card {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 16px;
    padding: 16px 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    border-left-width: 3px;
    background: rgba(255, 255, 255, 0.02);
    transition: border-color 0.15s, background 0.15s;
}

/* Status-based card coloring */
.user-admin-card--approved {
    border-left-color: rgba(74, 222, 128, 0.55);
}
.user-admin-card--pending {
    border-left-color: rgba(251, 191, 36, 0.7);
    background: rgba(251, 191, 36, 0.03);
}
.user-admin-card--rejected {
    border-left-color: rgba(168, 167, 159, 0.25);
    opacity: 0.6;
}

.user-admin-avatar {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 20px;
    overflow: hidden;
    background: linear-gradient(145deg, rgba(255, 138, 29, 0.18), rgba(255, 255, 255, 0.08));
    border: 1px solid rgba(255, 138, 29, 0.24);
}

.user-admin-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

/* Fallback initials — shown only if img fails to load */
.user-admin-avatar__initials {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Sora", sans-serif;
    font-weight: 800;
    font-size: 1rem;
    /* hidden by default; JS onerror on img reveals it */
    opacity: 0;
    pointer-events: none;
}

/* Status tag colors */
.tag--approved {
    background: rgba(74, 222, 128, 0.14);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.3);
}
.tag--pending {
    background: rgba(251, 191, 36, 0.14);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.3);
}
.tag--rejected {
    background: rgba(168, 167, 159, 0.1);
    color: var(--muted);
}

.user-admin-body {
    display: grid;
    gap: 12px;
}

.user-admin-row,
.user-admin-meta {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    align-items: start;
}

.user-admin-meta {
    color: var(--muted);
    font-size: 0.92rem;
}

.user-admin-tags {
    justify-content: flex-end;
    margin-bottom: 0;
}

.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(10px);
}

.confirm-box {
    width: min(560px, 100%);
    border-radius: 24px;
    padding: 24px;
    border: 1px solid var(--line);
    background: rgba(15, 15, 18, 0.96);
    box-shadow: var(--shadow);
}

.toggle-setting {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 18px;
    padding: 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
    margin-bottom: 18px;
}

.toggle-setting small {
    display: block;
    color: var(--muted);
    margin-top: 6px;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    width: 52px;
    height: 30px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.06);
    position: relative;
    transition: background 160ms ease, border-color 160ms ease;
}

.toggle-slider::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f3f0e8;
    transition: transform 160ms ease;
}

.toggle-input:checked + .toggle-slider {
    background: rgba(255, 138, 29, 0.24);
    border-color: rgba(255, 138, 29, 0.5);
}

.toggle-input:checked + .toggle-slider::after {
    transform: translateX(22px);
    background: var(--accent);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 14px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.provider-card {
    border-radius: 22px;
    padding: 18px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 14px;
}

.poster-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 28px;
}

.poster-metrics strong {
    display: block;
    font-size: 1.5rem;
}

.auth-shell,
.center-stage {
    min-height: 100vh;
    display: grid;
}

.auth-shell {
    grid-template-columns: 1fr 1fr;
    max-width: 960px;
    margin: 0 auto;
    align-items: center;
}

.auth-shell--centered {
    grid-template-columns: 1fr;
    place-items: center;
}

.auth-poster__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-heading);
    margin-bottom: 48px;
}

.auth-poster {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 48px;
}

.auth-poster__inner {
    max-width: 480px;
}

.auth-poster h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
    margin: 16px 0 0;
}

.auth-panel {
    display: grid;
    place-items: center;
    padding: 28px;
}

.auth-panel--single {
    grid-column: 1 / -1;
}

.auth-panel__card {
    width: 100%;
    max-width: 460px;
    padding: 28px;
    border-radius: 28px;
    background: rgba(17, 17, 20, 0.92);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.pending-state,
.verify-links {
    display: grid;
    gap: 14px;
}

.pending-state__icon {
    display: inline-flex;
    width: fit-content;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 187, 69, 0.12);
    border: 1px solid rgba(255, 187, 69, 0.2);
    color: #ffd287;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.verify-links {
    margin-top: 18px;
    color: var(--muted);
}

.tab-strip {
    display: inline-grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 6px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
    margin-bottom: 18px;
}

.tab-button {
    padding: 10px 14px;
    border-radius: 14px;
    border: 0;
    background: transparent;
    color: var(--muted);
}

.tab-button.is-active {
    background: var(--accent);
    color: #111;
    font-weight: 700;
}

.center-stage {
    place-items: center;
    padding: 24px;
}

.center-stage__panel {
    width: min(640px, 100%);
    padding: 34px;
    border-radius: 28px;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 320px;
    text-align: center;
    color: var(--muted);
}

.validation-message {
    color: #ffad9f;
    font-size: 0.88rem;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 12px;
    right: 12px;
    left: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    background: rgba(255, 111, 97, 0.94);
    color: white;
    z-index: 1000;
}

#blazor-error-ui .reload {
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}

/* ── Hamburger button (visible only on mobile) ──── */
.btn-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 6px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid var(--line);
    cursor: pointer;
    flex-shrink: 0;
    color: var(--text);
    font-size: 1rem;
}

.btn-hamburger span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
    width: 100%;
    transition: opacity 0.2s;
}

.btn-hamburger:hover {
    background: var(--bg-tint);
}

/* Mobile-only: 3-span classic hamburger */
.btn-hamburger--mobile {
    display: none;
    flex-direction: column;
    gap: 5px;
}

/* Desktop-only: FA bars icon */
.btn-hamburger--desktop {
    display: flex;
}

@media (max-width: 767px) {
    .btn-hamburger--mobile { display: flex; }
    .btn-hamburger--desktop { display: none; }
}

.shell-header__left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

/* ── Sidebar overlay (mobile backdrop) ─────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--mobile-overlay-bg);
    z-index: 199;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

@media (max-width: 1100px) {
    .auth-shell,
    .document-layout,
    .document-stage,
    .workspace-grid,
    .workspace-grid--account {
        grid-template-columns: 1fr;
    }

    .metric-grid,
    .chunk-grid,
    .form-grid,
    .mcp-connect__grid,
    .mcp-code-grid,
    .poster-metrics {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    /* ── Mobile: sidebar becomes a slide-in drawer ── */
    .app-shell {
        grid-template-columns: 1fr;
    }

    .shell-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        min-width: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        border-right: 1px solid color-mix(in srgb, var(--line-strong) 78%, transparent);
        background: var(--mobile-sidebar-bg);
        backdrop-filter: blur(22px) saturate(135%);
        -webkit-backdrop-filter: blur(22px) saturate(135%);
    }

    .shell-sidebar.is-open {
        transform: translateX(0);
        box-shadow: 14px 0 48px rgba(0, 0, 0, 0.36);
    }

    .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
        transition: opacity 0.26s ease;
    }

    /* ── Show hamburger button ── */
    .btn-hamburger {
        display: flex;
    }

    /* ── Padding adjustments ── */
    .shell-header,
    .shell-content {
        padding-left: 16px;
        padding-right: 16px;
    }

    .auth-poster,
    .auth-panel {
        padding-left: 18px;
        padding-right: 18px;
    }

    .section-toolbar,
    .hero-block,
    .panel,
    .auth-panel__card {
        padding: 16px;
    }

    /* ── Grid collapses ── */
    .metric-grid,
    .chunk-grid,
    .form-grid,
    .mcp-connect__grid,
    .mcp-code-grid,
    .poster-metrics,
    .brain-overview {
        grid-template-columns: 1fr;
    }

    .mcp-connect__header,
    .mcp-token-result,
    .mcp-token-list__header,
    .mcp-token-row {
        align-items: stretch;
        flex-direction: column;
    }

    .mcp-connect__header .button,
    .mcp-token-result .button,
    .mcp-token-row .button {
        justify-content: center;
        width: 100%;
    }

    .user-admin-card,
    .toggle-setting {
        grid-template-columns: 1fr;
    }

    /* ── Doc list rows wrap gracefully ── */
    .doc-row {
        padding: 9px 10px;
    }

    /* ── Toolbar wraps on mobile ── */
    .docs-toolbar {
        flex-direction: column;
        gap: 10px;
    }

    .toolbar-actions--grow {
        flex-wrap: wrap;
    }

    /* ── Smaller headings on mobile ── */
    .route-heading {
        font-size: 1.1rem;
    }

    /* ── Provider cards ── */
    .provider-card__body {
        grid-template-columns: 1fr;
    }

    /* ── Page action bar stacks ── */
    .page-actions-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* ── Section toolbar wraps on small screens ── */
    .section-toolbar,
    .hero-block {
        flex-wrap: wrap;
        padding: 16px;
        gap: 12px;
    }

    /* ── Contenuto: rag tree panel hidden on mobile ── */
    .contenuto-outer > .rag-tree-panel {
        display: none;
    }

    /* ── Emoji picker grid adapts ── */
    .emoji-picker__grid {
        grid-template-columns: repeat(5, 1fr);
        min-width: 180px;
    }

    /* ── Revisione: full-width stacked on mobile ── */
    .revision-editor-body { grid-template-columns: 1fr; }
    .revision-input-col { border-right: none; border-bottom: 1px solid var(--line); }

    /* ── Doc explorer: stacked on mobile ── */
    .doc-explorer { grid-template-columns: 1fr; }
    .doc-explorer__list { max-height: 240px; overflow-y: auto; position: static; }

    /* ── References / Authors: stacked on mobile ── */
    .authors-page { grid-template-columns: 1fr !important; }

    /* ── Tab strip: scrollable on small screens ── */
    .tab-strip--inline { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }

    /* ── Upload panel: less padding ── */
    .upload-panel { padding: 1rem; }

    /* ── Form row: stacked ── */
    .form-row { grid-template-columns: 1fr !important; }

    /* ── Chat: thread list hidden by default, accessible via mobile header ── */
    .chat-layout { grid-template-columns: 1fr; height: calc(100dvh - 56px); }
    .chat-threads-panel { display: none; }
    .chat-threads-panel.is-mobile-open {
        display: flex; position: fixed; inset: 0; z-index: 300; width: 100%;
    }
    .chat-mobile-bar {
        display: flex !important;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        border-bottom: 1px solid var(--line);
        background: var(--panel);
        flex-shrink: 0;
    }
    .chat-shell { display: flex; flex-direction: column; min-height: 0; }

    /* ── Editorial plan: see editorial-layout @media block above ── */

    /* ── Contenuto prompt picker: stacked on mobile (handled by .prompt-picker @media block) ── */

    /* ── Shell content: tighter padding on mobile ── */
    .shell-content { padding-top: 12px !important; padding-bottom: 20px !important; }

    /* ── Prevent panel headers from overflowing ── */
    .panel__header h2, .panel__header h3 {
        font-size: 1rem !important;
        word-break: break-word;
    }

    /* ── Inputs: never wider than viewport ── */
    .input, textarea.input, input.input, select.input {
        max-width: 100%;
        min-width: 0;
    }

    /* ── Document layout: stacked ── */
    .document-layout, .document-stage { grid-template-columns: 1fr; }

    /* ── Workspace grid: single column ── */
    .workspace-grid, .workspace-grid--account { grid-template-columns: 1fr; }

    /* ── Revision history layout: stacked ── */
    .revision-history-layout { grid-template-columns: 1fr; }
    .revision-history-list { max-height: 220px; }
    .revision-detail-columns { grid-template-columns: 1fr; }
    .revision-detail-col--right { border-left: none; border-top: 1px solid var(--line); }

    /* ── Auth page: single column ── */
    .auth-shell { grid-template-columns: 1fr; min-height: auto; }
    .auth-poster { display: none; } /* hide decorative poster column on mobile */
    .auth-panel { padding: 24px 16px !important; min-height: 100dvh; }

    /* ── Angle cards: stack action buttons ── */
    .angle-card { flex-direction: column; gap: .75rem; }
    .angle-card__num { display: none; }

    /* ── iOS safe area: bottom padding for home indicator ── */
    .shell-main {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .chat-input-bar {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    /* ── iOS zoom prevention: inputs must be ≥16px ── */
    .input, textarea.input, input.input, select.input,
    input[type="text"], input[type="url"], input[type="email"],
    input[type="password"], input[type="search"], textarea {
        font-size: 16px !important;
    }

    /* ── Contenuto outer: don't chain height:100% on mobile ── */
    .contenuto-outer {
        height: auto;
        flex-direction: column;
    }

    /* ── Contenuto stage: allow natural scroll ── */
    .contenuto-stage {
        overflow: visible;
        height: auto;
    }

    /* ── Contenuto: compact generate form ── */
    .input--xl { min-height: 120px !important; max-height: 200px !important; }
    .toolbar-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-actions .button {
        width: 100%;
        justify-content: center;
    }
    .toolbar-actions select.input {
        width: 100%;
    }

    /* ── Contenuto history layout ── */
    .history-layout {
        flex-direction: column !important;
        height: auto !important;
    }
    .history-list {
        max-height: 240px;
        overflow-y: auto;
    }
}

/* ── Responsive show/hide helpers ─────────────────── */
/* Usage: <Mobile> wraps .show-mobile, <Desktop> wraps .show-desktop */
.show-mobile { display: block; }
.show-desktop { display: block; }
@media (min-width: 761px) { .show-mobile { display: none !important; } }
@media (max-width: 760px) { .show-desktop { display: none !important; } }

/* ── Mobile chat bar (hidden on desktop) ── */
.chat-mobile-bar { display: none; }

/* ── Chat Layout: threads sidebar + main area ────── */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100%;
    gap: 0;
    overflow: hidden;
}

.chat-threads-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: var(--sidebar-bg, var(--panel));
    overflow: hidden;
}

.chat-threads-panel__top {
    padding: 14px 12px 10px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.chat-new-btn {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
}

.chat-threads-panel__list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

.chat-threads-empty {
    padding: 20px 12px;
    font-size: 0.8rem;
    color: var(--muted);
    text-align: center;
}

.chat-thread-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 9px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.12s;
    position: relative;
}

.chat-thread-item:hover {
    background: var(--bg-tint);
}

.chat-thread-item.is-active {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
}

.chat-thread-item__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-thread-item__topic {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-thread-item.is-active .chat-thread-item__topic {
    color: var(--accent);
}

.chat-thread-item__time {
    font-size: 0.7rem;
    color: var(--muted);
}

.chat-thread-item__del {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s;
    font-size: 0.75rem;
}

.chat-thread-item:hover .chat-thread-item__del {
    opacity: 1;
}

.chat-thread-item__del:hover {
    background: rgba(255, 80, 80, 0.12);
    color: #ff7070;
}

.chat-thread-item__actions {
    display: flex;
    flex-shrink: 0;
    gap: 2px;
}

.chat-thread-item:hover .chat-thread-item__actions .chat-thread-item__del {
    opacity: 1;
}

.chat-thread-item__rename-input {
    width: 100%;
    font-size: 0.82rem;
    font-weight: 500;
    background: var(--input-bg, var(--bg-tint));
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text);
    padding: 2px 6px;
    outline: none;
}

@media (max-width: 760px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }
    .chat-threads-panel {
        display: none;
    }
}

/* ── Chat Shell ────────────────────────────────── */

/* quando la shell contiene la chat, blocca lo scroll esterno */
.shell-main:has(.chat-layout) {
    overflow-y: hidden;
}
.shell-content:has(.chat-layout) {
    padding: 0;
    overflow: hidden;
}

.chat-shell {
    display: grid;
    grid-template-rows: auto 1fr auto; /* mobile-bar (hidden on desktop) + feed + input */
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.chat-feed {
    overflow-y: auto;
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}
@media (max-width: 760px) {
    .chat-feed { padding: 16px; gap: 16px; }
}

.chat-empty {
    align-self: flex-start;
    display: grid;
    gap: 10px;
    color: var(--muted);
}

.chat-empty__icon {
    font-size: 2.4rem;
    line-height: 1;
}

.chat-empty__title {
    font-family: "Sora", sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.chat-empty__sub {
    font-size: 0.92rem;
    margin: 0;
}

.chat-error-banner {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(255, 111, 97, 0.1);
    border: 1px solid rgba(255, 111, 97, 0.32);
    color: #ffb6ae;
}

.chat-error-banner strong {
    display: block;
    color: #ff8e85;
    margin-bottom: 4px;
    font-family: "Sora", sans-serif;
}

.chat-error-banner p {
    margin: 0;
    font-size: 0.9rem;
    color: #e8aca6;
    font-family: monospace;
    word-break: break-word;
}

.chat-error-banner__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 2px;
    color: #ff8e85;
}

.chat-error-banner__close {
    margin-left: auto;
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
    line-height: 1;
}

.chat-error-banner__close:hover {
    color: var(--text);
}

.chat-turn {
    display: grid;
    gap: 12px;
}

.chat-bubble {
    padding: 16px 20px;
    border-radius: 20px;
    line-height: 1.65;
    max-width: 86%;
}

.chat-bubble p {
    margin: 0;
}

.chat-bubble--user {
    align-self: flex-end;
    margin-left: auto;
    background: linear-gradient(135deg, rgba(255, 138, 29, 0.22), rgba(255, 176, 85, 0.1));
    border: 1px solid rgba(255, 138, 29, 0.3);
    color: #f5f0e8;
    border-bottom-right-radius: 6px;
}

.chat-bubble--assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    color: var(--text);
    border-bottom-left-radius: 6px;
    max-width: 92%;
}

.chat-answer {
    white-space: normal;
    line-height: 1.7;
}

.chat-bubble--loading {
    padding: 18px 22px;
}

.chat-typing {
    display: inline-block;
    color: var(--muted);
    font-size: 1rem;
}

.chat-meta {
    display: block;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--muted);
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.citations-toggle {
    margin-top: 12px;
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.citations-toggle summary {
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--accent);
    user-select: none;
    list-style: none;
}

.citations-toggle summary::-webkit-details-marker {
    display: none;
}

.citations-toggle[open] summary {
    margin-bottom: 10px;
}

/* composer */

.chat-composer {
    border-top: 1px solid var(--line);
    padding: 16px 24px 20px;
    background: rgba(8, 8, 10, 0.82);
    backdrop-filter: blur(18px);
    display: grid;
    gap: 12px;
}

.chat-composer__options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.chat-select {
    padding: 7px 12px;
    border-radius: 10px;
    border: 1px solid var(--line-strong);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-size: 0.88rem;
    cursor: pointer;
}

.chat-select:focus {
    outline: none;
    border-color: rgba(255, 138, 29, 0.55);
}

.chat-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--muted);
    user-select: none;
}

.chat-toggle:has(.chat-toggle__input:checked) .chat-toggle__label {
    color: var(--accent);
}

.chat-composer__row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 13px 16px;
    border-radius: 16px;
    border: 1px solid var(--line-strong);
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    resize: none;
    line-height: 1.55;
    font-size: 0.95rem;
    min-height: 52px;
    max-height: 220px;
    overflow-y: auto;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.chat-input:focus {
    outline: none;
    border-color: rgba(255, 138, 29, 0.6);
    box-shadow: 0 0 0 3px rgba(255, 138, 29, 0.12);
}

.chat-input:disabled {
    opacity: 0.55;
}

.chat-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(145deg, var(--accent), #ffb055);
    color: #111;
    font-size: 1.3rem;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    transition: opacity 160ms ease, transform 160ms ease;
}

.chat-send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* loading dots */

.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    animation: dot-bounce 1.2s infinite;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--muted);
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* -- RAG panel ---------------------------------------- */

.rag-panel {
    margin-top: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
}

.rag-panel__toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.rag-panel__toggle::-webkit-details-marker { display: none; }

.rag-panel__label {
    color: var(--accent);
}

.rag-panel__hint {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 400;
    font-style: italic;
}

.rag-panel__body {
    padding: 4px 12px 12px;
}

/* -- RAG tree ---------------------------------------- */

.rag-tree {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rag-tree__area {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rag-tree__area-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 4px 8px;
}

.rag-tree__doc {
    margin-left: 12px;
    border-left: 2px solid rgba(255, 255, 255, 0.08);
    padding-left: 10px;
    margin-bottom: 4px;
}

.rag-tree__doc--active {
    border-left-color: var(--accent);
}

.rag-tree__doc summary {
    list-style: none;
    cursor: pointer;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.rag-tree__doc summary::-webkit-details-marker { display: none; }
.rag-tree__doc summary::before {
    content: '▶';
    font-size: 0.6rem;
    color: var(--muted);
    transition: transform 0.15s;
    flex-shrink: 0;
}
.rag-tree__doc[open] summary::before { transform: rotate(90deg); }

.rag-tree__doc-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.rag-tree__doc-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    flex: 1;
}

.rag-tree__doc-badge {
    font-size: 0.7rem;
    color: var(--muted);
    background: rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 1px 7px;
    flex-shrink: 0;
}

/* copy button */
.chat-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.chat-copy-btn:hover { color: var(--text); border-color: var(--accent); }

.rag-tree__chunk {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    margin-top: 2px;
}

.rag-tree__chunk-score {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 700;
    color: #56e39f;
    background: rgba(86, 227, 159, 0.12);
    border-radius: 5px;
    padding: 1px 5px;
    font-family: monospace;
    margin-top: 2px;
}

.rag-tree__chunk-excerpt {
    margin: 0;
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* -- Prompt preview ------------------------------------ */

.prompt-preview {
    margin-top: 14px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    overflow: hidden;
}

.prompt-preview__toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
}

.prompt-preview__toggle::-webkit-details-marker { display: none; }
.prompt-preview__toggle:hover { color: var(--text); }

.prompt-preview__body {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.prompt-preview__section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 16px;
}

.prompt-preview__system {
    background: rgba(120, 120, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.prompt-preview__user {
    background: rgba(255, 255, 255, 0.02);
}

.prompt-preview__label {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.prompt-preview__text {
    margin: 0;
    font-size: 0.78rem;
    font-family: monospace;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
}

.prompt-preview__question-part {
    display: block;
    font-size: 0.78rem;
    font-family: monospace;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
    margin-bottom: 8px;
}

.prompt-preview__context-header {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    margin-bottom: 6px;
}

.prompt-preview__user-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prompt-preview__chunk {
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.prompt-preview__chunk-label {
    font-size: 0.7rem;
    font-weight: 700;
    font-family: monospace;
}

.prompt-preview__chunk-text {
    margin: 0;
    font-size: 0.75rem;
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    opacity: 0.85;
}

/* chunk accent colors */
.chunk-color-1 { background: rgba(255, 180,  80, 0.10); border-left: 3px solid #ffb450; }
.chunk-color-2 { background: rgba( 86, 227, 159, 0.10); border-left: 3px solid #56e39f; }
.chunk-color-3 { background: rgba(120, 160, 255, 0.10); border-left: 3px solid #78a0ff; }
.chunk-color-4 { background: rgba(255, 120, 180, 0.10); border-left: 3px solid #ff78b4; }
.chunk-color-5 { background: rgba(180, 120, 255, 0.10); border-left: 3px solid #b478ff; }
.chunk-color-6 { background: rgba( 80, 220, 220, 0.10); border-left: 3px solid #50dcdc; }
.chunk-color-7 { background: rgba(255, 200,  60, 0.10); border-left: 3px solid #ffc83c; }
.chunk-color-8 { background: rgba(255, 140, 100, 0.10); border-left: 3px solid #ff8c64; }

.chunk-color-1 .prompt-preview__chunk-label { color: #ffb450; }
.chunk-color-2 .prompt-preview__chunk-label { color: #56e39f; }
.chunk-color-3 .prompt-preview__chunk-label { color: #78a0ff; }
.chunk-color-4 .prompt-preview__chunk-label { color: #ff78b4; }
.chunk-color-5 .prompt-preview__chunk-label { color: #b478ff; }
.chunk-color-6 .prompt-preview__chunk-label { color: #50dcdc; }
.chunk-color-7 .prompt-preview__chunk-label { color: #ffc83c; }
.chunk-color-8 .prompt-preview__chunk-label { color: #ff8c64; }

/* -- System page -- */
.system-page{display:flex;flex-direction:column;gap:20px;max-width:860px;}
.system-card{display:flex;gap:20px;padding:24px;border-radius:16px;background:var(--surface);border:1px solid rgba(255,255,255,0.07);}
.system-card__icon{font-size:1.8rem;flex-shrink:0;width:44px;text-align:center;margin-top:2px;}
.system-card__body{flex:1;min-width:0;}
.system-card__body h2{font-size:1.05rem;font-weight:700;margin:0 0 10px;color:var(--text);}
.system-card__body p{margin:0 0 10px;font-size:0.88rem;color:var(--muted);line-height:1.65;}
.system-card__body code{font-family:monospace;font-size:0.82rem;background:rgba(255,255,255,0.08);border-radius:4px;padding:1px 5px;color:var(--accent);}
.system-detail{margin-top:12px;padding:10px 14px;border-radius:10px;background:rgba(255,180,80,0.07);border-left:3px solid var(--accent);font-size:0.82rem;color:var(--muted);line-height:1.6;}
.system-detail code{font-family:monospace;font-size:0.8rem;background:rgba(255,255,255,0.08);border-radius:4px;padding:1px 4px;color:var(--accent);}
.system-list{margin:8px 0 10px 18px;padding:0;display:flex;flex-direction:column;gap:6px;}
.system-list li{font-size:0.86rem;color:var(--muted);line-height:1.6;}
.system-steps{margin:8px 0 12px 18px;padding:0;display:flex;flex-direction:column;gap:6px;}
.system-steps li{font-size:0.86rem;color:var(--muted);line-height:1.6;}
.system-provider-grid{display:flex;flex-direction:column;gap:8px;margin-top:8px;}
.system-provider{display:flex;flex-direction:column;gap:2px;padding:10px 14px;border-radius:10px;background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.07);}
.system-provider strong{font-size:0.86rem;color:var(--text);}
.system-provider code{font-family:monospace;font-size:0.77rem;color:#56e39f;background:rgba(86,227,159,0.08);border-radius:4px;padding:1px 5px;width:fit-content;}
.system-provider span{font-size:0.78rem;color:var(--muted);line-height:1.5;}
.system-stack-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:8px;margin-top:8px;}
.system-stack-item{display:flex;align-items:center;gap:8px;font-size:0.84rem;color:var(--muted);padding:8px 12px;border-radius:8px;background:rgba(255,255,255,0.03);}
.system-stack-badge{font-size:0.68rem;font-weight:700;text-transform:uppercase;letter-spacing:0.06em;color:var(--accent);background:rgba(255,180,80,0.1);border-radius:5px;padding:2px 6px;flex-shrink:0;}

/* ── Preset question chips ── */
.chat-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    margin-top: 16px;
}

.chat-preset-chip {
    background: rgba(255, 138, 29, 0.1);
    border: 1px solid rgba(255, 138, 29, 0.3);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: left;
    line-height: 1.4;
}

.chat-preset-chip:hover {
    background: rgba(255, 138, 29, 0.2);
    border-color: rgba(255, 138, 29, 0.6);
}

/* ── Chat clear button ── */
.chat-clear-btn {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 12px;
    font-size: 0.82rem;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.chat-clear-btn:hover {
    color: var(--text);
    border-color: rgba(255, 138, 29, 0.5);
}

/* ── Markdown body rendering ── */
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    font-family: "Sora", sans-serif;
    font-weight: 700;
    margin: 1em 0 0.4em;
    line-height: 1.3;
    color: var(--text);
}
.markdown-body h1 { font-size: 1.3rem; }
.markdown-body h2 { font-size: 1.1rem; }
.markdown-body h3 { font-size: 1rem; }
.markdown-body p { margin: 0.5em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; margin: 0.5em 0; }
.markdown-body li { margin: 0.2em 0; }
.markdown-body strong { font-weight: 700; color: var(--text); }
.markdown-body em { font-style: italic; }
.markdown-body code {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: monospace;
    font-size: 0.9em;
}
.markdown-body pre {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0.7em 0;
}
.markdown-body pre code {
    background: none;
    padding: 0;
}
.markdown-body blockquote {
    border-left: 3px solid rgba(255, 138, 29, 0.5);
    padding-left: 12px;
    margin: 0.6em 0;
    color: var(--muted);
}
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.7em 0;
    font-size: 0.88rem;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--line);
    padding: 6px 10px;
    text-align: left;
}
.markdown-body th { background: rgba(255,255,255,0.05); font-weight: 600; }
.markdown-body a { color: rgba(255, 138, 29, 0.9); text-decoration: underline; }
.markdown-body hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }

/* ── Provider card improvements ── */
.provider-badge {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.provider-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.provider-card__title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.provider-type-label {
    font-size: 0.75rem;
    color: var(--muted);
    display: block;
    margin-top: 2px;
}

.provider-card__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.provider-card__body {
    display: grid;
    gap: 12px;
}

.provider-card__foot {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.provider-card--disabled {
    opacity: 0.5;
}

.input--ghost {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: "Sora", sans-serif;
    color: var(--text);
    width: 100%;
}

.input--ghost:focus {
    outline: none;
    border-bottom: 1px solid rgba(255, 138, 29, 0.5);
}

.input--sm {
    padding: 6px 10px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.add-provider-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.field__label-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field__link {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: rgba(255, 138, 29, 0.8);
    text-decoration: none;
}

.field__link:hover {
    text-decoration: underline;
}

.badge {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
}

.badge--green {
    background: rgba(72, 199, 116, 0.15);
    color: #48c774;
    border: 1px solid rgba(72, 199, 116, 0.3);
}

.badge--orange {
    background: rgba(255, 138, 29, 0.12);
    color: rgba(255, 138, 29, 0.9);
    border: 1px solid rgba(255, 138, 29, 0.3);
}

.section-sub {
    font-size: 0.88rem;
    color: var(--muted);
    margin: 4px 0 0;
}

.toggle-line--sm {
    font-size: 0.82rem;
}

/* ── Select dropdown dark background fix ── */
select.input,
select.chat-select,
select.input--sm {
    appearance: auto;
    background-color: #141416;
    color: var(--text);
    cursor: pointer;
}

select.input option,
select.chat-select option,
select.input--sm option {
    background-color: #1a1a1e;
    color: var(--text);
}

[data-theme="light"] select.input,
[data-theme="light"] select.chat-select,
[data-theme="light"] select.input--sm {
    background-color: #f0edea;
}

[data-theme="light"] select.input option,
[data-theme="light"] select.chat-select option,
[data-theme="light"] select.input--sm option {
    background-color: #f5f3ee;
}

/* ── Version bar ── */
.version-bar {
    position: sticky;
    bottom: 0;
    height: 28px;
    background: rgba(10, 10, 11, 0.96);
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 0 16px;
}

[data-theme="light"] .version-bar {
    background: rgba(238, 235, 229, 0.97);
}

.version-bar__text {
    font-size: 0.68rem;
    color: var(--muted);
    letter-spacing: 0.03em;
}

.version-bar__changelog {
    color: var(--accent);
    font-size: 0.68rem;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.version-bar__changelog:hover { background: rgba(255, 138, 29, 0.12); }

/* ── Release notes page ── */
.release-notes-list {
    display: flex;
    flex-direction: column;
    gap: 28px;
    max-width: 720px;
}

.release-note-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 24px 28px;
}

.release-note-card__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.release-note-card__ver {
    font-family: monospace;
    font-size: 0.78rem;
    background: rgba(255, 138, 29, 0.12);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 6px;
}

.release-note-card__date {
    font-size: 0.78rem;
    color: var(--muted);
}

.release-note-card__title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px;
}

.release-note-card__body {
    color: var(--fg-secondary);
    font-size: 0.88rem;
    line-height: 1.6;
}

/* ── Update banner ── */
.update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    background: linear-gradient(90deg, rgba(255, 138, 29, 0.92), rgba(255, 100, 50, 0.92));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 20px rgba(255, 138, 29, 0.4);
}

.update-banner__btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 8px;
    color: #fff;
    padding: 5px 14px;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.update-banner__btn:hover { background: rgba(255,255,255,0.3); }

.update-banner__dismiss {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    margin-left: 4px;
}

/* ── Update modal (blocks UI, forces upgrade) ───────── */
.update-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.update-modal {
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-xl);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    padding: 32px;
    max-width: 520px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-height: 80vh;
    overflow-y: auto;
}

.update-modal__header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.update-modal__icon {
    font-size: 2.2rem;
    line-height: 1;
    flex-shrink: 0;
}

.update-modal__title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
}

.update-modal__version {
    font-size: 0.8rem;
    color: var(--accent);
    font-family: monospace;
    margin-top: 2px;
}

.update-modal__notes {
    background: var(--bg-tint);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.update-modal__notes-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    font-weight: 700;
}

.update-modal__notes-heading {
    font-size: 0.95rem;
    color: var(--text);
}

.update-modal__notes-body {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.6;
}

.update-modal__notes-body ul {
    margin: 4px 0 0 16px;
    padding: 0;
}

.update-modal__notes-body li {
    margin-bottom: 2px;
}

.update-modal__cta {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 1rem;
    font-weight: 700;
}

/* ── Brand switcher ──────────────────────────────────────────────────────── */
.brand-switcher {
    position: relative;
    display: flex;
    align-items: center;
}

.brand-switcher__trigger {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-body);
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 14px 5px 10px;
    cursor: pointer;
    white-space: nowrap;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.15s, background 0.15s;
}
.brand-switcher__trigger:hover { border-color: var(--accent); background: var(--hover-bg); }
.brand-switcher.is-open .brand-switcher__trigger { border-color: var(--accent); background: var(--hover-bg); }

.brand-switcher__caret {
    font-size: 0.6rem;
    opacity: 0.5;
    flex-shrink: 0;
    transition: transform 0.2s;
    margin-left: 2px;
}
.brand-switcher.is-open .brand-switcher__caret { transform: rotate(180deg); }

/* Colored dot shown next to brand name */
.brand-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.15);
}

.brand-switcher__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 400;
    min-width: 200px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Label at top of dropdown */
.brand-switcher__label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-muted);
    padding: 4px 10px 6px;
}

.brand-switcher__opt {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.83rem;
    font-weight: 500;
    color: var(--color-body);
    background: transparent;
    border: none;
    border-radius: 9px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.12s;
}
.brand-switcher__opt:hover { background: var(--hover-bg); }
.brand-switcher__opt.is-active {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    font-weight: 700;
}
.brand-switcher__opt .fa-check { font-size: 0.65rem; opacity: 0.8; margin-left: auto; }
.brand-switcher__opt__name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.brand-switcher__backdrop {
    position: fixed;
    inset: 0;
    z-index: 399;
}

/* ── Document brand chip ─────────────────────────────────────────────────── */
.doc-row__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.doc-brand-chip {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--accent);
    background: rgba(255,115,0,0.12);
    border-radius: 4px;
    padding: 1px 5px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Persona panel (Contenuto) ──────────────────────────────────────────── */
.persona-panel {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    background: var(--panel-bg);
    margin-bottom: 0.75rem;
}

.persona-panel > summary {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    list-style: none;
    user-select: none;
}

.persona-panel > summary::-webkit-details-marker { display: none; }

.persona-panel[open] > summary {
    border-bottom: 1px solid var(--border);
}

.persona-panel > div,
.persona-panel > details > div {
    padding: 0.75rem 1rem;
}

.button--accent {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.button--accent:hover {
    background: var(--accent-hover, color-mix(in srgb, var(--accent) 80%, white));
}

.notice--error {
    background: rgba(255, 100, 80, 0.1);
    border: 1px solid rgba(255, 100, 80, 0.3);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: #ff8e85;
    margin-bottom: 16px;
}

/* ── RAG Document Tree Sidebar ─────────────────── */
.chat-outer {
    display: flex;
    height: 100%;
    gap: 0;
}

.chat-outer .chat-shell {
    flex: 1;
    min-width: 0;
}

.rag-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--panel);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, min-width 0.2s ease;
    overflow: hidden;
}

.rag-sidebar--collapsed {
    width: 36px;
    min-width: 36px;
}

.rag-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
    user-select: none;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    gap: 8px;
    white-space: nowrap;
}

.rag-sidebar__title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rag-sidebar__badge {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 0.7rem;
    font-weight: 700;
}

.rag-sidebar__body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 4px;
    font-size: 0.78rem;
}

.rag-sidebar__empty {
    color: var(--muted);
    padding: 12px;
    font-size: 0.8rem;
}

.rag-sidebar--collapsed .rag-sidebar__body {
    display: none;
}

/* ── Tree RAG highlight ─────────────────────────── */
.tree-file.is-rag {
    color: #f59e0b;
    font-weight: 600;
    background: rgba(245, 158, 11, 0.08);
    border-left: 2px solid #f59e0b;
}

.tree-file__rag-dot {
    color: #f59e0b;
    font-size: 0.6rem;
    margin-right: 4px;
    vertical-align: middle;
}

/* ── Prompt Card ────────────────────────────────── */
.prompt-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-top: 16px;
    overflow: hidden;
}

.prompt-card__toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    list-style: none;
    user-select: none;
}

.prompt-card__toggle::-webkit-details-marker { display: none; }

.prompt-card__body {
    border-top: 1px solid var(--line);
}

.prompt-card__section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
}

.prompt-card__section:last-child { border-bottom: none; }

.prompt-card__label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 6px;
}

.prompt-card__section--system .prompt-card__label { color: #818cf8; }
.prompt-card__section--user .prompt-card__label { color: #34d399; }

.prompt-card__text {
    font-family: 'JetBrains Mono', monospace, monospace;
    font-size: 0.74rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

.prompt-card__text--question {
    color: var(--text);
}

.prompt-card__text--context {
    color: var(--muted);
    font-size: 0.7rem;
}

.prompt-card__context-divider {
    text-align: center;
    font-size: 0.7rem;
    color: var(--muted);
    padding: 4px 0;
    border-top: 1px dashed var(--line);
    border-bottom: 1px dashed var(--line);
    margin: 4px 0;
}

/* ── Prompt template preview ────────────────────── */
.prompt-template-preview {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.prompt-template-preview > summary {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--muted);
    user-select: none;
}

.prompt-template-preview__body {
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    font-size: 0.82rem;
}

/* ── Contenuto layout with rag sidebar ─────────── */
/* ── Emoji Picker ──────────────────────────────────────── */
.emoji-picker {
    position: relative;
}

.emoji-picker__trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--input-bg, var(--bg-tint));
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    min-width: 110px;
    transition: border-color 0.15s;
}

.emoji-picker__trigger:hover {
    border-color: var(--accent);
}

.emoji-picker__none {
    font-size: 0.8rem;
    color: var(--muted);
}

.emoji-picker__caret {
    font-size: 0.65rem;
    color: var(--muted);
    margin-left: auto;
    transition: transform 0.15s;
}

.emoji-picker__caret.is-open {
    transform: rotate(180deg);
}

.emoji-picker__grid {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 10px;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-width: 220px;
}

.emoji-picker__opt {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.emoji-picker__opt:hover {
    background: var(--bg-tint);
    border-color: var(--line-strong);
}

.emoji-picker__opt.is-sel {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.emoji-picker__opt--clear {
    grid-column: 1 / -1;
    width: 100%;
    font-size: 0.78rem;
    gap: 6px;
    color: var(--muted);
    padding: 4px 8px;
    justify-content: flex-start;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
}

/* ── Contenuto history tab ──────────────────────────────── */
.history-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.history-list {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
}

.history-detail {
    flex: 1;
    min-width: 0;
}

/* ── Contenuto shell layout ─────────────────────────────── */
.contenuto-outer {
    display: flex;
    height: 100%;
    gap: 0;
}

.contenuto-outer .contenuto-shell {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Prompt picker — combobox autocomplete ───────────────── */
.prompt-picker {
    position: relative;   /* anchor per il dropdown absolute */
}

/* Combobox trigger row */
.prompt-picker__combobox {
    display: flex;
    align-items: center;
    gap: 0;
    height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--input-bg);
    padding: 0 12px;
    cursor: text;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.prompt-picker__combobox.is-open,
.prompt-picker__combobox:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt-picker__leading-icon {
    flex-shrink: 0;
    font-size: 1.1em;
    margin-right: 8px;
    line-height: 1;
    user-select: none;
}

.prompt-picker__leading-icon--search {
    opacity: 0.45;
    font-size: 0.95em;
}

.prompt-picker__input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.92rem;
    color: var(--text);
    padding: 0;
}

.prompt-picker__input::placeholder {
    color: var(--muted);
}

.prompt-picker__chevron {
    flex-shrink: 0;
    font-size: 0.75em;
    color: var(--muted);
    margin-left: 8px;
    transition: transform 0.18s;
    user-select: none;
}

.prompt-picker__chevron.is-open {
    transform: rotate(180deg);
}

/* Dropdown */
.prompt-picker__dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-height: 340px;
    overflow-y: auto;
    padding: 4px;
}

/* Option row */
.prompt-picker__option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}

.prompt-picker__option:hover {
    background: var(--accent-soft);
}

.prompt-picker__option.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.prompt-picker__option-icon {
    flex-shrink: 0;
    font-size: 1.05em;
    line-height: 1;
}

.prompt-picker__option-title {
    flex: 1;
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prompt-picker__option.is-active .prompt-picker__option-title {
    color: inherit;
}

.prompt-picker__empty {
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
}

/* ── User Menu (topbar) ────────────────────────────── */
.user-menu {
    position: relative;
}

.user-menu__trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, border-color 0.15s;
}

.user-menu__trigger:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--line-strong);
}

.user-menu__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.user-menu__avatar--lg {
    width: 44px;
    height: 44px;
}

.user-menu__name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu__caret {
    font-size: 0.72rem;
    color: var(--muted);
    margin-left: 2px;
}

.user-menu__backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
}

.user-menu__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: #1c1c1e;
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.48);
    z-index: 200;
    overflow: hidden;
    padding: 6px;
}

.user-menu__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px 8px;
}

.user-menu__fullname {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
}

.user-menu__role {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: capitalize;
}

.user-menu__divider {
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

.user-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
}

.user-menu__item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.user-menu__item--danger {
    color: #ff6f61;
}

.user-menu__item--danger:hover {
    background: rgba(255, 111, 97, 0.1);
}

/* ── Brain Panoramica ──────────────────────────────── */
.brain-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.brain-lobe {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.2s;
}

.brain-lobe:hover {
    border-color: var(--line-strong);
}

.brain-lobe__head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brain-lobe__icon {
    font-size: 1.6rem;
    line-height: 1;
}

.brain-lobe__name {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
}

.brain-lobe__count {
    font-size: 0.72rem;
    color: var(--muted);
}

.brain-lobe__desc {
    font-size: 0.82rem;
    color: var(--muted);
    margin: 0;
    line-height: 1.5;
}

.brain-lobe__docs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.brain-doc-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    text-align: left;
    max-width: 280px;
}

.brain-doc-chip:hover {
    background: rgba(255, 138, 29, 0.1);
    border-color: rgba(255, 138, 29, 0.4);
    color: var(--accent);
}

.brain-doc-chip__code {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 138, 29, 0.12);
    border-radius: 4px;
    padding: 1px 5px;
    flex-shrink: 0;
}

.brain-doc-chip__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brain-doc-chip__v {
    font-size: 0.65rem;
    color: var(--muted);
    flex-shrink: 0;
}

/* ── Document edit mode ────────────────────────────── */
.doc-edit-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.doc-edit-mode-toggle {
    display: inline-flex;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
}

.doc-edit-mode-toggle button {
    padding: 6px 14px;
    font-size: 0.8rem;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.doc-edit-mode-toggle button.is-active {
    background: var(--accent);
    color: #121212;
    font-weight: 700;
}

.doc-markdown-editor {
    width: 100%;
    min-height: 420px;
    padding: 16px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: #f0ede6;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--line);
    border-radius: 14px;
    resize: vertical;
}

.doc-edit-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}

/* ── Tab strip ─────────────────────────────────────── */
.tab-strip {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
}

.tab-btn {
    flex: 1;
    min-width: 84px;
    padding: 7px 14px;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 0.84rem;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

.tab-btn.is-active {
    background: rgba(255, 138, 29, 0.14);
    color: var(--accent);
    border-color: rgba(255, 138, 29, 0.3);
    font-weight: 600;
}

[data-theme="light"] .tab-strip {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .tab-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ── Light-theme shell header ───────────────────── */
[data-theme="light"] .shell-header {
    background: rgba(245, 243, 238, 0.95);
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

/* ── Light-theme user menu ───────────────────────── */
[data-theme="light"] .user-menu__trigger {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .user-menu__trigger:hover {
    background: rgba(0, 0, 0, 0.07);
}

[data-theme="light"] .user-menu__dropdown {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .user-menu__item:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .user-menu__item--danger:hover {
    background: rgba(255, 80, 50, 0.08);
}

/* ── Light-theme nav active state ───────────────── */
[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link.is-active {
    color: var(--accent);
    background: var(--accent-soft);
}

/* ── Light-theme chat ────────────────────────────── */
[data-theme="light"] .chat-composer {
    background: rgba(245, 243, 238, 0.97);
}

[data-theme="light"] .chat-input {
    background: rgba(255, 255, 255, 0.85);
}

[data-theme="light"] .chat-select {
    background: rgba(255, 255, 255, 0.85);
}

[data-theme="light"] .chat-bubble--user {
    color: var(--text);
}

[data-theme="light"] .chat-bubble--assistant {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .chat-error-banner {
    background: rgba(255, 80, 80, 0.1);
    color: var(--text);
    border-color: rgba(255, 80, 80, 0.3);
}

/* ── Field inline (checkbox + label row) ─────────── */
.field--inline {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* ── Doc stacked layout ─────────────────────────── */
.doc-stacked {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.doc-list-panel {
    padding: 16px 20px;
}

.doc-list-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.doc-chip {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, border-color 0.12s;
    min-width: 140px;
    max-width: 260px;
}

.doc-chip:hover {
    background: rgba(255, 138, 29, 0.08);
    border-color: rgba(255, 138, 29, 0.35);
}

.doc-chip.is-active {
    background: rgba(255, 138, 29, 0.14);
    border-color: rgba(255, 138, 29, 0.5);
    color: var(--text);
}

.doc-chip strong {
    font-size: 0.88rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-chip span {
    font-size: 0.76rem;
    color: var(--muted);
    white-space: nowrap;
}

.doc-chip__code {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 138, 29, 0.12);
    border-radius: 4px;
    padding: 1px 5px;
    align-self: flex-start;
}

.doc-list-count {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

/* Full-width detail panel when navigated directly to /documents/{id} */
.doc-view-panel--full {
    margin-top: 12px;
}

/* ── Document list (full, navigable rows) ── */
.doc-list-full {
    display: flex;
    flex-direction: column;
}

.doc-row-wrap {
    display: flex;
    border-bottom: 1px solid var(--line);
    transition: background 0.1s, opacity 0.15s;
    cursor: default;
}

.doc-row-wrap:last-child { border-bottom: none; }

.doc-row-wrap .doc-row {
    flex: 1;
    border-bottom: none;
}

.doc-row-wrap.drag-ghost {
    opacity: 0.35;
}

.doc-row-wrap.drag-over {
    background: var(--accent-soft);
    border-top: 2px solid var(--accent);
}

.btn-icon--xs {
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
    border-radius: 5px;
}

.doc-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s;
    cursor: pointer;
    min-width: 0;
}

.doc-row:last-child { border-bottom: none; }

.doc-row:hover,
.doc-row--active {
    background: var(--bg-tint);
}

.doc-row--active {
    border-left: 3px solid var(--accent);
}

/* Top row: grip | index | icon | chevron */
.doc-row__top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-row__grip {
    font-size: 0.7rem;
    color: var(--muted);
    opacity: 0;
    transition: opacity 0.15s;
    cursor: grab;
    flex-shrink: 0;
}

.doc-row-wrap:hover .doc-row__grip {
    opacity: 0.65;
}

.doc-row__index-num {
    font-size: 0.68rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    flex-shrink: 0;
}

.doc-row__icon {
    font-size: 0.95em;
    line-height: 1;
    flex-shrink: 0;
}

.doc-row__icon:empty {
    display: none;
}

.doc-row__arrow {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.65rem;
    flex-shrink: 0;
    opacity: 0.6;
}

/* Title: full width, no wrap */
.doc-row__title {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

/* Date below title */
.doc-row__meta {
    font-size: 0.68rem;
    color: var(--muted);
    white-space: nowrap;
}

.doc-view-panel {
    padding: 24px 28px;
}

.doc-view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.doc-view-header h2 {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.doc-view-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.doc-delete-btn {
    color: rgba(255, 100, 80, 0.8) !important;
    border-color: rgba(255, 100, 80, 0.3) !important;
}

.doc-delete-btn:hover {
    background: rgba(255, 100, 80, 0.1) !important;
    color: #ff7070 !important;
}

.confirm-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-radius: 14px;
    background: rgba(255, 80, 80, 0.07);
    border: 1px solid rgba(255, 80, 80, 0.2);
    margin-bottom: 16px;
}

.muted-text {
    font-size: 0.88rem;
    color: var(--muted);
    padding: 8px 4px;
}

/* ── Distillato page ─────────────────────────────────────────────────────── */

.distillato-page {
    padding: 0 24px 48px;
    max-width: 860px;
}

.distillato-empty {
    text-align: center;
    padding: 64px 24px;
}

.distillato-empty__icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.distillato-empty__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 8px;
}

.distillato-empty__sub {
    font-size: 0.9rem;
    color: var(--muted);
    margin: 0;
}

.distillato-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.distillato-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-tint);
    transition: border-color 0.15s;
}

.distillato-card--open {
    border-color: var(--accent);
}

.distillato-card__header {
    padding: 16px 20px;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.distillato-card__meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 6px;
}

.distillato-card__template {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.distillato-card__date {
    font-size: 0.78rem;
    color: var(--muted);
}

.distillato-card__note {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.distillato-card__preview {
    font-size: 0.92rem;
    color: var(--text);
    margin: 0;
    padding-right: 28px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.distillato-card__chevron {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.85rem;
}

.distillato-card__body {
    padding: 0 20px 20px;
    border-top: 1px solid var(--line);
}

.distillato-card__input {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
}

.distillato-card__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 6px;
}

.distillato-card__output {
    margin-bottom: 16px;
}

.distillato-card__admin {
    padding-top: 12px;
    border-top: 1px solid var(--line);
    margin-top: 12px;
}

.distillato-card__admin-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.distillato-admin-hint {
    margin-top: 24px;
    font-size: 0.85rem;
    color: var(--muted);
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.03);
}

.distillato-admin-hint a {
    color: var(--accent);
    text-decoration: none;
}

/* ── Runs tab (Talamo → Storico) ─────────────────────────────────────────── */

.runs-page {
    padding: 0 24px 48px;
    max-width: 860px;
}

.loading-row {
    padding: 32px 0;
    color: var(--muted);
}

.runs-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.run-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-tint);
    transition: border-color 0.15s;
}

.run-card--open {
    border-color: var(--accent);
}

.run-card__header {
    padding: 14px 18px;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.run-card__top {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 4px;
}

.run-card__template {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.run-card__date {
    font-size: 0.78rem;
    color: var(--muted);
}

.run-card__star {
    font-size: 0.82rem;
    color: #f5c542;
}

.run-card__preview {
    font-size: 0.9rem;
    color: var(--text);
    margin: 0;
    padding-right: 28px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.run-card__chevron {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.82rem;
}

.run-card__body {
    padding: 0 18px 18px;
    border-top: 1px solid var(--line);
}

.run-card__input {
    margin: 14px 0;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
}

.run-card__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 4px;
}

.run-card__output {
    margin-bottom: 12px;
}

.run-card__admin {
    padding-top: 12px;
    border-top: 1px solid var(--line);
    margin-top: 8px;
}

.run-card__admin-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.run-card__note {
    margin: 8px 0 0;
    font-size: 0.82rem;
    color: var(--muted);
}

/* Light theme for cards */
[data-theme="light"] .distillato-card,
[data-theme="light"] .run-card {
    background: #ffffff;
    border-color: rgba(0,0,0,0.1);
}

[data-theme="light"] .distillato-card__input,
[data-theme="light"] .run-card__input {
    background: rgba(0,0,0,0.03);
}

/* ── Costi API page ─────────────────────────────────────────────────────── */

.costs-page {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.costs-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 4px;
}

.costs-subtitle {
    font-size: 0.78rem;
    color: var(--muted);
    margin: 0;
    max-width: 560px;
}

.costs-period-select {
    flex-shrink: 0;
    padding-top: 4px;
}

.costs-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

@media (max-width: 640px) {
    .costs-cards { grid-template-columns: 1fr; }
}

.costs-card {
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px 20px;
}

.costs-card--accent {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.costs-card__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.costs-card__value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    margin-bottom: 4px;
}

.costs-card--accent .costs-card__value {
    color: var(--accent);
}

.costs-card__sub {
    font-size: 0.76rem;
    color: var(--muted);
}

.costs-section {
    padding: 20px 24px;
    overflow-x: auto;
}

.costs-section__title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.costs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.costs-table th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 6px 10px 8px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.costs-table th.num,
.costs-table td.num {
    text-align: right;
}

.costs-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.costs-table tr:last-child td {
    border-bottom: none;
}

.costs-table tr:hover td {
    background: var(--bg-tint);
}

.model-cell {
    font-size: 0.76rem;
    color: var(--muted);
    font-family: monospace;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cost-value {
    font-weight: 600;
    color: var(--accent);
}

.cost-unknown {
    color: var(--muted);
}

.provider-badge {
    font-size: 0.9em;
    margin-right: 3px;
}

.bar-cell {
    width: 120px;
    padding: 9px 10px;
    vertical-align: middle;
}

.cost-bar {
    height: 6px;
    min-width: 2px;
    border-radius: 4px;
    background: var(--accent);
    opacity: 0.7;
    transition: width 0.3s ease;
}

[data-theme="light"] .costs-card {
    background: #ffffff;
}

[data-theme="light"] .costs-card--accent {
    background: var(--accent-soft);
}

/* ── DocLibrary: encyclopedia split-panel ──────────────────────────────── */
.doc-explorer {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    align-items: start;
}

.doc-explorer__list {
    padding: 12px 16px;
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

.doc-explorer__list::-webkit-scrollbar {
    width: 6px;
}

.doc-explorer__list::-webkit-scrollbar-track {
    background: transparent;
}

.doc-explorer__list::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 3px;
}

.doc-explorer__list::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.doc-explorer__detail {
    min-width: 0;
}

.doc-explorer__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 64px 24px;
    color: var(--muted);
    font-size: 0.9rem;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
}

.doc-explorer__empty i {
    font-size: 2rem;
    opacity: 0.4;
}

/* On narrow screens, stack vertically */
@media (max-width: 900px) {
    .doc-explorer {
        grid-template-columns: 1fr;
    }

    .doc-explorer__list {
        position: static;
        max-height: none;
    }
}

/* ── Build toast notification ────────────────────── */
.build-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    min-width: 280px;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: toast-in 0.25s ease;
}
@keyframes toast-in {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.build-toast--running { border-left: 3px solid #f78b1e; }
.build-toast--queued  { border-left: 3px solid #6b7280; }
.build-toast--success { border-left: 3px solid #22c55e; }
.build-toast--failure { border-left: 3px solid #ef4444; }

.build-toast__icon { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }
.build-toast__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.build-toast__body strong { font-size: 0.88rem; color: var(--text); }
.build-toast__body span  { font-size: 0.82rem; color: var(--accent); }
.build-toast__body small { font-size: 0.76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.build-toast__close {
    background: none; border: none; color: var(--muted);
    cursor: pointer; padding: 2px 4px; font-size: 0.85rem;
    flex-shrink: 0;
}

/* ── Build page ──────────────────────────────────── */
.build-page { padding: 0 0 40px; }
.build-empty { padding: 40px; text-align: center; color: var(--muted); font-size: 0.9rem; }

.build-list { display: flex; flex-direction: column; gap: 0; }

.build-run {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    transition: background 0.1s;
}
.build-run:hover { background: var(--bg-tint); }
.build-run--active { background: var(--accent-soft); }

.build-run__status-icon { font-size: 1.2rem; flex-shrink: 0; width: 24px; text-align: center; }

.build-run--running .build-run__status-icon { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.build-run__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.build-run__title { display: flex; align-items: center; gap: 8px; }
.build-run__name { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.build-run__num  { font-size: 0.8rem; color: var(--muted); }
.build-run__meta { display: flex; gap: 12px; font-size: 0.76rem; color: var(--muted); }
.build-run__commit { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.build-run__right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.build-run__time { font-size: 0.76rem; color: var(--muted); }
.build-run__gh-link { color: var(--muted); font-size: 1rem; text-decoration: none; }
.build-run__gh-link:hover { color: var(--accent); }

.build-badge {
    font-size: 0.68rem; font-weight: 600; padding: 2px 7px;
    border-radius: 20px; text-transform: uppercase; letter-spacing: 0.03em;
}
.build-badge--running { background: rgba(247,139,30,0.15); color: #f78b1e; }

.build-jobs {
    background: var(--bg-tint);
    border-bottom: 1px solid var(--line);
    padding: 8px 18px 8px 56px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.build-job {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px; border-radius: 6px;
    font-size: 0.83rem;
}
.build-job--running { background: rgba(247,139,30,0.07); }
.build-job--success { background: rgba(34,197,94,0.06); }
.build-job--failure { background: rgba(239,68,68,0.07); }

.build-job__icon { font-size: 0.9rem; flex-shrink: 0; }
.build-job__name { flex: 1; color: var(--text); }
.build-job__duration { font-size: 0.76rem; color: var(--muted); }

/* ── Generic confirm modal ───────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 900;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
}
.modal {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px 28px 24px;
    width: 340px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
}
.modal__title {
    font-weight: 600;
    font-size: 1rem;
    margin: 0 0 8px;
    color: var(--text);
}
.modal__body {
    font-size: 0.88rem;
    color: var(--muted);
    margin: 0 0 24px;
}
.modal__actions {
    display: flex; gap: 10px; justify-content: flex-end;
}
.button--danger {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
}
.button--danger:hover { background: #dc2626; border-color: #dc2626; }

/* ── Tooltip engine (position:fixed, immune da overflow:hidden) ── */
.bb-tooltip {
    position: fixed;
    transform: translateY(-50%) translateX(-4px);
    white-space: nowrap;
    background: rgba(14, 14, 16, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: #e8e6df;
    border: 1px solid rgba(255, 138, 29, 0.28);
    border-radius: 10px;
    padding: 7px 13px;
    font-size: 0.79rem;
    font-weight: 400;
    letter-spacing: 0.01em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.16s ease, transform 0.16s ease;
    z-index: 9999;
    box-shadow: 0 8px 28px rgba(0,0,0,0.5), 0 0 0 0.5px rgba(255,138,29,0.10);
}
.bb-tooltip--visible {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}
[data-theme="light"] .bb-tooltip {
    background: rgba(255, 252, 245, 0.97);
    color: #1a1a18;
    border-color: rgba(255, 138, 29, 0.32);
    box-shadow: 0 6px 20px rgba(0,0,0,0.13), 0 0 0 0.5px rgba(255,138,29,0.18);
}

/* ── Panoramica chip: index + icon ──────────────────────── */
.brain-doc-chip { display: flex; align-items: center; gap: 6px; }
.brain-doc-chip__index { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.5em; }
.brain-doc-chip__icon { font-size: 1em; line-height: 1; }
.brain-doc-chip__title { flex: 1; font-size: 0.9rem; font-weight: 500; }

/* ── 3D Brain Graph ──────────────────────────────────────── */
.brain-graph-section {
    margin-bottom: 2rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--line);
    background: #0c0c0f;
    /* NO overflow:hidden — iOS Safari nasconde il canvas WebGL con overflow+border-radius */
    position: relative;
}
.brain-graph-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    gap: 1rem;
    flex-wrap: wrap;
}
.brain-graph-header__title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-muted);
    letter-spacing: 0.03em;
}
.brain-graph-header__hint {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.25);
    font-style: italic;
}
.brain-graph-canvas {
    width: 100%;
    height: 320px; /* fallback — JS lo sovrascrive con il valore corretto */
    display: block;
    min-height: 240px;
}
@media (max-width: 640px) {
    .brain-graph-canvas { height: 320px; }
    .brain-graph-header__hint { display: none; }
}
.brain-graph-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    height: 100%;
    min-height: 320px;
    color: rgba(255,255,255,0.25);
    font-size: 0.82rem;
    font-style: italic;
}
.brain-graph-loading__dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent, #ff8a1d);
    animation: brain-pulse 1.2s ease-in-out infinite;
}
@keyframes brain-pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50%       { opacity: 1;   transform: scale(1.2); }
}
.brain-graph-fullscreen-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    padding: 0;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-sm, 6px);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.45);
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.brain-graph-fullscreen-btn:hover {
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.85);
    border-color: rgba(255,255,255,0.3);
}
.brain-graph-section:fullscreen {
    border-radius: 0;
    background: #0c0c0f;
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
}
.brain-graph-section:fullscreen .brain-graph-canvas {
    flex: 1;
    height: 100% !important;
}
/* ── View toggle (Grafo / Archivio) ─────────────────────────── */
.brain-view-toggle {
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius-sm, 6px);
    padding: 2px;
}
.brain-view-toggle__btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 3px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255,255,255,0.4);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.brain-view-toggle__btn:hover {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.7);
}
.brain-view-toggle__btn--active {
    background: rgba(255,255,255,0.13);
    color: rgba(255,255,255,0.92);
}
/* Archive canvas: same sizing rules as force graph canvas */
#brain-archive-canvas {
    width: 100%;
    height: 520px;
    overflow: hidden;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
#brain-archive-canvas canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ── Contenuto: prompt icon ──────────────────────────────── */
.prompt-list-icon { font-size: 1.1em; line-height: 1; flex-shrink: 0; }

/* ── Star ratings ────────────────────────────────────────── */
.ratings-grid { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.rating-row { display: flex; align-items: center; gap: 10px; }
.rating-row__label { font-size: 0.82rem; color: var(--muted); min-width: 120px; }
.rating-row__stars { display: flex; gap: 2px; }
.star-btn {
    background: none; border: none; cursor: pointer;
    font-size: 1.25rem; color: var(--line-strong); padding: 0 1px;
    transition: color 0.12s, transform 0.1s;
}
.star-btn.is-active { color: #f59e0b; }
.star-btn:hover { color: #fbbf24; transform: scale(1.15); }
.ratings-grid--readonly .star-btn { cursor: default; pointer-events: none; }

/* ── Inline rename in doc list ───────────────────────────── */
.doc-row__rename-btn {
    opacity: 0; background: none; border: none; cursor: pointer;
    color: var(--muted); padding: 0 3px; font-size: 0.78rem;
    transition: opacity 0.15s;
    margin-left: auto;
}
.doc-row:hover .doc-row__rename-btn,
.doc-row--active .doc-row__rename-btn { opacity: 1; }
.doc-row__rename-input {
    flex: 1; font-size: 0.83rem; padding: 2px 6px;
    background: var(--panel); border: 1px solid var(--accent);
    border-radius: 4px; color: var(--text); outline: none;
    margin-top: 2px;
}
.doc-row__rename-actions { display: flex; gap: 4px; margin-top: 2px; }

/* ── Account hub ─────────────────────────────────────────── */
.account-hub {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 560px;
}

.account-hub-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 20px;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.account-hub-card:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    transform: translateX(2px);
}

.account-hub-card__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.account-hub-card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.account-hub-card__body strong {
    font-size: 0.95rem;
    font-weight: 600;
}

.account-hub-card__body span {
    font-size: 0.83rem;
    color: var(--muted);
}

.account-hub-card__arrow {
    color: var(--muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* Sotto-pagine account: layout a 1 colonna stretta */
.account-sub-layout {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 600px;
}

/* ── Import page ─────────────────────────────────────────── */
.import-shell {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 960px;
}

.import-textarea {
    min-height: 220px;
    font-size: 0.85rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    line-height: 1.55;
    resize: vertical;
}

.import-textarea--tall {
    min-height: 320px;
}

/* Two-column layout for Post + Analisi */
.import-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 700px) {
    .import-split { grid-template-columns: 1fr; }
}

.import-memory-hint {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    background: var(--accent-soft);
    border-radius: 10px;
    font-size: 0.84rem;
    color: var(--muted);
}

.import-memory-hint i {
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 2px;
}

.import-notice {
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-toolbar__desc {
    margin: 4px 0 0;
    font-size: 0.88rem;
    color: var(--muted);
}

/* ── Light theme: fix componenti con rgba(255,255,255,xx) hardcoded ── */
[data-theme="light"] .macro-card__header:hover {
    background: rgba(0, 0, 0, 0.035);
}
[data-theme="light"] .macro-card__count {
    background: rgba(0, 0, 0, 0.07);
}
[data-theme="light"] .macro-card--open {
    border-color: var(--accent);
}
[data-theme="light"] .topic-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .topic-btn.is-active {
    background: rgba(255, 115, 0, 0.13);
    color: var(--accent);
}
/* Pannelli che usano rgba white semi-transparent come background */
[data-theme="light"] .stack-item--button:hover,
[data-theme="light"] .stack-item--button.is-active {
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .button--secondary {
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .button--ghost:hover {
    background: rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .btn-icon:hover {
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .notice--neutral {
    background: rgba(0, 0, 0, 0.04);
}
/* Card e panel con overlay trasparente quasi invisibile nel light */
[data-theme="light"] .panel {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .user-admin-card {
    background: rgba(255, 255, 255, 0.7);
}

/* ── Riferimenti page ────────────────────────────────────── */
.references-page { display: flex; flex-direction: column; gap: 1rem; }
.references-toolbar { display: flex; align-items: center; }
.inline-form-box {
    background: var(--bg-card, var(--panel));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 10px;
}
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }
.authors-page { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; }
.authors-list { padding: 0; overflow: hidden; }
.authors-list .panel__header { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.author-row { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); transition: background 0.12s; }
.author-row:hover { background: var(--hover); }
.author-row--active { background: rgba(var(--accent-rgb, 255,138,29), 0.1); }
.author-row__name { font-size: 0.9rem; font-weight: 500; }
.author-row__role { font-size: 0.76rem; color: var(--muted); }
.authors-detail { display: flex; flex-direction: column; gap: 1rem; }

/* ── Revisione page ──────────────────────────────────────── */
.revision-page { display: flex; flex-direction: column; }
/* Editor panel: full width with internal two-col layout (input | result) */
.revision-editor-panel { overflow: hidden; }
.revision-editor-body {
    display: grid;
    grid-template-columns: minmax(300px, 2fr) 3fr;
    gap: 0;
    align-items: start;
    min-height: 480px;
}
.revision-input-col {
    padding: 1.25rem;
    border-right: 1px solid var(--line);
}
.revision-result-col {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.revision-textarea { min-height: 320px !important; resize: vertical; }
@media (max-width: 900px) {
    .revision-editor-body { grid-template-columns: 1fr; }
    .revision-input-col { border-right: none; border-bottom: 1px solid var(--line); }
    .authors-page { grid-template-columns: 1fr; }
}
.revision-output { display: flex; flex-direction: column; gap: 1rem; }
.revision-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; color: var(--muted); padding: 60px 0; font-size: 0.9rem;
}
.revision-placeholder i { font-size: 2.5rem; opacity: 0.4; }
.revision-issues .panel__header { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.issues-list { display: flex; flex-direction: column; gap: 0; }
.issue-item { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.issue-item:last-child { border-bottom: none; }
.issue-item__desc { font-size: 0.85rem; color: var(--text); }
.issue-item__original { font-size: 0.78rem; color: var(--muted); }
.issue-item__original .eyebrow, .issue-item__suggested .eyebrow { font-size: 0.7rem; color: var(--muted); display: block; }
.issue-item__suggested { font-size: 0.78rem; color: #4ade80; }
.revision-output-panel .panel__header { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.revision-text { padding: 14px 16px; font-size: 0.88rem; line-height: 1.65; color: var(--text); white-space: pre-wrap; }
.revision-text--muted { color: var(--muted); }
/* Legacy history accordion (unused but kept for safety) */
.revision-history { display: flex; flex-direction: column; gap: 8px; }
.history-item { cursor: pointer; padding: 0; overflow: hidden; }
.history-item--active { border-color: var(--accent); }
.history-item__header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.history-item__num { font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.5em; }
.history-item__date { font-size: 0.8rem; color: var(--muted); }
.tag--issues { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.2); }

/* New master-detail history layout */
.revision-history-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1rem;
    align-items: start;
}
.revision-history-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    max-height: 80vh;
    overflow-y: auto;
}
.revision-history-detail {
    min-height: 200px;
}
.revision-list-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    border-bottom: 1px solid var(--line);
    transition: background 0.1s;
    width: 100%;
}
.revision-list-item:last-child { border-bottom: none; }
.revision-list-item:hover { background: var(--hover); }
.revision-list-item--active { background: var(--hover); border-left: 3px solid var(--accent); padding-left: 9px; }
.revision-list-item__num { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.revision-list-item__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.revision-list-item__date { font-size: 0.78rem; color: var(--muted); }
.revision-list-item__preview { font-size: 0.78rem; color: var(--text-2); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Revision detail two-column layout */
.revision-detail-panel { overflow: hidden; }
.revision-detail-columns { display: grid; grid-template-columns: 1fr 1fr; }
.revision-detail-col { padding: 1rem 1.25rem; }
.revision-detail-col--right { border-left: 1px solid var(--line); }
/* Document selection chip */
.doc-selection-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 10px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text);
}
.doc-selection-chip__remove {
    background: none; border: none; cursor: pointer; padding: 0 2px;
    color: var(--muted); display: flex; align-items: center; line-height: 1;
}
.doc-selection-chip__remove:hover { color: var(--text); }
@media (max-width: 900px) {
    .revision-history-layout { grid-template-columns: 1fr; }
    .revision-history-list { max-height: 260px; }
    .revision-detail-columns { grid-template-columns: 1fr; }
    .revision-detail-col--right { border-left: none; border-top: 1px solid var(--line); }
}
.history-item__body { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; }
.history-item__section { display: flex; flex-direction: column; gap: 6px; }

/* ── Combobox ── */
.combobox { position: relative; }
.combobox__list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface-2, #1e1e2a);
    border: 1px solid var(--border, rgba(255,255,255,.12));
    border-radius: 8px;
    list-style: none;
    margin: 0; padding: 4px 0;
    max-height: 220px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.combobox__item {
    padding: 8px 14px;
    cursor: pointer;
    font-size: .875rem;
    color: var(--text-1, #e0e0e0);
    transition: background .12s;
}
.combobox__item:hover { background: var(--surface-3, rgba(255,255,255,.08)); }

/* ── Editorial Plan ── */
.editorial-page { display: flex; flex-direction: column; height: 100%; gap: 1rem; }
.editorial-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.editorial-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.25rem;
    flex: 1;
    min-height: 0;
    overflow: hidden; /* desktop: clipped scroll areas */
}
@media (max-width: 760px) {
    .editorial-layout {
        grid-template-columns: 1fr;
        overflow: visible;
        height: auto;
        flex: none;
    }
    .editorial-page { height: auto !important; flex: none !important; }
    .editorial-tree { max-height: 50vh; overflow-y: auto; flex-shrink: 0; }
    .editorial-panel { max-height: none; overflow-y: visible; }
    .editorial-toolbar { flex-wrap: wrap; }
}
.editorial-tree {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    overflow-y: auto;
    padding-right: 4px;
}
.macro-card {
    background: var(--surface-2, #1a1a28);
    border: 1px solid var(--border, rgba(255,255,255,.1));
    border-radius: 10px;
    overflow: hidden;
}
.macro-card--open { border-color: var(--accent, #f59e0b); }
.macro-card__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background .15s;
}
.macro-card__header:hover { background: rgba(255,255,255,.04); }
.macro-card__title { flex: 1; font-size: .875rem; font-weight: 600; }
.macro-card__count {
    font-size: .75rem;
    background: rgba(255,255,255,.08);
    color: var(--text-2, #aaa);
    border-radius: 99px;
    padding: 1px 7px;
}
.macro-card__chevron { font-size: .7rem; color: var(--text-2); }
.macro-card__topics { display: flex; flex-direction: column; gap: 2px; padding: 0 .5rem .5rem; }
.topic-btn {
    text-align: left;
    background: none;
    border: none;
    border-radius: 6px;
    padding: .45rem .75rem;
    font-size: .8125rem;
    color: var(--text-2, #bbb);
    cursor: pointer;
    transition: background .12s, color .12s;
    width: 100%;
}
.topic-btn:hover { background: rgba(255,255,255,.06); color: var(--text-1); }
.topic-btn.is-active { background: rgba(245,158,11,.12); color: #f59e0b; font-weight: 600; }
.topic-btn--macro { color: var(--text-1); font-style: italic; }

.editorial-panel { overflow-y: auto; }
.editorial-panel__inner { height: 100%; display: flex; flex-direction: column; }

.angles-list { display: flex; flex-direction: column; gap: 1rem; padding: 1rem 0; }
.angle-card {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface-3, rgba(255,255,255,.03));
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
    transition: border-color .15s;
}
.angle-card:hover { border-color: rgba(245,158,11,.3); }
.angle-card__num {
    font-size: 1.5rem;
    font-weight: 800;
    color: rgba(255,255,255,.1);
    min-width: 2rem;
    line-height: 1;
    padding-top: .25rem;
}
.angle-card__body { flex: 1; display: flex; flex-direction: column; gap: .4rem; }
.angle-card__type {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #f59e0b;
}
.angle-card__title { font-size: 1rem; font-weight: 700; color: var(--text-1); }
.angle-card__hook { font-size: .875rem; font-style: italic; color: var(--text-2); }
.angle-card__desc { font-size: .8125rem; color: var(--text-2); line-height: 1.5; }
.angle-card__web {
    font-size: .775rem;
    color: var(--text-3, #888);
    background: rgba(255,255,255,.04);
    border-radius: 6px;
    padding: .4rem .65rem;
}
.angle-card__web i { margin-right: .3rem; }
.angle-card__actions { margin-top: .5rem; }

.editorial-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editorial-editor__area {
    flex: 1;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: .8125rem;
    line-height: 1.6;
    resize: none;
    min-height: 500px;
}

/* ── Demographic Profiles admin page ────────────────────────────────────── */
.dp-lists {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}
.dp-list-block {
    background: var(--surface-2, rgba(255,255,255,.04));
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

/* ── Demographic profile preview in Contenuto ───────────────────────────── */
.dp-preview { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.dp-preview__group { display: flex; flex-direction: column; gap: 0.25rem; }

/* ── Demographic profile characteristics (Admin editor + Contenuto/Revisione) ── */
.dp-char-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.dp-char-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.55rem 0.65rem;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--panel);
    transition: border-color 0.15s;
}

.dp-char-row:hover {
    border-color: var(--line-strong, rgba(255,255,255,0.18));
}

.dp-char-row--editing {
    border-color: var(--accent, #f59e0b);
    background: rgba(245,158,11,0.05);
}

.dp-char-row--readonly {
    gap: 0.4rem;
    flex-direction: column;
    cursor: default;
}

.dp-char-row--readonly:hover {
    border-color: var(--line);
}

.dp-char-add {
    border-radius: 8px;
    border: 1px dashed var(--line-strong, rgba(255,255,255,0.18));
    background: var(--bg-subtle, rgba(255,255,255,0.03));
}

/* ── Demographic profile structured data table ── */
.dp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83em;
    margin-bottom: 0.75rem;
}
.dp-table th {
    text-align: left;
    padding: 4px 6px;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.dp-table td {
    padding: 5px 6px;
    vertical-align: top;
    border-bottom: 1px solid var(--line, rgba(255,255,255,0.06));
    word-break: break-word;
}
.dp-table tr:last-child td { border-bottom: none; }
.dp-table td:first-child { width: 35%; }
.dp-table td:last-child  { width: 32px; text-align: right; }

/* Inline add-row for a section */
.dp-add-row {
    display: grid;
    gap: 0.4rem;
    padding: 0.6rem;
    border-radius: 6px;
    border: 1px dashed var(--line-strong, rgba(255,255,255,0.14));
    background: var(--bg-subtle, rgba(255,255,255,0.02));
}

/* Profile preview (read-only) in Contenuto / Revisione */
.dp-preview { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.4rem; }
.dp-section { margin-top: 0.6rem; }
.dp-section__label {
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

/* Tag color variants */
.tag--green {
    background: rgba(34,197,94,.15);
    color: #4ade80;
    border-color: rgba(34,197,94,.25);
}
.tag--red {
    background: rgba(239,68,68,.15);
    color: #f87171;
    border-color: rgba(239,68,68,.25);
}
.tag--orange {
    background: rgba(249,115,22,.15);
    color: #fb923c;
    border-color: rgba(249,115,22,.25);
}

/* ─────────────────────────────────────────────────────────────
   UI system v2: centralized app workspaces
   These classes are intentionally generic and mobile-first enough
   to migrate pages away from inline layout rules incrementally.
   ───────────────────────────────────────────────────────────── */
:root,
[data-theme="amber"] {
    --bb-surface-0: var(--bg, #0a0a0b);
    --bb-surface-1: rgba(16, 16, 18, 0.88);
    --bb-surface-2: rgba(255, 255, 255, 0.045);
    --bb-surface-3: rgba(255, 255, 255, 0.075);
    --bb-border: var(--line, rgba(255, 255, 255, 0.08));
    --bb-border-strong: var(--line-strong, rgba(255, 255, 255, 0.16));
    --bb-text: var(--text, #f5f5f2);
    --bb-muted: var(--muted, #a8a79f);
    --bb-muted-2: rgba(245, 245, 242, 0.58);
    --bb-accent: var(--accent, #ff8a1d);
    --bb-accent-soft: var(--accent-soft, rgba(255, 138, 29, 0.14));
    --bb-danger: #ef4444;
    --bb-success: #22c55e;
    --bb-dashboard-card-bg: linear-gradient(180deg, rgba(14, 18, 28, 0.96), rgba(10, 13, 20, 0.96));
    --bb-dashboard-hero-bg:
        radial-gradient(circle at top right, rgba(232, 186, 75, 0.12), transparent 28%),
        linear-gradient(180deg, rgba(14, 18, 28, 0.98), rgba(10, 13, 20, 0.98));
    --bb-dashboard-card-border: rgba(255, 255, 255, 0.07);
    --bb-dashboard-inline-bg: rgba(255, 255, 255, 0.03);
    --bb-dashboard-inline-border: rgba(255, 255, 255, 0.06);
    --bb-radius-xs: 6px;
    --bb-radius-sm: 8px;
    --bb-radius-md: 10px;
    --bb-radius-lg: 12px;
    --bb-space-1: 4px;
    --bb-space-2: 8px;
    --bb-space-3: 12px;
    --bb-space-4: 16px;
    --bb-space-5: 20px;
    --bb-space-6: 24px;
    --bb-space-8: 32px;
}

[data-theme="light"] {
    --bb-surface-0: #f5f3ee;
    --bb-surface-1: rgba(255, 255, 255, 0.94);
    --bb-surface-2: rgba(0, 0, 0, 0.035);
    --bb-surface-3: rgba(0, 0, 0, 0.06);
    --bb-border: rgba(0, 0, 0, 0.08);
    --bb-border-strong: rgba(0, 0, 0, 0.15);
    --bb-text: #1a1918;
    --bb-muted: #72716a;
    --bb-muted-2: rgba(26, 25, 24, 0.58);
    --bb-dashboard-card-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(249, 247, 242, 0.96));
    --bb-dashboard-hero-bg:
        radial-gradient(circle at top right, rgba(255, 115, 0, 0.12), transparent 30%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(248, 245, 238, 0.97));
    --bb-dashboard-card-border: rgba(0, 0, 0, 0.08);
    --bb-dashboard-inline-bg: rgba(0, 0, 0, 0.025);
    --bb-dashboard-inline-border: rgba(0, 0, 0, 0.07);
}

.app-page {
    display: grid;
    gap: var(--bb-space-5);
    min-height: 0;
}

.app-page__header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--bb-space-4);
    min-width: 0;
}

.app-page__title-block {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.app-page__eyebrow,
.form-field__label,
.workspace-label {
    color: var(--bb-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-page__title {
    margin: 0;
    color: var(--bb-text);
    font-size: clamp(1.35rem, 2vw, 2rem);
    line-height: 1.08;
    letter-spacing: 0;
}

.app-page__subtitle {
    max-width: 760px;
    margin: 0;
    color: var(--bb-muted);
    font-size: 0.95rem;
    line-height: 1.45;
}

.app-page__actions,
.workspace-toolbar,
.workspace-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--bb-space-2);
    flex-wrap: wrap;
}

.workspace-toolbar {
    justify-content: space-between;
}

.workspace-filterbar {
    display: flex;
    align-items: center;
    gap: var(--bb-space-2);
    flex: 1;
    min-width: 240px;
}

.workspace-surface {
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-lg);
    background: var(--bb-surface-1);
    min-width: 0;
}

.workspace-surface--subtle {
    background: var(--bb-surface-2);
}

.workspace-panel {
    display: grid;
    gap: var(--bb-space-4);
    padding: var(--bb-space-4);
}

.workspace-split {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    gap: var(--bb-space-4);
    min-height: min(720px, calc(100dvh - 180px));
}

.workspace-list-pane,
.workspace-detail-pane,
.workspace-inspector {
    min-width: 0;
    min-height: 0;
    overflow: auto;
}

.workspace-list-pane {
    display: grid;
    align-content: start;
    gap: var(--bb-space-3);
}

.workspace-detail-pane {
    display: grid;
    gap: var(--bb-space-4);
}

.workspace-section {
    display: grid;
    gap: var(--bb-space-3);
}

.workspace-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bb-space-3);
}

.workspace-section__title {
    margin: 0;
    font-size: 1rem;
    line-height: 1.25;
}

.workspace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: var(--bb-space-3);
}

.workspace-grid--two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-field {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.form-field__hint {
    color: var(--bb-muted-2);
    font-size: 0.78rem;
    line-height: 1.35;
}

.empty-state {
    display: grid;
    place-items: center;
    gap: var(--bb-space-2);
    min-height: 220px;
    padding: var(--bb-space-8);
    color: var(--bb-muted);
    text-align: center;
    border: 1px dashed var(--bb-border);
    border-radius: var(--bb-radius-lg);
    background: var(--bb-surface-2);
}

.empty-state__icon {
    color: var(--bb-muted-2);
    font-size: 1.8rem;
}

.empty-state p {
    max-width: 420px;
    margin: 0;
}

.entity-list {
    display: grid;
    gap: var(--bb-space-2);
}

.entity-row {
    width: 100%;
    display: grid;
    gap: 5px;
    padding: var(--bb-space-3);
    color: var(--bb-text);
    text-align: left;
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-md);
    background: transparent;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.entity-row:hover,
.entity-row.is-active {
    background: var(--bb-accent-soft);
    border-color: color-mix(in srgb, var(--bb-accent) 45%, transparent);
}

.entity-row.is-active {
    transform: translateX(2px);
}

.entity-row__title {
    overflow-wrap: anywhere;
    font-weight: 800;
    line-height: 1.25;
}

.entity-row__meta {
    display: flex;
    gap: var(--bb-space-2);
    flex-wrap: wrap;
    color: var(--bb-muted);
    font-size: 0.78rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    width: fit-content;
    padding: 3px 8px;
    border: 1px solid var(--bb-border);
    border-radius: 999px;
    color: var(--bb-muted);
    background: var(--bb-surface-2);
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill--accent {
    color: var(--bb-accent);
    border-color: color-mix(in srgb, var(--bb-accent) 35%, transparent);
    background: var(--bb-accent-soft);
}

.status-pill--success {
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.28);
    background: rgba(34, 197, 94, 0.12);
}

.status-pill--warning {
    color: #f5c451;
    border-color: rgba(245, 196, 81, 0.28);
    background: rgba(245, 196, 81, 0.12);
}

.status-pill--neutral {
    color: var(--bb-text-muted);
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
}

.status-pill--danger {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.28);
    background: rgba(239, 68, 68, 0.12);
}

.mobile-only {
    display: none !important;
}

/* Ideation */
.ideation-item-actions,
.ideation-edit-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.ideation-action-button {
    align-items: center;
    gap: 6px;
}

.ideation-action-button i {
    flex-shrink: 0;
}

/* Funnel Studio */
.funnels-page {
    height: 100%;
}

.funnel-create {
    display: grid;
    gap: var(--bb-space-3);
}

.funnel-create__row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) 90px;
    gap: var(--bb-space-2);
}

.funnel-studio {
    display: grid;
    grid-template-columns: minmax(220px, 300px) minmax(0, 1.05fr) minmax(280px, 420px);
    gap: var(--bb-space-4);
    min-height: min(760px, calc(100dvh - 210px));
}

.funnel-column {
    display: grid;
    align-content: start;
    gap: var(--bb-space-3);
    min-width: 0;
    min-height: 0;
}

.funnel-strategy {
    display: grid;
    gap: var(--bb-space-3);
}

.funnel-title-input {
    font-size: 1.25rem;
    font-weight: 800;
}

.funnel-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--bb-space-2);
}

.funnel-metric {
    display: grid;
    gap: 3px;
    padding: var(--bb-space-3);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-md);
    background: var(--bb-surface-2);
}

.funnel-metric strong {
    font-size: 1.2rem;
}

.funnel-metric span {
    color: var(--bb-muted);
    font-size: 0.76rem;
}

.funnel-flow {
    display: grid;
    gap: var(--bb-space-2);
}

.funnel-step {
    width: 100%;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--bb-space-3);
    padding: var(--bb-space-3);
    text-align: left;
    color: var(--bb-text);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-md);
    background: var(--bb-surface-2);
    cursor: pointer;
}

.funnel-step:hover,
.funnel-step.is-active {
    border-color: color-mix(in srgb, var(--bb-accent) 42%, transparent);
    background: var(--bb-accent-soft);
}

.funnel-step__number {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    color: var(--bb-accent);
    background: rgba(255, 138, 29, 0.12);
    font-weight: 800;
    font-size: 0.78rem;
}

.funnel-step__body {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.funnel-step__title {
    font-weight: 800;
    overflow-wrap: anywhere;
}

.funnel-step__objective {
    color: var(--bb-muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.funnel-asset-list {
    display: flex;
    gap: var(--bb-space-2);
    flex-wrap: wrap;
}

.funnel-asset-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 4px 9px;
    border: 1px solid var(--bb-border);
    border-radius: 999px;
    background: var(--bb-surface-2);
    color: var(--bb-muted);
    font-size: 0.76rem;
}

.funnel-asset-chip.is-active {
    color: var(--bb-accent);
    border-color: color-mix(in srgb, var(--bb-accent) 36%, transparent);
    background: var(--bb-accent-soft);
}

.funnel-inspector {
    display: grid;
    gap: var(--bb-space-3);
    align-content: start;
}

.funnel-inspector__header {
    display: flex;
    justify-content: space-between;
    gap: var(--bb-space-3);
    align-items: flex-start;
}

.funnel-inspector__title {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.funnel-inspector__title strong {
    overflow-wrap: anywhere;
}

.funnel-body-editor {
    min-height: 260px;
    resize: vertical;
}

@media (max-width: 1180px) {
    .funnel-studio {
        grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
    }

    .funnel-inspector {
        grid-column: 1 / -1;
    }
}

@media (max-width: 900px) {
    .app-page__header {
        align-items: stretch;
        flex-direction: column;
    }

    .app-page__actions,
    .workspace-toolbar,
    .workspace-filterbar {
        width: 100%;
        justify-content: stretch;
    }

    .app-page__actions > *,
    .workspace-toolbar > *,
    .workspace-filterbar > * {
        min-width: 0;
        flex: 1 1 160px;
    }

    .workspace-split,
    .funnel-studio,
    .funnel-create__row,
    .workspace-grid--two {
        grid-template-columns: 1fr;
    }

    .workspace-list-pane,
    .workspace-detail-pane,
    .workspace-inspector {
        overflow: visible;
    }

    .funnel-studio {
        min-height: 0;
    }

    .funnel-column--list {
        order: 1;
    }

    .funnel-column--strategy {
        order: 2;
    }

    .funnel-inspector {
        order: 3;
    }

    .funnel-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: initial !important;
    }

    .ideation-item-actions,
    .ideation-edit-actions {
        gap: 5px;
    }

    .ideation-page .ideation-action-button,
    .ideation-page .ideation-item-actions .button,
    .ideation-page .ideation-edit-actions .button {
        width: 34px;
        min-width: 34px;
        height: 34px;
        padding: 0 !important;
        justify-content: center;
        flex: 0 0 34px;
        font-size: 0.82rem !important;
    }

    .ideation-page .ideation-action-label {
        display: none;
    }
}

@media (max-width: 560px) {
    .shell-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .workspace-panel {
        padding: var(--bb-space-3);
    }

    .funnel-metrics {
        grid-template-columns: 1fr;
    }

    .funnel-step {
        grid-template-columns: 30px minmax(0, 1fr);
    }

    .funnel-step > .status-pill {
        grid-column: 2;
    }
}
/* Bootstrap, dashboard and publishing refresh */
.app-boot,
.boot-authorizing {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top, rgba(232, 186, 75, 0.16), transparent 32%),
        linear-gradient(180deg, #0b0e14 0%, #090b10 100%);
}

.app-boot {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.app-boot--hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.app-boot__panel,
.boot-authorizing__panel {
    width: min(100%, 420px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 28px;
    background: rgba(10, 13, 20, 0.86);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(18px);
}

.app-boot__brand,
.boot-authorizing__panel {
    display: flex;
    align-items: center;
    gap: 18px;
}

.boot-authorizing__panel {
    align-items: flex-start;
}

.app-boot__mark,
.boot-authorizing__mark {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: rgba(255, 215, 64, 0.08);
    border: 1px solid rgba(255, 215, 64, 0.18);
    flex-shrink: 0;
}

.app-boot__copy,
.boot-authorizing__copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-boot__copy strong,
.boot-authorizing__copy strong {
    font-size: 1.05rem;
    color: #f8f6ef;
}

.app-boot__copy span,
.boot-authorizing__copy span {
    color: rgba(248, 246, 239, 0.72);
    font-size: 0.92rem;
}

.app-boot__status {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    color: rgba(248, 246, 239, 0.78);
    font-size: 0.92rem;
}

.app-boot__spinner,
.dashboard-loading__spinner {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 2px solid rgba(255, 215, 64, 0.18);
    border-top-color: #f5cc45;
    animation: bb-spin 0.8s linear infinite;
}

.shell-header {
    background: rgba(12, 16, 24, 0.9);
    backdrop-filter: blur(18px);
}

.dashboard-page .app-page__header {
    margin-bottom: var(--bb-space-4);
}

.dashboard-welcome {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dashboard-welcome strong {
    font-size: 1rem;
    color: var(--bb-text);
}

.dashboard-welcome span {
    color: var(--bb-text-muted);
    font-size: 0.92rem;
}

.dashboard-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 0;
    color: var(--bb-text-muted);
}

.dashboard-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--bb-space-3);
    margin-bottom: var(--bb-space-4);
}

.dashboard-stat {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 16px;
    padding: 20px;
    border-radius: 20px;
    background: var(--bb-dashboard-card-bg);
    border: 1px solid var(--bb-dashboard-card-border);
}

.dashboard-stat__icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    font-size: 1.3rem;
    border: 1px solid var(--bb-dashboard-card-border);
}

.dashboard-stat__icon--amber { color: #f0b44c; background: rgba(240, 180, 76, 0.12); }
.dashboard-stat__icon--violet { color: #9f73ff; background: rgba(159, 115, 255, 0.12); }
.dashboard-stat__icon--cyan { color: #6fb8ff; background: rgba(111, 184, 255, 0.12); }
.dashboard-stat__icon--emerald { color: #5fdf9d; background: rgba(95, 223, 157, 0.12); }

.dashboard-stat__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.dashboard-stat__body span,
.dashboard-stat__body small {
    color: var(--bb-text-muted);
}

.dashboard-stat__body strong {
    font-size: 2rem;
    line-height: 1;
    color: var(--bb-text);
}

.dashboard-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.9fr);
    gap: var(--bb-space-3);
    margin-bottom: var(--bb-space-3);
}

.dashboard-stage--secondary {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.dashboard-panel {
    padding: 24px;
}

.dashboard-panel--hero {
    background: var(--bb-dashboard-hero-bg);
}

.dashboard-panel__header,
.publish-history__header,
.publish-sidecard__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.dashboard-panel__header h2 {
    margin: 6px 0 0;
    font-size: 1.2rem;
}

.dashboard-panel__lead {
    margin: 18px 0 0;
    color: var(--bb-text-muted);
}

.dashboard-hero-actions,
.dashboard-shortcuts,
.dashboard-checklist,
.dashboard-doclist,
.publish-status-results,
.publish-history__list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dashboard-hero-actions {
    flex-direction: row;
    flex-wrap: wrap;
    margin-top: 20px;
}

.dashboard-check,
.dashboard-shortcut,
.dashboard-doc,
.publish-status-result,
.publish-history__item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--bb-dashboard-inline-bg);
    border: 1px solid var(--bb-dashboard-inline-border);
}

.dashboard-check i,
.dashboard-shortcut i {
    margin-top: 2px;
    color: var(--accent);
}

.dashboard-check div,
.dashboard-shortcut div,
.publish-history__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dashboard-check span,
.dashboard-shortcut span,
.dashboard-doc__path,
.publish-history__body span {
    color: var(--bb-text-muted);
    font-size: 0.9rem;
}

.dashboard-panel__link,
.publish-history__item a {
    color: var(--accent);
    font-size: 0.88rem;
    font-weight: 600;
}

.dashboard-doc {
    flex-direction: column;
    gap: 8px;
}

.dashboard-doc__meta,
.publish-history__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.dashboard-doc__area {
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.publish-modal {
    width: min(1180px, 96vw);
    max-width: 1180px;
}

.publish-modal__body {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.publish-modal__usage {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.publish-modal__usage div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.publish-modal__usage span:not(.status-pill) {
    color: var(--bb-text-muted);
    font-size: 0.9rem;
}

.publish-modal__grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
    gap: 18px;
}

.publish-modal__main,
.publish-modal__side {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.publish-modal__columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.publish-platforms {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.publish-platform {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: rgba(255, 255, 255, 0.03);
    color: var(--bb-text);
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.publish-platform:hover,
.publish-platform.is-selected {
    border-color: color-mix(in srgb, var(--accent) 56%, white 14%);
    background: color-mix(in srgb, var(--accent) 12%, rgba(255, 255, 255, 0.03));
    transform: translateY(-1px);
}

.publish-textarea {
    min-height: 132px;
    resize: vertical;
}

.publish-mode {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.publish-mode__option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.publish-sidecard,
.publish-statusbox,
.publish-history {
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.publish-sidecard {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.publish-sidecard__header span,
.publish-history__header span,
.publish-status-result span,
.publish-history__empty,
.publish-statusbox p,
.publish-statusbox small {
    color: var(--bb-text-muted);
    font-size: 0.88rem;
}

.publish-statusbox {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
}

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

.publish-status-result {
    align-items: center;
    justify-content: space-between;
}

.publish-status-result > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.publish-history {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.publish-history__item,
.publish-history__body {
    gap: 8px;
}

.publish-history__item {
    flex-direction: column;
}

.publish-modal__actions {
    justify-content: flex-end;
}

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

@media (max-width: 1100px) {
    .dashboard-metrics,
    .publish-modal__columns {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-stage,
    .dashboard-stage--secondary,
    .publish-modal__grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .dashboard-metrics,
    .publish-modal__columns {
        grid-template-columns: 1fr;
    }

    .dashboard-stat {
        grid-template-columns: 56px 1fr;
        padding: 16px;
    }

    .dashboard-stat__icon {
        width: 56px;
        height: 56px;
    }

    .app-boot__panel,
    .boot-authorizing__panel,
    .dashboard-panel,
    .publish-sidecard,
    .publish-statusbox,
    .publish-history {
        padding: 16px;
    }

    .publish-modal {
        width: min(100vw, 100vw);
        min-height: 100vh;
        border-radius: 0;
    }
}
