/* ───── Override parent template for Chat layout ───── */
body:has(.chat-shell) footer,
body:has(.chat-page) footer {
    display: none;
}

body:has(.chat-shell) .site-content,
body:has(.chat-page) .site-content {
    margin-bottom: 0;
    padding-bottom: 0;
}

.reportbot-shell:has(.chat-shell) {
    padding: 0;
}

.reportbot-shell:has(.chat-shell) .reportbot-container {
    max-width: 100%;
}

/* ───── Chat Page Layout ───── */
.chat-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 0.9rem;
    height: calc(100vh - 80px);
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 0.75rem 0.9rem;
}

.chat-sidebar {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-sidebar-header {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.chat-sidebar-title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    color: var(--text-main);
    font-size: 0.92rem;
}

.chat-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.78rem;
    transition: all 0.15s ease;
    font-family: inherit;
    white-space: nowrap;
}

.chat-new-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #003b6f08;
}

.chat-history {
    padding: 0.5rem;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.55rem 0.6rem;
    border-radius: 10px;
    border: 1px solid transparent;
    color: var(--text-main);
    transition: all 0.15s ease;
    position: relative;
}

.chat-history-item:hover {
    background: #f8fafc;
    border-color: #e5e7eb;
}

.chat-history-item.is-active {
    background: #003b6f10;
    border-color: #003b6f22;
}

