*{
    box-sizing:border-box;
}

:root{
    --navy:#061226;
    --orange:#ff8a00;
    --orange2:#ff7300;
    --line:#e5e7eb;
    --text:#07152d;
    --muted:#64748b;
}

body{
    margin:0;
    font-family:Arial,sans-serif;
    background:#e8edf5;
    color:var(--text);
    /* Prevent iOS body scroll — chat-body handles its own scroll */
    overflow:hidden;
    height:100%;
}

html{
    height:100%;
    overflow:hidden;
}

/* ─── MAIN APP SHELL ─────────────────────────────
   Uses 100dvh — this is the magic unit:
   it automatically shrinks when the iOS/Android
   keyboard opens, pushing the input bar up.
─────────────────────────────────────────────── */
.ai-app{
    max-width:520px;
    margin:0 auto;
    height:100dvh;          /* shrinks when keyboard opens */
    max-height:100dvh;
    background:#fff;
    display:flex;
    flex-direction:column;
    overflow:hidden;        /* clip children, not scroll */
}

/* ─── HEADER ──────────────────────────────────── */
.ai-header{
    background:var(--navy);
    color:#fff;
    padding:16px;
    display:flex;
    align-items:center;
    gap:12px;
    flex-shrink:0;          /* never squish */
    z-index:10;
}

.ai-header img{
    width:44px;
    background:#fff;
    border-radius:8px;
    padding:3px;
}

.ai-header strong{
    display:block;
    font-size:18px;
}

.ai-header span{
    color:var(--orange);
    font-weight:900;
    font-size:13px;
}

/* ─── CHAT BODY ───────────────────────────────────
   flex:1 fills all space between header and input.
   No fixed height, no calc() — flexbox handles it.
─────────────────────────────────────────────── */
.chat-body{
    flex:1;
    overflow-y:auto;
    overflow-x:hidden;
    -webkit-overflow-scrolling:touch;   /* iOS momentum */
    overscroll-behavior:contain;        /* prevent page scroll bleed */
    padding:18px 14px 20px;
    scroll-behavior:smooth;
}

/* ─── MESSAGE ─────────────────────────────────── */
.message-row{
    display:flex;
    align-items:flex-end;
    gap:10px;
    margin-bottom:14px;
}

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

.avatar{
    width:44px;
    height:44px;
    border-radius:50%;
    overflow:hidden;
    flex-shrink:0;
    background:#fff;
    box-shadow:0 6px 20px rgba(15,23,42,.14);
}

.avatar img{
    width:100%;
    height:100%;
    object-fit:cover;
    display:block;
}

.bubble{
    background:#fff;
    border:1px solid var(--line);
    border-radius:18px 18px 18px 4px;
    padding:13px 14px;
    max-width:82%;
    box-shadow:0 10px 25px rgba(15,23,42,.06);
}

.bubble p{
    margin:0;
    font-size:14px;
    line-height:1.55;
    color:#334155;
}

.message-row.user .bubble{
    background:var(--navy);
    border-color:var(--navy);
    border-radius:18px 18px 4px 18px;
}

.message-row.user .bubble p{
    color:#fff;
}

/* ─── TYPING ──────────────────────────────────── */
.typing-text{
    white-space:pre-wrap;
    line-height:1.55;
    font-size:14px;
    color:#334155;
}

.typing{
    display:flex;
    align-items:center;
    gap:5px;
    height:16px;
}

.typing span{
    width:7px;
    height:7px;
    border-radius:50%;
    background:#94a3b8;
    animation:typingBounce 1s infinite ease-in-out;
}

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

@keyframes typingBounce{
    0%,80%,100%{ transform:translateY(0); opacity:.35; }
    40%{         transform:translateY(-4px); opacity:1; }
}

/* ─── OPTIONS ─────────────────────────────────── */
.quick-options{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:10px;
    margin:10px 0 20px 54px;
    transition:opacity .2s;
}

.option-btn{
    width:100%;
    min-height:88px;
    border:1px solid var(--line);
    background:#fff;
    border-radius:18px;
    padding:14px;
    display:flex;
    gap:12px;
    align-items:center;
    text-align:left;
    cursor:pointer;
    box-shadow:0 10px 24px rgba(15,23,42,.04);
    /* Larger tap target feel on mobile */
    -webkit-tap-highlight-color:rgba(255,136,0,.12);
    touch-action:manipulation;
}

.option-icon{
    width:42px;
    height:42px;
    border-radius:14px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:21px;
    flex-shrink:0;
}

