/* Mira Management Portal — shared styles */

/* ---- Design tokens ---- */
:root {
    --color-primary: #1e3a5f;
    --color-header-bg: #51534A;
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1a1a2e;
    --color-text-muted: #64748b;
    --color-accent: #2d5280;
    --color-success: #16a34a;
    --color-warning: #ca8a04;
    --color-danger: #dc2626;
    --color-tier-1: #0891b2;
    --color-tier-2: #7c3aed;
    --color-tier-3: #b45309;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Portal header ---- */
.portal-header {
    background: var(--color-header-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.portal-header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.portal-header-brand .brand-name {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.portal-header-brand .brand-subtitle {
    font-size: 13px;
    font-weight: 400;
    opacity: 0.75;
}

.portal-header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.portal-header-user .user-name {
    font-weight: 500;
}

.portal-header-user a {
    color: rgba(255,255,255,0.8);
    font-size: 13px;
}
.portal-header-user a:hover { color: #fff; }

/* ---- Sidebar navigation ---- */
.portal-layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

.portal-nav {
    width: 220px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 16px 0;
    flex-shrink: 0;
}

.portal-nav a {
    display: block;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-muted);
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
}
.portal-nav a:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}
.portal-nav a.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    background: #eef2f7;
}
.portal-nav a.disabled {
    color: #c0c4cc;
    cursor: default;
    pointer-events: none;
}

/* ---- Nav group (collapsible) ---- */
.nav-group {
    margin-top: 4px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-muted);
    background: none;
    border: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background 0.15s, color 0.15s;
}

.nav-group-toggle:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.nav-group-arrow {
    font-size: 12px;
    transition: transform 0.15s;
}

.nav-group-items a {
    padding-left: 40px;
}

/* ---- Main content ---- */
.portal-main {
    flex: 1;
    padding: 32px 40px;
    min-width: 0;    /* prevents flex overflow with long content */
}

/* ---- Content width wrappers (per-page max-width inside .portal-main) ---- */
.content-narrow,
.content-medium,
.content-wide {
    margin: 0 auto;
    width: 100%;
}
.content-narrow { max-width: 900px; }
.content-medium { max-width: 1000px; }
.content-wide { max-width: 1200px; }

/* Chat is a height-flex column — the wrapper has to participate in the chain
   so .chat-container's flex:1 still resolves to the full available height. */
.chat-main > .content-narrow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.portal-main h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--color-text);
}

