/* ── Reset & Base ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #0d0d15;
    --bg-tertiary: #111119;
    --bg-hover: rgba(255, 255, 255, 0.04);
    --bg-active: rgba(139, 92, 246, 0.08);
    --border: rgba(255, 255, 255, 0.06);
    --border-active: rgba(139, 92, 246, 0.25);
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    --text-faint: #3f3f46;
    --accent: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.15);
    --accent-pink: #ec4899;
    --green: #22c55e;
    --red: #ef4444;
    --user-bubble: rgba(139, 92, 246, 0.1);
    --user-border: rgba(139, 92, 246, 0.15);
    --ai-bubble: rgba(255, 255, 255, 0.03);
    --ai-border: rgba(255, 255, 255, 0.06);
    --sidebar-width: 240px;
    --topbar-height: 52px;
    --font-main: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    line-height: 1.6;
    overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Top Bar ── */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-pink));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 800;
    color: white;
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.25);
}

.logo-text {
    font-size: 17px;
    font-weight: 800;
    color: white;
    letter-spacing: -0.3px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.model-select {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.model-select:hover {
    border-color: var(--border-active);
}

.model-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.model-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
    transition: background 0.3s;
}

.status-dot.error {
    background: var(--red);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: var(--accent-glow);
    border-color: var(--border-active);
    color: var(--accent);
}

/* ── Layout ── */
.layout {
    display: flex;
    height: 100vh;
    padding-top: var(--topbar-height);
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 14px 10px;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 12px 10px 6px;
}

.sidebar-label:first-child {
    padding-top: 4px;
}

.profile-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.profile-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 9px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.profile-item:hover {
    background: var(--bg-hover);
}

.profile-item.active {
    background: var(--bg-active);
    border-color: var(--border-active);
}

.profile-icon {
    font-size: 18px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.profile-info {
    overflow: hidden;
}

.profile-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.profile-item.active .profile-name {
    color: var(--accent);
}

.profile-desc {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── COORDINATOR Card (the big one at the top) ── */
.coordinator-item {
    padding: 14px 14px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), rgba(236, 72, 153, 0.05));
    border: 1px solid rgba(139, 92, 246, 0.15) !important;
    border-radius: 12px;
    margin-bottom: 4px;
}

.coordinator-item:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.14), rgba(236, 72, 153, 0.08));
    border-color: rgba(139, 92, 246, 0.3) !important;
}

.coordinator-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.18), rgba(236, 72, 153, 0.1));
    border-color: rgba(139, 92, 246, 0.4) !important;
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.1);
}

.coordinator-icon {
    font-size: 24px !important;
    width: 36px !important;
}

.coordinator-name {
    font-size: 15px !important;
    font-weight: 800 !important;
    letter-spacing: 0.3px;
}

.coordinator-desc {
    color: var(--text-secondary) !important;
    font-size: 12px !important;
}

/* ── Sidebar Divider ── */
.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 8px 6px;
}

/* ── Recent Chats Section ── */
.recent-chats-section {
    margin: 2px 0;
}

.recent-chats-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 6px !important;
}

.recent-chats-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.recent-chat-empty {
    font-size: 11px;
    color: var(--text-faint);
    padding: 6px 12px 8px;
    font-style: italic;
}

.recent-chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-chat-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.recent-chat-item .chat-icon {
    font-size: 12px;
    opacity: 0.5;
    flex-shrink: 0;
}

.recent-chat-item .chat-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Collapsible Category Headers ── */
.category-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 10px;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.15s;
    user-select: none;
}

.category-header:hover {
    background: var(--bg-hover);
}

.category-header.expanded {
    background: rgba(255, 255, 255, 0.02);
}

.category-arrow {
    font-size: 10px;
    color: var(--text-muted);
    width: 14px;
    text-align: center;
    flex-shrink: 0;
    transition: color 0.15s;
}

.category-header:hover .category-arrow {
    color: var(--text-secondary);
}

.category-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    flex: 1;
}

.category-header:hover .category-name {
    color: var(--text-secondary);
}

.category-count {
    font-size: 10px;
    color: var(--text-faint);
    background: rgba(255, 255, 255, 0.04);
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
}

/* ── Collapsible Category Content ── */
.category-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-left: 6px;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.25s ease, opacity 0.2s ease;
    opacity: 1;
}

.category-content.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.category-content .profile-item {
    padding: 8px 10px;
}

.category-content .profile-icon {
    font-size: 16px;
    width: 24px;
}

.category-content .profile-name {
    font-size: 12px;
}

.category-content .profile-desc {
    font-size: 10px;
}

