/* ═══════════════════════════════════════════════════════════════════════════
   Aseer Municipality AI Chatbot — chatbot.css
   Primary: #381f14  |  Secondary: #c2ae99
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

:root {
  --primary:            #381f14;
  --primary-dark:       #251009;
  --primary-mid:        #4a2a1c;
  --primary-light:      #5c3524;

  --secondary:          #c2ae99;
  --secondary-light:    #d4c4b0;
  --secondary-muted:    rgba(194, 174, 153, 0.15);
  --secondary-border:   rgba(194, 174, 153, 0.25);
  --secondary-border-strong: rgba(194, 174, 153, 0.5);

  --surface:            #f7f4f1;
  --surface-raised:     #fff;
  --surface-input:      #faf8f6;

  --text-primary:       #1a0f09;
  --text-secondary:     #5a4035;
  --text-dim:           #9a8070;
  --text-on-primary:    #f5ede8;

  --chat-width:         385px;
  --chat-height:        570px;
  --chat-toggle-size:   58px;
  --chat-radius:        18px;
  --chat-radius-sm:     12px;

  --chat-shadow:        0 24px 64px rgba(56,31,20,0.28), 0 0 0 1px rgba(194,174,153,0.2);
  --ease-spring:        cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:           cubic-bezier(0.4, 0, 0.2, 1);
  --font-ar:            'Tajawal', 'Cairo', 'Segoe UI', sans-serif;
}

/* ─── Toggle Button ──────────────────────────────────────────────────────── */
#chatbot-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: var(--chat-toggle-size);
    height: var(--chat-toggle-size);
    border-radius: 50%;
    background: #1b8354;
    border: none;
    cursor: pointer;
    box-shadow: unset !important;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease;
    outline: none;
}

#chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(56,31,20,0.55), 0 2px 12px rgba(0,0,0,0.25);
}

#chatbot-toggle:active { transform: scale(0.95); }

#chatbot-toggle .toggle-icon {
  width: 27px;
  height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chatbot-toggle .toggle-icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#chatbot-toggle .icon-chat  { display: flex; }
#chatbot-toggle .icon-close { display: none; }
#chatbot-toggle.is-open .icon-chat  { display: none; }
#chatbot-toggle.is-open .icon-close { display: flex; }

    #chatbot-toggle::before {
        content: '';
        position: absolute;
        inset: -5px;
        border-radius: 50%;
        border: 2px solid #1b8354;
        animation: pulse-ring 2.8s ease-out infinite;
    }

@keyframes pulse-ring {
  0%   { transform: scale(1);   opacity: 0.7; }
  70%  { transform: scale(1.4); opacity: 0;   }
  100% { transform: scale(1.4); opacity: 0;   }
}

#chatbot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #c0392b;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  font-family: var(--font-ar);
}
#chatbot-badge.visible { display: flex; }

/* ─── Chat Window ────────────────────────────────────────────────────────── */
#chatbot-window {
  position: fixed;
  bottom: calc(var(--chat-toggle-size) + 44px);
  right: 28px;
  width: var(--chat-width);
  height: var(--chat-height);
  background: var(--surface);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  border: 1px solid var(--secondary-border);
  transform-origin: bottom right;

  opacity: 0;
  transform: scale(0.88) translateY(18px);
  pointer-events: none;
  transition:
    opacity 0.28s var(--ease-out),
    transform 0.32s var(--ease-spring);
}

#chatbot-window.is-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
#chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 64px;
    background: #1b8354;
    border-bottom: 1px solid rgba(194,174,153,0.2);
    flex-shrink: 0;
    direction: rtl;
    position: relative;
}

#chat-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(194,174,153,0.4), transparent);
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  border: 1px solid rgba(194,174,153,0.3);
}

.chat-header-avatar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--secondary-light);
  stroke-width: 1.8;
  stroke-linecap: round;
}

/*.chat-header-avatar::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 10px;
  height: 10px;
  background: #4caf50;
  border-radius: 50%;
  border: 2px solid var(--primary);
}*/

.chat-header-info { flex: 1; }

.chat-header-info .chat-name {
  font-family: var(--font-ar);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 2px;
  line-height: 1.2;
}

    .chat-header-info .chat-status {
        font-family: var(--font-ar);
        font-size: 11px;
        color: #4caf50;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 5px;
    }

.chat-header-info .chat-status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #4caf50;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.chat-header-actions { display: flex; gap: 6px; }

.chat-header-btn {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: transparent;
    border: 1px solid #ffffff52;
    color: rgba(194,174,153,0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-header-btn:hover {
  background: rgba(194,174,153,0.12);
  border-color: rgba(194,174,153,0.4);
  color: var(--secondary-light);
}

.chat-header-btn svg {
  width: 14px;
  height: 14px;
  stroke: #fff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ─── Messages Area ──────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  direction: rtl;
  background: var(--surface);

  scrollbar-width: thin;
  scrollbar-color: rgba(56,31,20,0.2) transparent;
}

#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(56,31,20,0.2);
  border-radius: 2px;
}

/* Welcome */
.chat-welcome {
  text-align: center;
  padding: 18px 14px 10px;
  color: var(--text-secondary);
  font-family: var(--font-ar);
}

    .chat-welcome .welcome-icon {
        width: 52px;
        height: 52px;
        margin: 0 auto 12px;
        background: linear-gradient(145deg, rgba(27, 131, 84, 0.07), rgba(27, 131, 84, 0.08));
        border-radius: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(56,31,20,0.15);
    }

    .chat-welcome .welcome-icon svg {
        width: 26px;
        height: 26px;
        stroke: #1b8354;
        fill: none;
        stroke-width: 1.6;
    }

.chat-welcome h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 5px;
}

