/* ============================================================
   INSTANT AI TAB - Marken-Design (Periwinkle/Indigo, Discover-DNA)
   Tokens (:root) aus discover-tab.css. Periwinkle = Akzent, nicht Flaeche.
   ============================================================ */

/* ---- Welcome ---------------------------------------------- */
.instant-ai-welcome {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background:
        radial-gradient(120% 60% at 85% -6%, rgba(107, 127, 232, 0.16), transparent 55%),
        #0a0b12;
}

.ia-logo {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    left: 20px;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    object-fit: cover;
    box-shadow: 0 4px 14px rgba(107, 127, 232, 0.45);
    z-index: 5;
}

.ia-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: calc(env(safe-area-inset-top, 0px) + 80px) 20px 28px;
}
.ia-scroll::-webkit-scrollbar { display: none; }

.ia-hero { margin-bottom: 30px; }
.ia-hero h1 {
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1.12;
    color: #ffffff;
    margin: 0 0 10px;
}
.ia-sub {
    font-size: 14.5px;
    color: var(--dsc-mut, rgba(226, 229, 255, 0.6));
    line-height: 1.5;
    margin: 0 0 22px;
}
.ia-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    background: var(--brand-cta, linear-gradient(135deg, #6B7FE8 0%, #4F46E5 100%));
    border: none;
    border-radius: 16px;
    padding: 17px 24px;
    color: #ffffff;
    font-size: 17px;
    font-weight: 800;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    letter-spacing: -0.2px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ia-cta:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(79, 70, 229, 0.6); }
.ia-cta:active { transform: translateY(0); }
.ia-cta svg { flex-shrink: 0; }

.ia-topics { margin-bottom: 24px; }
.ia-lbl {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.4px;
    color: var(--dsc-mut2, rgba(226, 229, 255, 0.42));
    text-transform: uppercase;
    margin: 0 2px 12px;
}

/* Themen = 2x2 Foto-Panels (Beispiele, was man fragen kann; kein Chevron = nicht "drill-in") */
.ia-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.ia-tile {
    position: relative;
    height: 116px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--dsc-bd, rgba(165, 178, 255, 0.16));
    background: #1a1c28;
}
.ia-tile img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ia-tile-grad {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(10, 11, 18, 0.05) 30%, rgba(10, 11, 18, 0.88) 100%);
}
.ia-tile-cap {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 13px;
    z-index: 2;
}
.ia-tile-cap b {
    display: block;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: #ffffff;
    line-height: 1.1;
}
.ia-tile-cap span {
    display: block;
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.78);
    margin-top: 2px;
}
.ia-chev { color: var(--dsc-mut2, rgba(226, 229, 255, 0.42)); flex: 0 0 auto; }

.ia-tip {
    font-size: 12.5px;
    color: var(--dsc-mut2, rgba(226, 229, 255, 0.42));
    line-height: 1.5;
    text-align: center;
    margin: 8px 6px 0;
}
.ia-tip b { color: var(--dsc-mut, rgba(226, 229, 255, 0.6)); font-weight: 600; }

/* ============================================================
   CHAT SCREEN
   ============================================================ */

.instant-ai-chat {
    display: none;
    flex-direction: column;
    height: calc(var(--app-vh, 100dvh) - 90px); /* iOS-Tastatur: schrumpft mit visualViewport (keyboardAdapter.js) statt fix 100vh */
    background:
        radial-gradient(120% 50% at 85% -6%, rgba(107, 127, 232, 0.16), transparent 55%),
        #0a0b12;
    width: 100%;
    overflow: visible;
    position: relative;
}

.instant-ai-chat[style*="display: flex"] {
    display: flex !important;
}

.instant-ai-header-chat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(180deg, rgba(10, 11, 18, 0.96) 0%, rgba(10, 11, 18, 0.86) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--dsc-bd, rgba(165, 178, 255, 0.16));
    min-height: 60px;
}

.instant-ai-header-chat h1 {
    font-size: 24px;
    font-weight: 800;
    color: #ffffff;
    margin: 0;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    letter-spacing: -0.5px;
}

.header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* Credits Display - Premium Badge */
.credits-display-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.12) 0%, rgba(255, 165, 0, 0.06) 100%);
    border: 1px solid rgba(255, 215, 0, 0.25);
    white-space: nowrap;
}

.credits-display-header .credits-amount {
    color: var(--brand-gold);
    font-size: 14px;
    font-weight: 700;
}

.credits-display-header .credits-label {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 500;
    font-size: 12px;
}

/* Close Button - Premium Style */
.close-chat-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.6);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.close-chat-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    /* Extra bottom padding to account for fixed input-section height (~90px) */
    padding-bottom: 100px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.message-bubble {
    display: flex;
    margin-bottom: 8px;
    animation: instantMessageFadeIn 0.3s ease-in;
}

.message-bubble.user {
    justify-content: flex-end;
}

.message-bubble.ai {
    justify-content: flex-start;
}

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

.bubble-content {
    max-width: 80%;
    padding: 14px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.55;
}

