:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e6e8ec;
    --text: #0f172a;
    --text-muted: #64748b;
    --accent: #4f46e5;
    --accent-strong: #4338ca;
    --danger: #dc2626;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 24px rgba(15, 23, 42, 0.06);
}

html, body {
    font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

a { color: var(--accent); }

h1:focus { outline: none; }

/* ---- buttons ---- */
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger:active { transform: translateY(1px); }

/* ---- confirmation modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: grid;
    place-items: center;
    z-index: 100;
    animation: modal-fade 0.12s ease;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 1.8rem;
    width: 90%;
    max-width: 400px;
    animation: modal-pop 0.14s ease;
}

.modal-card h3 { margin: 0 0 0.5rem; font-size: 1.2rem; }
.modal-card p { color: var(--text-muted); margin: 0 0 1.5rem; word-break: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

/* Type-the-name confirmation for destructive actions (staging tenant delete/overwrite). */
.modal-confirm-input {
    width: 100%;
    box-sizing: border-box;
    margin: 0 0 1.2rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}
.modal-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- data viewer (CSV/API data sources): a near-fullscreen modal with a scrollable table ---- */
.data-viewer-card {
    max-width: min(1400px, 94vw);
    width: 94vw;
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    padding: 1.2rem 1.4rem 1.4rem;
}

.data-viewer-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.data-viewer-head h3 { margin: 0; }

/* Both axes scroll inside the card; the header row stays pinned while scrolling vertically. */
.data-viewer-scroll {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    flex: 1;
    min-height: 0;
}

/* Document viewer modal (PDF/MD data sources): the PDF iframe / markdown text fills the card.
   For PDFs the card takes its full allowed height so the embedded viewer gets maximum room. */
.document-viewer-card-pdf { height: 88vh; }
.document-viewer-frame {
    flex: 1;
    min-height: 0;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
}

.document-viewer-text {
    margin: 0;
    padding: 1rem 1.2rem;
    font-size: 0.85rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Rendered Markdown (Markdig) variant: modest document styling inside the scroll area. */
.document-viewer-markdown {
    padding: 1.2rem 1.6rem;
    font-size: 0.92rem;
    line-height: 1.6;
    word-break: break-word;
    max-width: 60rem;
}
.document-viewer-markdown h1 { font-size: 1.45rem; margin: 1.4rem 0 0.6rem; }
.document-viewer-markdown h2 { font-size: 1.2rem; margin: 1.3rem 0 0.5rem; }
.document-viewer-markdown h3 { font-size: 1.05rem; margin: 1.1rem 0 0.4rem; }
.document-viewer-markdown h4, .document-viewer-markdown h5, .document-viewer-markdown h6 { font-size: 0.95rem; margin: 1rem 0 0.3rem; }
.document-viewer-markdown h1:first-child, .document-viewer-markdown h2:first-child, .document-viewer-markdown h3:first-child { margin-top: 0; }
.document-viewer-markdown p { margin: 0 0 0.8rem; }
.document-viewer-markdown ul, .document-viewer-markdown ol { margin: 0 0 0.8rem; padding-left: 1.5rem; }
.document-viewer-markdown li { margin: 0.2rem 0; }
.document-viewer-markdown blockquote {
    margin: 0 0 0.8rem;
    padding: 0.2rem 1rem;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
}
.document-viewer-markdown code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05rem 0.3rem;
    font-size: 0.85em;
}
.document-viewer-markdown pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    overflow-x: auto;
    margin: 0 0 0.8rem;
}
.document-viewer-markdown pre code { background: none; border: none; padding: 0; }
.document-viewer-markdown table { border-collapse: collapse; margin: 0 0 0.8rem; }
.document-viewer-markdown th, .document-viewer-markdown td {
    border: 1px solid var(--border);
    padding: 0.35rem 0.6rem;
    text-align: left;
}
.document-viewer-markdown th { background: var(--surface-2); }
.document-viewer-markdown hr { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }
.document-viewer-markdown img { max-width: 100%; }

/* Same Markdown styling inside a Widget Chats transcript bubble: no document padding, no trailing gap. */
.chat-bubble-markdown { padding: 0; max-width: none; font-size: 0.88rem; }
.chat-bubble-markdown > :last-child { margin-bottom: 0; }

