/* ===== Reset & base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark theme – match reference UI */
    --bg-app: #0f0f0f;
    --bg-header: #1a1a1a;
    --bg-sidebar: #252525;
    --bg-sidebar-section: #252525;
    --bg-main: #171717;
    --bg-chat-bubble-user: #2d5a3d;
    --bg-chat-bubble-assistant: #2a2d3a;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --nav-active-bg: #343541;
    --history-active-bg: #343541;
    --input-bg: #1f1f1f;
    --input-border: rgba(255, 255, 255, 0.12);
    --max-chat-width: 768px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* ===== App container ===== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

/* ===== App header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header-right {
    display: flex;
    align-items: center;
}

.app-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.logo-icon {
    width: 24px;
    height: 24px;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-collapse {
    margin-left: 4px;
    color: var(--text-secondary);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.btn-user {
    margin-left: 4px;
}

.header-user-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-right: 8px;
}

.auth-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}
.auth-link:hover {
    text-decoration: underline;
}

/* ===== App body: sidebar + main ===== */
.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s, min-width 0.2s;
}

body.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right-width: 0;
}

.sidebar-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-section:last-of-type {
    border-bottom: none;
}

.sidebar-section-user {
    position: relative;
    padding: 0;
    border-top: 1px solid var(--border-subtle);
}

.sidebar-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    gap: 8px;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
    transition: background 0.2s;
}

.sidebar-user-row:hover {
    background: var(--nav-active-bg);
}

.sidebar-user-chevron {
    flex-shrink: 0;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    transition: transform 0.2s;
}

.sidebar-user-row[aria-expanded="true"] .sidebar-user-chevron {
    transform: rotate(180deg);
}

.sidebar-username {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-dropdown {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    padding: 4px 0;
    margin-bottom: 2px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-user-dropdown.open {
    display: flex;
}

.sidebar-user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.sidebar-user-dropdown-item:hover {
    background: var(--nav-active-bg);
    color: var(--accent);
}

.sidebar-user-dropdown-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.sidebar-user-dropdown-item:hover .sidebar-user-dropdown-icon {
    color: var(--accent);
}

.sidebar-logout-btn {
    flex-shrink: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.sidebar-logout-btn:hover {
    color: var(--accent);
}

.sidebar-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 16px 8px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.nav-item:hover {
    background: var(--nav-active-bg);
}

.nav-item.active {
    background: var(--nav-active-bg);
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.nav-item.active .nav-icon {
    color: var(--text-primary);
}

.nav-icon-ask {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--nav-active-bg);
    color: var(--text-primary);
}

/* History list */
.sidebar-section-history {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-section-history .sidebar-section-title {
    flex-shrink: 0;
}

.history-list {
    list-style: none;
    overflow-y: auto;
    padding: 0 8px;
}

.history-item-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 6px;
    margin-bottom: 2px;
}

.history-item-wrap:hover .history-item-delete,
.history-item-wrap:has(.history-item.active) .history-item-delete {
    opacity: 1;
}

.history-item {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
    gap: 10px;
}

.history-item::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpolyline points='14 2 14 8 20 8'/%3E%3Cline x1='16' y1='13' x2='8' y2='13'/%3E%3Cline x1='16' y1='17' x2='8' y2='17'/%3E%3C/svg%3E") no-repeat center;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.history-item.active {
    background: var(--history-active-bg);
}

.history-item-delete {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s, background 0.2s;
}

.history-item-wrap:hover .history-item-delete:hover,
.history-item-delete:focus {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    opacity: 1;
}

.history-empty {
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.sidebar-user-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

/* ===== Main content ===== */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    overflow: hidden;
}

.view-container {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.view-container.active {
    display: flex;
}

/* ===== Chat panel ===== */
.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-header-left,
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-icon {
    display: inline-flex;
    color: var(--text-secondary);
}

.chat-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Chat messages ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    width: 100%;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 120px;
}

.welcome-text {
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.message {
    display: flex;
    flex-direction: column;
    width: fit-content;
    max-width: min(85%, 900px);
    min-width: 0;
    animation: messageIn 0.25s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.assistant {
    align-items: flex-start;
    align-self: flex-start;
}

.message.user {
    align-items: flex-end;
    align-self: flex-end;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9375rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    min-width: 0;
}

.message.assistant .message-content {
    background: var(--bg-chat-bubble-assistant);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background: var(--bg-chat-bubble-user);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}

/* ----- Typing indicator (GPT-style) ----- */
.message.assistant.message-typing .message-content {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 20px;
    padding: 16px 20px;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    opacity: 0.7;
    animation: typingBounce 1.4s ease-in-out infinite both;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ----- Word-by-word reveal (GPT-style response) ----- */
.message-content.animate-words {
    overflow: hidden;
}

.message-content .word {
    display: inline;
    white-space: pre-wrap;
    word-wrap: break-word;
    opacity: 0;
    animation: wordIn 0.15s ease forwards;
}

@keyframes wordIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ----- Markdown inside assistant messages ----- */
.message-content-markdown p {
    margin: 0 0 0.75em 0;
}
.message-content-markdown p:last-child {
    margin-bottom: 0;
}
.message-content-markdown code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
}
.message-content-markdown pre {
    background: rgba(0, 0, 0, 0.35);
    padding: 12px 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75em 0;
    font-size: 0.875rem;
    line-height: 1.5;
}
.message-content-markdown pre code {
    background: none;
    padding: 0;
    font-size: inherit;
}
.message-content-markdown ul,
.message-content-markdown ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}
.message-content-markdown li {
    margin: 0.25em 0;
}
.message-content-markdown h1,
.message-content-markdown h2,
.message-content-markdown h3,
.message-content-markdown h4 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
    line-height: 1.3;
}
.message-content-markdown h1 { font-size: 1.25rem; }
.message-content-markdown h2 { font-size: 1.1rem; }
.message-content-markdown h3,
.message-content-markdown h4 { font-size: 1rem; }
.message-content-markdown blockquote {
    border-left: 4px solid var(--accent);
    margin: 0.75em 0;
    padding-left: 1em;
    color: var(--text-secondary);
}
.message-content-markdown a {
    color: var(--accent);
    text-decoration: none;
}
.message-content-markdown a:hover {
    text-decoration: underline;
}
.message-content-markdown hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 1em 0;
}
.message-content-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75em 0;
    font-size: 0.9rem;
}
.message-content-markdown th,
.message-content-markdown td {
    border: 1px solid var(--border-subtle);
    padding: 6px 10px;
    text-align: left;
}
.message-content-markdown th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

