@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --red:      #E53935;
    --red-dark: #B71C1C;
    --cream:    #FFFDF9;
    --warm:     #FBF8F3;
    --snow:     #FFFFFF;
    --slate:    #1A2332;
    --ink:      #2D3748;
    --muted:    #718096;
    --soft:     #A0AEC0;
    --border:   rgba(0,0,0,0.08);
    --r-shadow: rgba(229,57,53,0.2);
}

*,*::before,*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ── HTML + BODY BASE ── */
html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: 'Plus Jakarta Sans', 'Outfit', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--warm);
    background-image:
        radial-gradient(ellipse 60% 50% at 100% 0%, rgba(229,57,53,0.07) 0%, transparent 60%),
        radial-gradient(ellipse 50% 40% at 0% 100%, rgba(100,120,255,0.05) 0%, transparent 60%);
    overflow: hidden;
    /* Use dvh for dynamic viewport (handles mobile browser chrome collapsing) */
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

body.custom-bg {
    background: url('/static/snow_white_background.png') no-repeat center/cover fixed;
}

body.custom-bg::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    background: rgba(255,253,249,0.7);
}

/* ── SNOWFLAKES ── */
.snowflakes {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.snowflake {
    position: absolute;
    top: -30px;
    color: rgba(180,190,210,0.45);
    user-select: none;
    animation: fall linear infinite;
}

.snowflake:nth-child(1)  { left: 5%;  font-size: 11px; animation-duration: 14s; animation-delay: 0s;  }
.snowflake:nth-child(2)  { left: 18%; font-size: 16px; animation-duration: 18s; animation-delay: 3s;  }
.snowflake:nth-child(3)  { left: 32%; font-size: 9px;  animation-duration: 12s; animation-delay: 5s;  }
.snowflake:nth-child(4)  { left: 48%; font-size: 14px; animation-duration: 16s; animation-delay: 1s;  }
.snowflake:nth-child(5)  { left: 63%; font-size: 18px; animation-duration: 20s; animation-delay: 7s;  }
.snowflake:nth-child(6)  { left: 77%; font-size: 10px; animation-duration: 13s; animation-delay: 4s;  }
.snowflake:nth-child(7)  { left: 90%; font-size: 13px; animation-duration: 17s; animation-delay: 6s;  }
.snowflake:nth-child(8)  { left: 25%; font-size: 8px;  animation-duration: 15s; animation-delay: 9s;  }
.snowflake.star { color: rgba(255,200,100,0.35); }
.snowflake:nth-child(9)  { left: 10%; font-size: 8px;  animation-duration: 22s; animation-delay: 11s; }
.snowflake:nth-child(10) { left: 55%; font-size: 7px;  animation-duration: 19s; animation-delay: 8s;  }
.snowflake:nth-child(11) { left: 72%; font-size: 8px;  animation-duration: 24s; animation-delay: 13s; }
.snowflake:nth-child(12) { left: 88%; font-size: 7px;  animation-duration: 16s; animation-delay: 15s; }

@keyframes fall {
    0%   { transform: translateY(0) rotate(0deg);       opacity: 0; }
    8%   { opacity: 0.85; }
    92%  { opacity: 0.4; }
    100% { transform: translateY(108vh) rotate(360deg); opacity: 0; }
}

/* ── CHAT CONTAINER ── */
.chat-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 500px;
    height: 92vh;
    height: 92dvh;
    background: var(--cream);
    display: flex;
    flex-direction: column;
    border-radius: 32px;
    margin: 20px;
    overflow: hidden;
    border: 1px solid rgba(229,57,53,0.12);
    box-shadow:
        0 2px 4px rgba(0,0,0,0.03),
        0 8px 24px rgba(0,0,0,0.07),
        0 32px 64px rgba(0,0,0,0.06),
        inset 0 1px 0 rgba(255,255,255,0.9);
}

/* ── HEADER ── */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 22px;
    background: linear-gradient(135deg, var(--slate) 0%, #2C3E55 100%);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(to right, var(--red-dark), var(--red), #FF8A80, var(--red), var(--red-dark));
}

.logo-container { display: flex; align-items: center; gap: 13px; }