/* ---- Cards ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    padding: 20px 24px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

/* ---- Tier badge ---- */
.tier-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
    white-space: nowrap;
}
.tier-badge.tier-0 { background: #e0f2fe; color: #0369a1; }
.tier-badge.tier-1 { background: #ecfdf5; color: var(--color-tier-1); }
.tier-badge.tier-2 { background: #f3e8ff; color: var(--color-tier-2); }
.tier-badge.tier-3 { background: #fffbeb; color: var(--color-tier-3); }

/* ---- Assistant cards ---- */
.assistant-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 20px;
}

.assistant-card + .assistant-card {
    border-top: 1px solid var(--color-border);
}

.assistant-card .assistant-info { flex: 1; min-width: 0; }

.assistant-card .assistant-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.assistant-card .assistant-desc {
    font-size: 13px;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.assistant-card .assistant-channel {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.template-tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 8px;
    border-radius: 4px;
    background: #e8f0fe;
    color: #1a56db;
    vertical-align: middle;
    margin-left: 4px;
}

.assistant-card .assistant-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ---- Status dot ---- */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.active { background: var(--color-success); }
.status-dot.inactive { background: #94a3b8; }

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--color-text-muted);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 15px;
    max-width: 360px;
    margin: 0 auto;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-accent); }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }

a.btn:hover {
    text-decoration: none;
}

.btn:disabled, .btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Loading / spinner ---- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast notifications ---- */
.toast-container {
    position: fixed;
    top: 72px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ---- Error card ---- */
.error-card {
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 8px;
    padding: 20px 24px;
    text-align: center;
    color: var(--color-danger);
}

.error-card p { margin-bottom: 12px; }

/* ---- Sign-in page (standalone centered layout) ---- */
.signin-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.signin-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.signin-card .brand-logo {
    font-size: 28px;
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.signin-card h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.signin-card .tagline {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 32px;
}

.signin-card .signin-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 15px;
}

.signin-card .signin-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.signin-message {
    margin-top: 24px;
    font-size: 14px;
    padding: 12px 16px;
    border-radius: 8px;
}

.signin-message.error {
    background: #fee2e2;
    color: #991b1b;
}

.signin-message.info {
    background: #e0f2fe;
    color: #0c4a6e;
}

/* ---- Responsive: sidebar collapses to top nav ---- */
@media (max-width: 767px) {
    .portal-layout { flex-direction: column; }

    .portal-nav {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 8px 0;
        display: flex;
        overflow-x: auto;
    }

    .portal-nav a {
        border-left: none;
        border-bottom: 3px solid transparent;
        padding: 8px 16px;
        white-space: nowrap;
    }
    .portal-nav a.active {
        border-bottom-color: var(--color-primary);
        border-left-color: transparent;
    }

    .portal-main { padding: 20px 16px; }

    .portal-header {
        padding: 0 16px;
    }

    .portal-header-brand .brand-subtitle { display: none; }
}

/* Draft tag */
.draft-tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 8px;
    border-radius: 4px;
    background: #fef3c7;
    color: #92400e;
    vertical-align: middle;
    margin-left: 4px;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: var(--color-surface, #fff);
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-card h2 {
    margin: 0 0 4px 0;
    font-size: 1.25rem;
}

.modal-subtitle {
    color: var(--color-text-secondary, #6b7280);
    font-size: 0.9rem;
    margin: 0 0 20px 0;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 6px;
}

.form-group .required {
    color: #dc2626;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-input {
    resize: vertical;
}

.form-error {
    color: #dc2626;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* Sibling of .form-error for success/confirmation messages. Same shape,
   green hue. Used in the Phase 45.2 section-management modal. */
.form-success {
    color: #15803d;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* Edit page */
.edit-section {
    margin-bottom: 16px;
    padding: 20px 24px;
}

.edit-section h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    font-weight: 600;
}

.detail-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border-light, #f3f4f6);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    width: 180px;
    flex-shrink: 0;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text-secondary, #6b7280);
}

.detail-value {
    font-size: 0.875rem;
    color: var(--color-text, #1a1a2e);
}

.text-muted {
    color: var(--color-text-secondary, #9ca3af);
}

/* Status badges */
.status-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 10px;
    border-radius: 4px;
    margin-left: 12px;
    vertical-align: middle;
}

.status-badge.draft {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.published {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.template {
    background: #e8f0fe;
    color: #1a56db;
}

.publish-note {
    font-size: 0.85rem;
    color: var(--color-text-secondary, #6b7280);
    margin-left: 12px;
}

/* Toast styles */
.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: toast-in 0.3s ease forwards;
}

.toast.success {
    background: #d1fae5;
    color: #065f46;
}

.toast.error {
    background: #fee2e2;
    color: #991b1b;
}

.toast.info {
    background: #e8f0fe;
    color: #1a56db;
}

.toast.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Toggle label for checkbox */
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.875rem;
}

.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Form input within detail rows */
.detail-value .form-input {
    margin: 0;
}

/* Button small variant */
.btn-sm {
    padding: 4px 12px;
    font-size: 13px;
}

/* Section description */
.section-description {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

/* Tools multi-select grid */
.tools-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.tool-item:hover {
    background: var(--color-bg);
}

.tool-item:has(input:checked) {
    border-color: var(--color-primary);
    background: #eef2f7;
}

.tool-item input[type="checkbox"] {
    margin-top: 2px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

.tool-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-name {
    font-size: 0.875rem;
    font-weight: 500;
}

.tool-desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---- Specialist items ---- */
.specialist-item {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 10px;
    background: var(--color-surface);
    transition: border-color 0.15s;
}

.specialist-item:hover {
    border-color: var(--color-primary);
}

.specialist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.specialist-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.specialist-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.specialist-fields {
    border-top: 1px solid var(--color-border);
    padding-top: 8px;
}

.specialist-fields .detail-row {
    padding: 4px 0;
}

.specialist-fields .detail-label {
    font-size: 0.8rem;
}

.specialist-fields textarea.form-input {
    font-size: 0.85rem;
    min-height: 48px;
}

/* ---- Edit page header ---- */
.edit-header {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px 8px 0 0;
    padding: 20px 24px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.edit-header-row1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.edit-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.edit-header-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.edit-header-meta strong {
    color: var(--color-text);
    font-weight: 500;
}

.meta-sep {
    color: var(--color-border);
}

.edit-header-description {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 10px;
}

.edit-header-description .detail-label {
    padding-top: 6px;
}

/* ---- Tab bar ---- */
.edit-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 3px solid var(--color-border);
    margin-top: 12px;
}

.edit-tab {
    padding: 14px 20px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.edit-tab:hover {
    color: var(--color-text);
}

.edit-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ---- Tab content ---- */
.edit-tab-content {
    padding: 16px 0;
}

/* ---- Phase 40: tab intro banner + cross-tab status indicator ---- */
.tab-intro-banner {
    background: var(--color-bg-subtle, #f5f7fa);
    border-left: 3px solid var(--color-accent);
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}
.tab-intro-banner p { margin: 0; }

.cross-tab-status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--color-bg-subtle, #f5f7fa);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}
.cross-tab-status-label { color: var(--color-text-muted); }
.cross-tab-status-detail { color: var(--color-text-muted); flex: 1; }
.cross-tab-status-link { color: var(--color-accent); text-decoration: none; white-space: nowrap; }
.cross-tab-status-link:hover { text-decoration: underline; }

.highlight-target {
    background: var(--color-highlight, #fff3cd) !important;
    transition: background 0.3s ease;
}

/* ---- Toggle switch (pill style) ---- */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    border-radius: 20px;
    transition: background-color 0.2s;
}

.switch-slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch input:checked + .switch-slider {
    background-color: var(--color-primary);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(16px);
}

.switch-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

/* ---- Large textarea for prompts ---- */
.form-textarea-lg {
    min-height: 300px;
    resize: vertical;
}

/* ---- Content folders table ---- */
.folders-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.folders-table th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.folders-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
}

/* ---- Index status indicators ---- */
.index-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: default;
}
.index-status.ok {
    background: var(--color-green-bg, #e6f4ea);
    color: var(--color-green-text, #1e7e34);
}
.index-status.error {
    background: var(--color-red-bg, #fce8e6);
    color: var(--color-red-text, #c62828);
}
.index-status.indexing {
    background: var(--color-yellow-bg, #fff8e1);
    color: var(--color-yellow-text, #f57f17);
}
.index-status.pending {
    background: var(--color-muted-bg, #f0f0f0);
    color: var(--color-text-muted);
}

/* ---- Tooltip icon ---- */
.tooltip-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    font-size: 14px;
    color: var(--color-text-muted);
    cursor: help;
    margin-left: 4px;
}

/* ---- Required asterisk ---- */
.required {
    color: #dc2626;
}

/* ---- Danger button ---- */
.btn-danger {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}
.btn-danger:hover {
    background: #b91c1c;
}

/* ---- Category badge ---- */
.category-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}
.category-badge.institutional {
    background: #dbeafe;
    color: #1e40af;
}
.category-badge.case {
    background: #fef3c7;
    color: #92400e;
}

/* ---- Channel indicator ---- */
.channel-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
}
.channel-indicator.active {
    background: #22c55e;
}

/* ---- Folder row actions ---- */
.folder-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.folder-actions button {
    padding: 3px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.15s;
}
.folder-actions button:hover {
    background: var(--color-bg);
}
.folder-actions button.delete:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}

/* ---- Folder browser (SharePoint picker) ---- */
.folder-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    min-height: 24px;
}
.folder-breadcrumb .crumb {
    cursor: pointer;
    color: var(--color-primary);
    text-decoration: none;
}
.folder-breadcrumb .crumb:hover {
    text-decoration: underline;
}
.folder-breadcrumb .sep {
    margin: 0 2px;
    color: var(--color-text-muted);
}

.folder-list {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
}
.folder-list .folder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.1s;
}
.folder-list .folder-item:last-child {
    border-bottom: none;
}
.folder-list .folder-item:hover {
    background: var(--color-bg);
}
.folder-list .folder-item .folder-icon {
    margin-right: 8px;
    color: var(--color-text-muted);
}
.folder-list .folder-item .folder-select-btn {
    font-size: 0.75rem;
    padding: 2px 8px;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    background: transparent;
    color: var(--color-primary);
    cursor: pointer;
    transition: background 0.1s;
}
.folder-list .folder-item .folder-select-btn:hover {
    background: var(--color-primary);
    color: #fff;
}
.folder-list .empty-msg {
    padding: 16px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}
.folder-list .loading-msg {
    padding: 12px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.folder-selection {
    margin-top: 8px;
    padding: 8px 12px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #065f46;
}

.folder-selected-summary {
    padding: 10px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    color: var(--color-text-secondary);
}

/* ---- Responsive: tabs scroll on mobile ---- */
@media (max-width: 767px) {
    .edit-header-row1 {
        flex-direction: column;
        align-items: stretch;
    }
    .edit-header-actions {
        flex-wrap: wrap;
    }
    .edit-header-description {
        flex-direction: column;
    }
    .edit-tab {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* ---- Chat page ---- */

.chat-main {
    max-width: none;
    padding-top: 14px;
    padding-bottom: 0;
    /* Make chat-main itself the height-constrained flex parent so chat-container
       can fill it exactly via flex:1. Avoids the old fragile
       calc(100vh - 56px - <guess at header>) that broke whenever the
       header height changed. */
    height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-assistant-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--font-family);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
}

/* ---- Chat sidebar ---- */
.chat-sidebar {
    width: 280px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.chat-sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.chat-sidebar-empty {
    padding: 24px 16px;
    color: var(--color-text-muted);
    font-size: 13px;
    text-align: center;
}

.chat-sidebar-group-label {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text);
    transition: background 0.1s;
    border-left: 3px solid transparent;
    position: relative;
}

.chat-session-item:hover {
    background: var(--color-bg);
}

.chat-session-item.active {
    background: #eef2f7;
    border-left-color: var(--color-primary);
    font-weight: 500;
}

.chat-session-item .session-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-session-item .session-delete {
    display: none;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-session-item:hover .session-delete {
    display: block;
}

.chat-session-item .session-delete:hover {
    color: var(--color-danger, #dc2626);
    background: #fee2e2;
}

/* --- Session search --- */
.chat-session-search {
    width: 100%;
    padding: 6px 10px;
    margin-top: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}
.chat-session-search:focus {
    border-color: var(--color-primary);
}

/* --- Session rename inline input --- */
.session-rename-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid var(--color-primary);
    border-radius: 3px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

/* --- Chat header bar (two stacked rows: info row, then name row) --- */
.chat-header-bar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background: var(--color-surface);
}

.chat-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    min-height: 30px;
}

.chat-header-row-info {
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.chat-header-row-name {
    background: #eef2f7;
    border-bottom: 1px solid var(--color-border);
}

.chat-header-description {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--color-text);
    font-weight: 500;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
    text-align: left;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.chat-header-name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-name:hover {
    background: #ffffff;
}

/* Container for buttons rendered to the right of the chat name */
.header-name-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.chat-token-header-btn {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chat-token-header-btn:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: #ffffff;
}

.chat-header-rename {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 2px 8px;
    outline: none;
    width: 100%;
    max-width: 360px;
    background: #fff;
}

.chat-header-rename:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.15);
}

.chat-header-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-header-badge.draft {
    background: #fef3c7;
    color: #92400e;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.chat-header-badge.indexing {
    background: #dbeafe;
    color: #1e40af;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 0;
    scroll-behavior: smooth;
    max-width: 820px;    /* readable conversation column (~80 chars/line) */
    width: 100%;
    margin: 0 auto;
}

/* Message bubbles */
.chat-message {
    display: flex;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.assistant,
.chat-message.error {
    justify-content: flex-start;
}

.chat-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.55;
    font-size: 14px;
    word-break: break-word;
}

.chat-message.user .chat-bubble {
    background: var(--color-header-bg);
    color: #fff;
    max-width: 75%;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    max-width: 85%;
    border-bottom-left-radius: 4px;
}

.chat-message.error .chat-bubble {
    background: #fee2e2;
    color: #991b1b;
    max-width: 85%;
    border-bottom-left-radius: 4px;
}

/* HTML content inside assistant bubbles */
.chat-message.assistant .chat-bubble p { margin: 0 0 8px; }
.chat-message.assistant .chat-bubble p:last-child { margin-bottom: 0; }
.chat-message.assistant .chat-bubble ul,
.chat-message.assistant .chat-bubble ol { margin: 4px 0 8px 20px; }
.chat-message.assistant .chat-bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.chat-message.assistant .chat-bubble th,
.chat-message.assistant .chat-bubble td { border: 1px solid var(--color-border); padding: 4px 8px; }
.chat-message.assistant .chat-bubble th { background: var(--color-bg); font-weight: 600; }
.chat-message.assistant .chat-bubble a { color: var(--color-primary); text-decoration: underline; }

/* Input area */
.chat-input-area {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
    padding-bottom: 4px;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-attach-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    color: #555;
    padding: 0;
    transition: background 0.15s;
}
.chat-attach-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.chat-textarea {
    flex: 1;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font-family);
    line-height: 1.5;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    resize: none;
    overflow-y: auto;
    /* min-height matches the previous rows="4" default rendering
       (4 × 14px × 1.5 line-height + 20px padding + 2px border = 106px),
       so the textarea never visually shrinks on the first keystroke when
       autoResizeTextarea resets style.height to "auto". max-height caps
       growth at 40% of viewport; beyond that overflow-y handles scroll. */
    min-height: 106px;
    max-height: 40vh;
    background: var(--color-surface);
    color: var(--color-text);
}

.chat-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.12);
}

.chat-send-btn {
    height: 40px;
    padding: 0 20px;
    flex-shrink: 0;
}

/* Attachment chips above input */
.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 0;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f0f0f0;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 4px 8px 4px 10px;
    font-size: 12px;
    max-width: 220px;
}

.attachment-chip-icon {
    flex-shrink: 0;
}

.attachment-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}

.attachment-chip-size {
    color: var(--color-text-muted);
    flex-shrink: 0;
    font-size: 11px;
}

.attachment-chip-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}
.attachment-chip-remove:hover {
    color: #c00;
}

/* Upload modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    padding: 0;
    line-height: 1;
}
.modal-close:hover {
    color: #333;
}

.upload-drop-zone {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 32px;
    text-align: center;
    color: #888;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.upload-drop-zone.drag-over {
    border-color: var(--color-primary);
    background: #f0f7ff;
}
.upload-drop-zone p {
    margin: 0;
}

.upload-browse-link {
    color: var(--color-primary);
    cursor: pointer;
    text-decoration: underline;
}

.upload-limits {
    margin-top: 12px;
    font-size: 12px;
    color: #888;
    line-height: 1.6;
}

.upload-progress {
    margin-top: 16px;
}

.upload-progress-filename {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-progress-bar-track {
    height: 6px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-progress-status {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
}

.upload-error {
    margin-top: 12px;
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    color: #dc2626;
    font-size: 13px;
}

/* --- Chat input buttons (attach + mic, stacked vertically) --- */
.chat-input-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    align-self: flex-end;
}

.chat-mic-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    color: #555;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}
.chat-mic-btn:hover {
    background: #e0e0e0;
    color: #333;
}
.chat-mic-btn.voice-active {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

/* --- Token tracking bar (now under the chat header row, full width) --- */
.chat-token-bar {
    border-top: 1px solid var(--color-border);
    background: #eef2f7;
    font-size: 12px;
    color: #888;
}

.token-bar-summary {
    padding: 6px 12px;
    cursor: pointer;
}
.token-bar-summary:hover {
    color: #555;
    background: #f0f0f0;
    border-radius: 6px;
}

.token-bar-details {
    padding: 4px 12px 8px 12px;
    border-top: 1px solid #eee;
}

.token-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 12px;
    color: #666;
}

/* Welcome / empty states */
.chat-welcome,
.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--color-text-muted);
    font-size: 15px;
    text-align: center;
    padding: 40px;
}

/* Typing indicator */
.chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px 20px;
}