.chat-welcome p {
  font-size: 12.5px;
  line-height: 1.65;
  margin: 0;
  color: var(--text-secondary);
}

/* Quick questions */
.chat-quick-questions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 2px 6px;
}

.quick-question-btn {
  background: var(--surface-raised);
  border: 1px solid var(--secondary-border);
  border-radius: 9px;
  padding: 9px 13px;
  color: var(--text-secondary);
  font-family: var(--font-ar);
  font-size: 13px;
  text-align: right;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.4;
}

.quick-question-btn:hover {
  background: var(--secondary-muted);
  border-color: var(--secondary);
  color: var(--primary);
}

/* ─── Message Bubbles ────────────────────────────────────────────────────── */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
  animation: msg-in 0.28s var(--ease-spring);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.message-row.user-row {
  flex-direction: row;
  justify-content: flex-start;
}

.message-row.bot-row {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.message-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-row .message-avatar {
    background: #1b8354;
}

.bot-row .message-avatar {
    background: #1b8354;
}

.message-avatar svg {
  width: 13px;
  height: 13px;
  stroke: #fff;
  fill: none;
  stroke-width: 2.5;
}

.user-row .message-avatar svg { stroke: #fff; }

.message-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: var(--chat-radius-sm);
  font-family: var(--font-ar);
  font-size: 13.5px;
  line-height: 1.7;
  word-break: break-word;
}

/* User bubble */
.user-row .message-bubble {
    background: #1b8354;
    color: #fff;
    border-radius: var(--chat-radius-sm) var(--chat-radius-sm) var(--chat-radius-sm) 3px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(194,174,153,0.3);
}

/* Bot bubble */
.bot-row .message-bubble {
  background: var(--surface-raised);
  color: var(--text-primary);
  border-radius: var(--chat-radius-sm) var(--chat-radius-sm) 3px var(--chat-radius-sm);
  border: 1px solid var(--secondary-border);
  box-shadow: 0 1px 4px rgba(56,31,20,0.08);
}

.message-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 3px;
  font-family: var(--font-ar);
  text-align: center;
}

/* Markdown in bot messages */
.bot-row .message-bubble p { margin: 0 0 7px; }
.bot-row .message-bubble p:last-child { margin-bottom: 0; }
.bot-row .message-bubble ul,
.bot-row .message-bubble ol { margin: 5px 0; padding-right: 18px; }
.bot-row .message-bubble li { margin-bottom: 3px; }
.bot-row .message-bubble strong { color: var(--primary); }
.bot-row .message-bubble code {
  background: rgba(56,31,20,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  direction: ltr;
  display: inline-block;
}

/* ─── Typing Indicator ───────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 13px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary-light);
  animation: typing-bounce 1.3s ease-in-out infinite;
  opacity: 0.5;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1;   }
}

.message-error {
  background: rgba(192,57,43,0.08) !important;
  border-color: rgba(192,57,43,0.2) !important;
  color: #c0392b !important;
}

/* ─── Input Area ─────────────────────────────────────────────────────────── */
#chat-input-area {
  padding: 11px 13px 13px;
  background: var(--surface-raised);
  border-top: 1px solid var(--secondary-border);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-input);
  border: 1px solid var(--secondary-border);
  border-radius: var(--chat-radius-sm);
  padding: 8px 8px 8px 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  direction: rtl;
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(56,31,20,0.08);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  max-height: 96px;
  min-height: 20px;
  padding: 0;
  direction: rtl;
  scrollbar-width: none;
}

#chat-input::placeholder { color: var(--text-dim); }
#chat-input::-webkit-scrollbar { display: none; }

#chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: #1b8354;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    transition: all 0.2s var(--ease-out);
}

#chat-send-btn:hover:not(:disabled) {
  transform: scale(1.07);
  box-shadow: 0 3px 14px rgba(56,31,20,0.35);
}

#chat-send-btn:active:not(:disabled) { transform: scale(0.95); }

#chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#chat-send-btn svg {
  width: 16px;
  height: 16px;
  stroke: #fff;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: scaleX(-1);
}

.chat-input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 7px;
  direction: rtl;
}

#chat-char-count {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-ar);
}
#chat-char-count.near-limit { color: #e67e22; }
#chat-char-count.at-limit   { color: #c0392b; }

.powered-by {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-ar);
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --chat-width:  calc(100vw - 20px);
    --chat-height: 72vh;
  }
  #chatbot-window {
    right: 10px;
    bottom: calc(var(--chat-toggle-size) + 32px);
  }
  #chatbot-toggle {
    right: 14px;
    bottom: 18px;
  }
}

/* ─── Accessibility ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #chatbot-toggle::before { animation: none; }
  .typing-dot  { animation: none; opacity: 0.6; }
  .message-row { animation: none; }
}

.chat-header-btn:focus-visible,
.quick-question-btn:focus-visible,
#chat-send-btn:focus-visible,
#chatbot-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