.logo-wrapper {
    position: relative;
    width: 46px;
    height: 46px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.logo-orbit {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid transparent;
    border-top-color: rgba(255,138,128,0.6);
    border-right-color: rgba(255,255,255,0.15);
    animation: orbit 5s linear infinite;
}

@keyframes orbit { to { transform: rotate(360deg); } }

.logo {
    width: 44px;
    height: 44px;
    background: linear-gradient(145deg, var(--red), var(--red-dark));
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 16px rgba(229,57,53,0.45), 0 0 0 2px rgba(255,255,255,0.1);
    transition: transform 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    position: relative;
    z-index: 1;
}

.logo:hover { transform: scale(1.08) rotate(-6deg); }
.logo::after { content: 'N'; color: white; font-size: 21px; font-weight: 800; }

.header-info h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #FFFFFF, #FFB3AE);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-info p {
    font-size: 10px;
    color: rgba(255,255,255,0.45);
    font-weight: 500;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    margin-top: 1px;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

/* ── STATUS ── */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #4ADE80;
    background: rgba(74,222,128,0.12);
    padding: 5px 11px;
    border-radius: 20px;
    border: 1px solid rgba(74,222,128,0.2);
    white-space: nowrap;
}

.pulse {
    width: 7px;
    height: 7px;
    background: #4ADE80;
    border-radius: 50%;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74,222,128,0.5); }
    70%  { box-shadow: 0 0 0 7px rgba(74,222,128,0); }
    100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

/* ── LANG TOGGLE ── */
.lang-toggle {
    display: flex;
    background: rgba(255,255,255,0.1);
    padding: 3px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
}

.lang-btn {
    background: transparent;
    border: none;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
    font-family: inherit;
}

.lang-btn.active {
    background: var(--red);
    color: white;
    box-shadow: 0 2px 8px rgba(229,57,53,0.4);
}

/* ── MUTE ── */
.mute-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: rgba(255,255,255,0.6);
    transition: all 0.2s;
    flex-shrink: 0;
}

.mute-btn:hover { background: rgba(255,255,255,0.18); color: white; }
.mute-btn.muted { color: #FF8A80; background: rgba(229,57,53,0.2); border-color: rgba(229,57,53,0.3); }

/* ── VISUALIZER ── */
.visualizer-container { display: none; align-items: center; gap: 3px; height: 20px; }
.visualizer-container.active { display: flex; }
.visualizer-container .bar { width: 3px; height: 8px; background: #FF8A80; border-radius: 2px; animation: waveBar 0.5s ease-in-out infinite alternate; }
.visualizer-container .bar:nth-child(2) { animation-delay: .1s; height: 14px; }
.visualizer-container .bar:nth-child(3) { animation-delay: .2s; height: 10px; }
.visualizer-container .bar:nth-child(4) { animation-delay: .3s; height: 16px; }
.visualizer-container .bar:nth-child(5) { animation-delay: .4s; height: 9px;  }
@keyframes waveBar { from { transform: scaleY(1); } to { transform: scaleY(2); } }

/* ── CHAT BOX ── */
.chat-box {
    flex: 1;
    min-height: 0; /* crucial — allows flex child to shrink below content height */
    padding: 22px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(229,57,53,0.15) transparent;
    -webkit-overflow-scrolling: touch; /* smooth momentum scroll on iOS */
    overscroll-behavior: contain;
}

.chat-box::-webkit-scrollbar { width: 3px; }
.chat-box::-webkit-scrollbar-track { background: transparent; }
.chat-box::-webkit-scrollbar-thumb { background: rgba(229,57,53,0.2); border-radius: 10px; }

/* ── MESSAGES ── */
.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
    opacity: 0;
    animation: fadeUp 0.35s ease forwards;
}

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

.bot-message  { flex-direction: row;         justify-content: flex-start; }
.user-message { flex-direction: row-reverse; justify-content: flex-start; }

/* ── AVATARS ── */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 13px;
    font-weight: 800;
    flex-shrink: 0;
    align-self: flex-end;
}

.bot-message  .avatar { background: linear-gradient(145deg, var(--red), var(--red-dark)); color: white; box-shadow: 0 3px 12px rgba(229,57,53,0.3); }
.user-message .avatar { background: linear-gradient(135deg, var(--slate), var(--ink)); color: white; box-shadow: 0 3px 12px rgba(26,35,50,0.25); }

/* ── MESSAGE CONTENT ── */
.message-content {
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 42px - 10px);
    min-width: 0;
}

.bot-message  .message-content { align-items: flex-start; }
.user-message .message-content { align-items: flex-end; }

/* ── BUBBLES ── */
.bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14.5px;
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
    width: 100%;
    box-sizing: border-box;
}

