:root {
    --primary-color: #009CE8;
    --primary-hover: #0088cc;
    --page-background: #f5f7fa;
    --text-color: #243447;
    --brand-gray: #575757;
    --surface-color: #ffffff;
    --surface-muted: rgb(240, 240, 240);
    --surface-accent: #eef7fc;
    --surface-accent-hover: #dff1fb;
    --border-color: #e5edf5;
    --input-border: #d8e2ec;
    --muted-text: #596b7d;
    --button-primary: #0058a2;
    --button-primary-hover-text: #111111;
    --button-text: #ffffff;
    --button-radius: 8px;
    --focus-ring: rgba(0, 156, 232, 0.28);
    --accent-soft: rgba(0, 156, 232, 0.12);
    --accent-soft-hover: rgba(0, 156, 232, 0.2);
    --left-panel-width: 320px;
    --right-panel-width: 320px;
    --card-radius: 16px;
    --control-radius: 8px;
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    --overlay-shadow: 0 10px 24px rgba(0, 0, 0, 0.10);
}

* {
    box-sizing: border-box;
}

body {
    display: grid;
    grid-template-columns: minmax(180px, var(--left-panel-width)) 0 minmax(0, 1fr) 0 minmax(180px, var(--right-panel-width));
    gap: 0;
    margin: 0;
    min-height: 100vh;
    background: var(--page-background);
    color: var(--text-color);
    font-family: 'Open Sans', sans-serif;
    padding: 0;
}

body.source-overview-open {
    overflow: hidden;
}

body.panel-resizing {
    cursor: col-resize;
    user-select: none;
}

body.panel-resizing * {
    cursor: col-resize !important;
}

body.login-open,
body.auth-pending {
    display: block;
}

body.auth-pending .side-panel,
body.auth-pending .app-shell,
body.auth-pending .reference-panel,
body.auth-pending .panel-resizer,
body.auth-pending .source-overview-page,
body.login-open .side-panel,
body.login-open .reference-panel,
body.login-open .panel-resizer,
body.login-open .source-overview-page {
    display: none;
}

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

