/* ========================================
   Mobile Responsive
   ======================================== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        height: 100%;
        height: 100dvh;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        margin-left: 0;
        transition: transform var(--transition-smooth);
        width: 80%;
        max-width: 300px;
        box-shadow: var(--shadow-xl);
        z-index: 1001;
    }

    .sidebar-expanded-pane {
        width: 100% !important;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    #sidebar.collapsed {
        width: 80%;
        max-width: 300px;
        margin-left: 0;
        transform: translateX(-100%);
    }

    #sidebar.collapsed .sidebar-expanded-pane {
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateX(0) !important;
        pointer-events: auto !important;
        width: 100% !important;
    }

    #sidebar.collapsed .sidebar-collapsed-pane {
        opacity: 0 !important;
        visibility: hidden !important;
        transform: translateX(8px) !important;
        pointer-events: none !important;
    }

    [data-theme="dark"] #sidebar.mobile-open {
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }

    .mobile-only { display: flex !important; }
    .desktop-only { display: none !important; }

    .sidebar-toggle { display: flex !important; }

    #sidebar.mobile-open + #main .sidebar-toggle {
        display: none !important;
    }

    #chat-container {
        padding: 16px 4%;
    }

    .input-box {
        width: 94%;
        padding: 10px 12px;
    }

    @media (max-width: 480px) {
        .input-toolbar {
            flex-direction: column;
            align-items: stretch;
            gap: 10px;
        }
        .input-toolbar-left {
            justify-content: flex-start;
            flex-wrap: wrap;
            gap: 8px;
        }
        .input-toolbar-right {
            justify-content: flex-end;
        }
    }

    .modal-content {
        width: 95%;
        margin: 3vh auto;
    }

    .hero-brand-logo {
        width: min(330px, 86vw);
        height: 86px;
    }

    .hero-logo span {
        font-size: 24px;
    }

    .hero-title {
        font-size: 2rem;
    }

    .hero-header {
        gap: 10px;
    }

    .hero-subtitle {
        font-size: 0.95rem;
    }

    .message {
        max-width: 100%;
        margin-top: 20px;
        padding-inline: 0;
    }

    .message.grouped {
        margin-top: 6px;
    }

    .message-row {
        gap: 8px;
    }

    .message-side {
        flex-basis: 32px;
        width: 32px;
        min-height: 32px;
        top: 10px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .message-avatar img {
        width: 26px;
        height: 26px;
    }

    .message-avatar .material-symbols-rounded {
        font-size: 26px;
    }

    .message.user .message-content {
        max-width: calc(100% - 40px);
        padding: 12px 14px;
        border-radius: 14px;
        border-top-right-radius: 4px;
    }

    .message.assistant .message-content,
    .message.error .message-content {
        max-width: calc(100% - 40px);
    }

    .message.error .message-content {
        padding: 12px 14px;
    }

    .message-action-rail {
        gap: 2px;
        opacity: 1;
        pointer-events: auto;
        transform: none;
    }

    .message-action-btn,
    .copy-btn,
    .regenerate-btn,
    .edit-message-btn,
    .msg-delete-btn {
        width: 28px;
        height: 28px;
    }

    .log-container {
        max-width: 100%;
    }

    .hero-suggestions {
        gap: 6px !important;
    }

    .suggestion-chip {
        font-size: 12px;
        padding: 4px 10px;
    }

    .hero-hints {
        display: none !important;
    }
}

/* Small phones */
@media (max-width: 400px) {
    .hero-brand-logo {
        width: min(285px, 88vw);
        height: 74px;
    }

    .hero-subtitle {
        font-size: 0.9rem;
    }
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hero-logo {
        animation: none;
    }

    .logo-text {
        animation: none;
    }
}

/* ========================================
   Safe Area (notch devices)
   ======================================== */
@supports (padding: env(safe-area-inset-bottom)) {
    #input-area {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    #sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ========================================
   Code Block Header & Copy Button
   ======================================== */
.code-block-wrapper {
    position: relative;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    min-height: 38px;
    padding: 0.45rem 0.75rem;
    background-color: color-mix(in srgb, var(--bg) 72%, var(--bg-secondary));
    border-bottom: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    font-size: 12px;
}

.code-block-lang {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem 0.45rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-height: 26px;
    transition: all var(--transition-fast);
}

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

.code-copy-btn .material-symbols-rounded {
    font-size: 16px;
}

.markdown-body .code-block-wrapper code {
    border-radius: 0;
    display: block;
    max-height: 420px;
    overflow-y: auto;
    padding: 1rem;
    font-size: 13px;
    line-height: 1.6;
}

/* ========================================
   Search Progress Bar
   ======================================== */
.search-progress-bar {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 3px;
    background-color: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.search-progress-bar .progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6, var(--primary));
    background-size: 200% 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
    animation: progressPulse 2s ease-in-out infinite, progressShimmer 1.5s linear infinite;
}

@keyframes progressShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.search-progress-bar.done .progress-fill {
    width: 100% !important;
    background: var(--success);
    animation: none;
}
