/* =====================================================================
   AutoKorea.mn — Онлайн туслах (чат виджет)
   style.css болон mobile.css-ийн ДАРАА ачаална.
   Гаднын сан, CDN ашиглахгүй.
   ===================================================================== */

:root {
  --akb-nv: #123a63;
  --akb-nv2: #0e2c4d;
  --akb-ac: #ff6b35;
  --akb-ac2: #e85420;
  --akb-line: #e4e9ef;
  --akb-bg: #f4f7fa;
  --akb-ink: #1b2430;
  --akb-mut: #68727f;
  /* Хөвөгч товчны доод зай — утсанд .mobile-cta (76px)-ийн ДЭЭР суух */
  --akb-gap: 20px;
}

/* ---------------------------------------------------------------- */
/*  1. Хөвөгч товч                                                   */
/* ---------------------------------------------------------------- */

#akbot-fab {
  position: fixed;
  right: 18px;
  bottom: var(--akb-gap);
  z-index: 9998;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(135deg, var(--akb-ac) 0%, var(--akb-ac2) 100%);
  color: #fff;
  box-shadow: 0 6px 22px rgba(232, 84, 32, .38), 0 2px 6px rgba(18, 36, 54, .18);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
  -webkit-tap-highlight-color: transparent;
}
#akbot-fab:hover { transform: translateY(-2px) scale(1.04); }
#akbot-fab:active { transform: scale(.96); }
#akbot-fab svg { width: 27px; height: 27px; display: block; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#akbot-fab .akb-x { display: none; }
#akbot-fab.on .akb-chat { display: none; }
#akbot-fab.on .akb-x { display: block; }

/* Анхаарал татах цэг */
#akbot-fab .akb-dot {
  position: absolute; top: 3px; right: 3px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #17935c; border: 2px solid #fff;
}
#akbot-fab.on .akb-dot { display: none; }

/* Товчны хажуугийн бөмбөлөг (зөвхөн дэлгэц өргөн үед) */
#akbot-tip {
  position: fixed;
  right: 84px;
  bottom: calc(var(--akb-gap) + 12px);
  z-index: 9997;
  max-width: 210px;
  background: #fff;
  color: var(--akb-ink);
  border: 1px solid var(--akb-line);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 6px 22px rgba(18, 36, 54, .14);
  cursor: pointer;
}
#akbot-tip.hide { display: none; }

/* ---------------------------------------------------------------- */
/*  2. Самбар                                                        */
/* ---------------------------------------------------------------- */

#akbot-panel {
  position: fixed;
  right: 18px;
  bottom: calc(var(--akb-gap) + 70px);
  z-index: 9999;
  width: 374px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid var(--akb-line);
  border-radius: 16px;
  box-shadow: 0 18px 54px rgba(14, 44, 77, .26);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font: 14px/1.6 "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  color: var(--akb-ink);
}
#akbot-panel.open { display: flex; animation: akb-in .2s ease; }

@keyframes akb-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- толгой --- */
#akbot-panel .akb-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px;
  background: linear-gradient(135deg, var(--akb-nv) 0%, var(--akb-nv2) 100%);
  color: #fff;
  flex: 0 0 auto;
}
#akbot-panel .akb-av {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex: 0 0 auto;
}
#akbot-panel .akb-ttl { flex: 1; min-width: 0; }
#akbot-panel .akb-ttl b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.1px; }
#akbot-panel .akb-ttl span { display: block; font-size: 11.5px; opacity: .8; }
#akbot-panel .akb-ttl span:before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; margin-right: 5px; vertical-align: 1px;
}
#akbot-panel .akb-hbtn {
  background: rgba(255, 255, 255, .14); border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  font-size: 17px; line-height: 1; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
#akbot-panel .akb-hbtn:hover { background: rgba(255, 255, 255, .26); }

/* --- мессежүүд --- */
#akbot-log {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  background: var(--akb-bg);
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
#akbot-log::-webkit-scrollbar { width: 7px; }
#akbot-log::-webkit-scrollbar-thumb { background: #cdd6e0; border-radius: 4px; }

