:root {
    --router-primary: #0d6efd;
    --router-bg: #f6f7fb;
    --router-panel: #ffffff;
    --router-border: #d9dee8;
    --router-text: #1f2937;
}

body {
    background: var(--router-bg);
    color: var(--router-text);
}

.router-login-body {
    background: linear-gradient(135deg, #f6f7fb 0%, #eef4f8 52%, #f4f6f2 100%);
}

.router-login-card,
.card,
.btn,
.form-control,
.form-select,
.alert {
    border-radius: 0.5rem;
}

.router-logo-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--router-primary);
    color: #fff;
    font-weight: 700;
    font-size: 1.3rem;
}

.navbar-brand,
.nav-link,
.btn {
    letter-spacing: 0;
}

.table th {
    color: #5b6472;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}

.table td {
    white-space: nowrap;
}

.form-text,
dd {
    color: #6c757d;
}

textarea.form-control {
    min-height: 6rem;
}

.chat-page {
    overflow: hidden;
}

.chat-shell {
    height: calc(100vh - 57px);
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    background: var(--router-bg);
}

.chat-sidebar {
    background: #ffffff;
    border-right: 1px solid var(--router-border);
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-history {
    overflow-y: auto;
    padding: 0.75rem;
}

.chat-history-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 0.65rem 0.75rem;
    border-radius: 0.5rem;
    color: #374151;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-history-item:hover,
.chat-history-item.active {
    background: #eef4ff;
    color: #0d6efd;
}

.chat-main {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: #ffffff;
}

.chat-topbar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #ffffff;
}

.chat-messages {
    overflow-y: auto;
    padding: 1.25rem;
    background: #fbfcfe;
}

.empty-chat {
    max-width: 42rem;
    margin: 12vh auto 0;
    text-align: center;
    color: #6b7280;
    font-size: 1.05rem;
}

.chat-message {
    display: flex;
    margin-bottom: 1rem;
}

.chat-message-user {
    justify-content: flex-end;
}

.chat-message-assistant {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: min(760px, 86%);
    padding: 0.8rem 1rem;
    border-radius: 0.75rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.chat-message-user .chat-bubble {
    background: #0d6efd;
    color: #ffffff;
}

.chat-message-assistant .chat-bubble {
    background: #ffffff;
    border: 1px solid var(--router-border);
}

.chat-bubble pre {
    background: #111827;
    color: #f9fafb;
    padding: 0.85rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.75rem 0 0;
}

.chat-input {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--router-border);
    background: #ffffff;
}

.chat-input textarea {
    min-height: 52px;
    max-height: 180px;
    resize: vertical;
}

@media (max-width: 991.98px) {
    .chat-shell {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        position: fixed;
        z-index: 1050;
        top: 57px;
        bottom: 0;
        left: 0;
        width: min(86vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0.5rem 0 1.5rem rgba(15, 23, 42, 0.16);
    }

    .chat-sidebar.show {
        transform: translateX(0);
    }

    .chat-topbar {
        flex-wrap: wrap;
    }

    .chat-input {
        grid-template-columns: 1fr;
    }

    .chat-bubble {
        max-width: 94%;
    }
}

.usage-progress {
    height: 0.5rem;
    background: #e9edf5;
}

.chat-usage-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--router-border);
    background: #f8fafc;
    color: #64748b;
    font-size: 0.88rem;
}

.no-model-warning {
    max-width: 44rem;
    margin: 12vh auto 0;
}