.bot-message .bubble {
    background: var(--snow);
    color: var(--slate);
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--red);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    min-height: 44px;
    min-width: 40px;
}

.user-message .bubble {
    background: linear-gradient(135deg, var(--slate) 0%, var(--ink) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 18px rgba(26,35,50,0.22);
}

/* streaming cursor */
.bubble.streaming::after {
    content: '●';
    color: var(--red);
    font-size: 9px;
    margin-left: 3px;
    vertical-align: middle;
    animation: dotPulse 0.8s ease-in-out infinite;
}

@keyframes dotPulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.2; transform: scale(0.4); }
}

.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 700; color: var(--slate); }
.user-message .bubble strong { color: #fff; }

/* ── FEEDBACK ── */
.feedback-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding-left: 3px;
    width: 100%;
    animation: fadeUp 0.3s ease 0.3s both;
}

.feedback-label { font-size: 11px; color: var(--soft); font-weight: 500; flex-shrink: 0; }
.feedback-btn {
    background: var(--snow);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px 9px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.18s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.feedback-btn:hover:not(:disabled) { background: rgba(229,57,53,0.06); border-color: var(--red); transform: scale(1.12); }
.feedback-btn.selected { background: var(--red); border-color: var(--red); }
.feedback-btn:disabled { cursor: default; opacity: 0.5; }

/* ── SUGGESTION CHIPS ── */
.suggestion-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 4px;
    width: 100%;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.suggestion-chips::-webkit-scrollbar { display: none; }

.chip {
    background: var(--snow);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 11px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 7px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: all 0.22s cubic-bezier(0.34,1.56,0.64,1);
    flex-shrink: 0;
}

.chip:hover { border-color: var(--red); color: var(--red); transform: translateY(-3px); box-shadow: 0 6px 18px rgba(229,57,53,0.15); background: rgba(229,57,53,0.03); }
.chip:active { transform: translateY(0); }

.chip.video-chip {
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(229,57,53,0.35);
}
.chip.video-chip:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(229,57,53,0.45); color: white; }

/* ── SYSTEM MSG ── */
.system-message {
    align-self: center;
    background: rgba(251,191,36,0.1);
    border: 1px solid rgba(251,191,36,0.25);
    color: #92400e;
    font-size: 13px;
    font-weight: 500;
    padding: 10px 16px;
    border-radius: 12px;
    max-width: 90%;
    text-align: center;
    animation: fadeUp 0.4s ease forwards;
}

/* ── VIDEO ── */
.video-container {
    margin-top: 12px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    border: 1px solid var(--border);
    animation: fadeUp 0.4s ease forwards;
    width: 100%;
}
.video-container video { width: 100%; display: block; cursor: pointer; }

/* ── TYPING ── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    background: var(--snow);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--red);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    min-height: 44px;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--red), rgba(229,57,53,0.4));
    animation: waveTyping 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes waveTyping {
    0%,80%,100% { transform: scale(0.55) translateY(0); opacity: 0.35; }
    40%          { transform: scale(1.1) translateY(-4px); opacity: 1; }
}

.loading-label { font-size: 11px; font-weight: 600; color: var(--red); margin-left: 4px; opacity: 0.7; }

/* ── INPUT AREA ── */
.input-area-container {
    padding: 12px 18px;
    /* Safe area for iPhone notch / home indicator */
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    background: var(--cream);
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.input-area {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--snow);
    padding: 6px 6px 6px 18px;
    border-radius: 24px;
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), inset 0 1px 2px rgba(255,255,255,0.8);
    transition: border-color 0.22s, box-shadow 0.22s;
}

.input-area:focus-within {
    border-color: var(--red);
    box-shadow: 0 0 0 4px rgba(229,57,53,0.08), 0 2px 8px rgba(0,0,0,0.04);
}

#user-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--slate);
    padding: 9px 0;
    font-size: 14.5px;
    font-family: inherit;
    outline: none;
    /* Prevent iOS zoom on focus (font-size must be ≥16px or use this) */
    font-size: 16px;
}

#user-input::placeholder { color: var(--soft); }
#user-input:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn {
    background: transparent;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--soft);
    transition: all 0.18s;
    flex-shrink: 0;
    /* Minimum tap target */
    min-width: 44px;
    min-height: 44px;
}