button {
    border: 1px solid var(--button-primary);
    border-radius: var(--button-radius);
    background: var(--button-primary);
    color: var(--button-text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    padding: 13px 18px;
    transition: background 0.2s ease-in-out, border-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

button:hover {
    background: transparent;
    color: var(--button-primary-hover-text);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.app-shell {
    min-width: 0;
    width: 100%;
    margin: 0;
    padding: 0;
}

.side-panel {
    position: sticky;
    top: 0;
    z-index: 1;
    min-height: 100vh;
    height: 100vh;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: none;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-wrap: break-word;
    hyphens: auto;
    padding: 22px;
}

.panel-resizer {
    position: sticky;
    top: 0;
    align-self: start;
    z-index: 3;
    width: 16px;
    margin: 0 -8px;
    height: 100vh;
    border: 0;
    border-radius: 0;
    background: transparent;
    cursor: col-resize;
    padding: 0;
}

.panel-resizer::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 42px;
    border-radius: 999px;
    background: linear-gradient(to right, #b8c0c8 0 2px, transparent 2px 4px, #b8c0c8 4px 6px);
    transform: translate(-50%, -50%);
}

.panel-resizer:hover,
.panel-resizer:focus-visible {
    background: transparent;
}

.panel-resizer:hover::after,
.panel-resizer:focus-visible::after,
body.panel-resizing .panel-resizer::after {
    background: linear-gradient(to right, #b8c0c8 0 2px, transparent 2px 4px, #b8c0c8 4px 6px);
}

.side-panel h2 {
    margin: 0 0 14px;
    font-size: 18px;
}

.side-panel-title {
    margin-bottom: 16px;
}

.side-panel-title h1 {
    margin: 0;
    overflow: hidden;
    font-size: 26px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-panel-title h1.hyphenated-title {
    overflow: visible;
    hyphens: auto;
    overflow-wrap: break-word;
    text-overflow: clip;
    white-space: normal;
}

.side-panel-title p {
    margin: 8px 0 0;
    color: var(--muted-text);
    font-size: 14px;
    hyphens: auto;
    line-height: 1.4;
    overflow-wrap: break-word;
}

.new-session-panel-button {
    width: 100%;
    margin-bottom: 26px;
    padding: 10px 12px;
}

.selector-group {
    margin-bottom: 22px;
}

.selector-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 700;
}

.selector-group select {
    width: 100%;
    border: 2px solid var(--input-border);
    border-radius: var(--control-radius);
    background: var(--surface-color);
    color: var(--text-color);
    padding: 9px 10px;
}

.selector-help {
    margin: 8px 0 0;
    color: var(--muted-text);
    font-size: 12px;
    line-height: 1.35;
}

.options-status {
    min-height: 18px;
    margin: 10px 0 0;
    color: var(--muted-text);
    font-size: 12px;
    font-weight: 600;
}

.options-status.error {
    color: #c0392b;
}

.source-overview-button {
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
}

.source-overview-status {
    min-height: 20px;
    margin: 12px 0;
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 600;
}

.source-overview-status.error {
    color: #c0392b;
}

.source-overview-empty {
    margin: 6px 0 0;
    color: var(--muted-text);
    font-size: 12px;
    line-height: 1.35;
}

.source-overview-page {
    position: fixed;
    inset: 0;
    z-index: 40;
    overflow-y: auto;
    background: var(--page-background);
    padding: 24px;
}

.source-overview-page[hidden] {
    display: none;
}

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

.source-overview-header h1 {
    margin: 0;
}

.source-overview-header p {
    margin: 6px 0 0;
    color: var(--muted-text);
    font-weight: 600;
}

.source-overview-page-status {
    min-height: 22px;
    margin-bottom: 12px;
    color: var(--muted-text);
    font-size: 14px;
    font-weight: 600;
}

.source-overview-page-status.error {
    color: #c0392b;
}

.source-overview-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.source-overview-controls label {
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 700;
}

.source-overview-controls input {
    width: min(420px, 100%);
    border: 2px solid var(--input-border);
    border-radius: var(--control-radius);
    padding: 9px 10px;
}

.source-overview-count {
    min-height: 20px;
    margin-bottom: 12px;
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 700;
}

.source-overview-table-wrap {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
}

.source-overview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.source-overview-table th,
.source-overview-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}

.source-overview-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-muted);
    color: #34495e;
}

.source-overview-sort-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    font-weight: 700;
}

.source-overview-sort-button:hover {
    background: transparent;
    color: var(--primary-color);
}

.source-overview-sort-button[aria-sort="ascending"],
.source-overview-sort-button[aria-sort="descending"] {
    color: var(--primary-color);
}

.source-overview-filter-wrap {
    position: relative;
    display: inline-block;
    margin-left: 8px;
}

.source-overview-filter-button {
    width: 24px;
    height: 24px;
    padding: 4px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--surface-color);
    color: var(--muted-text);
    vertical-align: middle;
}

.source-overview-filter-button:hover,
.source-overview-filter-button.active {
    background: var(--surface-accent);
    color: var(--primary-color);
}

.source-overview-filter-button svg {
    display: block;
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.source-overview-filter-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 3;
    min-width: 180px;
    max-height: 280px;
    overflow: hidden;
    overflow-y: auto;
    border: 1px solid var(--input-border);
    border-radius: var(--control-radius);
    background: var(--surface-color);
    box-shadow: var(--overlay-shadow);
}

.source-overview-tag-filter-menu {
    min-width: 220px;
}

.source-overview-filter-option {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 0;
    background: var(--surface-color);
    color: var(--text-color);
    padding: 8px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
}

.source-overview-filter-option.active::before {
    content: "✓ ";
}

.source-overview-filter-option:hover,
.source-overview-filter-option.active {
    background: var(--surface-accent);
    color: var(--primary-color);
}

.source-title-cell {
    min-width: 260px;
    font-weight: 700;
}