/* Markdown edit modal: PSC editor variant scrolls as a whole; split variant is textarea | live preview. */
.markdown-edit-rich {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.markdown-edit-split {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

.markdown-edit-input {
    resize: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.2rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.55;
    background: var(--surface);
    color: inherit;
}
.markdown-edit-input:focus { outline: none; border-color: var(--text-muted); }

.markdown-edit-preview { background: var(--surface); }

.data-viewer-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85rem;
}

.data-viewer-table th,
.data-viewer-table td {
    padding: 0.4rem 0.7rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: top;
}

.data-viewer-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    box-shadow: 0 1px 0 var(--border);
    font-weight: 600;
    z-index: 1;
}

.data-viewer-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--border) 18%, transparent); }

.data-viewer-rownum {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
    width: 1%;
}

/* ---- generic centered notice (access denied / not authorized) ---- */
.centered-notice {
    max-width: 480px;
    margin: 12vh auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 2.5rem;
    text-align: center;
}

.centered-notice h1 { margin-top: 0; font-size: 1.4rem; }
.centered-notice p { color: var(--text-muted); }

/* ---- home ---- */
.home {
    /* .app-content is a column flex container, and the auto side margins that centre this box also cancel the
       default stretch — without width:100% the page would shrink to fit its content instead of the max-width. */
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
}

.home-hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 2.5rem;
}

.home-hero h1 { margin: 0 0 0.5rem; font-size: 1.9rem; letter-spacing: -0.02em; }
.home-hero p { color: var(--text-muted); font-size: 1.05rem; margin-bottom: 1.5rem; }

.home-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

.home-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.3rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.12s ease, transform 0.08s ease;
}

.home-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.home-card h3 { margin: 0.2rem 0 0.4rem; }
.home-card p { color: var(--text-muted); margin: 0; font-size: 0.92rem; }
.home-card-icon { font-size: 1.5rem; }

/* The admin dashboard below the shortcuts. Reuses the Statistics page's .stat-card / .stats-chart blocks. */
.home-stats { margin-top: 2.5rem; }

.home-stats-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.home-stats-head h2 { margin: 0; font-size: 1.25rem; }
.home-stats-link { font-size: 0.88rem; text-decoration: none; color: var(--accent); }
.home-stats-link:hover { text-decoration: underline; }
.home-stats-h3 { font-size: 1rem; margin: 1.6rem 0 0.5rem; }

.home-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.8rem;
}

.home-tile {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.12s ease;
}

.home-tile:hover { border-color: var(--accent); }
.home-tile-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.home-tile-label { font-size: 0.8rem; color: var(--text-muted); }

/* ---- login ---- */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 2.5rem;
    text-align: center;
}

.login-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin: 0 auto 1rem;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: #fff;
    font-size: 1.5rem;
}

.login-card h1 { font-size: 1.35rem; margin: 0 0 0.35rem; }
.login-card .sub { color: var(--text-muted); margin: 0 0 1.8rem; font-size: 0.95rem; }

.sso-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.8rem;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.sso-btn:hover { background: var(--surface-2); border-color: var(--text-muted); }
.sso-btn img, .sso-btn svg { width: 20px; height: 20px; }

.login-foot { margin-top: 1.2rem; font-size: 0.82rem; color: var(--text-muted); }

