/* =====================================================
   CSS Variables & Reset
   ===================================================== */
:root {
    --primary:       #4f46e5;
    --primary-dark:  #3730a3;
    --primary-light: #ede9fe;
    --surface:       #ffffff;
    --bg:            #f5f5f5;
    --border:        #e5e7eb;
    --text:          #111827;
    --text-muted:    #6b7280;
    --user-bubble:   #4f46e5;
    --user-text:     #ffffff;
    --bot-bubble:    #ffffff;
    --bot-text:      #111827;
    --danger:        #ef4444;
    --success:       #22c55e;
    --navbar-h:      58px;
    --footer-h:      40px;
    --radius:        12px;
    --shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:     0 4px 12px rgba(0,0,0,.10);
}

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

body {
    display: flex;
    flex-direction: column;
}

/* =====================================================
   Navbar
   ===================================================== */
.app-navbar {
    height: var(--navbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    z-index: 100;
    position: sticky;
    top: 0;
}

.navbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
}

.brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
}

.brand-text {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.2px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: background .15s, color .15s;
}

.nav-pill:hover {
    background: #f3f4f6;
    color: var(--text);
}

.nav-pill.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* =====================================================
   Main & Footer
   ===================================================== */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;    /* critical for flex children to shrink */
    overflow: hidden; /* contain scroll within children */
}

.app-footer {
    height: var(--footer-h);
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* =====================================================
   Documents page — scroll normally
   ===================================================== */
.page-scroll {
    flex: 1;
    overflow-y: auto;
}

/* =====================================================
   CHAT PAGE
   ===================================================== */
.chat-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Disclaimer banner */
.disclaimer-bar {
    background: #fffbeb;
    border-bottom: 1px solid #fde68a;
    padding: 8px 20px;
    font-size: 13px;
    color: #92400e;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

.disclaimer-bar .dismiss-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: #92400e;
    opacity: .6;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
}

.disclaimer-bar .dismiss-btn:hover { opacity: 1; }

/* Messages scroll area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }

/* ---- Empty state ---- */
.empty-state {
    max-width: 560px;
    margin: 40px auto 0;
    text-align: center;
    padding: 0 16px;
}

.empty-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 30px;
    color: var(--primary);
}

.empty-state h5 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

/* ---- Suggestion chips ---- */
.chips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
    text-align: left;
}

.chip {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .1s;
    text-align: left;
    line-height: 1.45;
}

.chip:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
    transform: translateY(-1px);
    color: var(--primary);
}

/* ---- Messages ---- */
.msg-row {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    animation: msgIn .2s ease;
}

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

.msg-row.user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
    align-self: flex-end;
}

.msg-avatar.bot  { background: var(--primary-light); color: var(--primary); }
.msg-avatar.user { background: #e0e7ff; color: var(--primary-dark); }

.msg-bubble {
    max-width: min(72%, 640px);
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.65;
    word-break: break-word;
}

.msg-row.user .msg-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.msg-row.bot .msg-bubble {
    background: var(--bot-bubble);
    color: var(--bot-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* markdown inside bot bubble */
.msg-bubble p           { margin-bottom: 8px; }
.msg-bubble p:last-child{ margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li          { margin-bottom: 4px; }
.msg-bubble strong      { font-weight: 600; }
.msg-bubble code        { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: .88em; color: #be185d; }

/* ---- Typing indicator ---- */
.typing-row {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

.typing-bubble {
    background: var(--surface);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 14px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 5px;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: bounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-7px); }
}

/* ---- Input bar ---- */
.chat-input-bar {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 14px 20px 16px;
    box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}

.input-row {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 11px 16px;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.5;
    background: #f9fafb;
    color: var(--text);
    max-height: 140px;
    overflow-y: auto;
    transition: border-color .2s, box-shadow .2s, background .2s;
    outline: none;
}

.chat-textarea:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.chat-textarea::placeholder { color: #9ca3af; }

/* Send button */
.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s, transform .1s, box-shadow .2s;
    box-shadow: 0 2px 8px rgba(79,70,229,.35);
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: 0 4px 14px rgba(79,70,229,.45);
    transform: translateY(-1px);
}

.btn-send:active { transform: scale(.96); }
.btn-send:disabled { background: #c7d2fe; box-shadow: none; cursor: not-allowed; }

/* New chat button */
.btn-new-chat {
    height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color .15s, color .15s, background .15s;
}

.btn-new-chat:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: #fef2f2;
}

.input-meta {
    max-width: 800px;
    margin: 6px auto 0;
    display: flex;
    justify-content: flex-end;
}

.char-count {
    font-size: 12px;
    color: #9ca3af;
}

/* =====================================================
   DOCUMENTS PAGE
   ===================================================== */
.docs-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 24px 48px;
    width: 100%;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h4 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-header p {
    font-size: 14px;
    color: var(--text-muted);
}

/* Upload card */
.upload-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 24px;
}

.upload-card h6 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 16px;
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 36px 24px;
    text-align: center;
    cursor: pointer;
    background: #fafafa;
    transition: border-color .2s, background .2s, box-shadow .2s;
    user-select: none;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: #f5f3ff;
    box-shadow: 0 0 0 4px rgba(79,70,229,.08);
}

.drop-zone .dz-icon {
    font-size: 40px;
    color: var(--primary);
    margin-bottom: 10px;
    display: block;
}

.drop-zone p {
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 15px;
}

.drop-zone span {
    font-size: 13px;
    color: var(--text-muted);
}

/* File preview */
.file-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    margin-top: 14px;
}

.file-preview .pdf-icon {
    width: 40px;
    height: 40px;
    background: #fee2e2;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--danger);
    flex-shrink: 0;
}

.file-preview .file-info { flex: 1; min-width: 0; }
.file-preview .file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview .file-size { font-size: 12px; color: var(--text-muted); }

/* Upload actions */
.upload-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    align-items: center;
    flex-wrap: wrap;
}

