:root {
    --bg-dark: #050816;
    --panel-dark: #0B1220;
    --sidebar-dark: #071427;
    --accent-blue: #2563EB;
    --glow-blue: #3B82F6;
    --text-primary: #FFFFFF;
    --text-secondary: #94A3B8;
    --border: #1E293B;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    height: 100vh;
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-container {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 340px;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* LEFT SIDEBAR */

.sidebar {
    background: var(--sidebar-dark);
    border-right: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 26px;
}

.brand img {
    width: 56px;
    height: 50px;
    object-fit: contain;
    border-radius: 8px;
    background: white;
}

.brand h2 {
    font-size: 25px;
    line-height: 1.1;
}

.brand p {
    color: var(--text-secondary);
    margin-top: 3px;
    white-space: nowrap;
}

.new-chat-btn {
    width: 100%;
    padding: 11px 12px;
    background: #f8fafc;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 17px;
    margin-bottom: 28px;
}

.nav-heading {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 14px;
}

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

.sidebar-nav a {
    display: block;
    text-decoration: none;
    color: #b8c9df;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 16px;
}

.sidebar-nav a:hover {
    background: #13243a;
    color: white;
}

.sidebar-nav a.active {
    background: var(--accent-blue);
    color: white;
}

.profile-card {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 22px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 50px;
    height: 50px;
    flex: 0 0 50px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-blue);
}

.profile-card strong {
    display: block;
    font-size: 14px;
}

.profile-card span {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 3px;
}

/* MAIN AREA */

.chat-area {
    min-width: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 30px 36px 24px;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.chat-header h1 {
    font-size: clamp(24px, 2.5vw, 34px);
    line-height: 1.2;
}

.chat-header p {
    font-size: 17px;
    margin-top: 7px;
}

.search-box {
    width: min(265px, 36%);
    min-width: 170px;
    background: var(--panel-dark);
    color: white;
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 13px 16px;
    outline: none;
}

.search-box:focus,
#user-input:focus,
select:focus {
    border-color: var(--glow-blue);
}

/* PAGE NAVIGATION */

.view-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.view-section[hidden] {
    display: none !important;
}

/* CHAT */

.chat-history {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 15px;
}

.message {
    max-width: 88%;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px 24px;
    margin-bottom: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.assistant-message {
    background: var(--panel-dark);
}

.user-message {
    background: #10244a;
    border-color: #1d4ed8;
    margin-left: auto;
    white-space: pre-wrap;
}

.message h3 {
    font-size: 20px;
    margin-bottom: 4px;
}

.message ul {
    padding-left: 26px;
    margin-top: 3px;
}

.message p {
    margin: 3px 0;
}

.message .sources {
    color: var(--text-secondary);
    font-size: 12px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 12px;
}

/* QUICK ACTIONS */

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 8px 0 28px;
}

.quick-action {
    border: 1px solid var(--border);
    color: #60a5fa;
    background: transparent;
    border-radius: 24px;
    padding: 10px 18px;
}

.quick-action:hover {
    background: #0f1b31;
    border-color: #31517e;
}

/* CHAT INPUT */

.chat-input-container {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 auto;
    background: var(--panel-dark);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px 18px;
}

.mic-btn {
    border: 0;
    background: transparent;
    color: white;
    padding: 4px 8px;
    font-size: 20px;
}

#user-input {
    flex: 1;
    min-width: 0;
    color: white;
    background: transparent;
    border: 1px solid transparent;
    outline: none;
    padding: 8px;
}

#user-input::placeholder {
    color: #8aa1c2;
}

#send-btn {
    width: 50px;
    height: 48px;
    flex: 0 0 50px;
    border: 0;
    border-radius: 11px;
    background: var(--accent-blue);
    color: white;
    font-size: 22px;
}

#send-btn:disabled,
#upload-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.status-line {
    min-height: 18px;
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 8px;
    overflow-wrap: anywhere;
}

