/* ===========================================================
   MusfirahLoom — AI Agent Platform
   agent-chat.css  ·  the shared chat component + rich cards

   Scoped under .ml-chat / .ml-product / .ml-cmp. Relies on
   style.css (tokens, .btn) and agents-theme.css (chat tokens).
=========================================================== */

.ml-chat{
  display:flex; flex-direction:column;
  background:var(--ml-chat-surface);
  border:1px solid var(--ml-chat-line);
  border-radius:var(--ml-radius-lg);
  box-shadow:var(--ml-shadow-card);
  overflow:hidden;
}

/* ---------- head ---------- */
.ml-chat__head{
  display:flex; align-items:center; justify-content:space-between; gap:.75rem;
  padding:.85rem 1rem; border-bottom:1px solid var(--ml-chat-line);
  background:var(--bg);
}
.ml-chat__title{
  font-family:var(--font-display);  font-weight:700; font-size:1rem;
}
.ml-chat__head-right{display:flex; align-items:center; gap:.6rem;}
.ml-chat__reset{
  font-family:var(--font-mono); font-size:.7rem; font-weight:500;
  letter-spacing:.04em; color:var(--ink-soft);
  background:transparent; border:1px solid var(--panel-line);
  border-radius:100px; padding:.35rem .7rem; cursor:pointer;
  transition:color .2s ease, border-color .2s ease, background .2s ease;
}
.ml-chat__reset:hover{color:var(--gold); border-color:var(--gold);}

/* ---------- log ---------- */
.ml-chat__log{
  flex:1; min-height:320px; max-height:min(58vh, 560px);
  overflow-y:auto; padding:1.1rem 1rem;
  display:flex; flex-direction:column; gap:1rem;
  scroll-behavior:smooth;
}
@media (prefers-reduced-motion: reduce){ .ml-chat__log{scroll-behavior:auto;} }

/* ---------- message rows ---------- */
.ml-msg{display:flex; flex-direction:column; gap:.25rem; max-width:86%;}
.ml-msg--user{align-self:flex-end; align-items:flex-end;}
.ml-msg--agent{align-self:flex-start; align-items:flex-start;}
.ml-msg--system{align-self:center; align-items:center; max-width:92%;}

.ml-msg__who{
  font-family:var(--font-mono); font-size:.6rem; letter-spacing:.12em;
  text-transform:uppercase; color:var(--ink-soft);
}
.ml-msg__time{font-size:.62rem; color:var(--ink-soft); opacity:.7;}

.ml-msg__bubble{
  font-size:.92rem; line-height:1.6; border-radius:var(--ml-radius);
  padding:.7rem .95rem; word-wrap:break-word;
}
.ml-msg--agent .ml-msg__bubble{
  background:var(--ml-bubble-bot-bg); color:var(--ml-bubble-bot-ink);
  border-bottom-left-radius:5px;
}
.ml-msg--user .ml-msg__bubble{
  background:var(--ml-bubble-user-bg); color:var(--ml-bubble-user-ink);
  border-bottom-right-radius:5px;
}
.ml-msg--system .ml-msg__bubble{
  background:var(--ml-bubble-sys-bg); color:var(--ml-bubble-sys-ink);
  border:1px dashed var(--panel-line); font-size:.82rem; text-align:center;
}

/* ---------- cards inside a bubble ---------- */
.ml-msg__cards{display:flex; flex-direction:column; gap:.7rem; margin-top:.7rem;}
.ml-msg__cards--row{margin-top:.7rem;}
@media (min-width:600px){
  .ml-msg__cards--row{flex-direction:row; flex-wrap:wrap;}
  .ml-msg__cards--row > .ml-product{flex:1 1 220px;}
}

/* ---------- typing indicator ---------- */
.ml-chat__typing{
  display:flex; align-items:center; gap:.55rem;
  padding:0 1rem 1rem; font-size:.78rem; color:var(--ink-soft);
}
.ml-chat__typing[hidden]{display:none;}   /* class display would otherwise win */
.ml-chat__dots{display:inline-flex; gap:3px;}
.ml-chat__dots i{
  width:6px; height:6px; border-radius:50%; background:var(--gold);
  opacity:.4; animation:mlBlink 1.2s infinite ease-in-out;
}
.ml-chat__dots i:nth-child(2){animation-delay:.15s;}
.ml-chat__dots i:nth-child(3){animation-delay:.3s;}
@keyframes mlBlink{0%,80%,100%{opacity:.25; transform:translateY(0);} 40%{opacity:1; transform:translateY(-3px);}}
@media (prefers-reduced-motion: reduce){ .ml-chat__dots i{animation:none; opacity:.6;} }

/* ---------- quick replies ---------- */
.ml-chat__quick{
  display:flex; flex-wrap:wrap; gap:.5rem; padding:0 1rem;
}
.ml-chat__quick:not(:empty){padding-bottom:.9rem;}
.ml-chat__chip{
  font-size:.78rem; font-weight:600; color:var(--gold);
  background:rgba(185,166,211,0.14); border:1px solid var(--panel-line);
  border-radius:100px; padding:.4rem .8rem; cursor:pointer;
  transition:background .2s ease, border-color .2s ease, transform .15s ease;
}
.ml-chat__chip:hover{background:rgba(185,166,211,0.22); border-color:var(--gold); transform:translateY(-1px);}