.typing-dot {
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    margin-right: 0.25rem;
    border-radius: 50%;
    background: #6b7280;
    animation: typingPulse 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typingPulse {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

.code-block {
    position: relative;
    margin-top: 0.75rem;
}

.copy-code-btn {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    border: 1px solid #374151;
    background: #1f2937;
    color: #f9fafb;
    border-radius: 0.35rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
}

.copy-code-btn:hover {
    background: #374151;
}

.model-access-table input,
.model-access-table select {
    min-width: 7rem;
}

.admin-form-note {
    color: #64748b;
    font-size: 0.9rem;
}

.payment-proof-preview {
    display: block;
    max-width: 100%;
    max-height: 260px;
    object-fit: contain;
    border: 1px solid var(--router-border);
    border-radius: 0.5rem;
    background: #fff;
}

.invoice-page {
    background: #ffffff;
}

.invoice-sheet {
    max-width: 900px;
    margin: 0 auto;
    background: #ffffff;
}

@media print {
    body {
        background: #ffffff;
    }

    .no-print,
    .navbar {
        display: none !important;
    }

    .invoice-sheet {
        box-shadow: none !important;
        border: 0 !important;
    }
}

.model-description {
    max-width: 38rem;
}

.model-sync-table td,
.model-access-table td {
    vertical-align: top;
}

.model-sync-table code,
.model-access-table code {
    white-space: normal;
    overflow-wrap: anywhere;
}

.chat-attachments-panel {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--router-border);
    background: #ffffff;
}

.attachment-help {
    color: #64748b;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.attachment-pill,
.message-attachments span {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid var(--router-border);
    border-radius: 0.5rem;
    background: #f8fafc;
    color: #334155;
    padding: 0.35rem 0.55rem;
    font-size: 0.84rem;
}

.attachment-pill button {
    border: 0;
    background: transparent;
    color: #b42318;
    padding: 0;
    font: inherit;
}

.chat-input {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.chat-input-tools {
    display: flex;
    align-items: end;
}

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.65rem;
}

@media (max-width: 991.98px) {
    .chat-input {
        grid-template-columns: 1fr;
    }

    .chat-input-tools {
        align-items: stretch;
    }
}

.chat-sidebar-head {
    padding: 0.85rem;
    background: #ffffff;
}

.chat-history-empty {
    padding: 0.75rem;
    color: #64748b;
    font-size: 0.9rem;
}

.chat-history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.35rem;
    align-items: center;
    padding: 0.35rem;
}

.chat-history-open {
    min-width: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 0.35rem;
}

.chat-history-title,
.chat-history-preview,
.chat-history-meta {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-history-title {
    font-weight: 600;
    color: #1f2937;
}

.chat-history-preview {
    color: #64748b;
    font-size: 0.8rem;
    margin-top: 0.1rem;
}

.chat-history-actions {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-history-actions button {
    border: 1px solid var(--router-border);
    background: #ffffff;
    color: #475569;
    border-radius: 0.35rem;
    font-size: 0.72rem;
    padding: 0.15rem 0.35rem;
}

.chat-badge {
    display: inline-flex;
    align-items: center;
    max-width: 6rem;
    margin: 0.25rem 0.25rem 0 0;
    border: 1px solid #cbd5e1;
    border-radius: 0.35rem;
    background: #f8fafc;
    color: #475569;
    padding: 0.05rem 0.3rem;
    font-size: 0.68rem;
    line-height: 1.3;
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}

.chat-actions .btn {
    white-space: nowrap;
}

.message-note {
    color: #64748b;
    font-size: 0.78rem;
    margin-bottom: 0.3rem;
}

.message-tools {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.6rem;
}

.chat-message-assistant .chat-bubble {
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chat-message-user .message-attachments span {
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

@media (max-width: 991.98px) {
    .chat-shell {
        height: calc(100dvh - 57px);
    }

    .chat-topbar {
        gap: 0.5rem;
        padding: 0.65rem;
    }

    .chat-topbar > .flex-grow-1 {
        flex-basis: 100%;
        order: 3;
    }

    .chat-actions {
        width: 100%;
        justify-content: flex-start;
        order: 4;
    }

    .chat-actions .btn,
    .chat-actions .btn-group {
        flex: 1 1 auto;
    }

    .chat-actions .btn {
        width: 100%;
        padding-left: 0.45rem;
        padding-right: 0.45rem;
        font-size: 0.86rem;
    }

    .chat-messages {
        padding: 0.85rem;
    }

    .chat-sidebar {
        width: min(92vw, 360px);
    }

    .chat-input {
        padding: 0.75rem;
    }

    .chat-input textarea {
        min-height: 76px;
    }
}

@media (max-width: 575.98px) {
    .chat-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chat-bubble {
        max-width: 96%;
        padding: 0.7rem 0.8rem;
    }

    .chat-history-item {
        grid-template-columns: 1fr;
    }

    .chat-history-actions {
        flex-direction: row;
        justify-content: flex-end;
    }
}

/* RouterAI Appearance Settings v1 */
:root {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

html[data-theme="dark"] body {
    background: #0f172a;
    color: #e5e7eb;
}

html[data-theme="dark"] .navbar,
html[data-theme="dark"] .bg-white {
    background-color: #111827 !important;
    color: #e5e7eb !important;
}

html[data-theme="dark"] .navbar {
    border-color: #1f2937 !important;
}

html[data-theme="dark"] .navbar-brand,
html[data-theme="dark"] .nav-link {
    color: #e5e7eb !important;
}

html[data-theme="dark"] .nav-link.active,
html[data-theme="dark"] .nav-link:hover {
    color: #93c5fd !important;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .list-group-item {
    background-color: #111827;
    color: #e5e7eb;
    border-color: #263244;
}

html[data-theme="dark"] .shadow-sm {
    box-shadow: 0 .125rem .25rem rgba(0,0,0,.45) !important;
}

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .form-text {
    color: #9ca3af !important;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] textarea {
    background-color: #0b1220;
    color: #e5e7eb;
    border-color: #374151;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus,
html[data-theme="dark"] textarea:focus {
    background-color: #111827;
    color: #ffffff;
    border-color: #60a5fa;
    box-shadow: 0 0 0 .25rem rgba(96,165,250,.2);
}

html[data-theme="dark"] .table {
    --bs-table-bg: #111827;
    --bs-table-color: #e5e7eb;
    --bs-table-border-color: #263244;
    --bs-table-striped-bg: #162033;
    --bs-table-hover-bg: #1f2937;
}

html[data-theme="dark"] .alert-info {
    background-color: #0c4a6e;
    border-color: #075985;
    color: #e0f2fe;
}

html[data-theme="dark"] .alert-success {
    background-color: #064e3b;
    border-color: #065f46;
    color: #d1fae5;
}

html[data-theme="dark"] .alert-danger {
    background-color: #7f1d1d;
    border-color: #991b1b;
    color: #fee2e2;
}

html[data-theme="dark"] .alert-warning {
    background-color: #78350f;
    border-color: #92400e;
    color: #fef3c7;
}

html[data-theme="dark"] .btn-outline-secondary {
    color: #d1d5db;
    border-color: #6b7280;
}

html[data-theme="dark"] .btn-outline-secondary:hover {
    color: #111827;
    background-color: #d1d5db;
}

html[data-theme="dark"] .btn-outline-danger {
    color: #fca5a5;
    border-color: #ef4444;
}

html[data-theme="dark"] .theme-preview-card {
    background: #0b1220;
    border: 1px solid #374151;
}

.theme-preview-card {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 1rem;
    background: #ffffff;
}

html[data-theme="dark"] .chat-shell,
html[data-theme="dark"] .chat-sidebar,
html[data-theme="dark"] .chat-main,
html[data-theme="dark"] .chat-input-wrap {
    background-color: #0f172a;
    color: #e5e7eb;
    border-color: #263244;
}

html[data-theme="dark"] .message,
html[data-theme="dark"] .chat-message,
html[data-theme="dark"] .conversation-item,
html[data-theme="dark"] .attachment-chip {
    background-color: #111827;
    color: #e5e7eb;
    border-color: #263244;
}

html[data-theme="dark"] .message.assistant,
html[data-theme="dark"] .chat-message.assistant {
    background-color: #111827;
}

html[data-theme="dark"] .message.user,
html[data-theme="dark"] .chat-message.user {
    background-color: #1d4ed8;
    color: #ffffff;
}

html[data-theme="dark"] code,
html[data-theme="dark"] pre {
    background-color: #020617;
    color: #e5e7eb;
    border-color: #1f2937;
}

/* RouterAI Chat Dark Mode Polish */
html[data-theme="dark"] body.chat-page {
    background: #0f172a;
}

html[data-theme="dark"] .chat-page .navbar {
    background: #0f172a !important;
    border-bottom-color: #1e293b !important;
}

html[data-theme="dark"] .chat-page .chat-sidebar {
    background: #0f172a !important;
    border-right: 1px solid #1e293b;
}

html[data-theme="dark"] .chat-page .chat-main,
html[data-theme="dark"] .chat-page .chat-panel,
html[data-theme="dark"] .chat-page .chat-body,
html[data-theme="dark"] .chat-page .messages,
html[data-theme="dark"] .chat-page #messages,
html[data-theme="dark"] .chat-page .conversation-area {
    background: #111827 !important;
    color: #e5e7eb !important;
}

html[data-theme="dark"] .chat-page .empty-state,
html[data-theme="dark"] .chat-page .chat-empty,
html[data-theme="dark"] .chat-page .text-muted {
    color: #9ca3af !important;
}

html[data-theme="dark"] .chat-page .conversation-item,
html[data-theme="dark"] .chat-page .chat-conversation,
html[data-theme="dark"] .chat-page .conversation-list-item {
    background: transparent !important;
    color: #dbeafe !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(148, 163, 184, .14) !important;
    padding: .8rem .55rem !important;
}

html[data-theme="dark"] .chat-page .conversation-item:hover,
html[data-theme="dark"] .chat-page .chat-conversation:hover,
html[data-theme="dark"] .chat-page .conversation-list-item:hover {
    background: #1e293b !important;
}

html[data-theme="dark"] .chat-page .conversation-title,
html[data-theme="dark"] .chat-page .conversation-item-title,
html[data-theme="dark"] .chat-page .chat-title {
    color: #e5e7eb !important;
    font-weight: 600;
}

html[data-theme="dark"] .chat-page .conversation-preview,
html[data-theme="dark"] .chat-page .conversation-meta,
html[data-theme="dark"] .chat-page .conversation-item small,
html[data-theme="dark"] .chat-page .chat-preview {
    color: #93a4bb !important;
}

html[data-theme="dark"] .chat-page .conversation-item .badge,
html[data-theme="dark"] .chat-page .chat-conversation .badge {
    background: #e5e7eb !important;
    color: #0f172a !important;
}

html[data-theme="dark"] .chat-page .conversation-item button,
html[data-theme="dark"] .chat-page .chat-conversation button,
html[data-theme="dark"] .chat-page .conversation-actions button {
    background: #f8fafc !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1 !important;
    font-size: .75rem;
    padding: .2rem .45rem;
    border-radius: .35rem;
}

html[data-theme="dark"] .chat-page .conversation-actions {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    align-items: flex-end;
}

html[data-theme="dark"] .chat-page input[type="search"],
html[data-theme="dark"] .chat-page .chat-search,
html[data-theme="dark"] .chat-page #conversationSearch {
    background: #020617 !important;
    color: #e5e7eb !important;
    border-color: #334155 !important;
}

html[data-theme="dark"] .chat-page input[type="search"]::placeholder,
html[data-theme="dark"] .chat-page textarea::placeholder {
    color: #64748b !important;
}

html[data-theme="dark"] .chat-page select,
html[data-theme="dark"] .chat-page .form-select {
    background-color: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

html[data-theme="dark"] .chat-page .chat-toolbar,
html[data-theme="dark"] .chat-page .chat-topbar,
html[data-theme="dark"] .chat-page .chat-actions {
    background: #f8fafc !important;
    border-bottom: 1px solid #cbd5e1;
}

html[data-theme="dark"] .chat-page .chat-toolbar .btn,
html[data-theme="dark"] .chat-page .chat-topbar .btn,
html[data-theme="dark"] .chat-page .chat-actions .btn {
    background: #ffffff;
    color: #334155;
    border-color: #cbd5e1;
}

html[data-theme="dark"] .chat-page .chat-toolbar .btn:disabled,
html[data-theme="dark"] .chat-page .chat-topbar .btn:disabled,
html[data-theme="dark"] .chat-page .chat-actions .btn:disabled {
    opacity: .45;
}

html[data-theme="dark"] .chat-page .chat-input-wrap,
html[data-theme="dark"] .chat-page .chat-composer,
html[data-theme="dark"] .chat-page .message-composer {
    background: #f8fafc !important;
    border-top: 1px solid #cbd5e1 !important;
    color: #334155 !important;
}

html[data-theme="dark"] .chat-page .attachment-status,
html[data-theme="dark"] .chat-page .attachment-help,
html[data-theme="dark"] .chat-page .attachment-note {
    color: #475569 !important;
}

html[data-theme="dark"] .chat-page textarea,
html[data-theme="dark"] .chat-page #messageInput {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
    border-radius: .55rem;
}

html[data-theme="dark"] .chat-page .message.user,
html[data-theme="dark"] .chat-page .chat-message.user {
    background: #2563eb !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .chat-page .message.assistant,
html[data-theme="dark"] .chat-page .chat-message.assistant {
    background: #1e293b !important;
    color: #e5e7eb !important;
    border: 1px solid #334155 !important;
}

html[data-theme="dark"] .chat-page .btn-primary {
    background: #2563eb !important;
    border-color: #2563eb !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .chat-page .btn-outline-secondary,
html[data-theme="dark"] .chat-page .btn-outline-primary {
    color: #334155;
    border-color: #cbd5e1;
    background: #ffffff;
}

html[data-theme="dark"] .chat-page .btn-outline-danger {
    color: #ef4444;
    border-color: #fca5a5;
    background: #ffffff;
}

@media (max-width: 768px) {
    .chat-page .chat-sidebar {
        max-height: 260px;
        overflow-y: auto;
    }

    .chat-page .conversation-actions {
        flex-direction: row;
    }

    .chat-page .chat-toolbar,
    .chat-page .chat-topbar,
    .chat-page .chat-actions {
        gap: .35rem;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* RouterAI Chat Dark Mode Fix v2 */
html[data-theme="dark"] .chat-page {
    background: #0f172a !important;
    color: #e5e7eb !important;
}

html[data-theme="dark"] .chat-page .bg-light,
html[data-theme="dark"] .chat-page .bg-white,
html[data-theme="dark"] .chat-page .card,
html[data-theme="dark"] .chat-page .card-body,
html[data-theme="dark"] .chat-page .list-group-item {
    background-color: #111827 !important;
    color: #e5e7eb !important;
    border-color: #263244 !important;
}

html[data-theme="dark"] .chat-page .text-dark,
html[data-theme="dark"] .chat-page .text-body,
html[data-theme="dark"] .chat-page p,
html[data-theme="dark"] .chat-page div,
html[data-theme="dark"] .chat-page span,
html[data-theme="dark"] .chat-page li {
    color: inherit;
}

html[data-theme="dark"] .chat-page .text-muted {
    color: #9ca3af !important;
}

/* Main chat layout */
html[data-theme="dark"] .chat-page main,
html[data-theme="dark"] .chat-page .chat-main,
html[data-theme="dark"] .chat-page .chat-content,
html[data-theme="dark"] .chat-page .chat-messages,
html[data-theme="dark"] .chat-page #chatMessages,
html[data-theme="dark"] .chat-page #messages,
html[data-theme="dark"] .chat-page .messages {
    background: #111827 !important;
    color: #e5e7eb !important;
}

/* Assistant message bubble */
html[data-theme="dark"] .chat-page .assistant,
html[data-theme="dark"] .chat-page .assistant-message,
html[data-theme="dark"] .chat-page .message-assistant,
html[data-theme="dark"] .chat-page .bot-message,
html[data-theme="dark"] .chat-page .ai-message,
html[data-theme="dark"] .chat-page .message-content,
html[data-theme="dark"] .chat-page .message-bubble,
html[data-theme="dark"] .chat-page .chat-bubble {
    background-color: #1e293b !important;
    color: #e5e7eb !important;
    border-color: #334155 !important;
}

/* User message bubble */
html[data-theme="dark"] .chat-page .user,
html[data-theme="dark"] .chat-page .user-message,
html[data-theme="dark"] .chat-page .message-user {
    background-color: #2563eb !important;
    color: #ffffff !important;
}

/* Keep user bubble text white */
html[data-theme="dark"] .chat-page .user *,
html[data-theme="dark"] .chat-page .user-message *,
html[data-theme="dark"] .chat-page .message-user * {
    color: #ffffff !important;
}

/* Assistant bubble text readable */
html[data-theme="dark"] .chat-page .assistant *,
html[data-theme="dark"] .chat-page .assistant-message *,
html[data-theme="dark"] .chat-page .message-assistant *,
html[data-theme="dark"] .chat-page .bot-message *,
html[data-theme="dark"] .chat-page .ai-message *,
html[data-theme="dark"] .chat-page .message-content *,
html[data-theme="dark"] .chat-page .message-bubble *,
html[data-theme="dark"] .chat-page .chat-bubble * {
    color: #e5e7eb !important;
}

/* Code blocks */
html[data-theme="dark"] .chat-page pre,
html[data-theme="dark"] .chat-page code {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

/* Toolbar */
html[data-theme="dark"] .chat-page .chat-toolbar,
html[data-theme="dark"] .chat-page .chat-topbar,
html[data-theme="dark"] .chat-page .chat-header,
html[data-theme="dark"] .chat-page .chat-actions {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

html[data-theme="dark"] .chat-page .chat-toolbar *,
html[data-theme="dark"] .chat-page .chat-topbar *,
html[data-theme="dark"] .chat-page .chat-header *,
html[data-theme="dark"] .chat-page .chat-actions * {
    color: #0f172a;
}

/* Sidebar */
html[data-theme="dark"] .chat-page .chat-sidebar {
    background: #0f172a !important;
    color: #e5e7eb !important;
    border-color: #1e293b !important;
}

html[data-theme="dark"] .chat-page .conversation-item,
html[data-theme="dark"] .chat-page .conversation-list-item,
html[data-theme="dark"] .chat-page .conversation-row {
    background: transparent !important;
    color: #e5e7eb !important;
}

html[data-theme="dark"] .chat-page .conversation-item.active,
html[data-theme="dark"] .chat-page .conversation-list-item.active,
html[data-theme="dark"] .chat-page .conversation-row.active {
    background: #e8f0ff !important;
    color: #0f172a !important;
    border-radius: .5rem;
}

html[data-theme="dark"] .chat-page .conversation-item.active *,
html[data-theme="dark"] .chat-page .conversation-list-item.active *,
html[data-theme="dark"] .chat-page .conversation-row.active * {
    color: #0f172a !important;
}

/* Composer */
html[data-theme="dark"] .chat-page .chat-input-wrap,
html[data-theme="dark"] .chat-page .chat-composer,
html[data-theme="dark"] .chat-page .composer,
html[data-theme="dark"] .chat-page .message-input-area {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

html[data-theme="dark"] .chat-page textarea,
html[data-theme="dark"] .chat-page #messageInput,
html[data-theme="dark"] .chat-page input,
html[data-theme="dark"] .chat-page select {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

html[data-theme="dark"] .chat-page textarea::placeholder,
html[data-theme="dark"] .chat-page input::placeholder {
    color: #94a3b8 !important;
}

/* Buttons inside chat */
html[data-theme="dark"] .chat-page .btn {
    border-radius: .5rem;
}

html[data-theme="dark"] .chat-page .btn-primary {
    background: #2563eb !important;
    border-color: #2563eb !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .chat-page .btn-outline-secondary,
html[data-theme="dark"] .chat-page .btn-outline-primary,
html[data-theme="dark"] .chat-page .btn-outline-danger {
    background: #ffffff !important;
    color: #0f172a !important;
}

html[data-theme="dark"] .chat-page .btn:disabled {
    opacity: .45;
}

/* Browser text selection in dark mode */
html[data-theme="dark"] .chat-page ::selection {
    background: #2563eb;
    color: #ffffff;
}

/* RouterAI Chat Dark Mode Fix v3 - keep model selector readable */
html[data-theme="dark"] .chat-page select.form-select,
html[data-theme="dark"] .chat-page .form-select,
html[data-theme="dark"] .chat-page #modelSelect,
html[data-theme="dark"] .chat-page select[name="model_id"],
html[data-theme="dark"] .chat-page select[name="model"] {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

html[data-theme="dark"] .chat-page select.form-select option,
html[data-theme="dark"] .chat-page .form-select option,
html[data-theme="dark"] .chat-page #modelSelect option,
html[data-theme="dark"] .chat-page select[name="model_id"] option,
html[data-theme="dark"] .chat-page select[name="model"] option {
    background-color: #ffffff !important;
    color: #0f172a !important;
}

/* Keep chat message textarea dark only */
html[data-theme="dark"] .chat-page textarea,
html[data-theme="dark"] .chat-page #messageInput {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

/* RouterAI Chat Dark Mode Polish v4
   Improves readability for chat sidebar, usage badges, attachment bar, and composer.
   CSS-only; no backend behavior changes.
*/

[data-theme="dark"] body,
body.theme-dark {
    background: #0f172a;
    color: #e5e7eb;
}

[data-theme="dark"] .navbar,
body.theme-dark .navbar {
    background: #111827 !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

[data-theme="dark"] .navbar .navbar-brand,
[data-theme="dark"] .navbar .nav-link,
body.theme-dark .navbar .navbar-brand,
body.theme-dark .navbar .nav-link {
    color: #f8fafc !important;
}

[data-theme="dark"] .navbar .nav-link:hover,
[data-theme="dark"] .navbar .nav-link.active,
body.theme-dark .navbar .nav-link:hover,
body.theme-dark .navbar .nav-link.active {
    color: #93c5fd !important;
}

/* Chat main layout */
[data-theme="dark"] .chat-shell,
body.theme-dark .chat-shell {
    background: #0f172a;
    color: #e5e7eb;
}

[data-theme="dark"] .chat-main,
body.theme-dark .chat-main {
    background: #111827;
    color: #e5e7eb;
}

/* Sidebar */
[data-theme="dark"] .chat-sidebar,
body.theme-dark .chat-sidebar {
    background: #0b1220;
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .chat-sidebar input,
[data-theme="dark"] .chat-sidebar .form-control,
body.theme-dark .chat-sidebar input,
body.theme-dark .chat-sidebar .form-control {
    background: #020617;
    border-color: rgba(148, 163, 184, 0.28);
    color: #f8fafc;
}

[data-theme="dark"] .chat-sidebar input::placeholder,
body.theme-dark .chat-sidebar input::placeholder {
    color: #94a3b8;
}

[data-theme="dark"] .chat-list-item,
body.theme-dark .chat-list-item {
    color: #e5e7eb;
    background: transparent;
    border-color: transparent;
}

[data-theme="dark"] .chat-list-item:hover,
body.theme-dark .chat-list-item:hover {
    background: rgba(59, 130, 246, 0.12);
    color: #ffffff;
}

[data-theme="dark"] .chat-list-item.active,
body.theme-dark .chat-list-item.active {
    background: rgba(37, 99, 235, 0.22) !important;
    border-color: rgba(96, 165, 250, 0.38) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .chat-list-item.active .text-muted,
[data-theme="dark"] .chat-list-item.active small,
body.theme-dark .chat-list-item.active .text-muted,
body.theme-dark .chat-list-item.active small {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .chat-list-item .btn,
body.theme-dark .chat-list-item .btn {
    background: #f8fafc;
    color: #0f172a;
    border-color: rgba(203, 213, 225, 0.8);
}

[data-theme="dark"] .chat-list-item .btn:hover,
body.theme-dark .chat-list-item .btn:hover {
    background: #dbeafe;
    color: #0f172a;
}

/* Chat header controls */
[data-theme="dark"] .chat-toolbar,
[data-theme="dark"] .chat-header,
body.theme-dark .chat-toolbar,
body.theme-dark .chat-header {
    background: #111827;
    border-color: rgba(148, 163, 184, 0.2);
    color: #e5e7eb;
}

[data-theme="dark"] .chat-toolbar select,
[data-theme="dark"] .chat-toolbar .form-select,
[data-theme="dark"] .chat-header select,
[data-theme="dark"] .chat-header .form-select,
body.theme-dark .chat-toolbar select,
body.theme-dark .chat-toolbar .form-select,
body.theme-dark .chat-header select,
body.theme-dark .chat-header .form-select {
    background-color: #f8fafc !important;
    color: #111827 !important;
    border-color: #cbd5e1 !important;
}

/* Messages */
[data-theme="dark"] .chat-message,
body.theme-dark .chat-message {
    color: #f8fafc;
}

[data-theme="dark"] .message-user,
[data-theme="dark"] .chat-message.user,
body.theme-dark .message-user,
body.theme-dark .chat-message.user {
    background: #1e293b;
    color: #ffffff;
    border-color: rgba(148, 163, 184, 0.2);
}

[data-theme="dark"] .message-assistant,
[data-theme="dark"] .chat-message.assistant,
body.theme-dark .message-assistant,
body.theme-dark .chat-message.assistant {
    background: #1f2937;
    color: #ffffff;
    border-color: rgba(96, 165, 250, 0.22);
}

[data-theme="dark"] .message-assistant .btn,
[data-theme="dark"] .chat-message.assistant .btn,
body.theme-dark .message-assistant .btn,
body.theme-dark .chat-message.assistant .btn {
    background: #f8fafc;
    color: #0f172a;
    border-color: #cbd5e1;
}

/* Bottom usage/status bar */
[data-theme="dark"] .chat-usage-bar,
[data-theme="dark"] .usage-bar,
[data-theme="dark"] .chat-limits,
body.theme-dark .chat-usage-bar,
body.theme-dark .usage-bar,
body.theme-dark .chat-limits {
    background: #111827 !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
    color: #e5e7eb !important;
}

[data-theme="dark"] .chat-usage-bar a,
[data-theme="dark"] .usage-bar a,
[data-theme="dark"] .chat-limits a,
body.theme-dark .chat-usage-bar a,
body.theme-dark .usage-bar a,
body.theme-dark .chat-limits a {
    color: #93c5fd !important;
    text-decoration: none;
    font-weight: 600;
}

[data-theme="dark"] .chat-usage-bar a:hover,
[data-theme="dark"] .usage-bar a:hover,
[data-theme="dark"] .chat-limits a:hover,
body.theme-dark .chat-usage-bar a:hover,
body.theme-dark .usage-bar a:hover,
body.theme-dark .chat-limits a:hover {
    color: #bfdbfe !important;
    text-decoration: underline;
}

[data-theme="dark"] .chat-usage-bar .badge,
[data-theme="dark"] .usage-bar .badge,
[data-theme="dark"] .chat-limits .badge,
body.theme-dark .chat-usage-bar .badge,
body.theme-dark .usage-bar .badge,
body.theme-dark .chat-limits .badge {
    background: rgba(37, 99, 235, 0.22) !important;
    color: #dbeafe !important;
    border: 1px solid rgba(96, 165, 250, 0.35);
    font-weight: 600;
}

/* Catch current plain usage text/links when not wrapped by custom classes */
[data-theme="dark"] .chat-main .border-top,
[data-theme="dark"] .chat-main .border-bottom,
body.theme-dark .chat-main .border-top,
body.theme-dark .chat-main .border-bottom {
    border-color: rgba(148, 163, 184, 0.22) !important;
}

[data-theme="dark"] .chat-main .text-muted,
body.theme-dark .chat-main .text-muted {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .chat-main a,
body.theme-dark .chat-main a {
    color: #93c5fd;
}

/* Attachment notice */
[data-theme="dark"] .attachment-help,
[data-theme="dark"] .attachment-notice,
[data-theme="dark"] .chat-attachments-note,
body.theme-dark .attachment-help,
body.theme-dark .attachment-notice,
body.theme-dark .chat-attachments-note {
    background: #111827 !important;
    color: #cbd5e1 !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

/* Composer */
[data-theme="dark"] .chat-composer,
body.theme-dark .chat-composer {
    background: #0f172a !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

[data-theme="dark"] .chat-composer textarea,
[data-theme="dark"] .chat-composer .form-control,
body.theme-dark .chat-composer textarea,
body.theme-dark .chat-composer .form-control {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: rgba(148, 163, 184, 0.32) !important;
}

[data-theme="dark"] .chat-composer textarea::placeholder,
[data-theme="dark"] .chat-composer .form-control::placeholder,
body.theme-dark .chat-composer textarea::placeholder,
body.theme-dark .chat-composer .form-control::placeholder {
    color: #93a4b8 !important;
}

[data-theme="dark"] .chat-composer .btn-outline-secondary,
body.theme-dark .chat-composer .btn-outline-secondary {
    background: #f8fafc;
    color: #0f172a;
    border-color: #cbd5e1;
}

[data-theme="dark"] .chat-composer .btn-outline-secondary:hover,
body.theme-dark .chat-composer .btn-outline-secondary:hover {
    background: #dbeafe;
    color: #0f172a;
}

/* Generic chat-page fallback selectors */
[data-theme="dark"] main textarea,
body.theme-dark main textarea {
    background-color: #020617;
    color: #f8fafc;
    border-color: rgba(148, 163, 184, 0.32);
}

[data-theme="dark"] main textarea::placeholder,
body.theme-dark main textarea::placeholder {
    color: #93a4b8;
}

[data-theme="dark"] main .bg-light,
body.theme-dark main .bg-light {
    background-color: #111827 !important;
    color: #e5e7eb !important;
}

/* Selection readability */
[data-theme="dark"] ::selection,
body.theme-dark ::selection {
    background: rgba(96, 165, 250, 0.45);
    color: #ffffff;
}


/* RouterAI Chat Dark Mode Polish v5
   Targeted fixes for unreadable selected sidebar item and bottom usage row.
*/

/* Left sidebar selected/current chat item */
[data-theme="dark"] .chat-sidebar .active,
body.theme-dark .chat-sidebar .active,
[data-theme="dark"] aside .active,
body.theme-dark aside .active {
    background: #1e293b !important;
    color: #ffffff !important;
    border-color: rgba(96, 165, 250, 0.45) !important;
}

[data-theme="dark"] .chat-sidebar .active *,
body.theme-dark .chat-sidebar .active *,
[data-theme="dark"] aside .active *,
body.theme-dark aside .active * {
    color: #ffffff !important;
}

[data-theme="dark"] .chat-sidebar .active small,
[data-theme="dark"] .chat-sidebar .active .small,
[data-theme="dark"] .chat-sidebar .active .text-muted,
body.theme-dark .chat-sidebar .active small,
body.theme-dark .chat-sidebar .active .small,
body.theme-dark .chat-sidebar .active .text-muted,
[data-theme="dark"] aside .active small,
[data-theme="dark"] aside .active .small,
[data-theme="dark"] aside .active .text-muted,
body.theme-dark aside .active small,
body.theme-dark aside .active .small,
body.theme-dark aside .active .text-muted {
    color: #dbeafe !important;
}

/* Keep Pin/Fav buttons readable inside selected sidebar item */
[data-theme="dark"] .chat-sidebar .active .btn,
body.theme-dark .chat-sidebar .active .btn,
[data-theme="dark"] aside .active .btn,
body.theme-dark aside .active .btn {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

/* Bottom usage row: catch current plain Bootstrap/light rows */
[data-theme="dark"] .chat-main > div,
body.theme-dark .chat-main > div {
    color: #e5e7eb;
}

/* The white usage strip directly above attachment note */
[data-theme="dark"] .chat-main .border-top,
body.theme-dark .chat-main .border-top {
    background: #111827 !important;
    color: #e5e7eb !important;
    border-color: rgba(148, 163, 184, 0.25) !important;
}

/* Force usage text readable even if it uses muted/light classes */
[data-theme="dark"] .chat-main .border-top *,
body.theme-dark .chat-main .border-top * {
    color: #e5e7eb !important;
}

[data-theme="dark"] .chat-main .border-top a,
body.theme-dark .chat-main .border-top a {
    color: #93c5fd !important;
    font-weight: 700 !important;
}

/* If the usage text is wrapped in spans without classes */
[data-theme="dark"] .chat-main span,
body.theme-dark .chat-main span {
    color: inherit;
}

/* Usage badges/text should look like readable pills, not selected text */
[data-theme="dark"] .chat-main .border-top span,
body.theme-dark .chat-main .border-top span {
    display: inline-block;
    background: rgba(37, 99, 235, 0.16);
    color: #dbeafe !important;
    border: 1px solid rgba(96, 165, 250, 0.25);
    border-radius: 6px;
    padding: 2px 6px;
    margin-right: 6px;
    font-weight: 600;
}

/* Do not make Details look like a pill if it is a link */
[data-theme="dark"] .chat-main .border-top a,
body.theme-dark .chat-main .border-top a {
    background: transparent !important;
    border: 0 !important;
    padding: 0 !important;
    margin-left: 4px;
}

/* Attachment capability row below usage */
[data-theme="dark"] .chat-main .border-top + div,
body.theme-dark .chat-main .border-top + div {
    background: #0f172a !important;
    color: #cbd5e1 !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

[data-theme="dark"] .chat-main .border-top + div *,
body.theme-dark .chat-main .border-top + div * {
    color: #cbd5e1 !important;
}

/* Composer white wrapper below attachment note */
[data-theme="dark"] .chat-main .border-top + div + div,
body.theme-dark .chat-main .border-top + div + div {
    background: #111827 !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

/* Strong fallback for any very light text inside chat area */
[data-theme="dark"] .chat-main [class*="text-light"],
body.theme-dark .chat-main [class*="text-light"] {
    color: #e5e7eb !important;
}


/* RouterAI Chat Copy Tools */
.message-tools {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.message-tools .btn {
    line-height: 1.2;
}

[data-theme="dark"] .message-tools .btn,
body.theme-dark .message-tools .btn {
    background: #f8fafc;
    color: #0f172a;
    border-color: #cbd5e1;
}

[data-theme="dark"] .message-tools .btn:hover,
body.theme-dark .message-tools .btn:hover {
    background: #dbeafe;
    color: #0f172a;
}

@media (max-width: 768px) {
    .chat-actions {
        gap: 0.4rem;
    }

    .chat-actions .btn {
        padding: 0.4rem 0.55rem;
        font-size: 0.875rem;
    }
}

/* RouterAI Task 20A: customer conversation export link */
.routerai-export-floating-link {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1050;
}

.routerai-export-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0.65rem 0.95rem;
    border-radius: 999px;
    background: #2563eb;
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(37, 99, 235, 0.28);
}

.routerai-export-btn:hover {
    color: #ffffff;
    text-decoration: none;
    filter: brightness(0.96);
}

@media (max-width: 640px) {
    .routerai-export-floating-link {
        right: 12px;
        bottom: 12px;
    }

    .routerai-export-btn {
        min-height: 38px;
        padding: 0.55rem 0.8rem;
        font-size: 0.85rem;
    }
}

/* RouterAI Task 20A Polish: customer conversation export page */
.routerai-export-page {
    background: #f5f7fb;
    color: #111827;
}

.routerai-export-shell {
    max-width: 1180px;
}

.routerai-export-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.06);
}

.routerai-export-note {
    border-radius: 14px;
}

.routerai-export-page .card {
    border-radius: 18px;
    overflow: hidden;
}

.routerai-export-page .table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #e2e8f0;
}

.routerai-export-page .table tbody td {
    vertical-align: middle;
}

.routerai-export-toolbar {
    padding: 1rem;
    margin: -1rem -1rem 1rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-bottom: 1px solid #e2e8f0;
}

.routerai-export-page .form-check-input {
    width: 1.15rem;
    height: 1.15rem;
}

@media (max-width: 768px) {
    .routerai-export-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .routerai-export-page .table {
        min-width: 720px;
    }
}

/* RouterAI Task 20C: current chat selected-message export */
.routerai-message-select-bar {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 1200;
    width: min(960px, calc(100% - 24px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(10px);
}

.routerai-message-select-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    color: #0f172a;
}

.routerai-message-select-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.45rem;
}

.routerai-message-select-mode .routerai-message-selectable {
    position: relative;
    outline: 2px dashed rgba(37, 99, 235, 0.35);
    outline-offset: 4px;
}

.routerai-message-select-wrap {
    position: absolute;
    top: -12px;
    left: 12px;
    z-index: 8;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: #ffffff;
    color: #0f172a;
    border: 1px solid rgba(37, 99, 235, 0.28);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}

.routerai-message-select-wrap input {
    margin: 0;
}

.routerai-message-select-mode .routerai-message-export-check:checked + span {
    color: #2563eb;
}

@media (max-width: 768px) {
    .routerai-message-select-bar {
        align-items: stretch;
        flex-direction: column;
        bottom: 10px;
    }

    .routerai-message-select-actions {
        justify-content: flex-start;
    }
}

/* RouterAI Task 20D: per-message model label */
.routerai-message-model-label {
    margin-top: 0.55rem;
    padding-top: 0.45rem;
    border-top: 1px solid rgba(148, 163, 184, 0.28);
    font-size: 0.76rem;
    font-weight: 600;
    color: #64748b;
}

[data-theme="dark"] .routerai-message-model-label {
    color: #94a3b8;
    border-top-color: rgba(148, 163, 184, 0.22);
}

/* RouterAI Task 20D: per-message model label */
.routerai-message-model-label {
    margin-top: 0.55rem;
    padding-top: 0.45rem;
    border-top: 1px solid rgba(148, 163, 184, 0.28);
    font-size: 0.76rem;
    font-weight: 600;
    color: #64748b;
}

[data-theme="dark"] .routerai-message-model-label {
    color: #94a3b8;
    border-top-color: rgba(148, 163, 184, 0.22);
}

/* RouterAI Task 21: Live Web Search toggle */
.web-search-toggle-wrap {
    margin-top: 0.65rem;
}

.web-search-toggle {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(124, 58, 237, 0.08));
    cursor: pointer;
}

.web-search-toggle input {
    margin-top: 0.22rem;
    transform: scale(1.12);
}

.web-search-toggle-main {
    display: block;
    font-size: 0.92rem;
    font-weight: 800;
    color: #1e3a8a;
}

.web-search-toggle-sub {
    display: block;
    margin-top: 0.12rem;
    font-size: 0.78rem;
    color: #64748b;
}

.web-search-toggle.is-disabled {
    cursor: not-allowed;
    opacity: 0.7;
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.28);
}

[data-theme="dark"] .web-search-toggle {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(139, 92, 246, 0.14));
    border-color: rgba(96, 165, 250, 0.28);
}

[data-theme="dark"] .web-search-toggle-main {
    color: #bfdbfe;
}

[data-theme="dark"] .web-search-toggle-sub {
    color: #94a3b8;
}

/* RouterAI Task 21E: customer capability strip */
.routerai-capability-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.24);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.06), rgba(124, 58, 237, 0.06));
}

.routerai-capability-strip span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0.26rem 0.58rem;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.82);
    color: #334155;
    font-size: 0.76rem;
    font-weight: 700;
}

.routerai-capability-strip .is-premium-on {
    border-color: rgba(37, 99, 235, 0.38);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(124, 58, 237, 0.12));
    color: #1d4ed8;
}

.routerai-capability-strip .is-premium-locked {
    opacity: 0.72;
}

[data-theme="dark"] .routerai-capability-strip {
    border-bottom-color: rgba(148, 163, 184, 0.18);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(124, 58, 237, 0.10));
}

[data-theme="dark"] .routerai-capability-strip span {
    background: rgba(15, 23, 42, 0.78);
    border-color: rgba(148, 163, 184, 0.22);
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-capability-strip .is-premium-on {
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.34);
}

/* RouterAI Task 21E: customer web search usage card */
.routerai-web-search-usage-card {
    border: 1px solid rgba(37, 99, 235, 0.16) !important;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
}

[data-theme="dark"] .routerai-web-search-usage-card {
    border-color: rgba(96, 165, 250, 0.22) !important;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(124, 58, 237, 0.10));
}

/* RouterAI Task 22B: Prompt Library */
.routerai-prompts-page {
    max-width: 1180px;
}

.routerai-prompts-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.4rem;
    border: 1px solid rgba(37, 99, 235, 0.14);
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(124, 58, 237, 0.08));
}

.routerai-prompts-kicker {
    margin-bottom: 0.35rem;
    color: #2563eb;
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.routerai-prompts-hero h1 {
    margin: 0;
    font-size: clamp(1.55rem, 3vw, 2.35rem);
    font-weight: 900;
}

.routerai-prompts-hero p {
    margin: 0.45rem 0 0;
    max-width: 720px;
    color: #64748b;
}

.routerai-prompts-toolbar {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) auto;
    gap: 0.85rem;
    align-items: end;
    padding: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 18px;
    background: #fff;
}

.routerai-prompts-toolbar-actions {
    display: flex;
    gap: 0.5rem;
}

.routerai-prompts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.routerai-prompt-card {
    display: flex;
    flex-direction: column;
    min-height: 260px;
    padding: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
}

.routerai-prompt-card-top {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.routerai-prompt-category,
.routerai-prompt-web-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
}

.routerai-prompt-category {
    background: rgba(100, 116, 139, 0.10);
    color: #334155;
}

.routerai-prompt-web-badge {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(124, 58, 237, 0.12));
    color: #1d4ed8;
}

.routerai-prompt-card h2 {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
    font-weight: 900;
}

.routerai-prompt-desc {
    margin: 0 0 0.75rem;
    color: #64748b;
    font-size: 0.9rem;
}

.routerai-prompt-preview {
    flex: 1;
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 14px;
    background: #f8fafc;
    color: #475569;
    font-size: 0.84rem;
}

.routerai-prompt-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

[data-theme="dark"] .routerai-prompts-hero,
[data-theme="dark"] .routerai-prompts-toolbar,
[data-theme="dark"] .routerai-prompt-card {
    background: #0f172a;
    border-color: rgba(148, 163, 184, 0.20);
}

[data-theme="dark"] .routerai-prompts-hero p,
[data-theme="dark"] .routerai-prompt-desc,
[data-theme="dark"] .routerai-prompt-preview {
    color: #94a3b8;
}

[data-theme="dark"] .routerai-prompt-preview {
    background: rgba(15, 23, 42, 0.78);
}

@media (max-width: 991.98px) {
    .routerai-prompts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .routerai-prompts-toolbar {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 575.98px) {
    .routerai-prompts-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .routerai-prompts-grid {
        grid-template-columns: 1fr;
    }

    .routerai-prompts-toolbar-actions {
        width: 100%;
    }

    .routerai-prompts-toolbar-actions .btn {
        flex: 1;
    }
}

/* RouterAI Task 22C-3: Academic integrity notice */
.routerai-academic-integrity-note {
    display: grid;
    gap: 0.25rem;
    padding: 0.95rem 1rem;
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-left: 5px solid #2563eb;
    border-radius: 16px;
    background: rgba(37, 99, 235, 0.06);
    color: #334155;
}

.routerai-academic-integrity-title {
    font-weight: 900;
    color: #1d4ed8;
}

[data-theme="dark"] .routerai-academic-integrity-note {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(96, 165, 250, 0.20);
    border-left-color: #60a5fa;
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-academic-integrity-title {
    color: #93c5fd;
}

/* RouterAI Task 23A: Chat Mode System */
.chat-mode-wrap {
    margin-top: 0.65rem;
    padding: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 14px;
    background: rgba(248, 250, 252, 0.92);
}

.chat-mode-wrap .form-select {
    max-width: 280px;
}

.chat-mode-help {
    margin-top: 0.35rem;
    color: #64748b;
    font-size: 0.8rem;
}

[data-theme="dark"] .chat-mode-wrap {
    background: rgba(15, 23, 42, 0.80);
    border-color: rgba(148, 163, 184, 0.20);
}

[data-theme="dark"] .chat-mode-help {
    color: #94a3b8;
}

@media (max-width: 767.98px) {
    .chat-mode-wrap .form-select {
        max-width: none;
    }
}

/* RouterAI Task 23B: Mode Quick Actions */
.routerai-mode-quick-actions {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(248, 250, 252, 0.78);
}

.routerai-mode-quick-title {
    margin-bottom: 0.45rem;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.routerai-mode-quick-scroll {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    -webkit-overflow-scrolling: touch;
}

.routerai-mode-chip {
    flex: 0 0 auto;
    border: 1px solid rgba(37, 99, 235, 0.20);
    border-radius: 999px;
    background: #ffffff;
    color: #1e293b;
    padding: 0.42rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.routerai-mode-chip:hover,
.routerai-mode-chip.is-active {
    border-color: rgba(37, 99, 235, 0.55);
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #ffffff;
    transform: translateY(-1px);
}

[data-theme="dark"] .routerai-mode-quick-actions {
    background: rgba(15, 23, 42, 0.82);
    border-bottom-color: rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .routerai-mode-quick-title {
    color: #94a3b8;
}

[data-theme="dark"] .routerai-mode-chip {
    background: #0f172a;
    border-color: rgba(96, 165, 250, 0.22);
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-mode-chip:hover,
[data-theme="dark"] .routerai-mode-chip.is-active {
    color: #ffffff;
}

/* RouterAI Task 23B UI Fit Fix: chat controls, quick actions, and overflow */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

.chat-shell,
.chat-main {
    min-width: 0;
}

.chat-topbar {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
}

.chat-topbar > .flex-grow-1 {
    min-width: 280px;
    max-width: 940px;
}

.chat-topbar .form-select {
    max-width: 100%;
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.4rem;
    max-width: 520px;
}

.chat-actions .btn,
.chat-actions .btn-group {
    flex: 0 0 auto;
}

.web-search-toggle-wrap,
.chat-mode-wrap {
    max-width: 100%;
}

.web-search-toggle {
    width: 100%;
}

.chat-mode-wrap {
    margin-top: 0.75rem;
}

.chat-mode-wrap .form-select {
    max-width: 280px;
}

.routerai-mode-quick-actions,
.routerai-capability-strip {
    max-width: 100%;
    overflow: hidden;
}

.routerai-mode-quick-scroll {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.routerai-mode-chip {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.routerai-capability-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.75rem 1rem;
}

.routerai-capability-strip span {
    flex: 0 0 auto;
    white-space: nowrap;
}

.chat-messages {
    min-width: 0;
}

/* Medium screens: make controls more compact */
@media (max-width: 1199.98px) {
    .chat-topbar {
        flex-wrap: wrap;
    }

    .chat-topbar > .flex-grow-1 {
        flex: 1 1 100%;
        max-width: none;
    }

    .chat-actions {
        justify-content: flex-start;
        max-width: none;
        width: 100%;
    }
}

/* Mobile/tablet: stack nicely */
@media (max-width: 767.98px) {
    .chat-topbar {
        padding: 0.75rem;
    }

    .chat-topbar > .flex-grow-1 {
        min-width: 0;
        width: 100%;
    }

    .chat-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .chat-actions .btn,
    .chat-actions .btn-group,
    .chat-actions .btn-group > .btn {
        width: 100%;
    }

    .chat-actions .dropdown-menu {
        width: 100%;
    }

    .web-search-toggle {
        align-items: flex-start;
        gap: 0.55rem;
        padding: 0.75rem;
    }

    .web-search-toggle-sub {
        display: block;
        line-height: 1.35;
    }

    .chat-mode-wrap .form-select {
        max-width: none;
        width: 100%;
    }

    .routerai-mode-quick-actions {
        padding: 0.7rem 0.75rem;
    }

    .routerai-mode-chip {
        max-width: 180px;
        font-size: 0.78rem;
        padding: 0.38rem 0.62rem;
    }

    .routerai-capability-strip {
        padding: 0.65rem 0.75rem;
    }

    .routerai-capability-strip span {
        font-size: 0.76rem;
    }
}

/* Very small phones */
@media (max-width: 480px) {
    .chat-actions {
        grid-template-columns: 1fr;
    }

    .routerai-mode-chip {
        max-width: 165px;
    }
}

/* RouterAI Task 23B UI: collapsible Quick Start */
.routerai-mode-quick-actions {
    padding: 0.55rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(248, 250, 252, 0.78);
}

.routerai-mode-quick-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.routerai-mode-quick-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-radius: 999px;
    background: #ffffff;
    color: #1d4ed8;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 900;
    cursor: pointer;
}

.routerai-mode-quick-toggle span {
    color: #64748b;
    font-size: 0.76rem;
    font-weight: 700;
}

.routerai-mode-quick-scroll {
    margin-top: 0.6rem;
    max-height: 82px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.15rem 0 0.35rem;
    transition: max-height 0.18s ease, opacity 0.18s ease, margin-top 0.18s ease;
}

.routerai-mode-quick-actions.is-collapsed .routerai-mode-quick-scroll {
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    pointer-events: none;
}

.routerai-mode-quick-actions.is-collapsed {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}

.routerai-mode-quick-actions.is-collapsed + .routerai-capability-strip {
    border-top: 0;
}

[data-theme="dark"] .routerai-mode-quick-toggle {
    background: #0f172a;
    border-color: rgba(96, 165, 250, 0.24);
    color: #93c5fd;
}

[data-theme="dark"] .routerai-mode-quick-toggle span {
    color: #94a3b8;
}

@media (max-width: 767.98px) {
    .routerai-mode-quick-actions {
        padding: 0.5rem 0.75rem;
    }

    .routerai-mode-quick-toggle {
        width: 100%;
        justify-content: space-between;
    }

    .routerai-mode-quick-toggle span {
        display: none;
    }

    .routerai-mode-quick-scroll {
        max-height: 120px;
    }
}

/* RouterAI Task 23C: AI Settings compact modal */
.routerai-ai-settings-button {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    max-width: 100%;
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-radius: 999px;
    background: #ffffff;
    color: #1d4ed8;
    padding: 0.5rem 0.8rem;
    font-weight: 900;
    cursor: pointer;
    text-align: left;
}

.routerai-ai-settings-main {
    flex: 0 0 auto;
}

.routerai-ai-settings-summary {
    min-width: 0;
    max-width: 620px;
    overflow: hidden;
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.routerai-ai-settings-modal .modal-header {
    border-bottom-color: rgba(148, 163, 184, 0.20);
}

.routerai-ai-setting-section {
    padding: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    background: #f8fafc;
}

.routerai-ai-setting-section + .routerai-ai-setting-section {
    margin-top: 1rem;
}

.routerai-ai-setting-section .web-search-toggle {
    margin-top: 0.25rem;
}

[data-theme="dark"] .routerai-ai-settings-button {
    background: #0f172a;
    border-color: rgba(96, 165, 250, 0.24);
    color: #93c5fd;
}

[data-theme="dark"] .routerai-ai-settings-summary {
    color: #94a3b8;
}

[data-theme="dark"] .routerai-ai-settings-modal .modal-content {
    background: #0f172a;
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-ai-setting-section {
    background: #111827;
    border-color: rgba(148, 163, 184, 0.20);
}

@media (max-width: 767.98px) {
    .routerai-ai-settings-button {
        width: 100%;
        justify-content: space-between;
    }

    .routerai-ai-settings-summary {
        max-width: 58vw;
    }
}

/* RouterAI Task 23C-2: vertical space polish */
.chat-topbar {
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
    min-height: auto !important;
}

.routerai-mode-quick-compact {
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
}

.routerai-capability-strip {
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
}

.chat-messages {
    min-height: 0 !important;
}

.chat-main > .routerai-mode-quick-compact + .routerai-capability-strip,
.routerai-mode-quick-compact + .routerai-capability-strip {
    margin-top: 0 !important;
}

.routerai-ai-settings-button,
.routerai-mode-quick-toggle {
    min-height: 36px;
    padding-top: 0.38rem !important;
    padding-bottom: 0.38rem !important;
}

@media (min-width: 768px) {
    .chat-topbar {
        align-items: center !important;
    }

    .routerai-mode-quick-compact {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .routerai-capability-strip {
        min-height: 44px;
        align-items: center;
    }
}

@media (max-width: 767.98px) {
    .chat-topbar {
        padding: 0.55rem 0.75rem !important;
    }

    .routerai-mode-quick-compact,
    .routerai-capability-strip {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* Task 23C-3: fix quick-start selected badge overlap */
.routerai-mode-quick-compact {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    position: relative !important;
    z-index: 1;
    padding: 0.45rem 0.75rem !important;
    min-height: 48px;
    margin: 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.routerai-mode-quick-compact .routerai-mode-quick-toggle,
.routerai-mode-quick-compact .routerai-mode-quick-current,
.routerai-mode-quick-compact .routerai-selected-quickstart,
.routerai-mode-quick-compact .routerai-selected-prompt {
    position: static !important;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    margin: 0 !important;
    vertical-align: middle;
}

.routerai-mode-quick-compact .routerai-mode-quick-current,
.routerai-mode-quick-compact .routerai-selected-quickstart,
.routerai-mode-quick-compact .routerai-selected-prompt {
    white-space: normal;
    word-break: break-word;
}

.routerai-capability-strip {
    position: relative !important;
    z-index: 0;
    margin-top: 0 !important;
    padding-top: 0.55rem !important;
    padding-bottom: 0.55rem !important;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chat-messages {
    position: relative;
    z-index: 0;
}

@media (max-width: 767.98px) {
    .routerai-mode-quick-compact {
        align-items: flex-start;
        min-height: auto;
    }
}

/* RouterAI Task 24C: PDF workflow quick actions */
.routerai-quickstart-group-pdf {
    border-color: rgba(124, 58, 237, 0.26);
    background: linear-gradient(180deg, rgba(124, 58, 237, 0.055), rgba(248, 250, 252, 0.96));
}

.routerai-quickstart-group-pdf .routerai-quickstart-group-title {
    color: #6d28d9;
}

[data-theme="dark"] .routerai-quickstart-group-pdf {
    border-color: rgba(167, 139, 250, 0.30);
    background: linear-gradient(180deg, rgba(88, 28, 135, 0.30), rgba(17, 24, 39, 0.96));
}

[data-theme="dark"] .routerai-quickstart-group-pdf .routerai-quickstart-group-title {
    color: #c4b5fd;
}

/* RouterAI Task 24D: attachment status display polish */
.routerai-attachment-status-card {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.4rem 0.75rem;
    align-items: center;
    width: 100%;
    border-radius: 14px;
    padding: 0.6rem 0.75rem;
}

.routerai-attachment-status-main {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    min-width: 0;
}

.routerai-attachment-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.10);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 900;
    padding: 0.2rem 0.45rem;
}

.routerai-attachment-name {
    min-width: 0;
    max-width: 420px;
    overflow: hidden;
    color: #0f172a;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.routerai-attachment-size {
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
}

.routerai-attachment-status-meta {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    color: #475569;
    font-size: 0.76rem;
    font-weight: 700;
}

.routerai-attachment-status-meta span {
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.05);
    padding: 0.18rem 0.5rem;
}

[data-theme="dark"] .routerai-attachment-type {
    background: rgba(96, 165, 250, 0.16);
    color: #93c5fd;
}

[data-theme="dark"] .routerai-attachment-name {
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-attachment-size,
[data-theme="dark"] .routerai-attachment-status-meta {
    color: #94a3b8;
}

[data-theme="dark"] .routerai-attachment-status-meta span {
    background: rgba(148, 163, 184, 0.12);
}

@media (max-width: 767.98px) {
    .routerai-attachment-status-card {
        grid-template-columns: 1fr;
    }

    .routerai-attachment-name {
        max-width: 70vw;
    }

    .routerai-attachment-status-card button {
        width: 100%;
    }
}

/* RouterAI Task 25A-3: URL Reader UI */
.routerai-url-reader-toggle {
    border-color: rgba(124, 58, 237, 0.22);
}

.routerai-url-reader-toggle .web-search-toggle-main {
    color: #6d28d9;
}

[data-theme="dark"] .routerai-url-reader-toggle {
    border-color: rgba(167, 139, 250, 0.26);
}

[data-theme="dark"] .routerai-url-reader-toggle .web-search-toggle-main {
    color: #c4b5fd;
}

/* RouterAI Task 25A-3: AI Settings modal width fix */
#aiSettingsModal .modal-body {
    overflow-x: hidden;
}

#aiSettingsModal .routerai-ai-setting-section,
#aiSettingsModal .web-search-toggle,
#aiSettingsModal .routerai-url-reader-toggle {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

#aiSettingsModal .web-search-toggle {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

#aiSettingsModal .web-search-toggle input[type="checkbox"] {
    flex: 0 0 auto;
    margin-top: 4px;
}

#aiSettingsModal .web-search-toggle-main {
    flex: 0 0 auto;
}

#aiSettingsModal .web-search-toggle-sub {
    flex: 1 1 220px;
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 576px) {
    #aiSettingsModal .web-search-toggle {
        gap: 8px;
    }

    #aiSettingsModal .web-search-toggle-main,
    #aiSettingsModal .web-search-toggle-sub {
        flex: 1 1 100%;
    }
}

/* RouterAI Task 26B: Model capability filter chips */
.routerai-model-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 10px;
}

.routerai-model-filter-chip {
    border: 1px solid rgba(15, 23, 42, 0.14);
    background: #ffffff;
    color: #334155;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.routerai-model-filter-chip:hover {
    transform: translateY(-1px);
    border-color: rgba(37, 99, 235, 0.35);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.routerai-model-filter-chip.is-active {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

[data-theme="dark"] .routerai-model-filter-chip {
    background: rgba(15, 23, 42, 0.75);
    color: #dbeafe;
    border-color: rgba(148, 163, 184, 0.22);
}

[data-theme="dark"] .routerai-model-filter-chip.is-active {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #ffffff;
}

/* RouterAI Task 26C: Selected model capability badges */
.routerai-selected-model-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    min-height: 24px;
}

.routerai-model-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 0.76rem;
    font-weight: 600;
    color: #334155;
    background: rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.routerai-model-badge-tier {
    color: #1d4ed8;
    background: rgba(37, 99, 235, 0.09);
    border-color: rgba(37, 99, 235, 0.16);
}

[data-theme="dark"] .routerai-model-badge {
    color: #dbeafe;
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .routerai-model-badge-tier {
    color: #bfdbfe;
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(96, 165, 250, 0.24);
}

/* RouterAI Task 27C: Rich markdown response rendering */
.chat-bubble-content h2,
.chat-bubble-content h3,
.chat-bubble-content h4,
.chat-bubble-content h5 {
    margin: 0.85rem 0 0.45rem;
    font-weight: 700;
    line-height: 1.25;
}

.chat-bubble-content h2:first-child,
.chat-bubble-content h3:first-child,
.chat-bubble-content h4:first-child,
.chat-bubble-content h5:first-child {
    margin-top: 0;
}

.chat-bubble-content p {
    margin: 0 0 0.65rem;
    line-height: 1.6;
}

.chat-bubble-content p:last-child {
    margin-bottom: 0;
}

.chat-bubble-content ul,
.chat-bubble-content ol {
    margin: 0.35rem 0 0.75rem 1.25rem;
    padding-left: 1rem;
}

.chat-bubble-content li {
    margin: 0.2rem 0;
    line-height: 1.55;
}

.chat-bubble-content strong {
    font-weight: 700;
}

.chat-bubble-content code {
    border-radius: 6px;
    padding: 0.08rem 0.28rem;
    background: rgba(15, 23, 42, 0.08);
    font-size: 0.92em;
}

.chat-bubble-content .code-block code {
    background: transparent;
    padding: 0;
}

.routerai-markdown-table-wrap {
    width: 100%;
    overflow-x: auto;
    margin: 0.75rem 0;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.10);
}

.routerai-markdown-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 0.92rem;
    background: rgba(255, 255, 255, 0.65);
}

.routerai-markdown-table th,
.routerai-markdown-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    text-align: left;
    vertical-align: top;
}

.routerai-markdown-table th {
    font-weight: 700;
    background: rgba(37, 99, 235, 0.08);
}

.routerai-markdown-table tr:last-child td {
    border-bottom: 0;
}

[data-theme="dark"] .chat-bubble-content code {
    background: rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .routerai-markdown-table-wrap {
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .routerai-markdown-table {
    background: rgba(15, 23, 42, 0.35);
}

[data-theme="dark"] .routerai-markdown-table th,
[data-theme="dark"] .routerai-markdown-table td {
    border-bottom-color: rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .routerai-markdown-table th {
    background: rgba(59, 130, 246, 0.18);
}

/* RouterAI Task 28D: Create Document UI */
.routerai-create-document-modal .modal-header {
    align-items: flex-start;
}

.routerai-create-document-flow {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.routerai-create-document-step {
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(15, 23, 42, 0.035);
    border-radius: 12px;
    padding: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    text-align: center;
    color: #475569;
}

.routerai-create-document-step.active {
    border-color: rgba(37, 99, 235, 0.28);
    background: rgba(37, 99, 235, 0.10);
    color: #1d4ed8;
}

.message-tools .create-document-inline {
    font-weight: 600;
}

[data-theme="dark"] .routerai-create-document-step {
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(148, 163, 184, 0.10);
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-create-document-step.active {
    border-color: rgba(96, 165, 250, 0.32);
    background: rgba(59, 130, 246, 0.18);
    color: #bfdbfe;
}

@media (max-width: 575.98px) {
    .routerai-create-document-flow {
        grid-template-columns: 1fr 1fr;
    }
}

/* RouterAI Task 28D-2: Create Document in-page notice */
.routerai-create-document-notice {
    max-width: 760px;
    margin: 12px auto;
    padding: 14px 16px;
    border: 1px solid rgba(37, 99, 235, 0.22);
    background: rgba(37, 99, 235, 0.08);
    color: #0f172a;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] .routerai-create-document-notice {
    border-color: rgba(96, 165, 250, 0.30);
    background: rgba(59, 130, 246, 0.16);
    color: #e5e7eb;
}

/* RouterAI Task 28E-2 Fix 2 */
.routerai-create-document-notice-error {
    border-color: rgba(220, 38, 38, 0.28);
    background: rgba(220, 38, 38, 0.08);
}

[data-theme="dark"] .routerai-create-document-notice-error {
    border-color: rgba(248, 113, 113, 0.32);
    background: rgba(220, 38, 38, 0.18);
}

/* RouterAI Task 28F: Document Preview Page */
.routerai-document-preview-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 34%),
        radial-gradient(circle at top right, rgba(124, 58, 237, 0.08), transparent 30%),
        #f8fafc;
}

.routerai-document-preview-shell {
    max-width: 1180px;
    margin: 0 auto;
}

.routerai-document-preview-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.routerai-document-preview-header h1 {
    margin: 0;
    font-size: clamp(1.45rem, 2.5vw, 2.2rem);
    font-weight: 800;
    color: #0f172a;
}

.routerai-document-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.routerai-document-meta span {
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.8);
    color: #475569;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 600;
}

.routerai-document-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.routerai-document-paper {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 20px;
    padding: clamp(22px, 4vw, 44px);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);
    color: #0f172a;
    line-height: 1.72;
}

.routerai-document-paper h2,
.routerai-document-paper h3,
.routerai-document-paper h4,
.routerai-document-paper h5 {
    margin-top: 1.6rem;
    margin-bottom: 0.7rem;
    font-weight: 800;
    color: #0f172a;
}

.routerai-document-paper h2:first-child,
.routerai-document-paper h3:first-child {
    margin-top: 0;
}

.routerai-document-paper p {
    margin-bottom: 1rem;
}

.routerai-document-paper ul,
.routerai-document-paper ol {
    padding-left: 1.35rem;
    margin-bottom: 1rem;
}

.routerai-document-paper li {
    margin-bottom: 0.4rem;
}

.routerai-document-paper code {
    background: rgba(15, 23, 42, 0.06);
    border-radius: 6px;
    padding: 1px 5px;
}

.routerai-document-code {
    background: #0f172a;
    color: #e5e7eb;
    border-radius: 14px;
    padding: 14px;
    overflow-x: auto;
}

.routerai-document-table-wrap {
    overflow-x: auto;
    margin: 1rem 0 1.2rem;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 14px;
}

.routerai-document-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
    background: #fff;
}

.routerai-document-table th,
.routerai-document-table td {
    padding: 11px 12px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    vertical-align: top;
}

.routerai-document-table th {
    background: rgba(37, 99, 235, 0.08);
    color: #1e3a8a;
    font-weight: 800;
}

.routerai-document-sidecard {
    position: sticky;
    top: 18px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.07);
}

.routerai-document-sidecard h2 {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 12px;
    color: #0f172a;
}

.routerai-document-sidecard dl {
    margin: 0;
}

.routerai-document-sidecard dt {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-top: 10px;
}

.routerai-document-sidecard dd {
    margin: 2px 0 0;
    color: #0f172a;
    font-weight: 600;
}

[data-theme="dark"] .routerai-document-preview-page {
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 34%),
        radial-gradient(circle at top right, rgba(139, 92, 246, 0.16), transparent 30%),
        #020617;
}

[data-theme="dark"] .routerai-document-preview-header h1,
[data-theme="dark"] .routerai-document-paper,
[data-theme="dark"] .routerai-document-paper h2,
[data-theme="dark"] .routerai-document-paper h3,
[data-theme="dark"] .routerai-document-paper h4,
[data-theme="dark"] .routerai-document-paper h5,
[data-theme="dark"] .routerai-document-sidecard h2,
[data-theme="dark"] .routerai-document-sidecard dd {
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-document-paper,
[data-theme="dark"] .routerai-document-sidecard {
    background: rgba(15, 23, 42, 0.92);
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .routerai-document-meta span {
    background: rgba(15, 23, 42, 0.88);
    border-color: rgba(148, 163, 184, 0.18);
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-document-table-wrap,
[data-theme="dark"] .routerai-document-table th,
[data-theme="dark"] .routerai-document-table td {
    border-color: rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .routerai-document-table {
    background: #0f172a;
}

[data-theme="dark"] .routerai-document-table th {
    background: rgba(59, 130, 246, 0.18);
    color: #bfdbfe;
}

[data-theme="dark"] .routerai-document-sidecard dt {
    color: #94a3b8;
}

@media (max-width: 991.98px) {
    .routerai-document-preview-header {
        flex-direction: column;
    }

    .routerai-document-actions {
        justify-content: flex-start;
    }

    .routerai-document-sidecard {
        position: static;
    }
}

@media (max-width: 575.98px) {
    .routerai-document-paper {
        border-radius: 16px;
        padding: 18px;
    }

    .routerai-document-actions .btn {
        width: 100%;
    }
}

/* RouterAI Task 28J: Exported file list */
.routerai-exported-file-list {
    display: grid;
    gap: 10px;
}

.routerai-exported-file-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 14px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.72);
}

.routerai-exported-file-main {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    min-width: 0;
}

.routerai-exported-file-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    padding: 4px 7px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.10);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
}

.routerai-exported-file-name {
    font-size: 0.86rem;
    font-weight: 700;
    color: #0f172a;
    word-break: break-word;
}

.routerai-exported-file-meta {
    margin-top: 2px;
    font-size: 0.74rem;
    color: #64748b;
}

[data-theme="dark"] .routerai-exported-file-item {
    border-color: rgba(148, 163, 184, 0.16);
    background: rgba(15, 23, 42, 0.72);
}

[data-theme="dark"] .routerai-exported-file-type {
    background: rgba(59, 130, 246, 0.18);
    color: #bfdbfe;
}

[data-theme="dark"] .routerai-exported-file-name {
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-exported-file-meta {
    color: #94a3b8;
}

@media (max-width: 575.98px) {
    .routerai-exported-file-item {
        grid-template-columns: 1fr;
    }

    .routerai-exported-file-item .btn {
        width: 100%;
    }
}

/* RouterAI Task 28J-2: My Documents page */
.routerai-documents-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 34%),
        radial-gradient(circle at top right, rgba(124, 58, 237, 0.08), transparent 30%),
        #f8fafc;
}

.routerai-documents-shell {
    max-width: 1180px;
    margin: 0 auto;
}

.routerai-documents-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
}

.routerai-documents-header h1 {
    margin: 0;
    font-size: clamp(1.55rem, 2.6vw, 2.25rem);
    font-weight: 800;
    color: #0f172a;
}

.routerai-documents-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.routerai-document-help-card,
.routerai-documents-card {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    box-shadow: 0 20px 56px rgba(15, 23, 42, 0.07);
}

.routerai-document-help-card {
    padding: 14px 16px;
}

.routerai-documents-card {
    padding: 18px;
}

.routerai-documents-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.routerai-documents-card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: #0f172a;
}

.routerai-empty-state {
    border: 1px dashed rgba(15, 23, 42, 0.16);
    border-radius: 14px;
    padding: 18px;
    color: #475569;
    background: rgba(248, 250, 252, 0.72);
}

.routerai-document-list,
.routerai-generated-file-list {
    display: grid;
    gap: 12px;
}

.routerai-document-list-item,
.routerai-generated-file-item {
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 16px;
    padding: 13px;
    background: rgba(255, 255, 255, 0.75);
}

.routerai-document-list-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}

.routerai-document-list-title,
.routerai-generated-file-title {
    font-weight: 800;
    color: #0f172a;
    word-break: break-word;
}

.routerai-document-list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
}

.routerai-document-list-meta span {
    border-radius: 999px;
    padding: 4px 8px;
    background: rgba(37, 99, 235, 0.09);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 700;
}

.routerai-document-list-actions,
.routerai-generated-file-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.routerai-generated-file-top {
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.routerai-generated-file-meta,
.routerai-generated-file-doc {
    color: #64748b;
    font-size: 0.78rem;
    margin-top: 5px;
}

.routerai-generated-file-actions {
    justify-content: flex-start;
    margin-top: 10px;
}

[data-theme="dark"] .routerai-documents-page {
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 34%),
        radial-gradient(circle at top right, rgba(139, 92, 246, 0.16), transparent 30%),
        #020617;
}

[data-theme="dark"] .routerai-documents-header h1,
[data-theme="dark"] .routerai-documents-card-header h2,
[data-theme="dark"] .routerai-document-list-title,
[data-theme="dark"] .routerai-generated-file-title {
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-document-help-card,
[data-theme="dark"] .routerai-documents-card,
[data-theme="dark"] .routerai-document-list-item,
[data-theme="dark"] .routerai-generated-file-item {
    background: rgba(15, 23, 42, 0.88);
    border-color: rgba(148, 163, 184, 0.16);
}

[data-theme="dark"] .routerai-empty-state {
    background: rgba(15, 23, 42, 0.70);
    border-color: rgba(148, 163, 184, 0.20);
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-document-list-meta span {
    background: rgba(59, 130, 246, 0.18);
    color: #bfdbfe;
}

[data-theme="dark"] .routerai-generated-file-meta,
[data-theme="dark"] .routerai-generated-file-doc {
    color: #94a3b8;
}

@media (max-width: 767.98px) {
    .routerai-documents-header,
    .routerai-document-list-item {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .routerai-documents-actions,
    .routerai-document-list-actions {
        justify-content: flex-start;
    }

    .routerai-document-list-actions .btn,
    .routerai-documents-actions .btn {
        width: 100%;
    }
}

/* RouterAI Task 28L: Generated file retention notice */
.routerai-retention-notice {
    border: 1px solid rgba(245, 158, 11, 0.28);
    background: rgba(245, 158, 11, 0.10);
    color: #92400e;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.84rem;
}

[data-theme="dark"] .routerai-retention-notice {
    border-color: rgba(251, 191, 36, 0.30);
    background: rgba(245, 158, 11, 0.16);
    color: #fde68a;
}

/* RouterAI Task 28L-2: Expiry badges */
.routerai-expiry-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    margin-top: 8px;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 0.72rem;
    font-weight: 800;
}

.routerai-expiry-ok {
    background: rgba(22, 163, 74, 0.10);
    color: #15803d;
}

.routerai-expiry-warning {
    background: rgba(245, 158, 11, 0.14);
    color: #92400e;
}

.routerai-expiry-danger {
    background: rgba(220, 38, 38, 0.10);
    color: #b91c1c;
}

[data-theme="dark"] .routerai-expiry-ok {
    background: rgba(34, 197, 94, 0.16);
    color: #86efac;
}

[data-theme="dark"] .routerai-expiry-warning {
    background: rgba(245, 158, 11, 0.18);
    color: #fde68a;
}

[data-theme="dark"] .routerai-expiry-danger {
    background: rgba(220, 38, 38, 0.18);
    color: #fca5a5;
}

/* Task 29C-1: Create from PDF AI Credit notice */
.routerai-ai-credit-notice {
    border: 1px solid rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.08);
    border-radius: 14px;
    padding: 12px 14px;
    margin: 0 0 16px;
    font-size: 0.92rem;
    line-height: 1.45;
}

.routerai-ai-credit-notice strong {
    display: block;
    margin-bottom: 3px;
}

[data-theme="dark"] .routerai-ai-credit-notice {
    border-color: rgba(96, 165, 250, 0.28);
    background: rgba(96, 165, 250, 0.12);
}

/* Task 30A: RouterAI User Guide Centre */
.routerai-help-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 32rem),
        radial-gradient(circle at top right, rgba(124, 58, 237, 0.10), transparent 30rem),
        #f6f8fb;
    color: #111827;
}

.routerai-help-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.routerai-help-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.routerai-help-kicker {
    margin: 0 0 6px;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
    color: #2563eb;
}

.routerai-help-header h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3rem);
    letter-spacing: -0.04em;
}

.routerai-help-header p {
    max-width: 760px;
    margin: 8px 0 0;
    color: #4b5563;
}

.routerai-help-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.routerai-help-search-card {
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.30);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 18px;
}