/* User Message Bubble - Brand Indigo */
.message-bubble.user .bubble-content {
    background: var(--brand-cta, linear-gradient(135deg, #6B7FE8 0%, #4F46E5 100%));
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
    font-weight: 500;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

/* AI Message Bubble - Glass Style */
.message-bubble.ai .bubble-content {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.95);
    border-radius: 18px 18px 18px 4px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* Loading Dots */
.loading-dots {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand-solid, #8B97F2);
    animation: bounce 1.4s infinite;
}

.dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Input Section */
.input-section {
    padding: 12px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(10, 11, 18, 0.92) 0%, #0a0b12 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--dsc-bd, rgba(165, 178, 255, 0.16));
    position: fixed;
    bottom: calc(83px + var(--tour-kb, 0px)); /* 83px = Tab-Bar-Höhe; --tour-kb hebt über die Tastatur */
    left: 0;
    right: 0;
    z-index: 1000;
    flex-shrink: 0;
}

/* iOS-Tastatur offen (.kb-open von keyboardAdapter.js): Tab-Bar hinter der
   Tastatur ist ungreifbar → ausblenden gibt dem Chat volle Breite und keine
   tote Fläche. Beim Schließen der Tastatur kommt sie automatisch zurück.
   Live-View hat keine Tab-Bar → kein Konflikt. */
html.kb-open .custom-tab-bar { display: none; }

/* I3: Bei offener Tastatur ist die Tab-Bar oben ausgeblendet — dann darf
   ihre 83px Höhe NICHT mehr im bottom der Input-Leiste stecken, sonst
   schwebt die Leiste 83px über der Tastatur. Nur --tour-kb bleibt. */
html.kb-open .input-section { bottom: var(--tour-kb, 0px); }

.input-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    position: relative;
}

.message-textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--dsc-bd, rgba(165, 178, 255, 0.16));
    border-radius: 24px;
    background: rgba(130, 141, 242, 0.1);
    color: #ffffff;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    resize: none;
    max-height: 100px;
    min-height: 44px;
    height: 44px;
    outline: none;
    transition: all 0.3s ease;
    overflow: hidden;
    line-height: 1.3;
}

.message-textarea:focus {
    border-color: rgba(139, 151, 242, 0.55);
    background: rgba(130, 141, 242, 0.15);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.message-textarea::placeholder {
    color: rgba(226, 229, 255, 0.5);
}

/* Textarea during recording */
.message-textarea.recording {
    border-color: rgba(255, 107, 107, 0.5) !important;
    background: rgba(255, 107, 107, 0.05) !important;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1) !important;
}

/* Placeholder during recording */
.message-textarea.recording::placeholder {
    color: rgba(255, 107, 107, 0.7);
}

/* Image Preview */
.image-preview {
    position: absolute;
    bottom: 76px;
    left: 20px;
    width: 64px;
    height: 64px;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(139, 151, 242, 0.4);
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideUp 0.3s ease;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.remove-image-btn:hover {
    background: rgba(255, 77, 77, 0.3);
    border-color: rgba(255, 77, 77, 0.5);
}

/* Icon Buttons - Premium Glass Style */
.icon-button {
    width: 48px;
    height: 48px;
    border: 1px solid var(--dsc-bd, rgba(165, 178, 255, 0.16));
    border-radius: 14px;
    background: rgba(130, 141, 242, 0.1);
    color: rgba(226, 229, 255, 0.7);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.icon-button svg {
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.icon-button:hover {
    background: rgba(130, 141, 242, 0.16);
    border-color: rgba(139, 151, 242, 0.4);
    color: #ffffff;
}

.icon-button:hover .camera-icon,
.icon-button:hover .mic-icon,
.icon-button:hover .send-icon {
    transform: scale(1.1);
}

.icon-button:active {
    transform: scale(0.95);
}

/* Microphone Button Recording State - Steady Red Glow */
.mic-button.recording {
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.25) 0%, rgba(255, 80, 80, 0.2) 100%);
    border-color: rgba(255, 107, 107, 0.5);
    color: #FF6B6B;
    box-shadow: 0 0 0 6px rgba(255, 107, 107, 0.2);
}

/* Send Button - Brand Indigo */
.send-button {
    background: var(--brand-cta, linear-gradient(135deg, #6B7FE8 0%, #4F46E5 100%));
    border: none;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45);
}

.send-button:hover {
    background: linear-gradient(135deg, #7C8DF0 0%, #5B52E8 100%);
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.55);
    border: none;
}

.send-button:hover .send-icon {
    transform: scale(1.1) translateX(2px);
    stroke: #ffffff;
}

.send-button:disabled {
    background: rgba(255, 255, 255, 0.08);
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    color: rgba(255, 255, 255, 0.4);
}

.send-button:disabled .send-icon {
    transform: none;
    stroke: currentColor;
}

/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */

@media (max-width: 600px) {
    .message-bubble { margin-bottom: 6px; }

    .bubble-content {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 16px;
    }

    .input-section {
        padding: 10px 12px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }

    .icon-button { width: 44px; height: 44px; }
    .icon-button svg { width: 20px; height: 20px; }

    .message-textarea {
        min-height: 40px;
        height: 40px;
        padding: 10px 14px;
    }
}

@media (max-width: 400px) {
    .instant-ai-header-chat h1 { font-size: 22px; }
    .ia-hero h1 { font-size: 26px; }
    .ia-cta { font-size: 16px; padding: 16px 20px; }

    .message-bubble { margin-bottom: 4px; }
    .bubble-content { max-width: 90%; font-size: 13px; }
}

/* ============================================================
   SCROLLBAR - versteckt (iOS-Premium, kein sichtbarer Balken)
   ============================================================ */

.messages-container { scrollbar-width: none; }
.messages-container::-webkit-scrollbar { display: none; }
