/* KAYSON STEEL — Chat Support Widget.
   Industrial-blue + gold + red language, shared public tokens.
   Craft: crisp surfaces, calm motion (transform/opacity only, <300ms),
   reduced-motion safe. No infinite loops, no heavy bounce. */
.ks-chat { position: fixed; inset: auto 0 0 auto; z-index: 900; pointer-events: none; }
.ks-chat * { box-sizing: border-box; }

/* Floating button */
.ks-chat__fab {
  position: fixed; bottom: 22px; right: 22px;
  width: 58px; height: 58px; border-radius: var(--r-pill);
  background: linear-gradient(135deg, var(--primary), var(--primary-light, #1c3a57));
  color: #fff; display: grid; place-items: center;
  box-shadow: var(--sh-3), 0 0 0 0 var(--ring, rgba(212,175,55,.5));
  cursor: pointer; pointer-events: auto;
  border: 1px solid rgba(255,255,255,.16);
  transition: transform var(--dur-2, 200ms) var(--ease-out, ease-out), box-shadow var(--dur-2, 200ms) var(--ease-out, ease-out);
  animation: ksChatIn var(--dur-3, 320ms) var(--ease-out, ease-out) both;
}
.ks-chat__fab svg { width: 26px; height: 26px; position: absolute; transition: opacity var(--dur-2, 200ms) var(--ease-out, ease-out), transform var(--dur-2, 200ms) var(--ease-out, ease-out); }
.ks-chat__fab .ks-chat__fab-close { opacity: 0; transform: rotate(-90deg) scale(.5); }
.ks-chat__fab.is-open { background: linear-gradient(135deg, var(--accent-dark, #b8941f), var(--accent, #d4af37)); }
.ks-chat__fab.is-open .ks-chat__fab-open { opacity: 0; transform: rotate(90deg) scale(.5); }
.ks-chat__fab.is-open .ks-chat__fab-close { opacity: 1; transform: rotate(0) scale(1); }
@media (hover: hover) and (pointer: fine) {
  .ks-chat__fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: var(--sh-3), 0 0 0 5px var(--ring, rgba(212,175,55,.35)); }
}
.ks-chat__fab:active { transform: scale(.94); }
.ks-chat__fab:focus-visible { outline: 3px solid var(--brand-300, #d4af37); outline-offset: 3px; }
@keyframes ksChatIn { from { opacity: 0; transform: translateY(16px) scale(.8); } to { opacity: 1; transform: translateY(0) scale(1); } }
.ks-chat__fab-badge {
  position: absolute; top: -4px; left: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  background: var(--red, #c8102e); color: #fff; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--surface, #fff); box-shadow: var(--sh-1);
}

/* ---------- Panel ---------- */
.ks-chat__panel {
  position: fixed; bottom: 94px; right: 22px;
  width: 384px; max-width: calc(100vw - 28px);
  height: min(640px, calc(100vh - 120px));
  background: var(--surface, #fff); color: var(--ink, #0b1422);
  border: 1px solid var(--border, #dce4ec); border-radius: var(--r-lg, 18px);
  box-shadow: var(--sh-3); overflow: hidden;
  display: flex; flex-direction: column;
  /* Closed panel is visually hidden (opacity:0) but still fills the viewport
     area — without disabling pointer-events it becomes an invisible overlay
     that swallows taps on everything beneath it (nav toggle, hero CTAs, etc.).
     Keep it non-interactive until opened. */
  pointer-events: none;
  transform-origin: bottom right;
  opacity: 0; transform: translateY(12px) scale(.96);
  transition: opacity var(--dur-2, 200ms) var(--ease-out, ease-out), transform var(--dur-2, 200ms) var(--ease-out, ease-out);
}
.ks-chat__panel.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* Header */
.ks-chat__head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border, #dce4ec);
  background: linear-gradient(135deg, var(--primary, #0a1e3f), var(--primary-light, #1c3a57));
  color: #fff;
}
.ks-chat__brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ks-chat__logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  background: var(--accent, #d4af37); color: var(--primary, #0a1e3f);
  display: grid; place-items: center; font-weight: 800; font-size: 19px;
  font-family: var(--font-fa, "Vazirmatn", sans-serif);
}
.ks-chat__brand-txt { display: flex; flex-direction: column; min-width: 0; }
.ks-chat__brand-txt b { font-size: 14.5px; line-height: 1.2; }
.ks-chat__brand-txt small { font-size: 11.5px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ks-chat__icon-btn {
  width: 34px; height: 34px; border-radius: 9px; flex: none; color: #fff;
  display: grid; place-items: center; background: rgba(255,255,255,.12);
  transition: background var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__icon-btn:hover { background: rgba(255,255,255,.24); }
.ks-chat__icon-btn svg { width: 18px; height: 18px; }

/* Mode switcher */
.ks-chat__modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.ks-chat__mode {
  display: flex; align-items: center; gap: 9px; text-align: right;
  padding: 10px 11px; border-radius: var(--r-md, 14px);
  border: 1px solid var(--border, #dce4ec); background: var(--surface-2, #f7fafc);
  cursor: pointer; transition: border-color var(--dur-1, 140ms) var(--ease-out, ease-out), background var(--dur-1, 140ms) var(--ease-out, ease-out), transform var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__mode:hover { transform: translateY(-1px); border-color: var(--border-strong, #c5d2de); }
.ks-chat__mode.is-active { border-color: var(--accent, #d4af37); background: color-mix(in srgb, var(--accent, #d4af37) 12%, var(--surface, #fff)); }
.ks-chat__mode-ic { font-size: 20px; line-height: 1; flex: none; }
.ks-chat__mode-txt { display: flex; flex-direction: column; min-width: 0; }
.ks-chat__mode-txt b { font-size: 13px; color: var(--ink, #0b1422); }
.ks-chat__mode-txt small { font-size: 10.5px; color: var(--ink-3, #6b7c8e); line-height: 1.3; }

/* Mode area (offline / online states) */
.ks-chat__modearea { padding: 0 12px; }
.ks-chat__offline {
  background: var(--down-bg, #fbeae8); border: 1px solid color-mix(in srgb, var(--red, #c8102e) 30%, transparent);
  border-radius: var(--r-md, 14px); padding: 12px; text-align: center; color: var(--ink, #0b1422);
}
.ks-chat__lock { font-size: 22px; }
.ks-chat__offline-title { font-weight: 700; font-size: 13.5px; margin-top: 4px; color: var(--down, #c5392b); }
.ks-chat__offline-sub { font-size: 12.5px; margin-top: 6px; color: var(--ink-2, #36475a); }
.ks-chat__offline-hint { font-size: 11.5px; margin-top: 8px; color: var(--ink-3, #6b7c8e); line-height: 1.7; }
.ks-chat__online {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: var(--up-bg, #e5f4ec); border-radius: var(--r-md, 14px); font-size: 12.5px; color: var(--ink-2, #36475a);
}
.ks-chat__on-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success, #1c8a57); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success, #1c8a57) 25%, transparent); flex: none; }

/* Conversation */
.ks-chat__conv { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.ks-chat__row { display: flex; flex-direction: column; max-width: 86%; }
.ks-chat__row--enter { opacity: 0; transform: translateY(8px); }
.ks-chat__row--bot { align-self: flex-start; align-items: flex-start; }
.ks-chat__row--user { align-self: flex-end; align-items: flex-end; }
.ks-chat__bubble {
  padding: 9px 13px; border-radius: var(--r-md, 14px); font-size: 13.5px; line-height: 1.7;
  word-break: break-word; white-space: pre-wrap;
}
.ks-chat__row--bot .ks-chat__bubble { background: var(--surface-2, #f7fafc); color: var(--ink, #0b1422); border: 1px solid var(--border, #dce4ec); border-bottom-right-radius: 4px; }
.ks-chat__row--user .ks-chat__bubble { background: linear-gradient(135deg, var(--primary, #0a1e3f), var(--primary-light, #1c3a57)); color: #fff; border-bottom-left-radius: 4px; }
.ks-chat__time { font-size: 10.5px; color: var(--ink-3, #6b7c8e); margin: 3px 4px 0; }

/* Typing indicator */
.ks-chat__typing { display: inline-flex; gap: 4px; align-items: center; }
.ks-chat__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3, #6b7c8e); animation: ksChatTyping 1.1s infinite ease-in-out; }
.ks-chat__typing span:nth-child(2) { animation-delay: .15s; }
.ks-chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes ksChatTyping { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* Related links / products */
.ks-chat__rel { display: flex; flex-direction: column; gap: 6px; align-self: flex-start; max-width: 90%; }
.ks-chat__rel-row { display: flex; flex-wrap: wrap; gap: 6px; }
.ks-chat__rel-link, .ks-chat__rel-prod {
  font-size: 12.5px; padding: 7px 11px; border-radius: var(--r-pill);
  border: 1px solid var(--accent, #d4af37); color: var(--accent-dark, #b8941f); background: color-mix(in srgb, var(--accent, #d4af37) 8%, var(--surface, #fff));
  text-decoration: none; transition: background var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__rel-link:hover, .ks-chat__rel-prod:hover { background: color-mix(in srgb, var(--accent, #d4af37) 18%, var(--surface, #fff)); }

/* Suggested chips */
.ks-chat__suggest { padding: 8px 12px 4px; border-top: 1px solid var(--border, #dce4ec); }
.ks-chat__suggest-lbl { font-size: 11.5px; color: var(--ink-3, #6b7c8e); display: block; margin-bottom: 7px; }
.ks-chat__chips { display: flex; flex-wrap: wrap; gap: 7px; }
.ks-chat__chip {
  font-size: 12.5px; padding: 7px 12px; border-radius: var(--r-pill);
  border: 1px solid var(--border, #dce4ec); background: var(--surface-2, #f7fafc); color: var(--ink-2, #36475a);
  cursor: pointer; transition: border-color var(--dur-1, 140ms) var(--ease-out, ease-out), color var(--dur-1, 140ms) var(--ease-out, ease-out), transform var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__chip:hover { border-color: var(--accent, #d4af37); color: var(--accent-dark, #b8941f); transform: translateY(-1px); }
.ks-chat__chip:active { transform: scale(.96); }

/* Composer */
.ks-chat__composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border, #dce4ec); background: var(--surface, #fff); }
.ks-chat__input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: var(--r-pill);
  border: 1px solid var(--border, #dce4ec); background: var(--surface-2, #f7fafc); color: var(--ink, #0b1422); font-size: 13.5px;
  transition: border-color var(--dur-1, 140ms) var(--ease-out, ease-out), box-shadow var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__input:focus { outline: none; border-color: var(--accent, #d4af37); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #d4af37) 22%, transparent); }
.ks-chat__send {
  width: 44px; height: 44px; flex: none; border-radius: var(--r-pill);
  background: linear-gradient(135deg, var(--primary, #0a1e3f), var(--primary-light, #1c3a57)); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: transform var(--dur-1, 140ms) var(--ease-out, ease-out), opacity var(--dur-1, 140ms) var(--ease-out, ease-out);
}
.ks-chat__send svg { width: 19px; height: 19px; transform: rotate(180deg); }
.ks-chat__send:hover { transform: scale(1.05); }
.ks-chat__send:active { transform: scale(.92); }
.ks-chat__send:focus-visible { outline: 3px solid var(--brand-300, #d4af37); outline-offset: 2px; }

/* ---------- Dark theme ---------- */
[data-theme="dark"] .ks-chat__panel,
body.dark-mode .ks-chat__panel { background: var(--surface, #13233a); color: var(--ink, #e7eef4); }
[data-theme="dark"] .ks-chat__mode,
body.dark-mode .ks-chat__mode { background: var(--surface-2, #0f1b2d); }
[data-theme="dark"] .ks-chat__row--bot .ks-chat__bubble,
body.dark-mode .ks-chat__row--bot .ks-chat__bubble { background: var(--surface-2, #0f1b2d); border-color: var(--border, #1c3a57); }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .ks-chat__fab { bottom: 16px; right: 16px; width: 54px; height: 54px; }
  .ks-chat__panel { bottom: 82px; right: 12px; left: 12px; width: auto; max-width: none; height: min(78vh, 640px); }
}
@media (max-width: 390px) {
  .ks-chat__panel { bottom: 78px; right: 8px; left: 8px; }
  .ks-chat__modes { grid-template-columns: 1fr; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .ks-chat__fab { animation: none; }
  .ks-chat__panel { transition: opacity var(--dur-1, 140ms) linear; transform: none; }
  .ks-chat__panel.is-open { transform: none; }
  .ks-chat__typing span { animation: none; }
  .ks-chat__row--enter { opacity: 1; transform: none; }
}