.routerai-help-search-card label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
}

.routerai-help-search-card input {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.42);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 1rem;
    outline: none;
    background: #fff;
}

.routerai-help-search-card input:focus {
    border-color: rgba(37, 99, 235, 0.70);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.routerai-help-search-card p {
    margin: 8px 0 0;
    color: #64748b;
    font-size: 0.9rem;
}

.routerai-help-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.routerai-help-toc {
    position: sticky;
    top: 16px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.30);
    border-radius: 18px;
    padding: 12px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    max-height: calc(100vh - 32px);
    overflow: auto;
}

.routerai-help-toc a {
    display: block;
    text-decoration: none;
    color: #334155;
    font-weight: 650;
    padding: 9px 10px;
    border-radius: 12px;
    margin-bottom: 3px;
}

.routerai-help-toc a:hover {
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
}

.routerai-help-content {
    display: grid;
    gap: 14px;
}

.routerai-help-section {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.30);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.06);
    scroll-margin-top: 20px;
}

.routerai-help-section h2 {
    margin: 0 0 10px;
    font-size: 1.28rem;
    letter-spacing: -0.02em;
}

.routerai-help-section p {
    margin: 8px 0;
    color: #374151;
    line-height: 1.6;
}

[data-theme="dark"] .routerai-help-page {
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 32rem),
        radial-gradient(circle at top right, rgba(124, 58, 237, 0.16), transparent 30rem),
        #07111f;
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-help-header p,
[data-theme="dark"] .routerai-help-search-card p,
[data-theme="dark"] .routerai-help-section p {
    color: #cbd5e1;
}

