/* ========================================
    56k Knowledge Hub - Main Styles
    Base tokens & resets provided by base.css
    ======================================== */

/* Loading screen styles now centralized in base.css */

/* ========================================
   Main Container
   ======================================== */

.container {
    background: white;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: calc(100% - 40px);
    max-width: 1400px;
    margin: 20px auto;
    display: none;
    flex-direction: column;
    height: calc(100vh - 40px);
    overflow: hidden;
}

:root[data-theme="dark"] .container {
    background: #1E2532;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.container.active {
    display: flex;
}

/* ========================================
   Header
   ======================================== */

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

.logo {
    width: 45px;
    height: 45px;
    background: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--primary);
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: none;
    cursor: pointer;
    transition: transform 0.25s ease;
}

.logo:focus-visible, .user-button:focus-visible, .service-check-btn:focus-visible, .model-selector:focus-visible, .new-chat-btn:focus-visible, .btn:focus-visible {
    outline: 3px solid rgba(124,58,237,0.4);
    outline-offset: 2px;
}

.logo:hover { transform: scale(1.05); }

.header h1 {
    font-size: 24px;
    font-weight: 600;
}

.header-subtitle {
    font-size: 14px;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.model-selector {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    min-width: 150px;
    backdrop-filter: blur(10px);
}

.model-selector option {
    color: var(--dark);
    background: white;
}

.connection-status {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-size: 12px;
    backdrop-filter: blur(10px);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

/* Per-service status badges */
.services-status { display:flex; align-items:center; gap:6px; }
.service-status { display:flex; align-items:center; }
.service-dot { width:10px; height:10px; border-radius:50%; background: var(--warning); box-shadow:0 0 0 1px rgba(255,255,255,0.25); }
.service-dot.connected { background: var(--success); }
.service-dot.disconnected { background: var(--danger); }
.service-label, .service-check-btn, .service-meta, .meta-last, .meta-error { display:none !important; }

/* Modal (simple) */
.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    color: var(--dark);
    padding: 20px;
    border-radius: 12px;
    min-width: 320px;
}

.status-dot.warning {
    background: var(--warning);
}

.user-menu {
    position: relative;
}

.user-button {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.user-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    min-width: 200px;
    display: none;
    z-index: 100;
    overflow: hidden;
}

.user-dropdown.active {
    display: block;
    animation: dropdownFadeIn 0.2s ease;
}

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

.dropdown-item {
    padding: 12px 20px;
    color: var(--dark);
    cursor: pointer;
    transition: background 0.3s ease;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--light);
}

/* ========================================
   Main Layout
   ======================================== */

.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
    width: 280px;
    background: var(--light);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    flex-shrink: 0;
}

.sidebar.hidden {
    margin-left: -280px;
}

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

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.new-chat-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.new-chat-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 5px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.conversation-item:hover {
    border-color: var(--primary);
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.1);
}

.conversation-item.active {
    background: var(--primary);
    color: white;
}

.conversation-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-date {
    font-size: 12px;
    opacity: 0.7;
}

.no-conversations {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ========================================
   Chat Container
   ======================================== */

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.messages {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Scrollbar styling */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: var(--light);
}

.messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========================================
   Welcome Screen
   ======================================== */

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.welcome-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 15px;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 40px;
    max-width: 600px;
    line-height: 1.6;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 800px;
    margin-bottom: 40px;
}

.feature-card {
    background: var(--light);
    padding: 25px;
    border-radius: 12px;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    cursor: pointer;
}

:root[data-theme="dark"] .feature-card {
    background:#243044;
    border-color:#334155;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.feature-icon {
    font-size: 36px;
    margin-bottom: 15px;
}

.feature-title {
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
    font-size: 16px;
}

.feature-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.suggested-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.query-chip {
    padding: 10px 20px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
}

.query-chip:hover {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
}

/* ========================================
   Messages
   ======================================== */

.message {
    display: flex;
    gap: 15px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    font-size: 14px;
    overflow: hidden;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.message.user .message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message-content {
    flex: 1;
    background: var(--light);
    padding: 20px;
    border-radius: 16px;
    line-height: 1.7;
    font-size: 15px;
    border: 1px solid var(--border);
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
}

/* ========================================
   Typing Indicator
   ======================================== */

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 15px 20px;
}

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

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* ========================================
   Input Area
   ======================================== */

.input-container {
    padding: 20px 30px;
    background: var(--light);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

.input-group {
    flex: 1;
}

.input-field {
    width: 100%;
    padding: 12px 20px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    transition: all 0.3s ease;
    background: white;
    resize: none;
    font-family: inherit;
    line-height: 1.5;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.input-field:disabled {
    background: var(--light);
    cursor: not-allowed;
}

.input-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(124, 58, 237, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--dark);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    background: var(--light);
    border-color: var(--primary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--dark);
    color: white;
    padding: 16px 24px;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    z-index: 2000;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.warning {
    background: var(--warning);
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .container {
        width: calc(100% - 20px);
        margin: 10px auto;
        height: calc(100vh - 20px);
        border-radius: 16px;
    }

    .sidebar {
        position: absolute;
        z-index: 10;
        height: 100%;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.1);
    }

    .features-grid {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        padding: 15px 20px;
    }

    .header-actions { flex-wrap: wrap; justify-content: center; }
    #mobileSidebarToggle { display: inline-flex !important; }
    .sidebar { margin-left: -280px; }
    .sidebar:not(.hidden) { margin-left: 0; }

    .messages {
        padding: 20px;
    }

    .input-container {
        padding: 15px 20px;
    }

    .welcome-title {
        font-size: 24px;
    }

    .welcome-subtitle {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .input-wrapper {
        flex-direction: column;
        gap: 10px;
    }

    .input-actions {
        justify-content: stretch;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }
}