/* ── Chat Area ── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* ── Welcome Screen ── */
.welcome {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    transition: opacity 0.3s;
    z-index: 1;
}

.welcome.hidden {
    opacity: 0;
    pointer-events: none;
}

.welcome-icon {
    font-size: 52px;
    margin-bottom: 14px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.welcome-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--green);
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.welcome-desc {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.welcome-hint {
    font-size: 13px;
    color: var(--text-faint);
    padding: 8px 16px;
    background: var(--bg-hover);
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* ── Messages ── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 2;
}

.message {
    max-width: 78%;
    animation: msgIn 0.25s ease-out;
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    border: 1px solid var(--user-border);
    border-radius: 16px 16px 4px 16px;
    color: var(--text-primary);
}

.message.assistant .message-bubble {
    background: #1a1a24;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px 16px 16px 16px;
    color: #ffffff !important;
    font-size: 14px;
}

/* Markdown in AI responses */
.message.assistant .message-bubble strong {
    color: var(--text-primary);
    font-weight: 700;
}

.message.assistant .message-bubble code {
    background: rgba(139, 92, 246, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--accent);
}

.message.assistant .message-bubble pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 10px 0;
    overflow-x: auto;
}

.message.assistant .message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
}

/* Copy button on AI messages */
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

/* ── Answer Footer (shows which profile + model answered) ── */
.message-footer {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    opacity: 0.6;
    transition: opacity 0.2s;
}

.message:hover .message-footer {
    opacity: 1;
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 11px;
    font-family: var(--font-main);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-copy:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 24px;
    z-index: 2;
}

.typing-indicator.visible {
    display: flex;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.typing-text {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Input Area ── */
.input-area {
    padding: 12px 24px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
    z-index: 2;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--border-active);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 150px;
    padding: 8px 0;
}

textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-pink));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    opacity: 0.5;
}

.btn-send.active {
    opacity: 1;
}

.btn-send.active:hover {
    transform: scale(1.05);
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
}

/* ── Attach Button ── */
.btn-attach {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.btn-attach:hover {
    color: var(--accent);
    background: var(--bg-hover);
}

/* ── File Preview ── */
.file-preview {
    display: none;
    padding: 0 0 8px;
}

.file-preview.visible {
    display: block;
}

.file-preview-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    transition: color 0.15s;
}

.file-remove:hover {
    color: var(--red);
}

/* ── Drag & Drop ── */
.chat-area.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
    background: rgba(139, 92, 246, 0.03);
}

/* ── Links in AI responses ── */
.message.assistant .message-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(139, 92, 246, 0.3);
    text-underline-offset: 2px;
    transition: all 0.15s;
}

.message.assistant .message-bubble a:hover {
    color: var(--accent-pink);
    text-decoration-color: var(--accent-pink);
}

/* ── Hamburger Menu ── */
.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
}

.hamburger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 98;
}

.sidebar-overlay.visible {
    display: block;
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .sidebar {
        display: none;
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 99;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        display: block;
    }

    .messages {
        padding: 16px;
    }

    .message {
        max-width: 90%;
    }

    .input-area {
        padding: 10px 12px 14px;
    }

    .welcome {
        padding: 24px;
    }

    .welcome-icon {
        font-size: 40px;
    }

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

    .topbar-center {
        display: none;
    }

    .logo-text {
        font-size: 16px;
    }

    .login-card {
        margin: 20px;
        padding: 36px 24px;
    }
}

/* ══════════════════════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════════════════════ */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
    overflow: auto;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 0 60px rgba(139, 92, 246, 0.08);
}

.login-logo {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-pink));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 800;
    color: white;
    margin-bottom: 16px;
    box-shadow: 0 0 30px rgba(139, 92, 246, 0.3);
}

.login-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-input-wrapper input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 16px;
    padding: 14px 0;
    letter-spacing: 2px;
}

.login-input-wrapper input::placeholder {
    color: var(--text-muted);
    letter-spacing: 0;
}

.toggle-visibility {
    background: none !important;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    opacity: 0.5;
    transition: opacity 0.15s;
    box-shadow: none !important;
    transform: none !important;
}

.toggle-visibility:hover {
    opacity: 1;
    transform: none !important;
    box-shadow: none !important;
}

.login-error {
    color: var(--red);
    font-size: 13px;
    min-height: 18px;
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.remember-me input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.login-btn {
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-pink));
    border: none;
    border-radius: 12px;
    color: white;
    font-family: var(--font-main);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

.login-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Logout button + user name in topbar ── */

.user-name {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.btn-logout {
    padding: 6px 10px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    border-color: var(--red);
    color: var(--red);
    background: none;
    transform: none;
    box-shadow: none;
}