.orange{ background:#fff0df; color:var(--orange2); }
.purple{ background:#eef2ff; color:#1e3a8a; }
.green{  background:#dcfce7; color:#166534; }

.option-btn strong{
    display:block;
    font-size:15px;
    margin-bottom:3px;
    color:#07152d;
}

.option-btn span{
    display:block;
    font-size:12px;
    color:var(--muted);
}

/* ─── PRODUCT ─────────────────────────────────── */
.product-card{
    margin:10px 0 14px 54px;
    padding:12px 0;
    background:#fff;
    border-bottom:1px solid var(--line);
}

.product-row{
    display:grid;
    grid-template-columns:88px 1fr;
    gap:12px;
    align-items:flex-start;
}

.product-thumb{
    width:88px;
    height:88px;
    min-width:88px;
    overflow:hidden;
    display:flex;
    align-items:center;
    justify-content:center;
}

.product-thumb img{
    width:88px;
    height:88px;
    object-fit:contain;
    display:block;
}

.product-details h4{
    margin:0 0 5px;
    font-size:15px;
    line-height:1.25;
    font-weight:800;
    color:#111827;
}

.product-meta{
    font-size:12px;
    color:var(--muted);
    line-height:1.35;
    margin-bottom:2px;
}

.product-price{
    margin-top:6px;
    font-size:15px;
    font-weight:900;
    color:#111827;
}

.product-actions{
    display:flex;
    align-items:center;
    gap:10px;
    margin-top:9px;
}

.qty-box{
    display:flex;
    align-items:center;
    height:34px;
    border:1px solid #cfd8dc;
    border-radius:4px;
    overflow:hidden;
    background:#fff;
}

.qty-btn{
    width:32px;
    height:34px;
    border:0;
    background:#f8fafc;
    color:#0f172a;
    font-size:18px;
    font-weight:800;
    cursor:pointer;
    touch-action:manipulation;
}

.qty-input{
    width:38px;
    height:34px;
    border:0;
    text-align:center;
    font-size:14px;
    font-weight:800;
    outline:none;
    background:#fff;
}

.product-add-btn{
    height:34px;
    padding:0 18px;
    border:0;
    border-radius:4px;
    background:#ff8800;
    color:#fff;
    font-size:14px;
    font-weight:900;
    cursor:pointer;
    touch-action:manipulation;
}

/* ─── ORDER CARD ──────────────────────────────── */
.order-card{
    margin:10px 0 16px 54px;
    background:#fff;
    border:1px solid var(--line);
    border-radius:18px;
    padding:14px;
    box-shadow:0 10px 24px rgba(15,23,42,.05);
}

.order-card h4{ margin:0 0 6px; }
.order-card small{ display:block; margin-bottom:4px; color:var(--muted); }

/* ─── NOTE ────────────────────────────────────── */
.chat-note{
    margin:10px 0 18px 54px;
    background:#fff7ed;
    border:1px solid #fed7aa;
    color:#9a3412;
    padding:12px;
    border-radius:16px;
    font-size:12px;
    font-weight:800;
}

/* ─── INPUT BAR ───────────────────────────────────
   KEY FIX: NOT position:fixed anymore.
   It is a flex child that naturally sits at the
   bottom of .ai-app. When dvh shrinks (keyboard
   opens), the whole app shrinks and this bar rides
   up above the keyboard automatically.
─────────────────────────────────────────────── */
.bottom-input{
    flex-shrink:0;              /* never squish */
    background:#fff;
    border-top:1px solid var(--line);
    padding:10px 12px;
    padding-bottom:max(10px, env(safe-area-inset-bottom)); /* iPhone notch */
    display:flex;
    gap:10px;
    z-index:10;
}

.bottom-input input{
    flex:1;
    background:#f8fafc;
    border:1px solid var(--line);
    border-radius:999px;
    padding:13px 16px;
    color:var(--text);
    font-size:16px;             /* 16px prevents iOS auto-zoom on focus */
    outline:none;
}

.bottom-input input:focus{
    border-color:var(--orange2);
    background:#fff;
    box-shadow:0 0 0 4px rgba(255,115,0,.12);
}

.send{
    width:46px;
    height:46px;
    flex-shrink:0;
    border:0;
    border-radius:50%;
    background:linear-gradient(135deg,var(--orange2),var(--orange));
    color:#fff;
    font-size:20px;
    cursor:pointer;
    touch-action:manipulation;
}

/* ─── FLOATING BASKET ─────────────────────────── */
#floatingBasket{
    position:fixed;
    bottom:80px;
    left:50%;
    transform:translateX(-50%);
    background:var(--navy);
    color:#fff;
    border:0;
    border-radius:999px;
    padding:12px 22px;
    font-size:14px;
    font-weight:700;
    cursor:pointer;
    z-index:99;
    white-space:nowrap;
    box-shadow:0 8px 24px rgba(6,18,38,.35);
}

/* ─── DESKTOP ─────────────────────────────────── */
@media(min-width:700px){
    body{
        padding:20px;
        overflow:auto;
        height:auto;
    }

    html{
        height:auto;
        overflow:auto;
    }

    .ai-app{
        border-radius:28px;
        overflow:hidden;
        box-shadow:0 30px 80px rgba(15,23,42,.16);
        /* Desktop doesn't have keyboard issues — use vh is fine */
        height:calc(100vh - 40px);
        max-height:calc(100vh - 40px);
    }

    .bottom-input{
        border-radius:0 0 28px 28px;
    }
}

/* ─── MOBILE ──────────────────────────────────── */
@media(max-width:520px){
    .chat-body{
        padding:16px 12px 16px;
    }

    .avatar{
        width:40px;
        height:40px;
    }

    .bubble{
        max-width:84%;
    }

    .quick-options,
    .product-card,
    .order-card,
    .chat-note{
        margin-left:50px;
    }

    .quick-options{
        grid-template-columns:1fr 1fr;
        gap:8px;
    }

    .option-btn{
        padding:12px;
        min-height:82px;
        border-radius:16px;
    }

    .option-icon{
        width:34px;
        height:34px;
        font-size:16px;
    }

    .option-btn strong{
        font-size:13px;
        line-height:1.2;
    }

    .option-btn span{
        font-size:10px;
        line-height:1.2;
    }

    .product-row{
        grid-template-columns:82px 1fr;
        gap:10px;
    }

    .product-thumb,
    .product-thumb img{
        width:82px;
        height:82px;
        min-width:82px;
    }

    .product-actions{
        gap:8px;
        flex-wrap:wrap;
    }

    .product-add-btn{
        padding:0 16px;
    }
}
