/* سعد – نظام الدعم الإلكتروني والدردشة الذكية */
.thahlan-saad-chat {
  --saad-bg: linear-gradient(145deg, #1a1612 0%, #2a2420 100%);
  --saad-surface: #2d2824;
  --saad-accent: #9a7b1a;
  --saad-accent-glow: rgba(154, 123, 26, 0.4);
  --saad-text: #f5f0e8;
  --saad-text-soft: rgba(245, 240, 232, 0.8);
  --saad-border: rgba(154, 123, 26, 0.25);
  --saad-shadow: 0 8px 32px rgba(0,0,0,0.5);
  font-family: 'Tajawal', 'Amiri', sans-serif;
  z-index: 9990;
}
.thahlan-saad-chat * { box-sizing: border-box; }

/* زر الفتح العائم – سادة في الصفحة، مع نص "للدعم الفني من سعد Ai" */
.thahlan-saad-toggle {
  position: fixed;
  bottom: 1.5rem;
  inset-inline-end: 1.5rem;
  min-width: 120px;
  height: 48px;
  padding: 0 1rem 0 0.75rem;
  border-radius: 8px;
  background: var(--saad-surface);
  color: var(--saad-text);
  border: 1px solid var(--saad-border);
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s, border-color 0.2s;
}
.thahlan-saad-toggle:hover {
  background: #35302b;
  border-color: rgba(154, 123, 26, 0.4);
}
.thahlan-saad-toggle[aria-expanded="true"] {
  background: #2a2520;
  border-color: var(--saad-border);
}
.saad-icon { font-size: 1.25rem; flex-shrink: 0; opacity: 0.9; }
.saad-toggle-label {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* النافذة */
.thahlan-saad-panel {
  position: fixed;
  bottom: 6rem;
  inset-inline-end: 1.5rem;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 520px;
  max-height: 75vh;
  background: var(--saad-bg);
  border: 1px solid var(--saad-border);
  border-radius: 20px;
  box-shadow: var(--saad-shadow);
  z-index: 9998;
  display: none;
  flex-direction: column;
  direction: rtl;
  overflow: hidden;
  animation: saadSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.thahlan-saad-panel.is-open { display: flex; }
@keyframes saadSlideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* الهيدر */
.thahlan-saad-panel-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #3d3530 0%, #2d2824 100%);
  border-bottom: 1px solid var(--saad-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.saad-header-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--saad-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.saad-header-title::before {
  content: '🏛️';
  font-size: 1.2rem;
}
.saad-close-btn {
  background: transparent;
  border: none;
  color: var(--saad-text-soft);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}
.saad-close-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--saad-text);
}

/* التبويبات */
.thahlan-saad-tabs {
  display: flex;
  border-bottom: 1px solid var(--saad-border);
}
.saad-tab {
  flex: 1;
  padding: 0.75rem;
  background: transparent;
  border: none;
  color: var(--saad-text-soft);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}
.saad-tab::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--saad-accent);
  transition: all 0.3s;
  transform: translateX(-50%);
}
.saad-tab:hover { color: var(--saad-text); background: rgba(255,255,255,0.05); }
.saad-tab.active { color: var(--saad-accent); font-weight: 600; }
.saad-tab.active::after { width: 60%; }

/* محتوى التبويب */
.thahlan-saad-tab-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.saad-tab-pane { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.saad-tab-pane.active { display: flex; }

/* حقل الاسم */
.saad-name-prompt {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  text-align: center;
}
.saad-name-prompt p {
  color: var(--saad-text);
  font-size: 1.1rem;
  margin-bottom: 1rem;
}
.saad-name-prompt input {
  width: 100%;
  max-width: 240px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--saad-border);
  border-radius: 12px;
  background: var(--saad-surface);
  color: var(--saad-text);
  font-family: inherit;
  font-size: 1rem;
  text-align: center;
  margin-bottom: 1rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.saad-name-prompt input:focus {
  outline: none;
  border-color: var(--saad-accent);
  box-shadow: 0 0 0 3px var(--saad-accent-glow);
}
.saad-name-prompt button {
  padding: 0.8rem 2rem;
  background: linear-gradient(135deg, #9a7b1a 0%, #6d5814 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.saad-name-prompt button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(154,123,26,0.4);
}

/* الرسائل */
.thahlan-saad-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.thahlan-saad-msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msgFadeIn 0.3s ease-out;
}
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.thahlan-saad-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #9a7b1a 0%, #7d6416 100%);
  color: #fff;
  border-bottom-left-radius: 4px;
}
.thahlan-saad-msg.saad {
  align-self: flex-start;
  background: var(--saad-surface);
  color: var(--saad-text);
  border: 1px solid var(--saad-border);
  border-bottom-right-radius: 4px;
}
.thahlan-saad-msg.intro-msg {
  background: linear-gradient(135deg, rgba(154,123,26,0.15) 0%, rgba(154,123,26,0.05) 100%);
  border: 1px solid var(--saad-accent);
}

