/* =========================================================
   Nestor Shopper Assistant — Shopper-side CSS (UPDATED)
   frontend/static/style.css
   ========================================================= */

/* ===== Theme ===== */
:root{
  --bg:#f3f4f6;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#6b7280;

  --brandBlue:#1f57d6;
  --infoBlue:#d9ecff;

  --green:#16a34a;
  --greenDot:#22c55e;
  --redDot:#ef4444;

  --shadow:0 22px 50px rgba(15,23,42,.18);

  --radius:22px;
  --radiusSm:16px;

  --ringGreen:0 0 0 4px rgba(34,197,94,.18);

  /* sizing */
  --shellW:520px;
  --headerIcon:44px;
  --avatar:44px;
  --micBtn:56px;

  /* ✅ Visual viewport height (set by JS in Shopper.html to fix keyboard split/zoom bug) */
  --vvh: 100vh;

  /* ✅ Safe areas (keep if used by HTML/CSS) */
  --safeTop: env(safe-area-inset-top, 0px);
  --safeBottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset ===== */
*{ box-sizing:border-box; margin:0; padding:0; }
html, body{ height:100%; }

body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color:var(--text);
  background: radial-gradient(1100px 520px at 50% 20%, #f7fbff 0%, #ffffff 60%);

  /* ✅ Critical: prevents the page from staying “scrolled/zoomed” after keyboard closes */
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

/* ===== Page + Shell ===== */
.page{
  /* ✅ Use visual viewport height so keyboard resize doesn't break layout */
  height: var(--vvh);
  display:flex;
  justify-content:center;
  align-items: stretch;

  padding:18px 12px;
  overflow:hidden;
}

.app-shell{
  width: min(520px, 100%);
  height: 100%;
  max-height: 920px;

  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;

  display: flex;
  flex-direction: column;

  /* ✅ Safe areas handled via padding (works with vvh) */
  padding-top: calc(var(--safeTop) + 14px);
  padding-bottom: calc(var(--safeBottom) + 14px);
}

.branding{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}

/* 🔵 Top-left logo container (NO BORDER) */
.logo-circle{
  width:var(--headerIcon);
  height:var(--headerIcon);
  border-radius:14px;
  background:#eef2ff;
  display:grid;
  place-items:center;
  overflow:hidden;
}

.logo-circle img{
  width:72%;
  height:72%;
  object-fit:contain;
  display:block;
}

/* Titles */
.branding h1{
  font-size:18px;
  font-weight:900;
  line-height:1.1;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.branding p{
  margin-top:3px;
  font-size:12.5px;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* ===== Connection pill ===== */
.conn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  border-radius:999px;
  background:#f3f4f6;
  font-size:13px;
  font-weight:800;
  white-space:nowrap;
  color:var(--green);
}

.conn-dot{
  width:10px;
  height:10px;
  border-radius:999px;
  background:var(--greenDot);
  box-shadow:0 0 0 4px rgba(34,197,94,.12);
}

.conn.offline{ color:#b91c1c; }
.conn.offline .conn-dot{
  background:var(--redDot);
  box-shadow:0 0 0 4px rgba(185,28,28,.10);
}

/* ===== Main ===== */
.app-main{
  flex:1;
  display:flex;
  flex-direction:column;
  background:#fff;
  min-height:0; /* allow chat-log to scroll */
  overflow:hidden; /* ✅ keep scrolling inside chat-log only */
}

.chat-wrap{
  flex:1;
  display:flex;
  flex-direction:column;
  padding:14px;
  min-height:0;
}

/* ===== Chat log ===== */
.chat-log{
  flex:1;
  overflow:auto;
  padding:4px 2px 8px;
  min-height:0;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
}

/* ===== Messages ===== */
.bubble-row{
  display:flex;
  gap:10px;
  margin:10px 0;
  align-items:flex-start; /* don't stretch bubble */
}

.from-user{ justify-content:flex-end; }
.from-bot{ justify-content:flex-start; }

/* Avatar (if used) */
.avatar{
  width:var(--avatar);
  height:var(--avatar);
  border-radius:999px;
  background:transparent;
  display:grid;
  place-items:center;
  overflow:hidden;
  flex:0 0 auto;
}

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

/* ✅ Bubbles: hug content (no wide empty bubble) */
.bubble{
  display:inline-block;
  width:fit-content;
  flex:0 0 auto;
  align-self:flex-start;

  max-width:78%;
  border-radius:16px;
  padding:10px 12px;
  font-size:14px;
  line-height:1.35;

  box-shadow:0 10px 18px rgba(15,23,42,.06);

  white-space:pre-wrap;
  word-break:break-word;

  direction:auto;
  unicode-bidi:plaintext;

  text-align:left;
}

/* Colors */
.bubble-user{
  background:var(--brandBlue);
  color:#fff;
  border-bottom-right-radius:10px;
}

.bubble-bot{
  background:#e9eef6;
  color:#0f172a;
  border-bottom-left-radius:10px;
}

/* ===== Disambiguation (clickable options) ===== */
.disambig-wrap{
  margin-top:10px;
  background:#ffffff;
  border:1px solid rgba(15,23,42,.10);
  border-radius:18px;
  padding:12px;
  box-shadow:0 10px 18px rgba(15,23,42,.06);
}

.disambig-head{ margin-bottom:10px; }

.disambig-item{
  width:100%;
  text-align:left;
  border:1px solid rgba(15,23,42,.12);
  background:#fff;
  border-radius:16px;
  padding:12px 12px;
  cursor:pointer;
  display:block;
  margin-top:10px;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
  box-shadow:0 6px 16px rgba(15,23,42,.06);
}

.disambig-item:hover{
  transform: translateY(-1px);
  border-color: rgba(31,87,214,.35);
  background:#f8fafc;
  box-shadow:0 10px 26px rgba(15,23,42,.10);
}

.disambig-name{
  font-weight:900;
  color:#0f172a;
}

.disambig-sub{
  margin-top:4px;
  font-size:12.5px;
  color:var(--muted);
}

/* ===== Composer ===== */
.composer{
  padding:12px 12px 14px;
  border-top:1px solid rgba(15,23,42,.08);
  background:#fff;
  position:relative;
  z-index:5;
}

.composer-row{
  display:flex;
  align-items:center;
  gap:10px;
}

.text-input{
  flex:1;
  height:46px;
  border-radius:999px;
  border:1px solid rgba(15,23,42,.18);
  padding:0 14px;
  font-size:14.5px;
  outline:none;

  /* ✅ Helps prevent iOS/Android zoom quirks */
  -webkit-text-size-adjust: 100%;
}

.text-input:focus{
  box-shadow:var(--ringGreen);
  border-color:rgba(22,163,74,.45);
}

/* 🎙 Mic button — NO BORDER, CLEAN */
.mic-btn{
  width:var(--micBtn);
  height:var(--micBtn);
  border-radius:999px;
  border:none;
  background:#fff;
  display:grid;
  place-items:center;
  cursor:pointer;
  box-shadow:0 14px 26px rgba(15,23,42,.12);
  position:relative;
  overflow:hidden;
}

.mic-btn img{
  width:44px;
  height:44px;
  object-fit:contain;
  display:block;
}

/* Recording state (green glow) */
.mic-btn.active,
.mic-btn.is-recording,
.mic-btn.recording,
.mic-btn.is-active{
  box-shadow:
    0 18px 40px rgba(34,197,94,.25),
    var(--ringGreen);
  background:linear-gradient(
    180deg,
    rgba(34,197,94,.10),
    #ffffff
  );
}

/* Pulse ring */
.mic-btn.active::after,
.mic-btn.is-recording::after,
.mic-btn.recording::after,
.mic-btn.is-active::after{
  content:"";
  position:absolute;
  inset:-10px;
  border-radius:999px;
  border:2px solid rgba(34,197,94,.28);
  animation:micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse{
  0%{ transform:scale(.92); opacity:.12; }
  50%{ transform:scale(1); opacity:.28; }
  100%{ transform:scale(.92); opacity:.12; }
}

/* Ask button */
.btn-primary{
  height:46px;
  padding:0 18px;
  border-radius:999px;
  border:none;
  cursor:pointer;
  font-weight:900;
  font-size:14px;
  background:var(--green);
  color:#fff;
  box-shadow:0 10px 24px rgba(22,163,74,.25);
}

/* ===== Responsive ===== */
@media (max-width:520px){
  .page{
    padding:12px 10px;
  }

  .app-shell{
    width: 100%;
    max-height: 920px;
    border-radius: 28px;
  }

  .bubble{
    max-width:86%;
  }
}

/* FORCE mic logo size (must be last in file) */
.mic-btn img#bottomLogo{
  width:44px !important;
  height:44px !important;
  object-fit:contain !important;
  display:block !important;
}

/* =========================================================
   HARD OVERRIDE — bubble should hug text (wins over inline CSS)
   Put this at the VERY END of style.css
   ========================================================= */

#chatLog .bubble-row{
  align-items:flex-start !important;
}

#chatLog .bubble{
  display:inline-block !important;
  width:auto !important;
  max-width:78% !important;

  flex:0 0 auto !important;   /* key: never grow */
  align-self:flex-start !important;

  white-space:pre-wrap !important;
  word-break:break-word !important;
  direction:auto !important;
  unicode-bidi:plaintext !important;
}
