/* BongoNet AI — ChatGPT-style layout (mobile + desktop) */
:root {
    --ai-sidebar-w: 260px;
    --ai-sidebar-bg: #f9f9f9;
    --ai-main-bg: #ffffff;
    --ai-border: rgba(0, 0, 0, 0.1);
    --ai-text: #0d0d0d;
    --ai-text-muted: #676767;
    --ai-hover: rgba(0, 0, 0, 0.05);
    --ai-user-bg: #f4f4f4;
    --ai-accent: #10a37f;
    --ai-accent-hover: #0d8f6f;
    --ai-blue: #0071e3;
    --ai-composer-max: 768px;
    --ai-msg-max: 768px;
    --ai-topbar-h: 52px;
    --ai-font: Söhne, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    font-family: var(--ai-font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ai-text);
    background: var(--ai-main-bg);
    -webkit-font-smoothing: antialiased;
}

.ai-app {
    display: flex;
    height: 100%;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
}

/* Sidebar */
.ai-sidebar {
    width: var(--ai-sidebar-w);
    min-width: var(--ai-sidebar-w);
    background: var(--ai-sidebar-bg);
    border-right: 1px solid var(--ai-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 200;
    transition: transform 0.25s ease;
}

.ai-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    gap: 8px;
    flex-shrink: 0;
}

.ai-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--ai-text);
    font-weight: 600;
    font-size: 0.9375rem;
    min-width: 0;
}

.ai-brand img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
}

.ai-brand span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--ai-text);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1.125rem;
}

.ai-icon-btn:hover { background: var(--ai-hover); }

.ai-new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 12px 8px;
    padding: 10px 12px;
    border: 1px solid var(--ai-border);
    border-radius: 10px;
    background: transparent;
    color: var(--ai-text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    width: calc(100% - 24px);
}

.ai-new-chat:hover { background: var(--ai-hover); }

.ai-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 8px 12px;
    -webkit-overflow-scrolling: touch;
}

.ai-history-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ai-text-muted);
    padding: 8px 8px 4px;
}

.ai-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--ai-text);
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
}

.ai-history-item i {
    font-size: 0.875rem;
    color: var(--ai-text-muted);
    flex-shrink: 0;
}

.ai-history-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-history-item:hover { background: var(--ai-hover); }
.ai-history-item.active { background: rgba(0, 0, 0, 0.08); }

.ai-sidebar-footer {
    border-top: 1px solid var(--ai-border);
    padding: 10px 12px max(12px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.ai-footer-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-footer-links a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--ai-text);
    text-decoration: none;
    font-size: 0.8125rem;
}

.ai-footer-links a:hover { background: var(--ai-hover); }
.ai-footer-links a i { color: var(--ai-text-muted); }

/* Main panel */
.ai-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    background: var(--ai-main-bg);
    position: relative;
}

.ai-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    height: var(--ai-topbar-h);
    padding: 0 12px;
    border-bottom: 1px solid var(--ai-border);
    background: var(--ai-main-bg);
    flex-shrink: 0;
    gap: 8px;
}

.ai-topbar-title {
    font-size: 0.9375rem;
    font-weight: 600;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-messages-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.ai-messages {
    max-width: var(--ai-msg-max);
    margin: 0 auto;
    padding: 24px 16px 120px;
    min-height: 100%;
}

/* Empty state */
.ai-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100dvh - 180px);
    padding: 24px 16px;
    text-align: center;
}

.ai-empty-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.ai-empty h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}

.ai-empty p {
    color: var(--ai-text-muted);
    font-size: 0.9375rem;
    margin: 0 0 28px;
    max-width: 420px;
}

.ai-starters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
    max-width: 640px;
}

@media (min-width: 540px) {
    .ai-starters { grid-template-columns: 1fr 1fr; }
}

.ai-starter {
    padding: 14px 16px;
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    background: var(--ai-main-bg);
    color: var(--ai-text);
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.15s ease;
}

.ai-starter:hover { background: var(--ai-hover); }
.ai-starter strong {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 4px;
}

/* Messages */
.ai-msg {
    margin-bottom: 24px;
    animation: aiFadeIn 0.25s ease;
}

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

.ai-msg-user {
    display: flex;
    justify-content: flex-end;
}