.chat-typing .dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.chat-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    font-style: italic;
    color: var(--color-text-muted);
}

.chat-status-text {
    font-size: 14px;
}

.chat-status-dots {
    display: inline-flex;
    gap: 4px;
}

.chat-status-dots .dot {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-status-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-status-dots .dot:nth-child(3) { animation-delay: 0.3s; }

/* ---- Portal chat dialog forms (ask_user) ---- */
.chat-dialog-form {
    max-width: 85%;
}

.dialog-question {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}

.dialog-question:last-of-type {
    border-bottom: none;
    margin-bottom: 12px;
    padding-bottom: 0;
}

.dialog-context {
    font-size: 12px;
    color: var(--color-text-muted);
    font-style: italic;
    margin-bottom: 6px;
}

.dialog-question-text {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.dialog-radio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.dialog-radio-row:hover {
    background: var(--color-bg);
}

.dialog-radio-row input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

.dialog-text-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 13px;
    resize: vertical;
}

.dialog-text-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.12);
}

.dialog-submit-btn {
    margin-top: 4px;
}

/* ---- Action button links in chat responses ---- */
.chat-message.assistant .chat-bubble a.action-btn {
    display: inline-block;
    background: var(--color-primary);
    color: #fff;
    padding: 8px 20px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 14px;
    text-decoration: none;
    margin-top: 8px;
}

