/* ============================================================
   ai.css — MurderAI chat bubble + panel.
   Brand tokens from app.css (--accent --card --card2 --line --text
   --muted --t-accent --r3 --r4 …). Dark-premium, matches the app.
   No style= attributes anywhere (CSP): everything is class-driven.
   ============================================================ */

.mbai{
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(var(--tabbar-h, 64px) + 16px + var(--safe-bottom, 0px));
  z-index: 60;
  display: block;
}
.mbai[hidden]{ display: none; }

/* ---- floating bubble ---- */
.mbai__bubble{
  position: relative;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 58px; height: 58px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--line2, #2b323d);
  background: linear-gradient(160deg, var(--accent, #e5484d), var(--accent2, #ff6b6b));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(229,72,77,.35), var(--shadow, 0 20px 60px rgba(0,0,0,.5));
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.mbai__bubble:hover{ transform: translateY(-2px); }
.mbai__bubble:active{ transform: translateY(0) scale(.96); }
.mbai__bubble:focus-visible{ outline: 2px solid var(--accent2, #ff6b6b); outline-offset: 3px; }
.mbai.is-open .mbai__bubble{ opacity: 0; pointer-events: none; }
.mbai__bubicon svg, .mbai__avatar svg, .mbai__x svg, .mbai__send svg{
  width: 24px; height: 24px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---- panel ---- */
.mbai__panel{
  position: fixed;
  right: 0; left: 0; bottom: 0;
  margin: 0 auto;
  width: 100%;
  max-width: var(--maxw, 720px);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--card, #12161c);
  border: 1px solid var(--line, #1e242d);
  border-top-left-radius: var(--r4, 16px);
  border-top-right-radius: var(--r4, 16px);
  box-shadow: var(--shadow, 0 20px 60px rgba(0,0,0,.5));
  overflow: hidden;
  animation: mbai-up .22s ease;
}
.mbai__panel[hidden]{ display: none; }
@keyframes mbai-up{ from{ transform: translateY(14px); opacity: 0; } to{ transform: translateY(0); opacity: 1; } }

/* desktop: anchor it as a card near the bubble instead of a full-width sheet */
@media (min-width: 760px){
  .mbai__panel{
    left: auto; right: 0; bottom: 74px;
    width: 380px;
    border-radius: var(--r4, 16px);
    max-height: 70vh;
  }
}

/* ---- header ---- */
.mbai__head{
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line, #1e242d);
  background: var(--card2, #161b22);
}
.mbai__avatar{
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--r-pill, 999px);
  background: var(--t-accent, rgba(229,72,77,.15));
  color: var(--accent2, #ff6b6b);
}
.mbai__avatar svg{ width: 18px; height: 18px; }
.mbai__headtxt{ display: flex; flex-direction: column; line-height: 1.15; }
.mbai__headtxt strong{ color: var(--text, #eceef1); font-size: 14px; }
.mbai__sub{ color: var(--muted, #9aa3ad); font-size: 11px; }
.mbai__x{
  margin-left: auto;
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: var(--r2, 10px);
  background: transparent; border: 1px solid transparent;
  color: var(--muted, #9aa3ad); cursor: pointer;
}
.mbai__x:hover{ background: var(--card, #12161c); border-color: var(--line, #1e242d); color: var(--text); }
.mbai__x svg{ width: 18px; height: 18px; }

/* ---- message list ---- */
.mbai__list{
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.mbai__msg{ display: flex; }
.mbai__msg--user{ justify-content: flex-end; }
.mbai__msg--ai{ justify-content: flex-start; }
.mbai__bubbletxt{
  max-width: 84%;
  padding: 9px 12px;
  border-radius: var(--r3, 12px);
  font-size: 14px; line-height: 1.4;
  white-space: pre-wrap; word-wrap: break-word;
}
.mbai__msg--user .mbai__bubbletxt{
  background: var(--accent, #e5484d); color: #fff;
  border-bottom-right-radius: 4px;
}
.mbai__msg--ai .mbai__bubbletxt{
  background: var(--card2, #161b22); color: var(--text, #eceef1);
  border: 1px solid var(--line, #1e242d);
  border-bottom-left-radius: 4px;
}

/* typing indicator */
.mbai__typing{ display: inline-flex; gap: 4px; align-items: center; }
.mbai__dot{
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted, #9aa3ad);
  animation: mbai-blink 1.2s infinite ease-in-out;
}
.mbai__dot:nth-child(2){ animation-delay: .2s; }
.mbai__dot:nth-child(3){ animation-delay: .4s; }
@keyframes mbai-blink{ 0%,80%,100%{ opacity: .3; } 40%{ opacity: 1; } }

/* ---- example chips ---- */
.mbai__examples{
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px 10px;
}
.mbai__chip{
  padding: 6px 10px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--line2, #2b323d);
  background: var(--card2, #161b22);
  color: var(--muted, #9aa3ad);
  font-size: 12px; cursor: pointer;
  transition: border-color .12s ease, color .12s ease;
}
.mbai__chip:hover{ color: var(--text, #eceef1); border-color: var(--accent, #e5484d); }

/* ---- input row ---- */
.mbai__form{
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px calc(10px + var(--safe-bottom, 0px));
  border-top: 1px solid var(--line, #1e242d);
  background: var(--card2, #161b22);
}
.mbai__input{
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 13px;
  border-radius: var(--r3, 12px);
  border: 1px solid var(--line2, #2b323d);
  background: var(--card, #12161c);
  color: var(--text, #eceef1);
  font-size: 15px; /* >=16px-ish prevents iOS zoom; 15 is fine with viewport */
  font-family: var(--font);
}
.mbai__input::placeholder{ color: var(--dim, #687180); }
.mbai__input:focus{ outline: none; border-color: var(--accent, #e5484d); }
.mbai__send{
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border-radius: var(--r3, 12px);
  border: 1px solid var(--line2, #2b323d);
  background: var(--accent, #e5484d); color: #fff;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.mbai__send:hover{ transform: translateY(-1px); }
.mbai__send:active{ transform: translateY(0) scale(.95); }
.mbai__send:focus-visible{ outline: 2px solid var(--accent2, #ff6b6b); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce){
  .mbai__panel, .mbai__bubble, .mbai__send, .mbai__dot{ animation: none !important; transition: none !important; }
}