/* ---- settings area: left menu + content ---- */
.settings-page {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    max-width: 1240px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.settings-menu {
    flex: 0 0 220px;
    position: sticky;
    top: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

.settings-menu-title { font-size: 1.1rem; margin: 0.2rem 0.4rem 0.9rem; }

.settings-menu-nav { display: flex; flex-direction: column; gap: 0.25rem; }

.settings-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.7rem;
    border-radius: 9px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
}

.settings-menu-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.settings-menu-item:hover { background: var(--surface-2); color: var(--text); }
.settings-menu-item.active { background: var(--accent); color: #fff; }

.settings-content { flex: 1; min-width: 0; }
.settings-content .users-page { margin: 0; padding: 0; max-width: none; }

.settings-tabs {
    display: flex;
    gap: 0.4rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.settings-tab {
    padding: 0.6rem 1.1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

@media (max-width: 720px) {
    .settings-page { flex-direction: column; }
    .settings-menu { position: static; width: 100%; flex-basis: auto; }
    .settings-menu-nav { flex-direction: row; flex-wrap: wrap; }
}

/* ---- AI model selection ---- */
.model-list { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1.2rem; }

.model-card {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.model-card:hover { border-color: var(--accent); }
.model-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.model-card input { margin-top: 0.25rem; accent-color: var(--accent); }

/* Disabled (unavailable) model: greyed out and non-interactive. */
.model-card.disabled { opacity: 0.55; cursor: not-allowed; background: var(--surface-muted, var(--surface)); }
.model-card.disabled:hover { border-color: var(--border); }
.model-card.disabled input { cursor: not-allowed; }

.model-card-body { flex: 1; min-width: 0; }
.model-card-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.model-card-name { font-weight: 600; font-size: 1rem; }
.model-card-desc { color: var(--text-muted); font-size: 0.9rem; margin: 0.35rem 0 0; }

/* ---- feature switches ---- */
.feature-list { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1.2rem; }

.feature-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.feature-card-body { flex: 1; min-width: 0; }
.feature-card-name { font-weight: 600; font-size: 1rem; }
.feature-card-desc { color: var(--text-muted); font-size: 0.9rem; margin: 0.35rem 0 0; }
.feature-card-note { color: var(--text-muted); font-size: 0.82rem; font-style: italic; margin: 0.3rem 0 0; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: 0 0 44px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.switch-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
    transition: transform 0.15s ease;
}
.switch input:checked + .switch-slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.switch input:disabled + .switch-slider { opacity: 0.6; }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 2px var(--accent); }

/* ---- users admin table ---- */
.users-page { max-width: 1000px; margin: 0 auto; padding: 2.5rem 1.5rem; }
.users-page h1 { font-size: 1.6rem; margin-top: 0; }
.users-page .muted { color: var(--text-muted); }

.users-invite {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.2rem;
    margin: 1.2rem 0 1.8rem;
    box-shadow: var(--shadow);
}

.users-invite label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.users-invite input, .users-invite select {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 0.92rem;
    min-width: 220px;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.user-table th, .user-table td {
    text-align: left;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.user-table th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; }
.user-table tr:last-child td { border-bottom: none; }

/* ---- data source column editor + inline edit ---- */
.ds-columns { display: flex; flex-direction: column; gap: 0.4rem; }
.ds-column { display: flex; align-items: center; gap: 0.6rem; }
.ds-column-name {
    min-width: 160px;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
}
.ds-column input {
    flex: 1;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
}

.ds-edit-row td { background: var(--surface-2); }
.ds-edit { display: flex; flex-direction: column; gap: 0.8rem; padding: 0.6rem 0.2rem; }
.ds-edit-field label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.ds-edit-field input, .ds-edit-field textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    font: inherit;
    font-size: 0.92rem;
}

.pill {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    /* A fixed radius, not 999px: a pill that wraps to two lines must stay a rectangle, not become an oval. */
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ---- widget settings form ---- */
.widget-form { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 1.2rem; max-width: 640px; }
.widget-form .feature-card { cursor: default; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text); }

.text-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    font-size: 0.92rem;
    background: var(--surface);
    color: var(--text);
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15); }
textarea.text-input { resize: vertical; min-height: 2.6rem; }

.field-hint { color: var(--text-muted); font-size: 0.82rem; margin: 0.1rem 0 0; }
.field-hint code { background: var(--surface-2); padding: 0.05rem 0.3rem; border-radius: 4px; }

/* multi-select language grid on the Ask AI / Widget settings pages (choose-in-chat mode) */
.lang-checkgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 0.4rem 1rem;
    margin-top: 0.5rem;
}
.lang-check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }
.lang-check input { flex: 0 0 auto; }

.color-row { display: flex; align-items: center; gap: 0.6rem; }
.color-input {
    width: 48px; height: 34px; padding: 2px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer;
}