.chat-history-item-link {
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.chat-history-item-title {
    font-size: 0.82rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-history-menu-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #d1d5db;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-history-item:hover .chat-history-menu-btn,
.chat-history-menu-btn.is-open {
    color: #9ca3af;
}

.chat-history-menu-btn:hover {
    background: #e5e7eb;
    color: var(--text-main);
}

.chat-history-dropdown {
    display: none;
    position: fixed;
    z-index: 9999;
    min-width: 130px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 0.3rem;
    animation: dropdownFadeIn 0.15s ease;
}

.chat-history-dropdown.is-open {
    display: block;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-history-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--text-main);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s ease;
}

.chat-history-dropdown-item:hover {
    background: #f3f4f6;
}

.chat-history-delete-btn {
    color: #ef4444;
}

.chat-history-delete-btn:hover {
    background: #fef2f2;
}

.chat-history-empty {
    padding: 0.75rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chat-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: none;
    margin: 0;
    background: var(--bg, #ebeff5);
    border-radius: 12px;
    overflow: hidden;
}

/* ───── Header ───── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    flex-shrink: 0;
}

.chat-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #003b6f, #0066cc);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.chat-header-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

/* ───── Messages Area ───── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #c4c9d4;
    border-radius: 3px;
}

/* ───── Welcome ───── */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 2rem 1rem;
    opacity: 0.92;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #003b6f20, #0066cc15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

.chat-welcome h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 0.4rem;
}

.chat-welcome p {
    font-size: 0.88rem;
    color: var(--text-muted);
    max-width: 400px;
    margin: 0 0 1.25rem;
    line-height: 1.55;
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.suggestion-chip {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: inherit;
}

.suggestion-chip:hover {
    border-color: var(--primary);
    background: #003b6f08;
    color: var(--primary);
    transform: translateY(-1px);
}

.suggestion-chip i {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* ───── Message Bubbles ───── */
.chat-msg {
    display: flex;
    gap: 0.6rem;
    max-width: 85%;
    animation: fadeInMsg 0.25s ease;
}

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

.chat-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg--bot {
    align-self: flex-start;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg--user .chat-msg-avatar {
    background: var(--primary);
    color: #fff;
}

.chat-msg--bot .chat-msg-avatar {
    background: #e5e7eb;
    color: #4b5563;
}

.chat-msg-bubble {
    border-radius: 12px;
    padding: 0.65rem 0.9rem;
    line-height: 1.55;
    font-size: 0.88rem;
    word-break: break-word;
}

.chat-msg--user .chat-msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg--bot .chat-msg-bubble {
    background: #fff;
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-msg-bubble p {
    margin: 0 0 0.4rem;
}

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

/* ───── Typing Indicator ───── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typingBounce 1.2s ease-in-out infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-6px); opacity: 1; }
}

/* ───── SQL Block ───── */
.chat-sql-block {
    background: #1e1e1e;
    border-radius: 8px;
    overflow: hidden;
    margin: 0.5rem 0;
    border: 1px solid #333;
}

.chat-sql-header {
    background: #2d2d2d;
    padding: 0.4rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid #333;
}

.chat-sql-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-sql-badge {
    background: rgba(198, 120, 221, 0.2);
    color: #c678dd;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
}

.chat-sql-block pre {
    margin: 0;
    background: #1e1e1e;
    border: none;
    padding: 0;
}

.chat-sql-block pre code {
    display: block;
    padding: 0.8rem 0.75rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    color: #d4d4d4;
}

.chat-sql-block .token.keyword  { color: #c678dd; }
.chat-sql-block .token.function { color: #61afef; }
.chat-sql-block .token.string   { color: #98c379; }
.chat-sql-block .token.number   { color: #d19a66; }
.chat-sql-block .token.operator,
.chat-sql-block .token.punctuation { color: #d4d4d4; }

/* ───── Confirm Buttons ───── */
.chat-confirm {
    margin-top: 0.5rem;
}

.chat-confirm-text {
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
    color: var(--text-main);
}

.chat-confirm-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: inherit;
    transition: all 0.15s ease;
}

.chat-btn--accept {
    background: #10b981;
    color: #fff;
}

.chat-btn--accept:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.chat-btn--decline {
    background: #fff;
    color: #6b7280;
    border-color: #d1d5db;
}

.chat-btn--decline:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

/* ───── Error ───── */
.chat-error {
    color: #ef4444;
    margin: 0;
}

.chat-error i {
    margin-right: 0.3rem;
}

/* ───── Data Table ───── */
.chat-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.chat-result-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.chat-result-count i {
    margin-right: 0.3rem;
}

.chat-result-actions {
    display: flex;
    gap: 0.4rem;
}

.chat-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    border-radius: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.15s ease;
}

.chat-export-btn--excel {
    background: #10b981;
    color: #fff;
}

.chat-export-btn--excel:hover {
    background: #059669;
    color: #fff;
}

.chat-export-btn--pdf {
    background: #ef4444;
    color: #fff;
}

.chat-export-btn--pdf:hover {
    background: #dc2626;
    color: #fff;
}

.chat-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    max-height: 400px;
    overflow-y: auto;
}

.chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.chat-table thead th {
    background: #f5f7fb;
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.chat-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-main);
}

.chat-table tbody tr:hover {
    background: #f9fafb;
}

.chat-table tr:last-child td {
    border-bottom: none;
}

.chat-table-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.5rem 0 0;
    font-style: italic;
}

.chat-empty-result {
    text-align: center;
    padding: 1rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chat-empty-result i {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.4rem;
    opacity: 0.4;
}

/* ───── Input Area ───── */
.chat-input-area {
    padding: 0.75rem 1rem 0.85rem;
    background: #fff;
    border-top: 1px solid var(--border);
    border-radius: 0;
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #f3f4f6;
    border-radius: 10px;
    padding: 0.4rem 0.5rem 0.4rem 0.85rem;
    border: 1px solid transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 59, 111, 0.08);
    background: #fff;
}

.chat-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.45;
    color: var(--text-main);
    outline: none;
    padding: 0.3rem 0;
    max-height: 120px;
    min-height: 22px;
}

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

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-dark, #00539c);
    transform: translateY(-1px);
}

.chat-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-input-hint {
    font-size: 0.7rem;
    color: #9ca3af;
    text-align: center;
}

.chat-input-hint kbd {
    background: #e5e7eb;
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    font-size: 0.65rem;
    font-family: inherit;
}

/* ───── Responsive ───── */
@media (max-width: 768px) {
    .chat-shell {
        grid-template-columns: 1fr;
        height: auto;
        padding: 0;
        gap: 0.6rem;
    }

    .chat-sidebar {
        border-radius: 0;
    }

    .chat-page {
        height: calc(100vh - 60px);
        border-radius: 0;
    }

    .chat-msg {
        max-width: 95%;
    }

    .chat-header {
        border-radius: 0;
    }

    .chat-input-area {
        border-radius: 0;
    }

    .welcome-suggestions {
        flex-direction: column;
        align-items: center;
    }
}