[data-theme="dark"] .routerai-help-search-card,
[data-theme="dark"] .routerai-help-toc,
[data-theme="dark"] .routerai-help-section {
    background: rgba(15, 23, 42, 0.84);
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .routerai-help-search-card input {
    background: rgba(15, 23, 42, 0.92);
    border-color: rgba(148, 163, 184, 0.25);
    color: #e5e7eb;
}

[data-theme="dark"] .routerai-help-toc a {
    color: #dbeafe;
}

[data-theme="dark"] .routerai-help-toc a:hover {
    background: rgba(96, 165, 250, 0.12);
    color: #bfdbfe;
}

@media (max-width: 860px) {
    .routerai-help-header {
        display: block;
    }

    .routerai-help-actions {
        justify-content: flex-start;
        margin-top: 14px;
    }

    .routerai-help-layout {
        grid-template-columns: 1fr;
    }

    .routerai-help-toc {
        position: static;
        max-height: none;
        display: flex;
        gap: 6px;
        overflow-x: auto;
    }

    .routerai-help-toc a {
        white-space: nowrap;
    }
}

/* Task 31A — Help Centre navigation/mobile polish */
.routerai-help-page {
    font-family: var(--bs-body-font-family);
}

.routerai-help-actions {
    align-items: center;
}

@media (max-width: 575.98px) {
    .routerai-help-shell {
        width: calc(100% - 20px);
        padding-top: 18px;
    }

    .routerai-help-actions {
        width: 100%;
        display: flex;
        gap: 8px;
    }

    .routerai-help-actions .btn {
        flex: 1 1 0;
    }

    .routerai-help-search-card {
        padding: 13px;
        border-radius: 15px;
    }

    .routerai-help-section {
        padding: 16px;
        border-radius: 16px;
    }
}

/* =========================================================
   Task 32A — Academic Research Workspace
   ========================================================= */

.routerai-research-page {
    min-height: 100vh;
}

.routerai-research-shell {
    max-width: 1380px;
}

.routerai-research-hero {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 24px;
    padding: clamp(22px, 4vw, 42px);
    background:
        radial-gradient(
            circle at top right,
            rgba(99, 102, 241, 0.14),
            transparent 34rem
        ),
        rgba(255, 255, 255, 0.92);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.06);
}