.widget-actions { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.widget-sep { border: none; border-top: 1px solid var(--border); margin: 0.4rem 0; }

.embed-snippet {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem 0.9rem;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.82rem;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0.2rem 0 0.6rem;
}

.pill-admin { background: #ede9fe; color: #6d28d9; }
.pill-user { background: #e2e8f0; color: #475569; }
.pill-active { background: #dcfce7; color: #15803d; }
.pill-disabled { background: #fee2e2; color: #b91c1c; }
/* Informational state that is neither good nor bad (a mode, an in-progress step) — red is for real problems. */
.pill-neutral { background: #e0e7ff; color: #4338ca; }

/* Tenant environment: production quiet-blue, staging loud-amber so a staging row can never be mistaken. */
.pill-production { background: #dbeafe; color: #1d4ed8; }
.pill-staging { background: #fef3c7; color: #b45309; }
.pill-playground { background: #ede9fe; color: #6d28d9; }
.tenant-row-staging td { background: #fffbeb; }
.tenant-row-playground td { background: #f5f3ff; }
.tenant-name-staging { padding-left: 2.2rem !important; }
.tenant-staging-arrow { color: #b45309; margin-right: 0.35rem; font-weight: 600; }

.row-actions { display: flex; gap: 0.4rem; }
.row-actions button, .row-actions .row-action-upload {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    font-size: 0.82rem;
    cursor: pointer;
}
.row-actions .row-action-upload { display: inline-block; margin: 0; font-weight: normal; }
.row-actions button:hover, .row-actions .row-action-upload:hover { background: var(--surface-2); }

/* Stacked variant (data sources table): the buttons sit under each other, right-aligned, all as wide as the
   widest one, each label on a single line — instead of a row of differently-sized buttons wrapping mid-label. */
.row-actions-stack {
    flex-direction: column;
    align-items: stretch;
    width: max-content;
    margin-left: auto;
}
.row-actions-stack button, .row-actions-stack .row-action-upload { white-space: nowrap; text-align: center; }

/* Bottom row of the stack: two buttons side by side, each taking half of the stack's width. */
.row-actions-split { display: flex; gap: 0.4rem; }
.row-actions-split button {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
}

/* ---- statistics page ---- */
.stats-page { max-width: 1100px; }
.stats-h2 { font-size: 1.15rem; margin: 1.6rem 0 0.5rem; }

/* A collapsible section heading: a real <button> for keyboard/screen-reader use, styled as the h2 it replaces. */
.stats-h2-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.stats-h2-toggle:hover { color: var(--accent); }
.stats-h2-caret { font-size: 0.85rem; color: var(--text-muted); }
.stats-h2-toggle:hover .stats-h2-caret { color: var(--accent); }
.stats-collapsed-hint { margin: 0.1rem 0 0; font-size: 0.85rem; }

.stats-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin: 1.3rem 0 0.4rem;
}
.stats-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.stats-preset {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.stats-preset:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.stats-preset.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.stats-preset:disabled { opacity: 0.6; cursor: default; }

.stats-range { display: flex; align-items: flex-end; gap: 0.6rem; }
.stats-range .field { gap: 0.25rem; }
.stats-range .text-input { width: auto; min-width: 150px; }

.stats-error { color: var(--danger); }
.stats-period { font-weight: 600; margin: 0.7rem 0 1rem; }
.stats-period .muted { font-weight: 400; margin-left: 0.3rem; }

.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 0.9rem;
}
.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}
.stat-card-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.stat-card-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; color: var(--text); }
.stat-card-split { font-size: 0.78rem; color: var(--text-muted); }

.stats-note { margin-top: 0.9rem; line-height: 1.5; }

.stats-legend { display: flex; gap: 1.1rem; margin: 0.2rem 0 0.8rem; font-size: 0.85rem; color: var(--text-muted); }
.stats-legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.stats-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.stats-swatch-askai { background: var(--accent); }
.stats-swatch-widget { background: #0d9488; }

.stats-chart-wrap { overflow-x: auto; padding-bottom: 0.2rem; }
.stats-chart { display: flex; align-items: flex-end; gap: 3px; min-width: 100%; }
.stat-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1 1 0;
    min-width: 12px;
    max-width: 46px;
}
.stat-bar-stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 62%;
    min-width: 8px;
    max-width: 22px;
}
.stat-bar { width: 100%; }
.stat-bar-askai { background: var(--accent); }
.stat-bar-widget { background: #0d9488; }
.stat-bar-col:hover .stat-bar-askai { background: var(--accent-strong); }
.stat-bar-col:hover .stat-bar-widget { background: #0f766e; }
.stat-bar-label { font-size: 0.62rem; color: var(--text-muted); }

.stats-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

.stats-table-wrap { overflow-x: auto; }
.stats-table th.num, .stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }

/* Suppress Blazor's default "An unhandled error has occurred" banner. Uncaught errors are reported to
   the server (→ Loggly) by js/ui.js instead. Overrides the inline display:block Blazor sets on error. */
#blazor-error-ui {
    display: none !important;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 1rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

/* ---- Settings sidebar: data-source type sub-items (PDF / CSV / MD / API) ---- */
.settings-menu-sub {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0.15rem 0 0.35rem;
    padding-left: 2.15rem; /* aligns the sub-items under the parent item's label (icon width + gaps) */
}

.settings-menu-subitem {
    padding: 0.32rem 0.55rem;
    border-radius: 7px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
}

.settings-menu-subitem:hover { background: var(--surface-2); color: var(--text); }
.settings-menu-subitem.active { background: var(--accent); color: #fff; }

@media (max-width: 720px) {
    .settings-menu-sub { flex-direction: row; flex-wrap: wrap; padding-left: 0; }
}

/* ---- API data sources: editable column rows (name + description + remove) and the push identifier chip ---- */
.ds-column-editable .ds-column-name-input {
    flex: 0 0 220px;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.84rem;
    font-weight: 600;
}

.ds-column-remove {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.ds-column-remove:hover { background: var(--surface-2); color: var(--text); }

/* Merged "Info" cell on the data-source tables: name first on its own line, then identifier/columns/size stacked. */
.ds-info { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; padding: 0.2rem 0; }
.ds-info-name { font-weight: 600; margin-bottom: 0.35rem; }

/* The Info cell is top-aligned: name first with a clear gap below it, then the identifier/meta lines. */
.ds-info-cell { vertical-align: top; }
.ds-info-cell .ds-info-name { margin-bottom: 0.9rem; }
.ds-info-meta { white-space: nowrap; }

.ds-key-row { display: flex; align-items: center; gap: 0.4rem; }

.ds-key {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.78rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.12rem 0.4rem;
    word-break: break-all;
}

.ds-key-copy {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 0.16rem 0.45rem;
    cursor: pointer;
    white-space: nowrap;
}

.ds-key-copy:hover { background: var(--surface-2); color: var(--text); }

/* ---- Tenant sync review: the big accordion modal with per-item approvals ---- */
.sync-card {
    max-width: min(1200px, 94vw);
    width: 94vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1.6rem;
}

.sync-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.sync-head h3 { margin-bottom: 0.35rem; }
.sync-head-note { max-width: 640px; font-size: 0.88rem; margin: 0; }

.sync-head-controls { display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.85rem; color: var(--text-muted); }
.sync-head-controls label { display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.sync-head-controls input[type="datetime-local"] {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

.sync-empty { color: var(--text-muted); padding: 1rem 0; }

.sync-items {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-right: 0.2rem;
    margin-bottom: 0.9rem;
}

.sync-item { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.sync-item-open { border-color: var(--accent); }

.sync-item-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: var(--text);
}
.sync-item-header:hover { background: var(--surface-2); border-radius: 10px; }

.sync-badge {
    flex: 0 0 auto;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.14rem 0.5rem;
    border-radius: 999px;
    white-space: nowrap;
}
.sync-badge-added { background: #dcfce7; color: #166534; }
.sync-badge-modified { background: #fef9c3; color: #854d0e; }
.sync-badge-deleted { background: #fee2e2; color: #b91c1c; }

.sync-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-item-subtitle { flex: 0 0 auto; font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }
.sync-item-when { flex: 1 1 auto; text-align: right; font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }

.sync-decision { flex: 0 0 auto; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.sync-decision-yes { color: #15803d; }
.sync-decision-no { color: var(--text-muted); }
.sync-decision-none { color: #b45309; }
.sync-chevron { flex: 0 0 auto; color: var(--text-muted); }

.sync-item-body { padding: 0.2rem 0.9rem 0.9rem; border-top: 1px solid var(--border); }
.sync-item-note { font-size: 0.85rem; margin: 0.7rem 0 0.6rem; }
.sync-item-note-danger { color: #b91c1c; }

.sync-table-wrap { overflow-x: auto; }
.sync-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.sync-table th, .sync-table td {
    text-align: left;
    vertical-align: top;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
}
.sync-table th { font-size: 0.76rem; color: var(--text-muted); font-weight: 600; }
.sync-field-name { font-weight: 600; white-space: nowrap; }
.sync-table td { max-width: 420px; }

.sync-copydata { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.84rem; margin-top: 0.7rem; }
.sync-copydata-disabled { color: var(--text-muted); }

.sync-item-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.sync-item-actions .sync-chosen { outline: 2px solid var(--accent); outline-offset: 1px; }

.sync-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 0.9rem;
}
.sync-progress { font-size: 0.85rem; color: var(--text-muted); }

/* Bulk decision shortcuts above the item list. */
.sync-bulk { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; margin-bottom: 0.6rem; }
.sync-bulk button { font-size: 0.8rem; padding: 0.35rem 0.8rem; }

/* The per-item Diff button sits alone in the bottom-right corner of the panel. */
.sync-diff-btn { margin-left: auto; }

/* The final type-the-name confirmation stacks on top of the (already overlaid) review modal. */
.sync-confirm-overlay { z-index: 110; }

/* ---- the Markdown content diff modal (stacks on top of the review modal) ---- */
.sync-diff-overlay { z-index: 110; }

.sync-diff-card {
    max-width: min(1300px, 96vw);
    width: 96vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1.6rem;
}

.sync-diff-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 0.8rem; }
.sync-diff-head h3 { margin: 0 0 0.35rem; }

.sync-diff-legend { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--text-muted); margin: 0; }
.sync-diff-swatch { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 3px; }
.sync-diff-swatch-del { background: #fee2e2; border: 1px solid #fca5a5; }
.sync-diff-swatch-add { background: #dcfce7; border: 1px solid #86efac; margin-left: 0.8rem; }

.sync-diff-pdf-note { margin-left: 1rem; font-style: italic; }

.sync-diff-status { color: var(--text-muted); margin: 0.5rem 0 0; }

.sync-diff-body { flex: 1 1 auto; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }

.sync-diff-table {
    width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
}
.sync-diff-table td { padding: 0 0.6rem; vertical-align: top; }
.sync-diff-num {
    width: 3.2rem;
    min-width: 3.2rem;
    text-align: right;
    color: var(--text-muted);
    user-select: none;
    border-right: 1px solid var(--border);
    background: var(--surface-2);
}
.sync-diff-text { white-space: pre-wrap; word-break: break-word; }
.sync-diff-add td { background: #dcfce7; }
.sync-diff-add .sync-diff-num { background: #bbf7d0; }
.sync-diff-del td { background: #fee2e2; }
.sync-diff-del .sync-diff-num { background: #fecaca; }
.sync-diff-collapsed td { color: var(--text-muted); font-style: italic; text-align: center; padding: 0.15rem 0.6rem; }

/* ---- Tenants page: operation status banner (sync/extract/delete results) + staging last-sync info ---- */
.tenant-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 0.9rem;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
    border: 1px solid;
}
.tenant-banner-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.tenant-banner-error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

.tenant-banner-close {
    flex: 0 0 auto;
    border: none;
    background: none;
    color: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0.7;
    padding: 0.1rem 0.3rem;
}
.tenant-banner-close:hover { opacity: 1; }

.tenant-last-sync { font-size: 0.74rem; color: var(--text-muted); margin-top: 0.3rem; white-space: nowrap; }

/* ---- AI context preview modal (Settings -> Ask AI / Widget -> Master prompt) ---- */
.ctx-note { margin: 0 0 0.7rem; }
.ctx-scroll { padding: 0.5rem; }
.ctx-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: var(--surface);
}
.ctx-item:last-child { margin-bottom: 0; }
.ctx-item > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.75rem;
    cursor: pointer;
    padding: 0.55rem 0.8rem;
    list-style: none;
}
.ctx-item > summary::before { content: "▸"; color: var(--text-muted); font-size: 0.75rem; }
.ctx-item[open] > summary::before { content: "▾"; }
.ctx-item-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
}
.ctx-item-title { font-weight: 600; font-size: 0.9rem; }
.ctx-item-stats { margin-left: auto; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
.ctx-item-note { background: transparent; border-style: dashed; }
.ctx-pre {
    margin: 0;
    padding: 0.7rem 0.8rem;
    border-top: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.76rem;
    line-height: 1.45;
    max-height: 26rem;
    overflow: auto;
}