.chat-message.assistant .chat-bubble a.action-btn:hover {
    background: var(--color-accent);
    text-decoration: none;
}

/* ---- Assistant-message action row (Copy + Read-aloud) ----
   Sits beneath assistant response bubbles. NOT rendered for user
   messages, error bubbles, typing/status indicators, or dialog forms. */
.chat-message-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-left: 4px;
}

.chat-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-action-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.chat-action-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.chat-action-btn.copied {
    color: #16a34a;
}

.chat-action-btn.speaking {
    color: var(--color-primary);
}

/* ---- Chat-area drag-and-drop overlay (Phase 46 Item 5) ----
   Shown by chat.js when a drag carrying files enters .chat-main.
   Document-level dragover/drop handlers preventDefault so the browser
   never navigates to a stray-dropped file anywhere on the portal. */
.chat-drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(30, 58, 95, 0.08);
    border: 2px dashed var(--color-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    pointer-events: none;
    /* Hidden by default; chat.js toggles display via the .visible class
       so child-element dragenter/dragleave events don't flicker the
       overlay (a counter in chat.js manages enter/leave parity). */
    display: none;
}

.chat-drop-overlay.visible {
    display: flex;
}

.chat-drop-overlay-label {
    background: var(--color-primary);
    color: #fff;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
}

