/* Maktomine AI Agent — chat widget. All selectors are prefixed .mka- and colors use --mka-* variables. */
.mka-widget {
  --mka-primary: #1e3a8a;
  --mka-on-primary: #ffffff;
  --mka-launcher-bg: var(--mka-primary);
  --mka-launcher-fg: var(--mka-on-primary);
  --mka-user-bg: var(--mka-primary);
  --mka-user-fg: var(--mka-on-primary);
  --mka-width: 380px;
  --mka-inline-height: 560px;
  --mka-bg: #ffffff;
  --mka-surface: #f3f4f6;
  --mka-text: #111827;
  --mka-muted: #6b7280;
  --mka-border: #e5e7eb;
  --mka-radius: 16px;
  --mka-shadow: 0 12px 40px rgba(17, 24, 39, .18);
  --mka-font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Bengali", sans-serif;
  font-family: var(--mka-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--mka-text);
  box-sizing: border-box;
}
.mka-widget *, .mka-widget *::before, .mka-widget *::after { box-sizing: inherit; }
.mka-widget [hidden] { display: none !important; }
/* Zero-specificity reset so component colours (button, send, chips) always win. */
:where(.mka-widget) :where(button, input, textarea) { font: inherit; color: inherit; margin: 0; }
.mka-icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.mka-icon svg { width: 100%; height: 100%; }

/* ── Floating mode ─────────────────────────────────────────────── */
/* Corner placement: bottom-right (default), bottom-left, top-right, top-left. Override the gap with --mka-offset. */
.mka-mode-floating { position: fixed; z-index: 999999; --mka-offset: 20px; }
.mka-mode-floating.mka-pos-bottom-right { bottom: var(--mka-offset); right: var(--mka-offset); }
.mka-mode-floating.mka-pos-bottom-left { bottom: var(--mka-offset); left: var(--mka-offset); }
.mka-mode-floating.mka-pos-top-right { top: var(--mka-offset); right: var(--mka-offset); }
.mka-mode-floating.mka-pos-top-left { top: var(--mka-offset); left: var(--mka-offset); }
/* Keep clear of the WordPress admin bar for logged-in users. */
body.admin-bar .mka-mode-floating.mka-pos-top-right, body.admin-bar .mka-mode-floating.mka-pos-top-left { top: calc(var(--mka-offset) + 32px); }
.mka-launcher {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 60px; height: 60px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--mka-launcher-bg); color: var(--mka-launcher-fg);
  border: 1px solid color-mix(in srgb, var(--mka-launcher-fg) 18%, transparent);
  box-shadow: var(--mka-shadow); cursor: pointer; transition: transform .15s ease;
  justify-content: center;
}
.mka-launcher .mka-icon { width: 26px; height: 26px; }
.mka-launcher:hover { transform: translateY(-2px); }
.mka-launcher:focus-visible, .mka-widget button:focus-visible, .mka-widget a:focus-visible { outline: 3px solid color-mix(in srgb, var(--mka-primary) 45%, transparent); outline-offset: 2px; }
.mka-launcher-label { font-weight: 600; white-space: nowrap; }
.mka-mode-floating.mka-open .mka-launcher { display: none; }
.mka-mode-floating .mka-panel {
  position: absolute; bottom: 0; width: var(--mka-width); max-width: calc(100vw - 40px);
  height: min(640px, calc(100vh - 40px));
  box-shadow: var(--mka-shadow);
  animation: mka-pop .18s ease-out;
}
.mka-mode-floating[class*="mka-pos-bottom"] .mka-panel { bottom: 0; }
.mka-mode-floating[class*="mka-pos-top"] .mka-panel { top: 0; bottom: auto; }
.mka-mode-floating[class*="-right"] .mka-panel { right: 0; }
.mka-mode-floating[class*="-left"] .mka-panel { left: 0; }
.mka-mode-floating[class*="mka-pos-top"] .mka-panel { animation-name: mka-pop-down; }
@keyframes mka-pop-down { from { opacity: 0; transform: translateY(-12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes mka-pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── Inline mode ───────────────────────────────────────────────── */
.mka-mode-inline { width: 100%; max-width: 760px; margin: 1.5em auto; }
.mka-mode-inline .mka-panel { height: var(--mka-inline-height); border: 1px solid var(--mka-border); }

/* ── Panel ─────────────────────────────────────────────────────── */
.mka-panel {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--mka-bg); border-radius: var(--mka-radius);
}
.mka-chat-view, .mka-lead-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.mka-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px;
  background: var(--mka-primary); color: var(--mka-on-primary);
}
.mka-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: none; }
.mka-avatar-default {
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
  background: color-mix(in srgb, var(--mka-on-primary) 22%, transparent);
}
.mka-header-text { flex: 1; min-width: 0; }
.mka-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mka-subtitle { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mka-header-actions { display: flex; gap: 4px; }
.mka-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer;
}
.mka-icon-btn:hover { background: color-mix(in srgb, var(--mka-on-primary) 18%, transparent); }