/* مؤشر الكتابة */
.thahlan-saad-typing {
  align-self: flex-start;
  padding: 0.6rem 1rem;
  color: var(--saad-text-soft);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.typing-dots span {
  animation: typingDot 1.4s infinite;
  opacity: 0.4;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.4; }
  30% { opacity: 1; }
}

/* نموذج الإرسال */
.thahlan-saad-panel-form {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--saad-border);
  display: flex;
  gap: 0.5rem;
  background: rgba(0,0,0,0.2);
}
.thahlan-saad-panel-form input {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 1px solid var(--saad-border);
  border-radius: 12px;
  background: var(--saad-surface);
  color: var(--saad-text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.thahlan-saad-panel-form input::placeholder { color: rgba(255,255,255,0.4); }
.thahlan-saad-panel-form input:focus {
  outline: none;
  border-color: var(--saad-accent);
  box-shadow: 0 0 0 3px var(--saad-accent-glow);
}
.thahlan-saad-panel-form button {
  padding: 0.7rem 1.25rem;
  background: linear-gradient(135deg, #9a7b1a 0%, #6d5814 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
}
.thahlan-saad-panel-form button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(154,123,26,0.4);
}
.thahlan-saad-panel-form button:disabled { opacity: 0.6; cursor: not-allowed; }

/* نموذج الدعم */
.saad-support-form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
}
.saad-support-form input,
.saad-support-form select,
.saad-support-form textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--saad-border);
  border-radius: 12px;
  background: var(--saad-surface);
  color: var(--saad-text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.saad-support-form input::placeholder,
.saad-support-form textarea::placeholder { color: rgba(255,255,255,0.4); }
.saad-support-form input:focus,
.saad-support-form select:focus,
.saad-support-form textarea:focus {
  outline: none;
  border-color: var(--saad-accent);
  box-shadow: 0 0 0 3px var(--saad-accent-glow);
}
.saad-support-form select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23f5f0e8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 1rem center;
  padding-left: 2.5rem;
}
.saad-support-form textarea { resize: vertical; min-height: 100px; }
.saad-support-form button {
  padding: 0.9rem;
  background: linear-gradient(135deg, #9a7b1a 0%, #6d5814 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.saad-support-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(154,123,26,0.4);
}
.saad-support-result {
  padding: 0.75rem;
  border-radius: 10px;
  text-align: center;
  font-size: 0.9rem;
}
.saad-support-result.sending { color: var(--saad-text-soft); }
.saad-support-result.success { background: rgba(34,197,94,0.15); color: #22c55e; }
.saad-support-result.error { background: rgba(239,68,68,0.15); color: #ef4444; }

/* الفوتر */
.saad-footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--saad-border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--saad-text-soft);
  background: rgba(0,0,0,0.2);
}
.saad-footer a { color: var(--saad-accent); text-decoration: none; }
.saad-footer a:hover { text-decoration: underline; }

/* تجاوب الجوال */
@media (max-width: 480px) {
  .thahlan-saad-toggle { bottom: 1rem; inset-inline-end: 1rem; height: 50px; padding: 0 0.75rem 0 0.5rem; min-width: auto; }
  .saad-toggle-label { font-size: 0.85rem; }
  .thahlan-saad-panel {
    bottom: 4.5rem;
    inset-inline-end: 0.75rem;
    width: calc(100vw - 1.5rem);
    height: 70vh;
    border-radius: 16px;
  }
}

/* الوضع الفاتح */
[data-theme=""] .thahlan-saad-chat,
html:not([data-theme="dark"]) .thahlan-saad-chat {
  --saad-bg: linear-gradient(145deg, #faf8f5 0%, #f0ebe3 100%);
  --saad-surface: #fff;
  --saad-text: #2d2824;
  --saad-text-soft: rgba(45, 40, 36, 0.7);
  --saad-border: rgba(154, 123, 26, 0.2);
  --saad-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
html:not([data-theme="dark"]) .thahlan-saad-panel-header {
  background: linear-gradient(135deg, #f5f0e8 0%, #ebe5da 100%);
}
html:not([data-theme="dark"]) .thahlan-saad-msg.saad {
  background: #fff;
  border-color: var(--saad-border);
}
html:not([data-theme="dark"]) .thahlan-saad-panel-form,
html:not([data-theme="dark"]) .saad-footer {
  background: rgba(0,0,0,0.03);
}
html:not([data-theme="dark"]) .saad-support-form input,
html:not([data-theme="dark"]) .saad-support-form select,
html:not([data-theme="dark"]) .saad-support-form textarea,
html:not([data-theme="dark"]) .thahlan-saad-panel-form input,
html:not([data-theme="dark"]) .saad-name-prompt input {
  background: #fff;
  color: #2d2824;
}
html:not([data-theme="dark"]) .saad-support-form input::placeholder,
html:not([data-theme="dark"]) .saad-support-form textarea::placeholder,
html:not([data-theme="dark"]) .thahlan-saad-panel-form input::placeholder {
  color: rgba(45,40,36,0.4);
}