/* The chat-main container must be the positioning ancestor for the
   overlay's position:absolute inset:0. Other portal pages don't have
   .chat-main, so this rule is chat-only. */
.chat-main {
    position: relative;
}

/* ---- Chat welcome content (builder) ---- */
.chat-welcome .welcome-content {
    text-align: left;
    max-width: 560px;
}

.chat-welcome .welcome-content h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.chat-welcome .welcome-content p {
    font-size: 14px;
    color: var(--color-text);
    margin-bottom: 12px;
    line-height: 1.6;
}

.chat-welcome .welcome-section {
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--color-text);
    line-height: 1.6;
}

.chat-welcome .welcome-section strong {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}

.chat-welcome .welcome-section ol,
.chat-welcome .welcome-section ul {
    margin: 4px 0 0 20px;
}

.chat-welcome .welcome-section li {
    margin-bottom: 2px;
}

/* Chat responsive */
@media (max-width: 767px) {
    .chat-sidebar { display: none; }
    .chat-main { padding: 12px 12px 0; height: calc(100vh - 56px); }
    .chat-container { height: auto; }
    .chat-message.user .chat-bubble { max-width: 90%; }
    .chat-message.assistant .chat-bubble { max-width: 90%; }
    /* Tighter textarea cap on mobile so a grown textarea doesn't
       collide with the on-screen keyboard. */
    .chat-textarea { max-height: 30vh; }
}