.status-line.error {
    color: #fca5a5;
}

.status-line.success {
    color: #86efac;
}

/* RIGHT SIDEBAR */

.info-sidebar {
    background: #08111f;
    border-left: 1px solid var(--border);
    padding: 28px;
    height: 100vh;
    overflow-y: auto;
}

.upload-card,
.recent-docs {
    background: var(--panel-dark);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 24px;
    margin-bottom: 24px;
}

.upload-card h2,
.recent-docs h2 {
    font-size: 21px;
    margin-bottom: 18px;
}

.upload-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 155px;
    border: 2px dashed #26364e;
    border-radius: 15px;
    color: #9bb0cc;
    cursor: pointer;
    text-align: center;
    padding: 16px;
    margin-bottom: 16px;
}

.upload-dropzone.drag-over {
    border-color: var(--glow-blue);
    background: #10203a;
}

.upload-dropzone strong {
    font-size: 16px;
}

.upload-dropzone span:last-child {
    font-size: 13px;
}

.file-icon {
    font-size: 24px;
    color: #d8e4f7;
}

#pdf-upload {
    display: block;
    width: 100%;
    max-width: 100%;
    margin-bottom: 12px;
    color: #9bb0cc;
    font-size: 13px;
}

.primary-button {
    background: var(--accent-blue);
    color: white;
    border: 0;
    border-radius: 10px;
    padding: 13px 16px;
    font-weight: 600;
}

.upload-button {
    width: 100%;
}

.primary-button:hover,
#send-btn:hover {
    background: #1d4ed8;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.section-heading h2 {
    margin-bottom: 18px;
}

.text-button {
    color: #3b82f6;
    background: transparent;
    border: 0;
    padding: 4px 0 14px;
}

.muted {
    color: var(--text-secondary);
    line-height: 1.5;
}

.doc-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.doc-item:last-child {
    border-bottom: 0;
}

.doc-item strong {
    display: block;
    font-size: 14px;
    margin-bottom: 4px;
}

.doc-item span {
    color: var(--text-secondary);
    font-size: 12px;
}

/* DASHBOARD PAGES */

.page-card {
    background: var(--panel-dark);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    margin-bottom: 20px;
}

.page-card h2 {
    font-size: 24px;
    margin-bottom: 10px;
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 22px 0;
}

.four-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
    background: #08111f;
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
}

.stat-card strong {
    font-size: 26px;
}

.data-list {
    margin-top: 14px;
}

.page-card label {
    display: block;
    margin: 18px 0 8px;
    color: #cbd5e1;
}

.page-card select {
    width: 100%;
    background: #08111f;
    border: 1px solid var(--border);
    color: white;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 14px;
}

.report-output {
    white-space: pre-wrap;
    line-height: 1.6;
    overflow-wrap: anywhere;
    background: #08111f;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-top: 18px;
    min-height: 140px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    border-bottom: 1px solid var(--border);
    padding: 18px 0;
}

.setting-row p {
    margin-top: 5px;
}

.danger-button {
    color: white;
    background: #991b1b;
    border: 1px solid #b91c1c;
    border-radius: 9px;
    padding: 10px 14px;
    white-space: nowrap;
}

.small-note {
    font-size: 12px;
    margin-top: 20px;
}

/* RESPONSIVE LAYOUT */

@media (max-width: 1120px) {

    .app-container {
        grid-template-columns: 220px minmax(0, 1fr) 290px;
    }

    .sidebar {
        padding: 18px;
    }

    .info-sidebar {
        padding: 18px;
    }

    .chat-area {
        padding: 24px;
    }

    .brand h2 {
        font-size: 21px;
    }

}