/* ===== Chat input ===== */
.chat-input-wrap {
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-main);
    flex-shrink: 0;
}

.input-row {
    width: min(100%, 900px);
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 10px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

#chatInput {
    flex: 1;
    min-height: 44px;
    max-height: 200px;
    padding: 10px 4px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-family: inherit;
    resize: none;
    line-height: 1.5;
}

#chatInput::placeholder {
    color: var(--text-muted);
}

#chatInput:focus {
    outline: none;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
    align-self: center;
}

.send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* ===== Upload view ===== */
.upload-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
}

.upload-view-header {
    margin-bottom: 24px;
}

.upload-view-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-view-desc {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.upload-zone {
    border: 2px dashed var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(34, 197, 94, 0.06);
}

.upload-zone-dragover {
    border-color: var(--accent);
    background: rgba(34, 197, 94, 0.1);
}

.upload-zone-icon {
    display: block;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.upload-zone:hover .upload-zone-icon,
.upload-zone-dragover .upload-zone-icon {
    color: var(--accent);
}

.upload-zone-text {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.upload-zone-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.upload-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: center;
}

.btn-upload {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-upload:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-upload:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.btn-clear-files {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--input-border);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-clear-files:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.upload-file-list {
    margin-top: 16px;
}

.upload-file-items {
    list-style: none;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.upload-file-items li {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.upload-status {
    margin-top: 16px;
    font-size: 0.875rem;
    min-height: 1.5em;
}

.upload-status-success {
    color: var(--accent);
}

.upload-status-error {
    color: #ef4444;
}

.upload-status-info {
    color: var(--text-secondary);
}

/* ===== Weblink view ===== */
.weblink-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
}

.weblink-view-header {
    margin-bottom: 24px;
}

.weblink-view-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.weblink-view-desc {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.weblink-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.weblink-label {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.weblink-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    box-sizing: border-box;
}

.weblink-input::placeholder {
    color: var(--text-muted);
}

.weblink-input:focus {
    outline: none;
    border-color: var(--accent);
}

.weblink-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn-weblink-submit {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-weblink-submit:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-weblink-submit:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.weblink-status {
    margin-top: 16px;
    font-size: 0.875rem;
    min-height: 1.5em;
}

.weblink-status-success {
    color: var(--accent);
}

.weblink-status-error {
    color: #ef4444;
}

.weblink-status-info {
    color: var(--text-secondary);
}

/* ===== Manage Documents view ===== */
.manage-docs-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    width: 100%;
    min-width: 0;
}

.manage-docs-header {
    margin-bottom: 20px;
}

.manage-docs-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.manage-docs-desc {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.manage-docs-toolbar {
    margin-bottom: 16px;
}

.btn-refresh-docs {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--input-border);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-refresh-docs:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--text-muted);
}

.manage-docs-list-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    /* Use available height; scroll only when doc count exceeds visible area */
    max-height: calc(100vh - 200px);
}

.manage-docs-loading,
.manage-docs-error {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.manage-docs-error {
    color: #ef4444;
}

.manage-docs-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.manage-docs-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.manage-docs-item-name {
    flex: 1;
    min-width: 0;
}

.manage-docs-item-delete {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
}

.manage-docs-item-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

.manage-docs-item-delete:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.manage-docs-item:last-child {
    margin-bottom: 0;
}

.manage-docs-empty {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* ===== Statistics view (admin) ===== */
.statistics-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    width: 100%;
    min-width: 0;
}

.statistics-view-header {
    margin-bottom: 20px;
}

.statistics-view-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.statistics-view-desc {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.statistics-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.statistics-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
    background: var(--input-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    min-width: 140px;
}

.statistics-card-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.statistics-card-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.statistics-actions {
    margin-bottom: 16px;
}

.btn-test-llm {
    display: inline-flex;
    align-items: center;
    padding: 10px 18px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-test-llm:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-test-llm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.statistics-llm-result {
    font-size: 0.9375rem;
    margin-top: 12px;
}

.statistics-llm-ok {
    color: var(--success, #22c55e);
}

.statistics-llm-error {
    color: #ef4444;
}

.statistics-toolbar {
    margin-top: 8px;
}

.btn-refresh-stats {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--input-border);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-refresh-stats:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--text-muted);
}

/* ===== Placeholder views ===== */
.placeholder-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    color: var(--text-secondary);
}

.placeholder-view h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.placeholder-view p {
    font-size: 0.9375rem;
    max-width: 400px;
}

/* ===== Personalization modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.modal-overlay.open {
    display: flex;
}

.personalization-modal {
    background: var(--bg-header);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    margin: -4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.personalization-section {
    margin-bottom: 20px;
}

.personalization-section:last-child {
    margin-bottom: 0;
}

.personalization-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.personalization-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    line-height: 1.45;
}

.personalization-select,
.personalization-input,
.personalization-textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-family: inherit;
}

.personalization-select:focus,
.personalization-input:focus,
.personalization-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.personalization-textarea {
    resize: vertical;
    min-height: 80px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.btn-modal {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}

.btn-cancel {
    background: var(--nav-active-bg);
    color: var(--text-primary);
    border: 1px solid var(--input-border);
}

.btn-cancel:hover {
    background: #3d3d4a;
}

.btn-save {
    background: var(--accent);
    color: #fff;
    border: none;
}

.btn-save:hover {
    background: var(--accent-hover);
}

/* ===== Toasts ===== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    min-width: 220px;
    max-width: 420px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    background: #222;
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    font-size: 0.875rem;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast-success {
    border-color: rgba(34, 197, 94, 0.45);
}

.toast-error {
    border-color: rgba(239, 68, 68, 0.45);
}

.toast-info {
    border-color: rgba(59, 130, 246, 0.45);
}

.toast-hide {
    opacity: 0;
    transform: translateY(-6px);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        max-width: 100%;
    }

    .sidebar {
        width: 220px;
        min-width: 220px;
    }

    .message-content {
        max-width: 92%;
    }
}