/* ---- Help icon in portal header ---- */
.portal-header-user .help-link {
    color: rgba(255, 255, 255, 0.8);
    display: inline-flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
.portal-header-user .help-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
}
.portal-header-user .help-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* ---- Generic create-flow choice dialog ---- */
.create-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.create-dialog {
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    width: 100%;
    max-width: 460px;
    overflow: hidden;
    font-family: var(--font-family);
}

.create-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.create-dialog-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.create-dialog-close {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.create-dialog-close:hover { color: var(--color-text); }

.create-dialog-body {
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.create-dialog-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 12px 14px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.create-dialog-option:hover {
    border-color: var(--color-primary);
    background: #f8fafc;
    box-shadow: 0 2px 8px rgba(30, 58, 95, 0.06);
}

.create-dialog-option-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 2px;
}

.create-dialog-option-description {
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* ---- Help page layout ---- */
.help-main {
    /* Pin the main area to the viewport so the sidebar stays put while
       help content scrolls independently. Same pattern .chat-main uses. */
    height: calc(100vh - 56px);
    overflow-y: auto;
}

.help-search-wrapper {
    margin-bottom: 20px;
}

.help-search-input {
    width: 100%;
    max-width: 500px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.help-search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}

.help-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.help-category-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.help-category-heading {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.help-doc-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 14px 18px;
    color: var(--color-text);
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.help-doc-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(30, 58, 95, 0.08);
    text-decoration: none;
}

.help-doc-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.help-doc-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-primary);
}