.akb-msg { max-width: 86%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.6; }
.akb-msg a { color: var(--akb-ac2); text-decoration: underline; word-break: break-all; }
.akb-bot  { align-self: flex-start; background: #fff; border: 1px solid var(--akb-line); border-bottom-left-radius: 5px; box-shadow: 0 1px 2px rgba(18, 36, 54, .05); }
.akb-me   { align-self: flex-end; background: var(--akb-nv); color: #fff; border-bottom-right-radius: 5px; }
.akb-me a { color: #ffd2c0; }

/* --- бичиж байна --- */
.akb-typing { align-self: flex-start; background: #fff; border: 1px solid var(--akb-line); border-radius: 14px; border-bottom-left-radius: 5px; padding: 12px 15px; display: flex; gap: 4px; }
.akb-typing i { width: 7px; height: 7px; border-radius: 50%; background: #9fb0c2; display: block; animation: akb-bounce 1.1s infinite; }
.akb-typing i:nth-child(2) { animation-delay: .18s; }
.akb-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes akb-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* --- машины карт --- */
.akb-cars { align-self: stretch; display: flex; flex-direction: column; gap: 8px; }
.akb-car {
  display: flex; gap: 10px; align-items: stretch;
  background: #fff; border: 1px solid var(--akb-line); border-radius: 12px;
  padding: 8px; text-decoration: none; color: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.akb-car:hover { border-color: #c3d3e4; box-shadow: 0 4px 14px rgba(18, 36, 54, .1); transform: translateY(-1px); }
.akb-car img { width: 86px; height: 64px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: #eef2f6; }
.akb-car .akb-cb { min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.akb-car .akb-cn { font-weight: 700; font-size: 13.5px; line-height: 1.35; color: var(--akb-nv2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.akb-car .akb-cs { font-size: 11.5px; color: var(--akb-mut); }
.akb-car .akb-cp { font-size: 15px; font-weight: 800; color: var(--akb-ac2); letter-spacing: -.2px; }

/* --- түргэн хариулт --- */
#akbot-quick { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px; padding: 9px 12px 0; background: #fff; border-top: 1px solid var(--akb-line); }
#akbot-quick:empty { display: none; padding: 0; border-top: 0; }
.akb-chip {
  background: #eef3f8; border: 1px solid #dbe4ee; color: var(--akb-nv);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; line-height: 1.3;
  transition: background .15s ease, border-color .15s ease;
}
.akb-chip:hover { background: #e2ebf5; border-color: #c3d3e4; }
.akb-chip:active { transform: scale(.97); }

/* --- оруулах хэсэг --- */
#akbot-panel .akb-foot {
  flex: 0 0 auto;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff; border-top: 1px solid var(--akb-line);
}
#akbot-in {
  flex: 1; resize: none; min-height: 42px; max-height: 110px;
  border: 1px solid var(--akb-line); border-radius: 11px;
  padding: 10px 12px; font: inherit; font-size: 14.5px; line-height: 1.45;
  background: #f8fafc; color: var(--akb-ink); outline: 0;
}
#akbot-in:focus { border-color: #b9cde3; background: #fff; box-shadow: 0 0 0 3px rgba(18, 58, 99, .08); }
#akbot-send {
  flex: 0 0 auto; width: 42px; height: 42px; border: 0; border-radius: 11px; cursor: pointer;
  background: var(--akb-ac); color: #fff;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
#akbot-send:hover { background: var(--akb-ac2); }
#akbot-send:disabled { opacity: .45; cursor: default; }
#akbot-send svg { width: 19px; height: 19px; fill: currentColor; display: block; }

#akbot-panel .akb-note { flex: 0 0 auto; font-size: 10.5px; color: var(--akb-mut); text-align: center; padding: 0 12px 8px; background: #fff; }

/* ---------------------------------------------------------------- */
/*  3. Гар утас — бүтэн дэлгэц, наалдсан мөрний ДЭЭР                  */
/* ---------------------------------------------------------------- */

@media (max-width: 860px) {
  :root { --akb-gap: 18px; }

  /* .mobile-cta (76px өндөр) байгаа хуудсанд товчийг дээш өргөнө */
  body:has(.mobile-cta) { --akb-gap: calc(88px + env(safe-area-inset-bottom, 0px)); }
  /* :has() дэмжихгүй хөтчид зориулсан нөөц анги (JS тавина) */
  body.akb-has-cta { --akb-gap: calc(88px + env(safe-area-inset-bottom, 0px)); }

  #akbot-fab { width: 54px; height: 54px; right: 14px; }
  #akbot-fab svg { width: 25px; height: 25px; }
  #akbot-tip { display: none; }

  #akbot-panel {
    right: 0; left: 0; top: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 100%; max-height: 100%;
    border-radius: 0; border: 0;
  }
  #akbot-panel.open ~ #akbot-fab,
  body.akb-open #akbot-fab { display: none; }
  #akbot-panel .akb-head { padding-top: calc(13px + env(safe-area-inset-top, 0px)); }
  #akbot-log { padding: 12px; }
  .akb-msg { max-width: 90%; font-size: 15px; }
  #akbot-in { font-size: 16px; }   /* iOS дээр автомат томсголтоос сэргийлнэ */

  /* Чат нээлттэй үед ард нь гүйлгэхгүй */
  body.akb-open { overflow: hidden; }
  body.akb-open .mobile-cta,
  body.akb-open .cmpbar { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  #akbot-panel.open { animation: none; }
  .akb-typing i { animation: none; }
  #akbot-fab, .akb-car { transition: none; }
}

@media print {
  #akbot-fab, #akbot-panel, #akbot-tip { display: none !important; }
}