/* Progress bar */
.upload-progress {
    margin-top: 14px;
    background: #f3f4f6;
    border-radius: 8px;
    padding: 12px 16px;
}

.progress-label {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.progress-bar-track {
    height: 4px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    animation: indeterminate 1.4s infinite linear;
    width: 40%;
    transform-origin: left;
}

@keyframes indeterminate {
    0%   { transform: translateX(-100%) scaleX(1); }
    50%  { transform: translateX(80%) scaleX(1.5); }
    100% { transform: translateX(250%) scaleX(1); }
}

/* Documents table card */
.docs-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.docs-card-header h6 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

/* Table */
.docs-table {
    width: 100%;
    border-collapse: collapse;
}

.docs-table thead th {
    background: #f9fafb;
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.docs-table tbody td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.docs-table tbody tr:last-child td { border-bottom: none; }
.docs-table tbody tr:hover td { background: #fafafa; }

.doc-name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.doc-name-cell .pdf-badge {
    width: 32px;
    height: 32px;
    background: #fee2e2;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--danger);
    font-size: 15px;
    flex-shrink: 0;
}

.chunk-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

/* ---- Shared button styles ---- */
.btn-primary-solid {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .2s, box-shadow .2s, transform .1s;
    box-shadow: 0 2px 8px rgba(79,70,229,.3);
    text-decoration: none;
}

.btn-primary-solid:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(79,70,229,.4);
    transform: translateY(-1px);
    color: #fff;
}

.btn-primary-solid:disabled {
    background: #a5b4fc;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: 9px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
}

.btn-ghost:hover {
    border-color: #9ca3af;
    color: var(--text);
    background: #f9fafb;
}

.btn-danger-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: transparent;
    color: var(--danger);
    border: 1.5px solid #fca5a5;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.btn-danger-ghost:hover {
    background: #fef2f2;
    border-color: var(--danger);
}

.btn-sm-icon {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.btn-sm-icon:hover {
    border-color: #9ca3af;
    color: var(--text);
}

/* ---- Empty state (shared) ---- */
.empty-table-state {
    padding: 52px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-table-state i {
    font-size: 40px;
    opacity: .3;
    display: block;
    margin-bottom: 12px;
}

.empty-table-state p { font-size: 14px; margin: 0; }
.empty-table-state small { font-size: 13px; }

/* ---- Toast ---- */
.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast-item {
    pointer-events: all;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-md);
    animation: toastIn .25s ease;
    max-width: 360px;
}

.toast-item.success { background: #16a34a; }
.toast-item.error   { background: var(--danger); }

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

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 8000;
    animation: fadeIn .2s ease;
}

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

.modal-box {
    background: var(--surface);
    border-radius: 14px;
    padding: 28px;
    max-width: 380px;
    width: calc(100% - 40px);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: scaleIn .2s ease;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(.95); }
    to   { opacity: 1; transform: scale(1); }
}

.modal-box h6 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-box p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 22px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* spinner */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 600px) {
    .brand-text { display: none; }
    .nav-pill span { display: none; }
    .nav-pill { padding: 8px 10px; }
    .chips-grid { grid-template-columns: 1fr; }
    .msg-bubble { max-width: 85%; }
    .docs-page { padding: 20px 16px 40px; }
}