.source-tags-cell {
    min-width: 220px;
}

.source-tag-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0 6px 6px 0;
    border: 1px solid var(--input-border);
    border-radius: 999px;
    background: var(--surface-color);
    color: #111827;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.source-tag-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
}

.source-tag-extra {
    display: inline-block;
    color: var(--muted-text);
    font-size: 12px;
    font-style: italic;
    font-weight: 700;
    white-space: nowrap;
}

.source-overview-table a {
    color: var(--primary-color);
    font-weight: 700;
}

.login-card,
.chat-shell {
    background: var(--surface-color);
    border-radius: 0;
    box-shadow: var(--card-shadow);
}

.login-card[hidden],
.chat-shell[hidden] {
    display: none;
}

.login-card {
    width: min(460px, 100%);
    margin: 10vh auto 0;
    padding: 28px;
}

.login-card label {
    display: block;
    margin: 20px 0 8px;
    font-weight: 600;
}

.login-card input {
    width: 100%;
    border: 2px solid var(--input-border);
    border-radius: var(--control-radius);
    margin-bottom: 16px;
    padding: 12px 14px;
}

.login-card input:focus,
.chat-form textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
    outline: none;
}

.chat-shell {
    position: relative;
    z-index: 2;
    display: flex;
    min-height: 100vh;
    border: 1px solid var(--border-color);
    margin-bottom: 0;
    box-shadow: -6px 0 18px rgba(0, 0, 0, 0.05), 6px 0 18px rgba(0, 0, 0, 0.05);
    overflow: visible;
    flex-direction: column;
}

.chat-shell::before,
.chat-shell::after {
    display: none;
}

.chat-shell::before {
    top: 0;
}

.chat-shell::after {
    bottom: 0;
}

.chat-shell .chat-header {
    flex-shrink: 0;
}

.chat-header {
    display: none;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 8;
    min-height: 16px;
    margin: -1px -1px 0;
    border: 1px solid var(--border-color);
    border-bottom: 0;
    border-radius: 0;
    background: var(--surface-color);
    padding: 0;
}

.chat-header h1,
.login-card h1 {
    margin: 0;
}

.chat-header p,
.login-card p {
    margin: 8px 0 0;
    color: var(--muted-text);
}

.mobile-chat-title,
.mobile-chatbot-picker {
    display: none;
}

.mobile-menu-toggle,
.mobile-controls {
    display: none;
}