.help-doc-assistant-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #eef2f7;
    color: var(--color-accent);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.help-doc-summary {
    font-size: 14px;
    color: var(--color-text);
    margin-top: 4px;
    line-height: 1.5;
}

.help-doc-meta {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 6px;
}

.help-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
}

/* ---- Help article mode ---- */
.help-breadcrumb {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}
.help-breadcrumb a {
    color: var(--color-text-muted);
}
.help-breadcrumb a:hover {
    color: var(--color-primary);
}
.help-breadcrumb-category {
    color: var(--color-text-muted);
}

#help-article > h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 16px;
}

.help-article-body {
    max-width: 760px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--color-text);
}
.help-article-body h1,
.help-article-body h2,
.help-article-body h3 {
    margin-top: 24px;
    margin-bottom: 10px;
    color: var(--color-text);
}
.help-article-body h2 { font-size: 20px; font-weight: 600; }
.help-article-body h3 { font-size: 16px; font-weight: 600; }
.help-article-body p { margin-bottom: 12px; }
.help-article-body ul,
.help-article-body ol { margin-bottom: 12px; padding-left: 24px; }
.help-article-body li { margin-bottom: 4px; }
.help-article-body code {
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
}
.help-article-body pre {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 12px;
}
.help-article-body pre code {
    background: transparent;
    padding: 0;
}
.help-article-body a {
    color: var(--color-primary);
    text-decoration: underline;
}
.help-article-body img {
    max-width: 100%;
    border-radius: 6px;
}
.help-article-body blockquote {
    border-left: 3px solid var(--color-primary);
    padding: 6px 14px;
    color: var(--color-text-muted);
    margin: 12px 0;
    background: #f8f9fa;
}