.icon-btn:hover:not(:disabled) { background: rgba(0,0,0,0.04); color: var(--slate); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn.primary {
    background: linear-gradient(145deg, var(--red), var(--red-dark));
    color: white;
    box-shadow: 0 4px 14px rgba(229,57,53,0.38);
}

.icon-btn.primary:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(229,57,53,0.5);
    transform: scale(1.07);
}

#mic-btn.recording {
    background: rgba(229,57,53,0.1);
    color: var(--red);
    animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
    0%   { box-shadow: 0 0 0 0 rgba(229,57,53,0.4); }
    70%  { box-shadow: 0 0 0 9px rgba(229,57,53,0); }
    100% { box-shadow: 0 0 0 0 rgba(229,57,53,0); }
}

/* ═══════════════════════════════════════════
   MOBILE RESPONSIVE — max-width: 768px
   Covers all phones: iPhone SE → iPhone 16 Pro Max, Android
═══════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Body: use dvh so layout reacts to browser chrome collapsing */
    body,
    body.custom-bg {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: stretch !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 100vh !important;
        min-height: -webkit-fill-available !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    /* Drop overlay on mobile — saves compositing layers */
    body.custom-bg::before { display: none; }

    /* Reduce snowflake opacity on mobile for performance */
    .snowflakes { opacity: 0.3; }

    /* ── Container: full-bleed, no rounded corners ── */
    .chat-container {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        position: relative !important;   /* avoid position:fixed scroll bugs on iOS */
        top: auto !important;
        left: auto !important;
        flex: 1 1 auto !important;
        box-shadow: none !important;
    }

    /* ── Header: safe-area inset for notch ── */
    .chat-header {
        padding: 10px 14px;
        padding-top: calc(10px + env(safe-area-inset-top));
        gap: 8px;
    }

    .logo-wrapper { width: 36px; height: 36px; }
    .logo { width: 36px; height: 36px; }
    .logo::after { font-size: 17px; }
    .logo-orbit { display: none; }

    .header-info h1 { font-size: 16px; }
    .header-info p  { font-size: 8px; letter-spacing: 0.8px; }

    .header-actions { gap: 7px; flex-shrink: 0; }

    /* Hide "Online" text on small screens — keep dot only */
    #status-text { display: none; }
    .status-indicator { padding: 5px 8px; }

    /* Slightly smaller lang buttons */
    .lang-btn { padding: 3px 7px; font-size: 10px; }

    /* ── Chat box: ensure flex-grow scrolls correctly ── */
    .chat-box {
        flex: 1 1 0;
        min-height: 0;
        padding: 14px;
        gap: 12px;
    }

    /* ── Bubbles ── */
    .bubble { padding: 10px 13px; font-size: 14px; }
    .avatar { width: 28px; height: 28px; font-size: 11px; }

    /* ── Input area: safe-area bottom for home indicator ── */
    .input-area-container {
        padding: 10px 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        flex-shrink: 0;
    }

    .input-area {
        padding: 4px 4px 4px 14px;
        border-radius: 20px;
    }

    /* Prevent iOS auto-zoom on input focus: font-size must be ≥16px */
    #user-input { font-size: 16px; }

    /* Ensure tap targets are at least 44×44px */
    .icon-btn { min-width: 44px; min-height: 44px; }
    .mute-btn { width: 36px; height: 36px; min-width: 36px; min-height: 44px; }

    /* ── Suggestion chips ── */
    .suggestion-chips { gap: 8px; }
    .chip { padding: 9px 14px; font-size: 12px; border-radius: 12px; }
}

/* ── Very small phones (iPhone SE, Galaxy A series) ── */
@media (max-width: 375px) {
    .header-info p { display: none; }
    .header-actions { gap: 5px; }
    .lang-btn { padding: 3px 5px; font-size: 9px; }
    .mute-btn { width: 30px; height: 30px; }
    .chat-box { padding: 10px; }
    .bubble { font-size: 13.5px; }
}

/* ── Landscape phone: shorter header, larger chat area ── */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .chat-header {
        padding: 6px 14px;
        padding-top: calc(6px + env(safe-area-inset-top));
    }

    .logo-wrapper, .logo { width: 30px; height: 30px; }
    .logo::after { font-size: 14px; }
    .header-info h1 { font-size: 14px; }
    .header-info p { display: none; }

    .chat-box { padding: 8px 14px; gap: 8px; }
    .bubble { font-size: 13px; padding: 8px 12px; }

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

    .suggestion-chips { margin-bottom: 6px; }
}