/* ===== Light mode overrides ===== */
html.light body { background: #f8fafc; color: #1e293b; }
html.light #sidebar { background: #ffffff; border-color: #e2e8f0; }
html.light #topbar { background: #ffffff; border-color: #e2e8f0; }
html.light .nav-link { color: #64748b; }
html.light .nav-link:hover { background: rgba(37, 99, 235, 0.08); }
html.light .nav-link.active { background: rgba(37, 99, 235, 0.1); color: #1e40af; }

/* Light mode cards and surfaces */
html.light .bg-helm-card, html.light [class*="bg-helm-card"] { background: #ffffff !important; }
html.light .bg-helm-bg, html.light [class*="bg-helm-bg"] { background: #f1f5f9 !important; }
html.light .bg-helm-surface, html.light [class*="bg-helm-surface"] { background: #ffffff !important; }
html.light .bg-helm-sidebar, html.light [class*="bg-helm-sidebar"] { background: #ffffff !important; }
html.light .border-helm-border, html.light [class*="border-helm-border"] { border-color: #e2e8f0 !important; }

/* Light mode text */
html.light .text-gray-200 { color: #334155 !important; }
html.light .text-gray-300 { color: #475569 !important; }
html.light .text-gray-400 { color: #64748b !important; }
html.light .text-gray-500 { color: #94a3b8 !important; }
html.light .text-gray-600 { color: #475569 !important; }
html.light .text-white { color: #0f172a !important; }

/* Light mode inputs and buttons */
html.light .chat-textarea { background: #ffffff; border-color: #e2e8f0; color: #1e293b; }
html.light .chat-textarea::placeholder { color: #94a3b8; }
html.light .btn-secondary { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
html.light .btn-secondary:hover { background: #e2e8f0; border-color: #2563eb; }
html.light select { background: #ffffff !important; color: #334155 !important; border-color: #e2e8f0 !important; }
html.light input[type="text"] { background: #ffffff !important; color: #334155 !important; border-color: #e2e8f0 !important; }

/* Light mode chat */
html.light .chat-msg pre { background: #f1f5f9; border-color: #e2e8f0; }
html.light .chat-msg code { color: #1e40af; }
html.light .chat-msg blockquote { color: #64748b; }

/* Light mode cards */
html.light .card-hover { border-color: #e2e8f0; }
html.light .card-hover:hover { box-shadow: 0 8px 25px rgba(0,0,0,0.08); }

/* Light mode terminal blocks */
html.light .terminal-block { background: #fefce8; border-color: rgba(245, 158, 11, 0.3); }
html.light .terminal-header { background: rgba(245, 158, 11, 0.08); }
html.light .terminal-output pre { color: #1e293b !important; }

/* Light mode scrollbar */
html.light ::-webkit-scrollbar-thumb { background: #cbd5e1; }
html.light ::-webkit-scrollbar-thumb:hover { background: #2563eb; }

/* ===== Transitions ===== */
#content { transition: opacity 0.15s ease; }
#content.loading { opacity: 0.3; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1b2533; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #2563eb; }

/* ===== Chat bubbles ===== */
.chat-msg { animation: fadeUp 0.2s ease; }
.chat-msg pre {
    background: #0b0f14;
    border: 1px solid #1b2533;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.chat-msg code {
    font-size: 0.85rem;
    font-family: 'Consolas', 'Monaco', monospace;
}
.chat-msg p { margin: 4px 0; }
.chat-msg ul, .chat-msg ol { margin: 4px 0 4px 20px; }
.chat-msg li { margin: 2px 0; }
.chat-msg a { color: #60a5fa; text-decoration: underline; }
.chat-msg h1, .chat-msg h2, .chat-msg h3 { font-weight: 700; margin: 8px 0 4px; }
.chat-msg h1 { font-size: 1.25rem; }
.chat-msg h2 { font-size: 1.1rem; }
.chat-msg h3 { font-size: 1rem; }
.chat-msg blockquote {
    border-left: 3px solid #2563eb;
    padding-left: 12px;
    margin: 8px 0;
    color: #9ca3af;
}
.chat-msg img {
    max-width: 300px;
    border-radius: 8px;
    margin: 8px 0;
    cursor: pointer;
}

/* ===== Animations ===== */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fade-in { animation: fadeIn 0.3s ease; }
.animate-slide-in { animation: slideIn 0.3s ease; }
.animate-pulse-slow { animation: pulse 2s infinite; }

/* ===== Toast ===== */
.toast { animation: slideIn 0.3s ease; }

/* ===== Nav link active state ===== */
.nav-link {
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}
.nav-link:hover {
    background: rgba(37, 99, 235, 0.1);
    border-left-color: rgba(37, 99, 235, 0.3);
}
.nav-link.active {
    background: rgba(37, 99, 235, 0.15);
    border-left-color: #2563eb;
    color: white;
}

/* ===== Typing indicator ===== */
.typing-dot {
    width: 6px; height: 6px;
    background: #6b7280;
    border-radius: 50%;
    animation: pulse 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ===== Card hover ===== */
.card-hover {
    transition: all 0.2s ease;
    border: 1px solid #1b2533;
}
.card-hover:hover {
    border-color: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

/* ===== Button styles ===== */
.btn-primary {
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    border: none;
    cursor: pointer;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: #131c2a;
    color: #d1d5db;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    border: 1px solid #1b2533;
    cursor: pointer;
}
.btn-secondary:hover { background: #1b2533; border-color: #2563eb; }

/* ===== Textarea ===== */
.chat-textarea {
    background: #0b0f14;
    border: 1px solid #1b2533;
    border-radius: 12px;
    color: #e5e7eb;
    resize: none;
    padding: 12px 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    transition: border-color 0.15s ease;
}
.chat-textarea:focus {
    outline: none;
    border-color: #2563eb;
}
.chat-textarea::placeholder { color: #4b5563; }

/* ===== Provider toggle button ===== */
.provider-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid;
}
.provider-gpt {
    background: rgba(37, 99, 235, 0.15);
    border-color: rgba(37, 99, 235, 0.3);
    color: #60a5fa;
}
.provider-gpt:hover {
    background: rgba(37, 99, 235, 0.25);
    border-color: #2563eb;
}
.provider-claude {
    background: rgba(147, 51, 234, 0.15);
    border-color: rgba(147, 51, 234, 0.3);
    color: #c084fc;
}
.provider-claude:hover {
    background: rgba(147, 51, 234, 0.25);
    border-color: #9333ea;
}
.provider-gemini {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.3);
    color: #34d399;
}
.provider-gemini:hover {
    background: rgba(16, 185, 129, 0.25);
    border-color: #10b981;
}
.provider-groq {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
    color: #fb923c;
}
.provider-groq:hover {
    background: rgba(249, 115, 22, 0.25);
    border-color: #f97316;
}

/* Provider select dropdown */
.provider-select {
    background: rgba(19, 28, 42, 0.8);
    appearance: auto;
    min-width: 160px;
}

/* ===== Claude Code working indicator ===== */
.claude-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(147, 51, 234, 0.3);
    border-top-color: #c084fc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Terminal output blocks ===== */
.terminal-block {
    background: #0a0e13;
    border: 1px solid rgba(245, 158, 11, 0.2);
    width: 100%;
}
.terminal-header {
    background: rgba(245, 158, 11, 0.06);
    border-bottom: 1px solid rgba(245, 158, 11, 0.1);
}
.terminal-output {
    max-height: 400px;
    overflow-y: auto;
}
.terminal-output pre {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}
.terminal-footer {
    background: rgba(245, 158, 11, 0.04);
    border-top: 1px solid rgba(245, 158, 11, 0.1);
}
.terminal-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(245, 158, 11, 0.3);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== War Room ===== */
.warroom-round {
    animation: fadeUp 0.3s ease;
}

/* ===== Knowledge Base ===== */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Supabase table ===== */
.sb-table th { position: sticky; top: 0; z-index: 1; }
.sb-table td { max-width: 300px; }

/* ===== Chat Status Bar ===== */
.status-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(37, 99, 235, 0.3);
    border-top-color: #3b82f6;
    border-radius: 50%;
}
.status-spinner.spinning {
    animation: spin 0.8s linear infinite;
}
.status-spinner.status-done {
    border-color: #10b981;
    background: #10b981;
    animation: none;
}

/* Activity log */
#chat-activity-log {
    transition: max-height 0.3s ease;
}
#chat-activity-entries div {
    padding: 1px 0;
    line-height: 1.4;
}
.activity-chevron {
    transition: transform 0.2s ease;
}
.activity-chevron.rotate-180 {
    transform: rotate(180deg);
}

/* Light mode status bar */
html.light #chat-status-bar { background: #ffffff; }
html.light #chat-activity-log { background: #f1f5f9; }

/* ===== Code block header ===== */
.code-block-wrapper {
    margin: 8px 0;
}
.code-block-header {
    font-size: 0.75rem;
}
.code-block-wrapper pre {
    margin-top: 0 !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}
html.light .code-block-header {
    background: #e2e8f0 !important;
    border-color: #e2e8f0 !important;
}

/* ===== Message actions (hover bar) ===== */
.msg-actions {
    z-index: 10;
}
html.light .msg-actions {
    background: #ffffff;
    border-color: #e2e8f0;
}

/* ===== Search highlight ===== */
.search-highlight {
    background: rgba(37, 99, 235, 0.3);
    color: white;
    border-radius: 2px;
    padding: 0 2px;
}
html.light .search-highlight {
    background: rgba(37, 99, 235, 0.2);
    color: #1e40af;
}

/* ===== Suggestion chips ===== */
.suggestion-chip {
    cursor: pointer;
    transition: all 0.15s ease;
}
.suggestion-chip:hover {
    transform: translateY(-1px);
}

/* ===== Slash command menu ===== */
#chat-slash-menu {
    backdrop-filter: blur(8px);
}
.slash-item {
    transition: background 0.1s ease;
}

/* ===== Comparison grid ===== */
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }

/* ===== Voice recording indicator ===== */
.voice-recording {
    animation: pulse 1s infinite;
}

/* ===== Nav link compact ===== */
.nav-link {
    font-size: 0.8rem;
    padding: 6px 16px;
}

/* ===== Mobile Responsive ===== */
/* ===== Quick Actions FAB ===== */
.fab-container { position: fixed; bottom: 24px; right: 24px; z-index: 50; }
.fab-btn {
    width: 48px; height: 48px; border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 15px rgba(37,99,235,0.4);
    border: none;
}
.fab-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(37,99,235,0.6); }
.fab-panel {
    position: absolute; bottom: 56px; right: 0; width: 220px;
    background: #0f1923; border: 1px solid #1b2533; border-radius: 12px;
    padding: 8px; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.fab-action {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 8px; cursor: pointer; transition: background 0.15s;
    font-size: 0.8rem; color: #d1d5db; width: 100%;
    background: transparent; border: none; text-align: left;
}
.fab-action:hover { background: rgba(37,99,235,0.15); color: white; }
.fab-action i { flex-shrink: 0; }

/* Diff viewer */
.diff-add { color: #4ade80; background: rgba(74,222,128,0.05); }
.diff-remove { color: #f87171; background: rgba(248,113,113,0.05); }
.diff-header { color: #60a5fa; font-weight: 600; }

/* Handoff button */
.handoff-btn {
    background: linear-gradient(135deg, rgba(147,51,234,0.2), rgba(37,99,235,0.2));
    border: 1px solid rgba(147,51,234,0.3);
    color: #c084fc;
    transition: all 0.15s;
}
.handoff-btn:hover {
    background: linear-gradient(135deg, rgba(147,51,234,0.3), rgba(37,99,235,0.3));
    border-color: #9333ea;
}

/* Message edit mode */
.msg-edit-textarea {
    background: #0b0f14; border: 1px solid #2563eb; border-radius: 8px;
    color: #e5e7eb; padding: 8px 12px; font-size: 0.875rem;
    width: 100%; min-height: 60px; resize: vertical;
}

/* Pin indicator */
.pin-indicator {
    color: #f59e0b;
    font-size: 0.7rem;
}

/* Syntax highlighting */
.syn-keyword { color: #60a5fa; }
.syn-string { color: #4ade80; }
.syn-comment { color: #6b7280; font-style: italic; }
.syn-number { color: #fb923c; }
.syn-function { color: #fbbf24; }

/* ===== Light mode — Quick Actions & new styles ===== */
html.light .fab-panel { background: #ffffff; border-color: #e2e8f0; box-shadow: 0 10px 40px rgba(0,0,0,0.15); }
html.light .fab-action { color: #475569; }
html.light .fab-action:hover { background: rgba(37,99,235,0.1); color: #1e40af; }
html.light .handoff-btn { background: linear-gradient(135deg, rgba(147,51,234,0.1), rgba(37,99,235,0.1)); }
html.light .handoff-btn:hover { background: linear-gradient(135deg, rgba(147,51,234,0.15), rgba(37,99,235,0.15)); }
html.light .msg-edit-textarea { background: #ffffff; border-color: #2563eb; color: #1e293b; }
html.light .diff-add { color: #16a34a; background: rgba(22,163,74,0.05); }
html.light .diff-remove { color: #dc2626; background: rgba(220,38,38,0.05); }
html.light .diff-header { color: #2563eb; }
html.light .syn-keyword { color: #2563eb; }
html.light .syn-string { color: #16a34a; }
html.light .syn-comment { color: #94a3b8; }
html.light .syn-number { color: #ea580c; }
html.light .syn-function { color: #ca8a04; }

/* ===== Mobile Responsive ===== */

/* Sidebar overlay backdrop */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 35;
    backdrop-filter: blur(2px);
}
#sidebar-overlay.active { display: block; }

/* Hamburger button — hidden on desktop */
#mobile-menu-btn { display: none; }

@media (max-width: 768px) {
    /* Fix mobile viewport height (iOS Safari address bar issue) */
    body { height: 100dvh; }
    #content { max-height: calc(100dvh - 56px); display: flex; flex-direction: column; }

    /* Sidebar — off-canvas drawer */
    #sidebar {
        position: fixed;
        left: -280px;
        z-index: 40;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
        width: 260px;
        height: 100dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    #sidebar.open { left: 0; }

    /* Show hamburger button */
    #mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 8px;
        background: transparent;
        border: 1px solid #1b2533;
        color: #9ca3af;
        cursor: pointer;
        flex-shrink: 0;
        margin-right: 8px;
    }
    #mobile-menu-btn:hover { background: rgba(37, 99, 235, 0.1); border-color: #2563eb; }

    /* Topbar adjustments */
    #topbar {
        padding-left: 12px;
        padding-right: 12px;
        gap: 8px;
    }
    #page-title { font-size: 0.9rem; }

    /* Chat topbar actions — scrollable row */
    .chat-topbar-actions {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-shrink: 1;
        min-width: 0;
    }
    .chat-topbar-actions::-webkit-scrollbar { display: none; }

    /* Provider select — smaller on mobile */
    .provider-select { min-width: 100px !important; font-size: 0.75rem; padding: 4px 8px; }

    /* Thread select — constrain width */
    #chat-thread-select { max-width: 120px; font-size: 0.75rem; }

    /* Hide text labels in topbar buttons, keep icons */
    .chat-topbar-actions .btn-secondary { padding: 6px 8px; }
    .chat-topbar-actions .btn-label { display: none; }
    #chat-token-count { display: none; }

    /* iOS zoom prevention */
    .chat-textarea { font-size: 16px; }

    /* Reduce padding globally */
    .p-6 { padding: 1rem !important; }
    .p-5 { padding: 0.875rem !important; }
    .px-6 { padding-left: 1rem !important; padding-right: 1rem !important; }

    /* Chat messages — tighter spacing */
    .chat-msg { padding: 8px 12px !important; }
    .chat-msg pre { font-size: 0.75rem; padding: 8px; }
    .chat-msg img { max-width: 200px; }

    /* Message action buttons — always visible on touch (no hover) */
    .msg-actions { opacity: 1 !important; }

    /* Chat page — force flex layout to keep composer visible */
    #content > .flex.flex-col.h-full {
        height: 100%;
        max-height: 100%;
        min-height: 0;
    }
    #chat-messages {
        flex: 1 1 0;
        min-height: 0;
    }

    /* Composer area — always pinned at bottom */
    #content .border-t.border-helm-border.bg-helm-surface:last-child {
        flex-shrink: 0;
    }

    /* FAB — adjust position for mobile */
    .fab-container { bottom: 80px; right: 16px; }
    .fab-btn { width: 44px; height: 44px; }

    /* Dashboard grid — single column */
    .grid-cols-2 { grid-template-columns: 1fr !important; }
    .grid-cols-3 { grid-template-columns: 1fr !important; }

    /* Slash menu — full width */
    #chat-slash-menu { width: calc(100vw - 32px) !important; left: 16px !important; }

    /* Code blocks — horizontal scroll */
    .chat-msg pre { max-width: calc(100vw - 80px); }

    /* Comparison grid — stack vertically */
    .compare-grid { grid-template-columns: 1fr !important; }

    /* Terminal blocks — constrain */
    .terminal-output { max-height: 250px; }

    /* Tables — horizontal scroll */
    .overflow-x-auto { -webkit-overflow-scrolling: touch; }

    /* Supabase textarea */
    #sb-query { font-size: 14px; }

    /* Toast position */
    #toasts { bottom: 70px; right: 12px; left: 12px; }
    #toasts .toast { width: 100%; }
}

@media (max-width: 480px) {
    .text-3xl { font-size: 1.5rem !important; }
    .text-2xl { font-size: 1.25rem !important; }
    .text-lg { font-size: 0.95rem !important; }

    /* Page title even smaller */
    #page-title { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }

    /* Sidebar — full width on small phones */
    #sidebar { width: 100vw; left: -100vw; }

    /* Cards — tighter padding */
    .card-hover { padding: 12px !important; }

    /* Dashboard status grid �� single column */
    .md\:grid-cols-5 { grid-template-columns: repeat(2, 1fr) !important; }

    /* Chat composer — stack send button below */
    .btn-primary { padding: 8px 12px; font-size: 0.8rem; }

    /* Quick action buttons — wrap tighter */
    .flex-wrap { gap: 6px !important; }
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        #chat-composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
        .fab-container { bottom: calc(80px + env(safe-area-inset-bottom)); }
        #toasts { bottom: calc(70px + env(safe-area-inset-bottom)); }
    }
}