.routerai-research-summary-card {
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 20px;
    padding: 22px;
    background: rgba(255, 255, 255, 0.78);
}

.routerai-research-project-list {
    display: grid;
    gap: 8px;
}

.routerai-research-project-item {
    display: block;
    text-decoration: none;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 14px;
    padding: 12px 13px;
    transition:
        transform 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.routerai-research-project-item strong,
.routerai-research-project-item span {
    display: block;
}

.routerai-research-project-item span {
    margin-top: 4px;
    font-size: 0.82rem;
    color: var(--bs-secondary-color);
}

.routerai-research-project-item:hover {
    transform: translateY(-1px);
    border-color: rgba(99, 102, 241, 0.40);
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

.routerai-research-project-item.active {
    border-color: rgba(13, 110, 253, 0.55);
    background: rgba(13, 110, 253, 0.07);
}

.routerai-research-module-card {
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    padding: 20px;
    background: var(--bs-body-bg);
    box-shadow: 0 12px 35px rgba(15, 23, 42, 0.05);
}

.routerai-research-empty-state {
    min-height: 420px;
    display: grid;
    place-content: center;
    text-align: center;
    border: 1px dashed rgba(148, 163, 184, 0.50);
    border-radius: 22px;
    padding: 30px;
}

[data-theme="dark"] .routerai-research-hero,
[data-theme="dark"] .routerai-research-summary-card {
    background: rgba(15, 23, 42, 0.90);
    border-color: rgba(148, 163, 184, 0.18);
}

[data-theme="dark"] .routerai-research-module-card {
    border-color: rgba(148, 163, 184, 0.18);
}

@media (max-width: 767.98px) {
    .routerai-research-hero {
        border-radius: 18px;
        padding: 20px;
    }

    .routerai-research-summary-card {
        border-radius: 16px;
        padding: 18px;
    }

    .routerai-research-module-card {
        border-radius: 16px;
        padding: 17px;
    }
}

/* =========================================================
   Task 33A — Academic Manuscript Workspace
   ========================================================= */

.routerai-manuscript-page {
    min-height: 100vh;
}

.routerai-manuscript-shell {
    max-width: 1500px;
}

.routerai-manuscript-list {
    display: grid;
    gap: 8px;
}

.routerai-manuscript-list-item {
    display: block;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    text-decoration: none;
}

.routerai-manuscript-list-item strong,
.routerai-manuscript-list-item span {
    display: block;
}

.routerai-manuscript-list-item span {
    color: var(--bs-secondary-color);
    font-size: 0.82rem;
    margin-top: 3px;
}

.routerai-manuscript-list-item.active {
    border-color: rgba(13, 110, 253, 0.55);
    background: rgba(13, 110, 253, 0.07);
}

.routerai-manuscript-section-card {
    background: var(--bs-body-bg);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 18px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 10px 34px rgba(15, 23, 42, 0.05);
}

.routerai-manuscript-section-header,
.routerai-manuscript-section-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.routerai-manuscript-section-header {
    margin-bottom: 14px;
}

.routerai-manuscript-section-footer {
    margin-top: 12px;
}

.routerai-manuscript-section-text {
    line-height: 1.65;
    resize: vertical;
    min-height: 150px;
}

.routerai-save-state {
    min-width: 90px;
    text-align: right;
}

.routerai-manuscript-empty {
    min-height: 430px;
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    padding: 32px;
    border-radius: 20px;
    border: 1px dashed rgba(148, 163, 184, 0.48);
}

[data-theme="dark"] .routerai-manuscript-section-card {
    border-color: rgba(148, 163, 184, 0.18);
}

@media (max-width: 575.98px) {

    .routerai-manuscript-section-card {
        border-radius: 15px;
        padding: 15px;
    }

    .routerai-manuscript-section-header {
        align-items: flex-start;
    }

    .routerai-manuscript-section-footer {
        display: block;
    }

    .routerai-manuscript-section-footer .btn {
        width: 100%;
        margin-top: 10px;
    }

    .routerai-save-state {
        min-width: 0;
    }
}

/* =========================================================
   Task 33B — Academic Research Source Library
   ========================================================= */

.routerai-research-sources-page {
    min-height: 100vh;
}

.routerai-research-sources-shell {
    max-width: 1450px;
}

.routerai-research-source-list {
    display: grid;
    gap: 14px;
}

.routerai-research-source-item {
    border:
        1px solid
        rgba(148, 163, 184, 0.24);

    border-radius: 16px;

    padding: 18px;

    background: var(--bs-body-bg);

    box-shadow:
        0 8px 28px
        rgba(15, 23, 42, 0.04);
}

.routerai-research-source-main {
    min-width: 0;
    flex: 1 1 420px;
}

.routerai-research-source-actions {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 7px;
}

.routerai-research-source-empty {
    min-height: 280px;

    display: grid;

    place-content: center;

    text-align: center;

    border:
        1px dashed
        rgba(148, 163, 184, 0.48);

    border-radius: 16px;

    padding: 26px;
}

[data-theme="dark"]
.routerai-research-source-item {
    border-color:
        rgba(148, 163, 184, 0.18);
}

@media (max-width: 575.98px) {

    .routerai-research-source-item {
        padding: 15px;
        border-radius: 14px;
    }

    .routerai-research-source-actions {
        width: 100%;
    }

    .routerai-research-source-actions
    .btn,
    .routerai-research-source-actions
    form {
        flex: 1 1 auto;
    }

    .routerai-research-source-actions
    form
    .btn {
        width: 100%;
    }
}

/* TASK38B_MODEL_RECOMMENDATION_UI */
.routerai-model-recommendation-panel {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.85rem;
    background: var(--bs-tertiary-bg);
    padding: 0.9rem;
    margin-bottom: 0.85rem;
    min-width: 0;
}

.routerai-model-recommendation-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.7rem;
}

.routerai-model-recommendation-count {
    flex: 0 0 auto;
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    padding: 0.18rem 0.55rem;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    background: var(--bs-body-bg);
}

.routerai-model-recommendation-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
    min-width: 0;
}