.chat-header-actions {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.header-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.new-session-panel-button .new-session-icon {
    display: none;
}

.mobile-menu-icon {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-menu-icon span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.mobile-menu-toggle[aria-expanded="true"] .mobile-menu-icon span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.mobile-menu-toggle[aria-expanded="true"] .mobile-menu-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .mobile-menu-icon span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

.secondary-button {
    border: 1px solid var(--button-primary);
    background: transparent;
    color: var(--button-primary-hover-text);
}

.secondary-button:hover {
    border-color: var(--button-primary);
    background: var(--button-primary);
    color: var(--button-text);
}

.chatbot-tabs {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 4px;
    position: sticky;
    top: 0;
    z-index: 8;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
    padding: 12px 24px 0;
}

.chatbot-tabs[hidden] {
    display: none;
}

.chatbot-tab {
    position: relative;
    bottom: -1px;
    border: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    background: var(--page-background, #f5f7fa);
    color: var(--muted-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 9px 18px;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chatbot-tab:hover {
    color: var(--primary-color);
}

.chatbot-tab:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.chatbot-tab.active {
    border-color: var(--border-color);
    border-bottom-color: var(--surface-color);
    background: var(--surface-color);
    color: var(--text-color);
    box-shadow: 0 -2px 4px rgba(36, 52, 71, 0.04);
}

.chatbot-tab.active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -1px;
    height: 3px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: var(--primary-color);
}

body.selector-tabs #chatbotSelectorGroup {
    display: none;
}

.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
    padding: 24px 24px calc(24px + var(--chat-form-space, 120px));
}

.scroll-bottom-button {
    position: fixed;
    right: 50%;
    bottom: var(--scroll-bottom-offset, 112px);
    z-index: 9;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--surface-color);
    color: var(--text-color);
    box-shadow: 0 8px 18px rgba(36, 52, 71, 0.18);
    padding: 0;
    transform: translateX(50%);
}

.scroll-bottom-button[hidden] {
    display: none;
}

.scroll-bottom-button:hover {
    background: var(--surface-color);
    color: var(--primary-color);
}

.scroll-bottom-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.message {
    display: flex;
    margin-bottom: 18px;
}

.message.user {
    justify-content: flex-end;
}
.message.assistant {
    flex-direction: column;
    align-items: flex-start;
}

.message.system {
    justify-content: center;
}

.message.system .message-content {
    max-width: min(640px, 90%);
    background: var(--surface-accent);
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.message-content {
    width: fit-content;
    max-width: min(720px, 86%);
    border-radius: 14px;
    padding: 14px 16px;
    line-height: 1.5;
}
.message.user .message-content {
    white-space: pre-wrap;
}
.message-content p {
    margin: 0 0 10px;
}
.message-content p:last-child,
.message-content ul:last-child,
.message-content ol:last-child {
    margin-bottom: 0;
}
.message-content ul,
.message-content ol {
    margin: 8px 0 10px 22px;
    padding: 0;
}
.message-content li {
    margin: 5px 0;
}
.message-content a {
    color: var(--primary-color);
}

.message-content table {
    border-collapse: collapse;
    margin: 10px 0;
}

.message-content th,
.message-content td {
    border: 1px solid #b8c7d6;
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}

.message-content th {
    background: #e6edf4;
}

.message-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.message-status-text {
    color: #5f6368;
    font-style: italic;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 48px;
}

.message-status .typing-indicator {
    min-width: 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #8f9297;
    animation: typing-bounce 1s infinite ease-in-out;
}

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

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

@keyframes typing-bounce {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.45;
    }

    40% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

.inline-citation {
    display: inline-flex;
    align-items: center;
    margin: 0 2px;
    border: 0;
    border-radius: 6px;
    background: #8f9297;
    color: #ffffff;
    min-width: 2.35em;
    min-height: 1.35em;
    padding: 2px 8px;
    font-size: 0.72em;
    font-weight: 700;
    line-height: 1.25;
    vertical-align: 0.08em;
}

.inline-citation:hover {
    background: #73777d;
}

.inline-citation.pending {
    opacity: 0.55;
    pointer-events: none;
}

.message.user .message-content {
    background: var(--primary-color);
    color: #ffffff;
}

.message.assistant .message-content {
    background: var(--surface-muted);
    color: var(--text-color);
}

.references {
    margin-top: 8px;
    max-width: min(720px, 86%);
    width: 100%;
}

.references-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    border: 0;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--primary-color);
    padding: 4px 8px;
    font-size: 12px;
}

.references-toggle:hover {
    background: var(--accent-soft-hover);
}

.references-toggle-arrow {
    display: inline-block;
    transition: transform 0.2s ease;
}

.references-toggle-arrow.open {
    transform: rotate(90deg);
}

.reference-list {
    display: flex;
    margin-top: 8px;
    flex-direction: column;
    gap: 6px;
}

.reference-list[hidden] {
    display: none;
}

.reference-button {
    display: flex;
    align-items: center;
    max-width: 100%;
    width: fit-content;
    gap: 6px;
    border: 0;
    background: transparent;
    color: var(--text-color);
    padding: 3px 0;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}

.reference-button:hover {
    background: transparent;
    color: var(--primary-color);
    text-decoration: underline;
}

.reference-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    color: var(--primary-color);
}