.ai-msg-user .ai-msg-bubble {
    background: var(--ai-user-bg);
    border-radius: 18px;
    padding: 12px 16px;
    max-width: 85%;
    font-size: 0.9375rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg-assistant .ai-msg-inner {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.ai-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    flex-shrink: 0;
    object-fit: cover;
}

.ai-msg-content {
    flex: 1;
    min-width: 0;
    font-size: 0.9375rem;
    line-height: 1.65;
    color: var(--ai-text);
}

.ai-msg-content p { margin: 0 0 0.75em; }
.ai-msg-content p:last-child { margin-bottom: 0; }
.ai-msg-content ul, .ai-msg-content ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.ai-msg-content li { margin-bottom: 0.35em; }
.ai-msg-content h1, .ai-msg-content h2, .ai-msg-content h3 {
    font-size: 1em;
    font-weight: 600;
    margin: 1em 0 0.5em;
}
.ai-msg-content h1:first-child, .ai-msg-content h2:first-child, .ai-msg-content h3:first-child { margin-top: 0; }
.ai-msg-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    background: rgba(0, 0, 0, 0.06);
    padding: 0.15em 0.35em;
    border-radius: 4px;
}
.ai-msg-content pre {
    background: #1e1e1e;
    color: #e6e6e6;
    padding: 12px 14px;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 0.8125rem;
    margin: 0.75em 0;
}
.ai-msg-content pre code { background: none; padding: 0; color: inherit; }
.ai-msg-content a { color: var(--ai-blue); }
.ai-msg-content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.875rem;
    margin: 0.75em 0;
}
.ai-msg-content th, .ai-msg-content td {
    border: 1px solid var(--ai-border);
    padding: 8px 10px;
    text-align: left;
}
.ai-msg-content blockquote {
    border-left: 3px solid var(--ai-border);
    margin: 0.75em 0;
    padding-left: 12px;
    color: var(--ai-text-muted);
}

/* Typing indicator */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ai-text-muted);
    animation: aiBounce 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aiBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

.ai-msg-content--streaming {
    min-height: 1.4em;
}

.ai-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--ai-accent, #2563eb);
    animation: aiCursorBlink 0.9s step-end infinite;
}

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

/* Composer */
.ai-composer-wrap {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 12px max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
    background: linear-gradient(to top, var(--ai-main-bg) 78%, rgba(255, 255, 255, 0));
    flex-shrink: 0;
}

.ai-composer-inner {
    width: 100%;
    max-width: var(--ai-composer-max);
    margin: 0 auto;
}

.ai-composer {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 10px 16px;
    border: 1px solid var(--ai-border);
    border-radius: 26px;
    background: var(--ai-main-bg);
    box-shadow: 0 0 0 0 transparent, 0 4px 16px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.ai-composer:focus-within {
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow: 0 0 0 0 transparent, 0 4px 20px rgba(0, 0, 0, 0.08);
}

.ai-composer textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    max-height: 200px;
    min-height: 24px;
    padding: 2px 0;
    background: transparent;
    color: var(--ai-text);
}

.ai-composer textarea::placeholder { color: #aaa; }

.ai-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--ai-text);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1rem;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.ai-send-btn:not(:disabled):hover { background: #333; }
.ai-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ai-send-btn.loading { pointer-events: none; }

.ai-composer-note {
    width: 100%;
    margin: 10px 0 0;
    padding: 0 8px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--ai-text-muted);
    line-height: 1.45;
    font-weight: 400;
    letter-spacing: -0.01em;
}

@media (max-width: 480px) {
    .ai-composer-note {
        font-size: 0.6875rem;
        padding: 0 4px;
        line-height: 1.4;
    }
}

/* Overlay (mobile sidebar) */
.ai-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 150;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.ai-overlay.visible {
    display: block;
    opacity: 1;
}

/* Error toast */
.ai-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a1a1a;
    color: #fff;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 0.8125rem;
    max-width: min(90vw, 420px);
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.ai-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Mobile */
@media (max-width: 767.98px) {
    .ai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    }

    .ai-sidebar.open { transform: translateX(0); }

    .ai-topbar { display: flex; }

    .ai-messages { padding-top: 16px; }

    .ai-empty h1 { font-size: 1.375rem; }

    .ai-sidebar-close { display: inline-flex; }
}

@media (min-width: 768px) {
    .ai-sidebar-close { display: none; }
    .ai-topbar { display: none !important; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ai-sidebar, .ai-overlay, .ai-toast, .ai-msg { transition: none; animation: none; }
}
