/* Page layout: sidebar, main panel, header, sidebar sub-sections
   (new-chat button, chat history, action buttons, database selector),
   and the responsive @media breakpoint. */

.container {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    width: 100vw;
}

.main-panel {
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border);
}

.header {
    background: var(--bg-main);
    color: var(--text-main);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    flex: 1;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
}

.theme-toggle:hover {
    border-color: var(--primary);
    background: var(--bg-sidebar);
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary);
}

.header p {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 400;
}

.side-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    padding: 16px;
    gap: 12px;
    overflow: hidden;
}

.panel {
    background: transparent;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.panel h3 {
    color: var(--text-muted);
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* New Chat Button */
.new-chat-btn {
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Chivo', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s;
}
.new-chat-btn:hover {
    background: rgba(27, 68, 121, 0.05);
    border-color: var(--primary);
}
.new-chat-btn span {
    font-size: 16px;
    font-weight: 400;
}

/* Chat History Section */
.chat-history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.chat-history-section h3 {
    margin-bottom: 8px;
}
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-history-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.15s;
    position: relative;
}
.chat-history-item:hover {
    background: rgba(255, 255, 255, 0.5);
}
.chat-history-item.active {
    background: rgba(255, 255, 255, 0.9);
}
.chat-history-item .chat-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-history-item .chat-date {
    font-size: 11px;
    color: var(--text-muted);
}
.chat-history-item .chat-kb {
    font-size: 10px;
    color: var(--secondary);
    font-weight: 500;
    background: rgba(4, 145, 154, 0.1);
    padding: 1px 6px;
    border-radius: 10px;
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-history-item .delete-chat-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    color: var(--text-muted);
    z-index: 10;
    pointer-events: auto;
}
.chat-history-item:hover .delete-chat-btn {
    opacity: 0.7;
}
.chat-history-item .delete-chat-btn:hover {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}
.chat-history-item .chat-select-checkbox {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--secondary);
    z-index: 10;
}
.chat-history-item.select-mode {
    padding-left: 32px;
}
.chat-history-item.select-mode .chat-title {
    max-width: calc(100% - 60px);
}

/* History Action Buttons */
.history-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}
.history-action-btn {
    background: transparent;
    border: none;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    opacity: 0.6;
    transition: opacity 0.2s, background 0.2s;
    color: var(--text-muted);
}
.history-action-btn:hover {
    opacity: 1;
    background: var(--bg-tertiary);
}
.history-action-btn.select-mode-active {
    background: var(--secondary);
    color: white;
    opacity: 1;
}
.clear-history-btn {
    background: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    opacity: 0.6;
    transition: opacity 0.2s, background 0.2s;
}
.clear-history-btn:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.1);
}

/* Database Selector Section */
.db-section {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.db-section h3 {
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
}
.db-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}
.db-option {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.db-option:hover {
    border-color: var(--primary-light);
}
.db-option.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.db-option input {
    display: none;
}
.db-select-all {
    font-size: 11px;
    color: var(--secondary);
    cursor: pointer;
    margin-top: 6px;
    display: inline-block;
}
.db-select-all:hover {
    text-decoration: underline;
}

@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
    }
    .side-panel {
        display: none;
    }
}