.routerai-model-recommendation-card {
    width: 100%;
    min-width: 0;
    text-align: left;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.75rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.routerai-model-recommendation-card:hover,
.routerai-model-recommendation-card:focus-visible {
    border-color: var(--bs-primary);
    transform: translateY(-1px);
    outline: none;
}

.routerai-model-recommendation-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.routerai-model-recommendation-card-top strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.routerai-model-recommendation-label {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 0.14rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
}

.routerai-model-recommendation-meta,
.routerai-model-recommendation-reason,
.routerai-model-recommendation-verification {
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    overflow-wrap: anywhere;
}

.routerai-model-recommendation-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.routerai-model-recommendation-badges span {
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    padding: 0.1rem 0.38rem;
    font-size: 0.68rem;
    background: var(--bs-tertiary-bg);
}

.routerai-model-recommendation-verification {
    border-top: 1px dashed var(--bs-border-color);
    padding-top: 0.35rem;
    margin-top: 0.1rem;
}

.routerai-model-compatibility-warning {
    overflow-wrap: anywhere;
}

.routerai-model-badge-recommended {
    border-color: var(--bs-primary-border-subtle);
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
}

.routerai-model-badge-warning {
    border-color: var(--bs-warning-border-subtle);
    background: var(--bs-warning-bg-subtle);
    color: var(--bs-warning-text-emphasis);
}

@media (max-width: 991.98px) {
    .routerai-model-recommendation-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 575.98px) {
    .routerai-model-recommendation-panel {
        padding: 0.75rem;
    }

    .routerai-model-recommendation-head,
    .routerai-model-recommendation-card-top {
        flex-direction: column;
    }

    .routerai-model-recommendation-count,
    .routerai-model-recommendation-label {
        align-self: flex-start;
    }
}