/* ---------- empty state ---------- */
.ml-chat__empty{
  margin:auto; text-align:center; padding:1.5rem .5rem; max-width:34ch;
  display:flex; flex-direction:column; align-items:center; gap:.4rem;
}
.ml-chat__empty-icon{
  width:44px; height:44px; border-radius:12px; display:flex;
  align-items:center; justify-content:center; font-size:1.3rem; color:var(--on-accent);
  background:var(--agent-accent, var(--gold)); margin-bottom:.3rem;
}
.ml-chat__empty-title{font-family:var(--font-display);  font-size:1.1rem;}
.ml-chat__empty-sub{font-size:.82rem; color:var(--ink-soft); line-height:1.55;}
.ml-chat__samples{display:flex; flex-wrap:wrap; gap:.5rem; justify-content:center; margin-top:.6rem;}

/* ---------- error ---------- */
.ml-chat__error{
  align-self:center; display:flex; align-items:center; gap:.8rem; flex-wrap:wrap;
  justify-content:center; text-align:center;
  background:rgba(169,112,47,0.10); border:1px solid rgba(169,112,47,0.4);
  color:var(--ink); border-radius:var(--ml-radius-sm);
  padding:.7rem .9rem; font-size:.82rem;
}

/* ---------- composer ---------- */
.ml-chat__form{
  border-top:1px solid var(--ml-chat-line); padding:.8rem 1rem 1rem;
  background:var(--bg);
}
.ml-chat__input{
  width:100%; resize:none; font:inherit; font-size:.92rem; line-height:1.5;
  color:var(--ink); background:var(--white);
  border:1px solid var(--panel-line); border-radius:var(--ml-radius-sm);
  padding:.65rem .8rem; max-height:140px;
  transition:border-color .2s ease;
}
.ml-chat__input:focus{outline:none; border-color:var(--gold);}
.ml-chat__input:disabled{opacity:.6;}
.ml-chat__formfoot{
  display:flex; align-items:center; justify-content:space-between; gap:.8rem;
  margin-top:.55rem;
}
.ml-chat__count{
  font-family:var(--font-mono); font-size:.68rem; color:var(--ink-soft);
}
.ml-chat__count.is-over{color:var(--agent-cart, #A9702F); font-weight:600;}
.ml-chat__send{font-size:.8rem;}
.ml-chat__send:disabled{opacity:.45; cursor:not-allowed; transform:none;}

/* ===========================================================
   PRODUCT CARD
=========================================================== */
.ml-product{
  display:flex; gap:.85rem; background:var(--white);
  border:1px solid var(--panel-line); border-radius:var(--ml-radius);
  padding:.75rem; text-align:left;
}
.ml-product--compact{flex-direction:column;}
.ml-product__thumb{
  flex-shrink:0; width:76px; height:76px; border-radius:var(--ml-radius-sm);
  display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); font-weight:700; font-size:1.4rem; color:#fff;
  letter-spacing:.02em;
}
.ml-product--compact .ml-product__thumb{width:100%; height:96px;}
.ml-product__body{display:flex; flex-direction:column; gap:.3rem; min-width:0;}
.ml-product__cat{
  font-family:var(--font-mono); font-size:.6rem; letter-spacing:.12em;
  text-transform:uppercase; color:var(--ink-soft);
}
.ml-product__title{font-size:.9rem; font-weight:700; line-height:1.3;}
.ml-product__pricerow{display:flex; align-items:baseline; gap:.6rem; flex-wrap:wrap;}
.ml-product__price{
  font-family:var(--font-display); font-weight:700; font-size:1rem; color:var(--gold);
}
.ml-product__rating{font-size:.7rem; color:var(--gold); letter-spacing:.02em;}
.ml-product__reason{font-size:.78rem; line-height:1.5; color:var(--ink-soft);}
.ml-product__actions{display:flex; gap:.5rem; flex-wrap:wrap; margin-top:.35rem;}
.ml-product__actions .btn{padding:.5rem 1rem; font-size:.74rem;}

/* ===========================================================
   COMPARISON TABLE
=========================================================== */
.ml-cmp-wrap{margin-top:.7rem; overflow-x:auto;}
.ml-cmp{
  width:100%; border-collapse:collapse; font-size:.8rem;
  background:var(--white); border:1px solid var(--panel-line);
  border-radius:var(--ml-radius-sm); overflow:hidden;
}
.ml-cmp th, .ml-cmp td{
  padding:.5rem .65rem; text-align:left; border-bottom:1px solid var(--panel-line);
  vertical-align:top;
}
.ml-cmp thead th{
  background:var(--panel); font-family:var(--font-display); 
  font-weight:600; font-size:.82rem;
}
.ml-cmp tbody th{
  font-family:var(--font-mono); font-size:.64rem; letter-spacing:.08em;
  text-transform:uppercase; color:var(--ink-soft); white-space:nowrap;
}
.ml-cmp tr:last-child th, .ml-cmp tr:last-child td{border-bottom:none;}
.ml-cmp__actions{display:flex; gap:.5rem; flex-wrap:wrap; margin-top:.6rem;}
.ml-cmp__actions .btn{padding:.45rem .9rem; font-size:.72rem;}
.ml-cmp__empty{font-size:.82rem; color:var(--ink-soft);}

/* ===========================================================
   ORDER / RETURN / HANDOFF CARDS  (Support agent)
   Sibling of .ml-product — same shell, tuned for structured
   key/value detail instead of a price + reason.
=========================================================== */
.ml-order{
  display:flex; gap:.85rem; margin-top:.7rem;
  background:var(--white); border:1px solid var(--panel-line);
  border-radius:var(--ml-radius); padding:.8rem;
}
.ml-order__thumb{
  flex-shrink:0; width:44px; height:44px; border-radius:var(--ml-radius-sm);
  display:flex; align-items:center; justify-content:center;
  font-size:1.15rem; color:#fff;
}
.ml-order__body{display:flex; flex-direction:column; gap:.45rem; min-width:0; flex:1;}
.ml-order__head{display:flex; align-items:center; gap:.6rem; flex-wrap:wrap;}
.ml-order__id{
  font-family:var(--font-display);  font-weight:700; font-size:1rem;
}
.ml-order__status{
  font-family:var(--font-mono); font-size:.62rem; font-weight:500;
  letter-spacing:.1em; text-transform:uppercase;
  border:1px solid currentColor; border-radius:100px; padding:.2rem .55rem;
}
.ml-order__grid{display:flex; flex-direction:column; gap:.28rem;}
.ml-order__row{display:flex; gap:.6rem; font-size:.8rem; line-height:1.45;}
.ml-order__dt{
  flex-shrink:0; width:5.5rem;
  font-family:var(--font-mono); font-size:.62rem; letter-spacing:.06em;
  text-transform:uppercase; color:var(--ink-soft); padding-top:.12rem;
}
.ml-order__dd{color:var(--ink); word-break:break-word;}
.ml-order__note{
  font-size:.72rem; line-height:1.5; color:var(--ink-soft);
  background:var(--ml-bubble-sys-bg); border:1px dashed var(--panel-line);
  border-radius:var(--ml-radius-sm); padding:.45rem .6rem;
}
.ml-order__actions{display:flex; gap:.45rem; flex-wrap:wrap; margin-top:.15rem;}
.ml-order__actions .btn{padding:.45rem .85rem; font-size:.72rem;}

/* ===========================================================
   CART RECOVERY  (Agent #3) — reuses .ml-order* shell
=========================================================== */
.ml-recovery-list{display:flex; flex-direction:column; gap:.6rem; margin-top:.7rem;}
.ml-recovery-list .ml-order{margin-top:0;}

/* recovery message preview — quoted draft */
.ml-quote{
  margin:.15rem 0 0; padding:.6rem .75rem;
  border-left:3px solid var(--agent-cart, #A9702F);
  background:var(--panel); border-radius:0 var(--ml-radius-sm) var(--ml-radius-sm) 0;
  font-size:.82rem; line-height:1.55; color:var(--ink); white-space:pre-line;
}

/* recovery metrics panel */
.ml-metrics{
  margin-top:.7rem; display:grid; gap:.5rem;
  grid-template-columns:repeat(2, 1fr);
}
@media (min-width:560px){ .ml-metrics{grid-template-columns:repeat(4, 1fr);} }
.ml-metrics__tile{
  background:var(--white); border:1px solid var(--panel-line);
  border-radius:var(--ml-radius-sm); padding:.6rem .7rem;
  display:flex; flex-direction:column; gap:.15rem;
}
.ml-metrics__value{
  font-family:var(--font-display); font-weight:700; font-size:1.15rem; color:var(--gold);
  line-height:1.1;
}
.ml-metrics__label{
  font-family:var(--font-mono); font-size:.58rem; letter-spacing:.06em;
  text-transform:uppercase; color:var(--ink-soft);
}

/* ===========================================================
   LEADS + BOOKING  (Agent #4) — reuses .ml-order* + .ml-metrics
=========================================================== */
.ml-lead-list{display:flex; flex-direction:column; gap:.6rem; margin-top:.7rem;}
.ml-lead-list .ml-order{margin-top:0;}

/* ===========================================================
   RESPONSIVE
=========================================================== */
@media (max-width:560px){
  .ml-chat__log{padding:.9rem .75rem; min-height:280px;}
  .ml-msg{max-width:94%;}
  .ml-chat__head{padding:.7rem .8rem;}
  .ml-chat__title{font-size:.9rem;}
  .ml-product{flex-direction:column;}
  .ml-product__thumb{width:100%; height:90px;}
  .ml-order__row{flex-direction:column; gap:.05rem;}
  .ml-order__dt{width:auto;}
}