.help-article-footer {
    max-width: 760px;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.help-meta {
    font-size: 12px;
    color: var(--color-text-muted);
}
.help-back-link {
    font-size: 13px;
    color: var(--color-primary);
}

.help-error {
    padding: 30px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

/* ---- Chat page per-assistant help flyout ---- */
.chat-assistant-help-wrapper {
    position: relative;
    margin-left: 8px;
}
.chat-assistant-help-btn {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.chat-assistant-help-btn:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: #eef2f7;
}
.chat-assistant-help-flyout {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    min-width: 260px;
    max-width: 320px;
    z-index: 50;
    padding: 6px 0;
}
.chat-assistant-help-flyout a {
    display: block;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--color-text);
    text-decoration: none;
    border-bottom: 1px solid var(--color-border);
}
.chat-assistant-help-flyout a:last-child { border-bottom: none; }
.chat-assistant-help-flyout a:hover {
    background: #f3f4f6;
    color: var(--color-primary);
}
.chat-assistant-help-flyout-title {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}
.chat-assistant-help-flyout-summary {
    display: block;
    font-size: 11px;
    color: var(--color-text-muted);
}

/* Help page responsive */
@media (max-width: 767px) {
    .help-search-input { max-width: 100%; }
}

/* --- Voice input overlay + transcribing indicator --- */
.chat-textarea-wrap {
    /* Positioning container for the voice overlay (#voice-input-overlay
       is position:absolute and anchors here). flex: 1 lets the wrap take
       the remaining horizontal space in .chat-input-row.

       Intentionally NOT a flex container. Phase 46 regression cause: when
       the wrap was display:flex;flex-direction:column and the inner
       textarea had flex:1 (== flex:1 1 0%), the textarea's flex-basis:0%
       overrode its inline style.height in the main axis, so the wrap
       never grew with the JS-set height. */
    position: relative;
    flex: 1;
}

.chat-textarea-wrap .chat-textarea {
    /* width 100% so the textarea fills the wrap horizontally;
       box-sizing border-box so padding/border don't push it out.
       NO flex declaration here — the textarea is a block child of a
       non-flex wrap, so its inline style.height is authoritative. */
    width: 100%;
    box-sizing: border-box;
}

.voice-input-overlay {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.voice-overlay-waveform {
    flex: 1;
    height: 32px;
    min-width: 0;
    background: #f8fafc;
    border-radius: 4px;
}

.voice-overlay-timer {
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    color: var(--color-text-muted);
    min-width: 36px;
    text-align: center;
}

.voice-overlay-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.05s;
}

.voice-overlay-btn:active {
    transform: scale(0.95);
}

.voice-overlay-cancel {
    background: #f3f4f6;
    color: #6b7280;
}
.voice-overlay-cancel:hover {
    background: #e5e7eb;
    color: #374151;
}

.voice-overlay-submit {
    background: var(--color-primary);
    color: #ffffff;
}
.voice-overlay-submit:hover {
    background: #16315a;
}

.voice-transcribing {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--color-text-muted);
    z-index: 10;
}

.voice-transcribing-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #d1d5db;
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: voice-spin 0.8s linear infinite;
}

@keyframes voice-spin {
    to { transform: rotate(360deg); }
}

/* --- Contextual voice toasts (anchored above .chat-input-area) ---
   Distinct from the global #toast-container in the upper-right. */
.voice-toast-container {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    pointer-events: none;
    z-index: 20;
}

.voice-toast {
    pointer-events: auto;
    max-width: 540px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
    border: 1px solid;
    background: var(--color-surface);
    color: var(--color-text);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.voice-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.voice-toast.info {
    background: #eef2f7;
    border-color: #c7d2e0;
    color: var(--color-text);
}

.voice-toast.error {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}