/* ── Messages ──────────────────────────────────────────────────── */
.mka-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.mka-msg { display: flex; }
.mka-msg-user { justify-content: flex-end; }
.mka-bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere;
  background: var(--mka-surface); color: var(--mka-text);
}
.mka-msg-assistant .mka-bubble { border-bottom-left-radius: 4px; }
.mka-msg-user .mka-bubble { background: var(--mka-user-bg); color: var(--mka-user-fg); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.mka-msg-error .mka-bubble { background: #fef2f2; color: #991b1b; }
.mka-msg-success .mka-bubble { background: #ecfdf5; color: #065f46; }
.mka-bubble p { margin: 0 0 .5em; }
.mka-bubble p:last-child { margin-bottom: 0; }
.mka-bubble ul { margin: .25em 0 .5em; padding-left: 1.2em; }
.mka-bubble li { margin: .15em 0; }
.mka-bubble a { color: inherit; text-decoration: underline; }
.mka-typing .mka-bubble { display: inline-flex; gap: 4px; padding: 14px; }
.mka-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--mka-muted); animation: mka-blink 1.2s infinite ease-in-out; }
.mka-typing span:nth-child(2) { animation-delay: .15s; }
.mka-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes mka-blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ── Chips / actions ───────────────────────────────────────────── */
.mka-suggestions, .mka-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.mka-suggestions:empty { display: none; }
.mka-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border: 1px solid color-mix(in srgb, var(--mka-primary) 35%, var(--mka-border)); border-radius: 999px;
  background: var(--mka-bg); color: var(--mka-primary); font-size: 13px; line-height: 1.3;
  cursor: pointer; text-decoration: none; text-align: left;
}
.mka-chip:hover { background: color-mix(in srgb, var(--mka-primary) 8%, var(--mka-bg)); }
.mka-chip .mka-icon { width: 16px; height: 16px; }
.mka-chip-whatsapp { color: #128c4b; border-color: #a7e3c0; }
.mka-chip-whatsapp:hover { background: #effaf3; }

/* ── Composer ──────────────────────────────────────────────────── */
.mka-composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--mka-border); }
.mka-input {
  flex: 1; resize: none; min-height: 42px; max-height: 120px; padding: 10px 12px;
  border: 1px solid var(--mka-border); border-radius: 12px; background: var(--mka-bg); line-height: 1.4;
}
.mka-input:focus { outline: none; border-color: var(--mka-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mka-primary) 18%, transparent); }
.mka-send {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; flex: none;
  border: 0; border-radius: 12px; background: var(--mka-primary); color: var(--mka-on-primary); cursor: pointer;
}
.mka-send:disabled { opacity: .5; cursor: progress; }
.mka-footer { padding: 0 14px 10px; }
.mka-privacy { margin: 0; font-size: 11.5px; color: var(--mka-muted); text-align: center; }

/* ── Lead form ─────────────────────────────────────────────────── */
.mka-lead-view { overflow-y: auto; }
.mka-lead-form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.mka-lead-title { margin: 0; font-size: 17px; }
.mka-lead-intro { margin: 0; color: var(--mka-muted); font-size: 14px; }
.mka-field { display: flex; flex-direction: column; gap: 4px; }
.mka-field label { font-size: 13px; font-weight: 600; }
.mka-field input, .mka-field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--mka-border); border-radius: 10px; background: var(--mka-bg);
}
.mka-field input:focus, .mka-field textarea:focus { outline: none; border-color: var(--mka-primary); }
.mka-consent { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.mka-consent input { margin-top: 3px; }
.mka-hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.mka-form-status { color: #b91c1c; font-size: 13px; min-height: 1em; }
.mka-form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.mka-btn { padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; }
.mka-btn-primary { background: var(--mka-primary); color: var(--mka-on-primary); }
.mka-btn-primary:disabled { opacity: .6; cursor: progress; }
.mka-btn-secondary { background: var(--mka-bg); border-color: var(--mka-border); }

.mka-admin-hint { padding: 8px 12px; border-left: 4px solid #d63638; background: #fcf0f1; font-size: 14px; }

/* ── Responsive / visibility ───────────────────────────────────── */
@media (max-width: 600px) {
  .mka-mode-floating { --mka-offset: 14px; }
  body.admin-bar .mka-mode-floating.mka-pos-top-right, body.admin-bar .mka-mode-floating.mka-pos-top-left { top: calc(var(--mka-offset) + 46px); }
  .mka-mode-floating.mka-open { inset: 0; }
  .mka-mode-floating.mka-open .mka-panel { position: fixed; inset: 0; width: auto; max-width: none; height: auto; border-radius: 0; animation: none; }
  @supports (height: 100dvh) { .mka-mode-floating.mka-open .mka-panel { height: 100dvh; bottom: auto; } }
  .mka-hide-mobile { display: none !important; }
  .mka-input { font-size: 16px; } /* prevents iOS zoom */
}
@media (min-width: 601px) { .mka-hide-desktop { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .mka-widget * { animation: none !important; transition: none !important; } }
