/* ==============================
   Mashahir AI Chat Widget
   ============================== */

:root {
  --mc-accent:      oklch(52% 0.18 250);
  --mc-accent-dark: oklch(42% 0.18 250);
  --mc-surface:     oklch(98% 0 0);
  --mc-raised:      oklch(100% 0 0);
  --mc-border:      oklch(88% 0 0);
  --mc-text:        oklch(18% 0 0);
  --mc-muted:       oklch(52% 0 0);
  --mc-user-bg:     oklch(52% 0.18 250);
  --mc-bot-bg:      oklch(94% 0.01 250);
  --mc-radius-sm:   6px;
  --mc-radius-md:   12px;
  --mc-radius-lg:   20px;
  --mc-shadow:      0 2px 12px oklch(18% 0 0 / 0.12);
}

/* Toggle button */
#mashahir-chat-toggle {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 52px;
  height: 52px;
  background: var(--mc-accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--mc-shadow);
  z-index: 9999;
  transition: background 160ms ease, transform 160ms ease;
  user-select: none;
}
#mashahir-chat-toggle:hover,
#mashahir-chat-toggle:focus-visible {
  background: var(--mc-accent-dark);
  transform: scale(1.06);
  outline: 2px solid var(--mc-accent);
  outline-offset: 3px;
}

/* Chat box */
#mashahir-chat-box {
  position: fixed;
  bottom: 88px;
  left: 24px;
  width: 340px;
  max-height: 520px;
  background: var(--mc-raised);
  border: 1px solid var(--mc-border);
  border-radius: var(--mc-radius-lg);
  box-shadow: var(--mc-shadow);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 14px;
  color: var(--mc-text);
  direction: rtl;

  /* Hidden by default */
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}
#mashahir-chat-box.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Header */
#mashahir-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--mc-accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
#mashahir-chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--mc-radius-sm);
  transition: background 120ms ease;
}
#mashahir-chat-close:hover,
#mashahir-chat-close:focus-visible {
  background: oklch(100% 0 0 / 0.15);
  outline: none;
}

/* Messages */
#mashahir-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--mc-surface);
}

.mc-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: var(--mc-radius-md);
  line-height: 1.6;
  word-break: break-word;
}
.mc-msg.mc-user {
  background: var(--mc-user-bg);
  color: #fff;
  align-self: flex-start;
  border-bottom-right-radius: var(--mc-radius-sm);
}
.mc-msg.mc-bot {
  background: var(--mc-bot-bg);
  color: var(--mc-text);
  align-self: flex-end;
  border-bottom-left-radius: var(--mc-radius-sm);
}
.mc-msg.mc-error {
  background: oklch(96% 0.04 25);
  color: oklch(40% 0.18 25);
  align-self: center;
  font-size: 13px;
  border: 1px solid oklch(88% 0.06 25);
}
.mc-typing {
  align-self: flex-end;
  color: var(--mc-muted);
  font-size: 13px;
  padding: 4px 0;
}

/* Input area */
#mashahir-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--mc-border);
  background: var(--mc-raised);
}
#mashahir-chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--mc-border);
  border-radius: var(--mc-radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--mc-text);
  background: var(--mc-surface);
  outline: none;
  transition: border-color 150ms ease;
}
#mashahir-chat-input:focus {
  border-color: var(--mc-accent);
}
#mashahir-chat-send {
  padding: 8px 14px;
  background: var(--mc-accent);
  color: #fff;
  border: none;
  border-radius: var(--mc-radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms ease;
  white-space: nowrap;
}
#mashahir-chat-send:hover,
#mashahir-chat-send:focus-visible {
  background: var(--mc-accent-dark);
  outline: 2px solid var(--mc-accent);
  outline-offset: 2px;
}
#mashahir-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Scrollbar */
#mashahir-chat-messages::-webkit-scrollbar { width: 4px; }
#mashahir-chat-messages::-webkit-scrollbar-track { background: transparent; }
#mashahir-chat-messages::-webkit-scrollbar-thumb { background: var(--mc-border); border-radius: 4px; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #mashahir-chat-box,
  #mashahir-chat-toggle { transition: none; }
}

/* Mobile */
@media (max-width: 400px) {
  #mashahir-chat-box {
    left: 8px;
    right: 8px;
    width: auto;
    bottom: 80px;
  }
}