@media (max-width: 850px) {

    body {
        overflow: auto;
        height: auto;
    }

    .app-container {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .sidebar {
        height: auto;
        overflow: visible;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .profile-card {
        margin-top: 20px;
    }

    .chat-area {
        height: 75vh;
        min-height: 620px;
        padding: 20px;
    }

    .info-sidebar {
        height: auto;
        overflow: visible;
    }

    .chat-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .search-box {
        width: 100%;
    }

}
/* Recent Documents: preserve the dark dashboard design */

#recent-documents-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

#recent-documents-list .clickable-document {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border: 1px solid #1e293b;
    border-radius: 10px;
    background: #0b1220;
    color: #e2e8f0;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    box-sizing: border-box;
}

#recent-documents-list .clickable-document:hover {
    background: #13264a;
    border-color: #2563eb;
}

#recent-documents-list .clickable-document span {
    min-width: 0;
    overflow-wrap: anywhere;
}

#recent-documents-list .clickable-document small {
    flex-shrink: 0;
    color: #93c5fd;
}

#recent-documents-list .clickable-document:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* =========================================================
   SAVED CONVERSATIONS
   ========================================================= */

.chat-history-section {
    width: 100%;
    margin: -8px 0 24px;
    min-width: 0;
}

.chat-history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.chat-history-refresh {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: #bfdbfe;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
}

.chat-history-refresh:hover {
    background: #13243a;
    border-color: var(--glow-blue);
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.chat-list-empty {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.5;
    padding: 10px 8px;
    overflow-wrap: anywhere;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    padding: 4px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.chat-list-item:hover {
    background: #0f1b31;
    border-color: #1e3352;
}

.chat-list-item.active {
    background: #10244a;
    border-color: #1d4ed8;
}

.chat-list-title {
    flex: 1;
    min-width: 0;
    padding: 9px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #dbeafe;
    text-align: left;
    font-size: 13px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-list-title:hover {
    color: #ffffff;
}

.chat-list-title:disabled,
.chat-delete-btn:disabled,
.chat-history-refresh:disabled {
    opacity: 0.55;
    cursor: wait;
}

.chat-delete-btn {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: #94a3b8;
    font-size: 19px;
    line-height: 1;
    opacity: 0.7;
}

.chat-list-item:hover .chat-delete-btn,
.chat-list-item.active .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    background: #451a1a;
    border-color: #7f1d1d;
    color: #fecaca;
}

.chat-list-title:focus-visible,
.chat-delete-btn:focus-visible,
.chat-history-refresh:focus-visible {
    outline: 2px solid var(--glow-blue);
    outline-offset: 2px;
}

/* Keep long conversation titles from widening the sidebar. */
.sidebar,
.chat-history-section,
.chat-list,
.chat-list-item {
    min-width: 0;
}

/* Match the existing dashboard message classes used by main.js. */
.chat-message {
    max-width: 88%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px 20px;
    margin-bottom: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.chat-message.assistant-message {
    background: var(--panel-dark);
}

.chat-message.user-message {
    margin-left: auto;
    background: #10244a;
    border-color: #1d4ed8;
}

.message-avatar {
    flex: 0 0 auto;
    min-width: 32px;
    padding: 5px 7px;
    border-radius: 8px;
    background: #172554;
    color: #bfdbfe;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
}

.message-body {
    min-width: 0;
    flex: 1;
}

.message-content {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-sources {
    margin: 8px 0 14px 44px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #08111f;
    color: var(--text-secondary);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.message-sources ul {
    margin: 8px 0 0;
    padding-left: 22px;
}

.message-sources li {
    margin: 4px 0;
}

.welcome-message {
    max-width: 760px;
    margin: auto;
    padding: 28px 20px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.6;
}

.welcome-message h2 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: clamp(22px, 2vw, 30px);
}

.welcome-message p {
    margin: 0;
}

/* Small screens */
@media (max-width: 850px) {
    .chat-history-section {
        margin-top: 0;
    }

    .chat-message {
        max-width: 100%;
        padding: 14px;
        gap: 9px;
    }

    .message-sources {
        margin-left: 0;
    }
}