.reference-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.reference-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-form {
    display: flex;
    align-items: flex-end;
    position: sticky;
    bottom: 0;
    z-index: 8;
    flex-shrink: 0;
    order: 2;
    gap: 12px;
    padding: 18px 24px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.chat-form::before {
    content: "";
    position: absolute;
    right: 24px;
    bottom: 0;
    left: 24px;
    z-index: 0;
    height: 50%;
    background: var(--surface-color);
    pointer-events: none;
}

.chat-input-shell {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: stretch;
    flex: 1;
    min-width: 0;
    border: 1px solid var(--input-border);
    border-radius: 28px;
    background: var(--surface-color);
    padding: 18px 14px 12px 20px;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
}

.chat-input-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.active-chatbot-tag {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 4px;
    max-width: 100%;
    min-height: 30px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-accent);
    color: var(--primary-color);
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.active-chatbot-tag strong {
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
}

.chat-input-action-group {
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    gap: 8px;
}

.send-button-icon {
    display: inline-flex;
}

.chat-input-actions #sendButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    border-radius: 999px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.send-button-text {
    display: none;
}

.send-button-icon svg {
    display: block;
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-form textarea {
    flex: 0 0 auto;
    width: 100%;
    min-height: 32px;
    max-height: 180px;
    border: 0;
    border-radius: 0;
    line-height: 1.45;
    overflow-y: hidden;
    padding: 3px;
    resize: none;
}

.chat-form textarea:focus {
    border-color: transparent;
    box-shadow: none;
}

.status-message {
    min-height: 22px;
    margin-top: 12px;
    color: var(--muted-text);
    font-size: 14px;
    font-weight: 600;
}

.chat-shell > .status-message {
    flex-shrink: 0;
    order: 1;
    min-height: 0;
    margin: 0;
    padding: 0 24px 8px;
    background: var(--surface-color);
}

.chat-shell > .status-message:empty {
    display: none;
}

.status-message.error {
    color: #c0392b;
}

.reference-panel {
    position: sticky;
    top: 0;
    z-index: 1;
    min-width: 0;
    height: 100vh;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: none;
    padding: 28px;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-wrap: break-word;
    hyphens: auto;
}

.reference-panel[hidden] {
    display: block;
    visibility: visible;
}

.reference-panel[hidden] > * {
    visibility: hidden;
}

.reference-close {
    float: right;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    padding: 0;
}

.reference-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.reference-panel a {
    display: inline-block;
    color: var(--primary-color);
}

.reference-panel a[hidden] {
    display: none;
}

.reference-panel a:not([href]) {
    color: var(--muted-text);
    cursor: default;
    text-decoration: none;
}

.reference-find-button {
    margin-bottom: 12px;
    padding: 8px 12px;
    font-size: 13px;
}

.reference-find-button:disabled {
    opacity: 0.65;
}

.reference-match-status {
    min-height: 20px;
    margin-bottom: 10px;
    color: var(--muted-text);
    font-size: 13px;
    font-weight: 600;
}

.reference-match-status.error {
    color: #c0392b;
}

.reference-match-status a {
    color: var(--primary-color);
}

.reference-match-result {
    margin-bottom: 16px;
    color: #34495e;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px;
}

.reference-match-result h3 {
    margin: 0 0 8px;
    font-size: 14px;
}

.reference-match-context {
    margin: 0;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.reference-match-context mark {
    border-radius: 4px;
    background: #fff2a8;
    padding: 0 2px;
}

.reference-match-context mark.chunk-highlight {
    display: inline;
    background: #9fddff;
    box-shadow: 0 0 0 2px rgba(0, 156, 232, 0.35);
}

.reference-panel pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    color: #34495e;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
}

.json-reference-content {
    color: #34495e;
    background: var(--surface-muted);
    padding: 0;
}

.json-reference-label {
    margin-bottom: 14px;
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.json-reference-field + .json-reference-field {
    margin-top: 16px;
}

.json-reference-field h3 {
    margin: 0 0 6px;
    font-size: 14px;
}

.json-reference-field p {
    margin: 0;
    line-height: 1.55;
    white-space: pre-wrap;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 680px) {
    body {
        display: block;
        padding: 0;
    }

    .side-panel,
    .reference-panel[hidden] {
        display: none;
    }

    .panel-resizer {
        display: none;
    }

    .reference-panel {
        position: fixed;
        inset: 0;
        z-index: 20;
        width: 100%;
        height: auto;
        border-radius: 0;
        box-shadow: -12px 0 30px rgba(0, 0, 0, 0.16);
    }

    .app-shell {
        width: 100%;
        padding: 0;
    }

    .chat-shell {
        height: 100vh;
        height: 100dvh;
        min-height: 100vh;
        min-height: 100dvh;
        border: 0;
        margin-bottom: 0;
        overflow: hidden;
        border-radius: 0;
    }

    .chat-shell::before,
    .chat-shell::after {
        display: none;
    }

    .chatbot-tabs {
        display: none;
    }

    body.mobile-menu-open {
        overflow: hidden;
    }

    .chat-header {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 31;
        flex: 0 0 auto;
        align-items: center;
        gap: 12px;
        min-height: 0;
        margin: 0;
        border: 0;
        border-radius: 0;
        background: var(--surface-color);
        box-shadow: 0 8px 18px rgba(36, 52, 71, 0.12);
        padding: 5px 16px;
        justify-content: flex-start;
    }

    .chat-form {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-header-actions {
        order: 1;
        margin-left: auto;
        align-items: center;
    }

    .mobile-chat-title {
        order: 0;
        display: block;
        flex: 1;
        min-width: 0;
    }

    .mobile-chat-title h1 {
        display: inline-flex;
        align-items: center;
        max-width: 100%;
        margin: 0;
        overflow: hidden;
        padding: 0;
        font-size: 18px;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chat-title p {
        display: none;
    }

    .mobile-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        min-width: 44px;
        min-height: 44px;
        border-color: transparent;
        background: transparent;
        color: var(--text-color);
        padding: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:focus,
    .mobile-menu-toggle:focus-visible,
    .mobile-menu-toggle:active,
    .mobile-menu-toggle[aria-expanded="true"] {
        border-color: transparent;
        background: transparent !important;
        color: var(--text-color);
        outline: none;
    }

    .mobile-controls {
        position: fixed;
        top: 12px;
        right: 12px;
        left: 12px;
        z-index: 32;
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
        border: 1px solid var(--border-color);
        border-radius: var(--card-radius);
        background: var(--surface-color);
        box-shadow: var(--overlay-shadow);
        padding: 16px;
    }

    .mobile-controls[hidden] {
        display: none;
    }

    .mobile-controls-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .mobile-controls-header h2 {
        margin: 0;
        font-size: 18px;
    }

    .mobile-control-group[hidden] {
        display: none;
    }

    .mobile-control-group label {
        display: block;
        margin-bottom: 5px;
        color: var(--muted-text);
        font-size: 12px;
        font-weight: 700;
    }

    .mobile-control-group select,
    .mobile-source-button {
        width: 100%;
        min-height: 44px;
    }

    .mobile-control-group select {
        border: 2px solid var(--input-border);
        border-radius: var(--control-radius);
        background: var(--surface-color);
        color: var(--text-color);
        padding: 10px 12px;
    }

    .mobile-chatbot-picker {
        position: relative;
        display: block;
        flex: 0 1 auto;
        min-width: 0;
        padding: 0;
    }

    .mobile-chatbot-picker[hidden] {
        display: none;
    }

    .mobile-chatbot-picker-button {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        max-width: 100%;
        min-height: 36px;
        border: 0;
        border-radius: 999px;
        background: var(--surface-accent);
        color: var(--primary-color);
        padding: 7px 12px;
        box-shadow: none;
        font-weight: 700;
    }

    .mobile-chatbot-picker-button::after {
        content: "";
        width: 7px;
        height: 7px;
        flex: 0 0 auto;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: translateY(-2px) rotate(45deg);
    }

    .mobile-chatbot-picker-button[aria-expanded="true"]::after {
        transform: translateY(2px) rotate(225deg);
    }

    .mobile-chatbot-picker-button:hover {
        background: var(--surface-accent);
        color: var(--primary-color);
    }

    .mobile-chatbot-picker-button span {
        color: var(--primary-color);
        overflow: hidden;
        font-size: 14px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chatbot-options {
        position: absolute;
        right: auto;
        bottom: calc(100% + 6px);
        left: 0;
        z-index: 10;
        width: min(320px, calc(100vw - 28px));
        max-height: 240px;
        overflow-y: auto;
        border: 1px solid var(--input-border);
        border-radius: var(--card-radius);
        background: var(--surface-color);
        box-shadow: var(--overlay-shadow);
        padding: 6px;
    }

    .mobile-chatbot-options[hidden] {
        display: none;
    }

    .mobile-chatbot-option {
        display: block;
        width: 100%;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--text-color);
        padding: 10px 12px;
        text-align: left;
        font-weight: 700;
    }

    .mobile-chatbot-option:hover,
    .mobile-chatbot-option.active {
        background: var(--surface-accent);
        color: var(--primary-color);
    }

    .chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        padding: 18px 14px;
    }

    .scroll-bottom-button {
        position: absolute;
        bottom: var(--scroll-bottom-offset, 112px);
    }

    .message-content {
        hyphens: auto;
        max-width: 96%;
        overflow-wrap: break-word;
        padding: 13px 14px;
    }

    .references {
        max-width: 96%;
    }

    .reference-button {
        width: 100%;
    }

    .reference-title {
        white-space: normal;
    }

    .chat-form {
        position: sticky;
        bottom: 0;
        z-index: 8;
        flex: 0 0 auto;
        order: 2;
        gap: 10px;
        border: 0;
        border-radius: 0;
        background: var(--surface-color);
        padding: 10px 14px 14px;
    }

    .chat-form::before {
        display: none;
    }

    .chat-shell > .status-message {
        z-index: 8;
        flex: 0 0 auto;
        order: 1;
        min-height: 0;
        background: var(--surface-color);
        padding: 0 22px 6px;
    }

    .chat-shell > .status-message:empty {
        display: none;
    }

    .chat-input-shell {
        display: flex;
        border: 1px solid var(--input-border);
        border-radius: 24px;
        background: var(--surface-color);
        padding: 14px 12px 10px;
        flex-direction: column;
        gap: 6px;
        box-shadow: var(--card-shadow);
    }

    .chat-input-shell:focus-within {
        border-color: var(--input-border);
        box-shadow: var(--card-shadow);
    }

    .mobile-chatbot-tag {
        display: inline-flex;
        align-items: center;
        flex: 0 1 auto;
        max-width: 100%;
        min-height: 36px;
        overflow: hidden;
        border-radius: 999px;
        background: var(--surface-accent);
        color: var(--primary-color);
        padding: 7px 12px;
        font-size: 14px;
        font-weight: 700;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chatbot-tag[hidden] {
        display: none;
    }

    .active-chatbot-tag {
        display: none;
    }

    .chat-form textarea {
        flex: 0 0 auto;
        min-height: 28px;
        max-height: 140px;
        border: 0;
        border-radius: 0;
        line-height: 1.4;
        overflow-y: hidden;
        padding: 0;
        resize: none;
    }

    .chat-form textarea:focus {
        border-color: transparent;
        box-shadow: none;
    }

    .chat-input-actions {
        width: 100%;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .chat-input-action-group {
        display: flex;
        flex: 1;
        min-width: 0;
        align-items: center;
        gap: 8px;
    }

    .chat-input-actions #sendButton {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
        border-radius: 999px;
        padding: 0;
        font-size: 22px;
        line-height: 1;
    }

    .send-button-text {
        display: none;
    }

    .send-button-icon {
        display: inline;
    }

    .send-button-icon svg {
        display: block;
        width: 24px;
        height: 24px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2.5;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .source-overview-page {
        padding: 18px 14px;
    }

    .source-overview-header,
    .source-overview-controls {
        flex-direction: column;
        align-items: stretch;
    }

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

    .source-overview-table {
        min-width: 680px;
    }
}
