:root {
  color-scheme: light;
}

/* Theme toggle (fancy sun/moon) */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(180, 140, 60, 0.18);
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(18px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 8px 20px rgba(44, 36, 22, 0.06);
}

.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(201, 168, 76, 0.28) 0%, transparent 52%);
  opacity: 0.9;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(44, 36, 22, 0.08);
  border-color: rgba(201, 168, 76, 0.45);
}

.theme-toggle:active {
  transform: translateY(0);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  position: absolute;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease;
  z-index: 1;
}

.theme-toggle .sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  color: #8a6520;
}

.theme-toggle .moon {
  opacity: 0;
  transform: rotate(-25deg) scale(0.8);
  color: #2a2f3a;
}

/* Shared site header (injected by site-header.js) */
.header {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(30px);
  border-bottom: 1px solid rgba(180, 140, 60, 0.08);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 30px rgba(138, 101, 32, 0.04);
  position: relative;
  z-index: 100;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 140, 60, 0.15), transparent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.menu-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.08), rgba(160, 120, 48, 0.08));
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 8px;
}

.menu-btn:hover::before {
  opacity: 1;
}

.menu-icon {
  width: 18px;
  height: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.menu-icon span {
  width: 100%;
  height: 1.5px;
  background: linear-gradient(90deg, #a07830, #c9a84c);
  border-radius: 2px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-btn:hover .menu-icon span:nth-child(1) {
  width: 70%;
}

.menu-btn:hover .menu-icon span:nth-child(3) {
  width: 85%;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  background: linear-gradient(135deg, #8a6520, #c9a84c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

.header-btn {
  padding: 8px 18px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: #8a6520;
  font-size: 13px;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  letter-spacing: -0.2px;
}

.header-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.06), rgba(160, 120, 48, 0.06));
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 8px;
}

.header-btn:hover::before {
  opacity: 1;
}

.header-btn:hover {
  color: #a07830;
  transform: translateY(-1px);
}

.header-btn.primary {
  background: linear-gradient(135deg, #c9a84c 0%, #a07830 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(180, 140, 60, 0.15);
}

.header-btn.primary::before {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
}

.header-btn.primary:hover {
  box-shadow: 0 4px 20px rgba(180, 140, 60, 0.25);
  transform: translateY(-2px);
  color: #fff;
}

/* User Dropdown Menu (from auth-modal.js) */
.user-dropdown {
  position: relative;
  display: inline-block;
}

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  min-width: 220px;
  background: linear-gradient(135deg, #ffffff 0%, #fdfbf7 100%);
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(201, 168, 76, 0.1);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.96);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000;
}

.user-dropdown-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.user-dropdown-menu::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 20px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-left: 1px solid rgba(201, 168, 76, 0.25);
  border-top: 1px solid rgba(201, 168, 76, 0.25);
  transform: rotate(45deg);
}

.user-dropdown-header {
  padding: 16px;
  border-bottom: 1px solid rgba(201, 168, 76, 0.15);
  margin-bottom: 8px;
}

.user-dropdown-name {
  font-size: 15px;
  font-weight: 700;
  color: #5a4a3a;
  margin-bottom: 4px;
}

.user-dropdown-contact {
  font-size: 12px;
  color: #8b7355;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #5a4a3a;
  font-size: 14px;
  font-weight: 500;
}

.user-dropdown-item:hover {
  background: rgba(201, 168, 76, 0.1);
  color: #8a6520;
}

.user-dropdown-item svg {
  width: 18px;
  height: 18px;
  color: #c9a84c;
}

.user-dropdown-item.logout {
  color: #c44;
  border-top: 1px solid rgba(201, 168, 76, 0.15);
  margin-top: 8px;
  padding-top: 14px;
}

.user-dropdown-item.logout:hover {
  background: rgba(204, 68, 68, 0.08);
  color: #a33;
}

.user-dropdown-item.logout svg {
  color: #c44;
}

/* Divider in header */
.divider {
  width: 1px;
  height: 20px;
  background: linear-gradient(180deg, transparent, rgba(180, 140, 60, 0.15), transparent);
  margin: 0 4px;
}

/* Shared site footer */
body.has-site-footer .main-content {
  padding-bottom: 10px !important;
}

body.has-site-footer .container {
  gap: 10px !important;
}

body.has-site-footer .input-area-fixed {
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}

body.has-site-footer .admin-content {
  padding-bottom: 16px !important;
}

body.has-site-footer .chat-history-page {
  min-height: 0 !important;
}

.site-footer {
  width: 100%;
  flex: 0 0 auto;
  flex-shrink: 0 !important;
  position: relative;
  z-index: 50;
  border-top: 1px solid rgba(180, 140, 60, 0.1);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(22px);
  box-shadow: 0 -8px 24px rgba(44, 36, 22, 0.04);
}

.site-footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 4px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
}

.site-footer-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.site-footer-label {
  color: #8a6520;
  font-size: 12px;
  font-weight: 700;
  margin-left: 2px;
}

.site-footer-link {
  border: none;
  background: transparent;
  color: #6a5a40;
  font-family: "Vazirmatn", sans-serif;
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.site-footer-link:hover {
  background: rgba(201, 168, 76, 0.1);
  color: #8a6520;
  transform: translateY(-1px);
}

.site-footer-link-share {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.2), rgba(160, 120, 48, 0.12));
  color: #8a6520;
  font-weight: 600;
}

.site-footer-link-donate {
  background: linear-gradient(135deg, rgba(220, 100, 100, 0.15), rgba(200, 80, 80, 0.1));
  color: #c44;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.site-footer-link-donate:hover {
  background: linear-gradient(135deg, rgba(220, 100, 100, 0.25), rgba(200, 80, 80, 0.15));
  color: #a33;
}

.site-footer-link-donate svg {
  flex-shrink: 0;
}

.site-footer-admin {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.site-footer-link-admin {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.2), rgba(160, 120, 48, 0.12));
  color: #8a6520;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.site-footer-link-admin:hover {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.3), rgba(160, 120, 48, 0.2));
  color: #6d4e10;
}

.site-footer-link-admin svg {
  flex-shrink: 0;
}

.site-footer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.site-footer-status {
  font-size: 11px;
  color: #8a7560;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(180, 140, 60, 0.08);
  border: 1px solid rgba(180, 140, 60, 0.12);
  white-space: nowrap;
}

.site-footer-status[data-tone="success"] {
  color: #6f5a1f;
  background: rgba(201, 168, 76, 0.16);
  border-color: rgba(201, 168, 76, 0.2);
}

.site-footer-status[data-tone="error"] {
  color: #b24b4b;
  background: rgba(220, 60, 60, 0.08);
  border-color: rgba(220, 60, 60, 0.16);
}


html[data-theme="dark"] .theme-toggle .sun {
  opacity: 0;
  transform: rotate(35deg) scale(0.75);
}

html[data-theme="dark"] .theme-toggle .moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Generic dark mode overrides for all pages */
html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(ellipse 120% 80% at 100% 0%, rgba(201, 168, 76, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse 90% 70% at 0% 100%, rgba(160, 120, 48, 0.08) 0%, transparent 55%),
    linear-gradient(165deg, #0f1115 0%, #101318 40%, #0d0f13 100%) !important;
  color: #ece7dc !important;
}

/* Header — answer language (site-header.js) */
.header-lang-wrap {
  display: flex;
  align-items: center;
  margin: 0 2px;
  position: relative;
}

.header-lang-icon {
  width: 16px;
  height: 16px;
  color: #8a6520;
  flex-shrink: 0;
  position: absolute;
  right: 8px;
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
}

/* RTL: icon on the left */
[dir="rtl"] .header-lang-icon {
  right: auto;
  left: 8px;
}

.header-lang-select {
  padding: 7px 30px 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(180, 140, 60, 0.25);
  background: rgba(255, 255, 255, 0.85);
  color: #8a6520;
  font-size: 12px;
  font-family: "Vazirmatn", "Segoe UI", system-ui, sans-serif;
  font-weight: 500;
  cursor: pointer;
  max-width: 118px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%238a6520' d='M3 4.5L6 8l3-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

/* RTL: icon on left, dropdown arrow also on left */
[dir="rtl"] .header-lang-select {
  padding: 7px 10px 7px 30px;
  background-position: left 8px center;
}

.header-lang-select:hover,
.header-lang-select:focus {
  border-color: rgba(201, 168, 76, 0.55);
  outline: none;
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.12);
}

/* Input sources dropdown */
.input-box.has-sources {
  position: relative;
  padding-right: 112px !important;
}

.sources-dropdown {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
}

.sources-btn {
  border: 1px solid rgba(180, 140, 60, 0.26);
  background: rgba(255, 255, 255, 0.92);
  color: #8a6520;
  border-radius: 999px;
  height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Vazirmatn", sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sources-btn:hover {
  border-color: rgba(201, 168, 76, 0.48);
  background: #fff;
}

.sources-btn-chevron {
  font-size: 10px;
  opacity: 0.75;
}

.sources-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 250px;
  max-height: 260px;
  overflow: auto;
  background: #fff;
  border: 1px solid rgba(180, 140, 60, 0.18);
  border-radius: 14px;
  box-shadow: 0 16px 34px rgba(44, 36, 22, 0.16);
  padding: 7px;
  display: none;
}

.sources-menu.open {
  display: block;
}

.sources-item {
  width: 100%;
  border: none;
  background: transparent;
  text-align: right;
  border-radius: 10px;
  padding: 9px 10px;
  color: #5c4f3d;
  font-family: "Vazirmatn", sans-serif;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
}

.sources-item-name {
  flex: 1;
  text-align: right;
}

.sources-modal-chunks {
  font-size: 11px;
  color: rgba(138, 101, 32, 0.6);
  margin-right: 8px;
}

html[data-theme="dark"] .sources-modal-chunks {
  color: rgba(236, 231, 220, 0.5);
}

.sources-item-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: transparent;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.sources-item:hover {
  background: rgba(201, 168, 76, 0.08);
  color: #8a6520;
  border-color: rgba(201, 168, 76, 0.2);
}

.sources-item.selected {
  background: rgba(56, 175, 121, 0.12);
  color: #256f4d;
  border-color: rgba(56, 175, 121, 0.28);
}

.sources-item.selected .sources-item-check {
  background: #38af79;
  color: #fff;
  opacity: 1;
  transform: scale(1);
}

.sources-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: #9b8a74;
}

/* Auth states (header + account card) */
.header-btn.primary.logged-in {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 210px;
  padding: 7px 10px 7px 12px;
  background: linear-gradient(135deg, #2e9c66 0%, #41b07a 56%, #68c58d 100%);
  border: 1px solid rgba(46, 156, 102, 0.42);
  color: #fff;
  box-shadow: 0 6px 18px rgba(46, 156, 102, 0.28), 0 0 0 0 rgba(104, 197, 141, 0.36);
  animation: authHeaderGlow 2.4s ease-in-out infinite;
}

.header-btn.primary.logged-in:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(46, 156, 102, 0.3), 0 0 0 8px rgba(104, 197, 141, 0.12);
}

.header-btn.primary.logged-in .auth-profile-avatar {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #f5fff8;
  flex-shrink: 0;
}

.header-btn.primary.logged-in .auth-profile-avatar svg {
  width: 16px;
  height: 16px;
}

.header-btn.primary.logged-in .auth-profile-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.15;
}

.header-btn.primary.logged-in .auth-profile-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.header-btn.primary.logged-in .auth-profile-contact {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 500;
  opacity: 0.92;
}

@keyframes authHeaderGlow {
  0%, 100% {
    box-shadow: 0 6px 18px rgba(46, 156, 102, 0.26), 0 0 0 0 rgba(104, 197, 141, 0.3);
  }
  50% {
    box-shadow: 0 9px 22px rgba(46, 156, 102, 0.32), 0 0 0 8px rgba(104, 197, 141, 0.14);
  }
}

#accountCard.logged-in {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(56, 175, 121, 0.16), rgba(27, 106, 70, 0.08));
  border-color: rgba(56, 175, 121, 0.3);
  box-shadow: 0 12px 26px rgba(30, 120, 82, 0.14);
}

#accountCard.logged-in::after {
  content: "";
  position: absolute;
  inset: -30% auto -30% -70%;
  width: 55%;
  transform: rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.23), transparent);
  animation: authCardShine 3.2s linear infinite;
  pointer-events: none;
}

.account-avatar.logged-in {
  background: linear-gradient(135deg, #2d9764, #46b47e);
  box-shadow: 0 0 0 3px rgba(56, 175, 121, 0.16);
}

.account-avatar.logged-in.has-profile-icon svg {
  width: 18px;
  height: 18px;
}

.account-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #1e8458;
  background: rgba(56, 175, 121, 0.14);
  border: 1px solid rgba(56, 175, 121, 0.24);
  border-radius: 999px;
  padding: 3px 10px;
}

.account-status-badge svg {
  width: 12px;
  height: 12px;
}

.account-status-badge .account-contact-text {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-login-btn.logged-in {
  display: none !important;
}

@keyframes authCardShine {
  from {
    transform: translateX(0) rotate(18deg);
  }
  to {
    transform: translateX(290%) rotate(18deg);
  }
}

html[data-theme="dark"] .header-lang-select {
  background: rgba(18, 20, 26, 0.85) !important;
  border-color: rgba(201, 168, 76, 0.28) !important;
  color: #e9d18a !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%23e9d18a' d='M3 4.5L6 8l3-3.5'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
}

html[data-theme="dark"] [dir="rtl"] .header-lang-select {
  background-position: left 8px center !important;
}

html[data-theme="dark"] .header-lang-select:hover,
html[data-theme="dark"] .header-lang-select:focus {
  border-color: rgba(201, 168, 76, 0.45) !important;
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.15) !important;
}

html[data-theme="dark"] .header-lang-icon,
html[data-theme="dark"] [dir="rtl"] .header-lang-icon,
html[data-theme="dark"] [dir="ltr"] .header-lang-icon {
  color: #e9d18a !important;
}

html[data-theme="dark"] .sources-btn {
  background: rgba(12, 13, 16, 0.72) !important;
  border-color: rgba(201, 168, 76, 0.3) !important;
  color: #e9d18a !important;
}

html[data-theme="dark"] .sources-menu {
  background: rgba(18, 20, 26, 0.96) !important;
  border-color: rgba(201, 168, 76, 0.16) !important;
}

html[data-theme="dark"] .sources-item {
  color: rgba(236, 231, 220, 0.86) !important;
}

html[data-theme="dark"] .sources-item:hover {
  background: rgba(201, 168, 76, 0.1) !important;
  color: #f5ecd4 !important;
  border-color: rgba(201, 168, 76, 0.2) !important;
}

html[data-theme="dark"] .sources-item.selected {
  background: rgba(64, 177, 126, 0.18) !important;
  color: #a8edc9 !important;
  border-color: rgba(103, 201, 146, 0.32) !important;
}

html[data-theme="dark"] .sources-item.selected .sources-item-check {
  background: #3aa973 !important;
  color: #fff !important;
}

html[data-theme="dark"] .sources-empty {
  color: rgba(236, 231, 220, 0.55) !important;
}

html[data-theme="dark"] .header-btn.primary.logged-in {
  background: linear-gradient(135deg, #2b8e5e 0%, #399b6a 55%, #55b67f 100%) !important;
  border-color: rgba(103, 201, 146, 0.45) !important;
  color: #f4fff8 !important;
}

html[data-theme="dark"] #accountCard.logged-in {
  background: linear-gradient(135deg, rgba(64, 177, 126, 0.18), rgba(21, 87, 58, 0.26)) !important;
  border-color: rgba(103, 201, 146, 0.34) !important;
}

html[data-theme="dark"] .account-avatar.logged-in {
  box-shadow: 0 0 0 3px rgba(103, 201, 146, 0.18) !important;
}

html[data-theme="dark"] .account-status-badge {
  color: #9fe5bf !important;
  background: rgba(64, 177, 126, 0.16) !important;
  border-color: rgba(103, 201, 146, 0.3) !important;
}

html[data-theme="dark"] .account-login-btn.logged-in {
  color: #9fe5bf !important;
  background: rgba(64, 177, 126, 0.14) !important;
  border-color: rgba(103, 201, 146, 0.36) !important;
}

/* Headers */
html[data-theme="dark"] .header {
  background: rgba(18, 20, 26, 0.72) !important;
  border-bottom-color: rgba(201, 168, 76, 0.12) !important;
  box-shadow: 0 1px 30px rgba(0, 0, 0, 0.35) !important;
}

html[data-theme="dark"] .header-title {
  -webkit-text-fill-color: transparent;
  background: linear-gradient(135deg, #e9d18a, #c9a84c) !important;
  background-clip: text !important;
}

/* Surfaces/cards/modals/drawers */
html[data-theme="dark"] .drawer,
html[data-theme="dark"] .login-modal,
html[data-theme="dark"] .section-card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .hadith-container,
html[data-theme="dark"] .input-box,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .message.bot {
  background: rgba(18, 20, 26, 0.85) !important;
  border-color: rgba(201, 168, 76, 0.16) !important;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35) !important;
}

html[data-theme="dark"] .message.user {
  background: rgba(201, 168, 76, 0.10) !important;
  border-color: rgba(201, 168, 76, 0.22) !important;
}

/* history.html — chat bubbles match index dark surfaces */
html[data-theme="dark"] .chat-bubble.bot {
  background: rgba(18, 20, 26, 0.85) !important;
  border-color: rgba(201, 168, 76, 0.16) !important;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35) !important;
}

html[data-theme="dark"] .chat-bubble.user {
  background: rgba(201, 168, 76, 0.10) !important;
  border-color: rgba(201, 168, 76, 0.22) !important;
}

html[data-theme="dark"] .bubble-text {
  color: #ece7dc !important;
}

html[data-theme="dark"] .chat-title-bar {
  background: rgba(18, 20, 26, 0.72) !important;
  border-bottom-color: rgba(201, 168, 76, 0.12) !important;
}

html[data-theme="dark"] .chat-title-text {
  color: #ece7dc !important;
}

html[data-theme="dark"] .chat-title-meta,
html[data-theme="dark"] .bubble-time {
  color: rgba(236, 231, 220, 0.55) !important;
}

html[data-theme="dark"] .scroll-bottom-btn {
  background: rgba(18, 20, 26, 0.9) !important;
  border-color: rgba(201, 168, 76, 0.18) !important;
  color: #e9d18a !important;
}

html[data-theme="dark"] .input-area-fixed {
  background: linear-gradient(180deg, transparent 0%, rgba(18, 20, 26, 0.94) 32%) !important;
  border-top-color: rgba(201, 168, 76, 0.14) !important;
}

html[data-theme="dark"] .date-separator span {
  color: rgba(236, 231, 220, 0.55) !important;
  background: rgba(201, 168, 76, 0.08) !important;
  border-color: rgba(201, 168, 76, 0.12) !important;
}

html[data-theme="dark"] .hadith-ref {
  background: rgba(201, 168, 76, 0.08) !important;
  color: rgba(236, 231, 220, 0.82) !important;
  border-right-color: #c9a84c !important;
}

html[data-theme="dark"] .hadith-ref .ref-source {
  color: rgba(236, 231, 220, 0.5) !important;
}

html[data-theme="dark"] .subtitle,
html[data-theme="dark"] .footer,
html[data-theme="dark"] .page-crumb,
html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .stat-hint,
html[data-theme="dark"] .history-item-date,
html[data-theme="dark"] table.data th {
  color: rgba(236, 231, 220, 0.72) !important;
}

html[data-theme="dark"] .history-item-title,
html[data-theme="dark"] table.data td,
html[data-theme="dark"] .drawer-title,
html[data-theme="dark"] .section-title {
  color: #ece7dc !important;
}

html[data-theme="dark"] table.data th {
  background: rgba(201, 168, 76, 0.08) !important;
}

html[data-theme="dark"] table.data td {
  border-bottom-color: rgba(201, 168, 76, 0.10) !important;
}

html[data-theme="dark"] .form-input,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-textarea,
html[data-theme="dark"] .input-box textarea {
  color: #ece7dc !important;
  background: rgba(12, 13, 16, 0.65) !important;
  border-color: rgba(201, 168, 76, 0.18) !important;
}

html[data-theme="dark"] .input-box textarea::placeholder,
html[data-theme="dark"] .form-input::placeholder {
  color: rgba(236, 231, 220, 0.45) !important;
}

html[data-theme="dark"] .menu-icon span {
  background: linear-gradient(90deg, #c9a84c, #e9d18a) !important;
}

html[data-theme="dark"] .theme-toggle {
  background: rgba(18, 20, 26, 0.7);
  border-color: rgba(201, 168, 76, 0.22);
}

html[data-theme="dark"] .theme-toggle::before {
  background: radial-gradient(circle at 30% 20%, rgba(201, 168, 76, 0.12) 0%, transparent 52%);
}

html[data-theme="dark"] .site-footer {
  background: rgba(18, 20, 26, 0.82) !important;
  border-top-color: rgba(201, 168, 76, 0.12) !important;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.22) !important;
}

html[data-theme="dark"] .site-footer-label {
  color: #e9d18a !important;
}

html[data-theme="dark"] .site-footer-link {
  color: rgba(236, 231, 220, 0.84) !important;
}

html[data-theme="dark"] .site-footer-link:hover {
  background: rgba(201, 168, 76, 0.12) !important;
  color: #f5ecd4 !important;
}

html[data-theme="dark"] .site-footer-link-share {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.2), rgba(160, 120, 48, 0.14)) !important;
  color: #f0dfaa !important;
}

html[data-theme="dark"] .site-footer-link-donate {
  background: linear-gradient(135deg, rgba(220, 120, 120, 0.2), rgba(200, 100, 100, 0.12)) !important;
  color: #ff9999 !important;
}

html[data-theme="dark"] .site-footer-link-donate:hover {
  background: linear-gradient(135deg, rgba(220, 120, 120, 0.3), rgba(200, 100, 100, 0.2)) !important;
  color: #ffaaaa !important;
}

html[data-theme="dark"] .site-footer-link-admin {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.25), rgba(160, 120, 48, 0.15)) !important;
  color: #f0dfaa !important;
}

html[data-theme="dark"] .site-footer-link-admin:hover {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.35), rgba(160, 120, 48, 0.25)) !important;
  color: #ffe0aa !important;
}

html[data-theme="dark"] .site-footer-status {
  color: rgba(236, 231, 220, 0.66) !important;
  background: rgba(201, 168, 76, 0.08) !important;
  border-color: rgba(201, 168, 76, 0.14) !important;
}

html[data-theme="dark"] .site-footer-status[data-tone="success"] {
  color: #f0dfaa !important;
  background: rgba(201, 168, 76, 0.14) !important;
  border-color: rgba(201, 168, 76, 0.22) !important;
}

html[data-theme="dark"] .site-footer-status[data-tone="error"] {
  color: #f0b2b2 !important;
  background: rgba(220, 60, 60, 0.1) !important;
  border-color: rgba(220, 60, 60, 0.18) !important;
}

/* Index: chat mode input strip (dark) */
html[data-theme="dark"] .main-content.chat-mode .input-area {
  background: linear-gradient(180deg, transparent 0%, rgba(18, 20, 26, 0.94) 32%) !important;
  border-top-color: rgba(201, 168, 76, 0.14) !important;
}

/* Admin page: override its CSS variables (works even with inline styles) */
html[data-theme="dark"] body {
  --ink: #ece7dc;
  --muted: rgba(236, 231, 220, 0.72);
  --gold: #c9a84c;
  --gold-deep: #e9d18a;
  --gold-mid: #c9a84c;
  --surface: rgba(18, 20, 26, 0.72);
  --stroke: rgba(201, 168, 76, 0.16);
}

/* Admin: right sidebar (منو) — dark surfaces */
html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #151820 0%, #101218 55%, #0e1016 100%) !important;
  border-left-color: rgba(201, 168, 76, 0.14) !important;
  box-shadow: -10px 0 48px rgba(0, 0, 0, 0.5) !important;
}

html[data-theme="dark"] .sidebar-brand {
  border-bottom-color: rgba(201, 168, 76, 0.12) !important;
}

html[data-theme="dark"] .sidebar-sub {
  color: rgba(236, 231, 220, 0.62) !important;
}

html[data-theme="dark"] .nav-section {
  color: rgba(236, 231, 220, 0.42) !important;
}

html[data-theme="dark"] .nav-item {
  color: rgba(236, 231, 220, 0.9) !important;
}

html[data-theme="dark"] .nav-item:hover {
  background: rgba(201, 168, 76, 0.12) !important;
  color: #f0e6c8 !important;
}

html[data-theme="dark"] .nav-item.active {
  background: linear-gradient(
    135deg,
    rgba(201, 168, 76, 0.2),
    rgba(160, 120, 48, 0.12)
  ) !important;
  border-color: rgba(201, 168, 76, 0.38) !important;
  color: #f5ecd4 !important;
}

html[data-theme="dark"] .nav-item .nav-icon {
  color: rgba(236, 231, 220, 0.82);
  stroke: currentColor;
}

html[data-theme="dark"] .sidebar-foot {
  border-top-color: rgba(201, 168, 76, 0.12) !important;
}

html[data-theme="dark"] .sidebar-link {
  color: #e9d18a !important;
}

html[data-theme="dark"] .sidebar-link:hover {
  background: rgba(201, 168, 76, 0.12) !important;
}

/* Admin header title row (page-heading) */
html[data-theme="dark"] .page-title {
  -webkit-text-fill-color: transparent !important;
  background: linear-gradient(135deg, #f2e6b8, #c9a84c) !important;
  background-clip: text !important;
}

html[data-theme="dark"] .header-btn:not(.primary) {
  color: rgba(233, 209, 138, 0.95) !important;
}

html[data-theme="dark"] .header-btn:not(.primary):hover {
  background: rgba(201, 168, 76, 0.12) !important;
  color: #fff6dd !important;
}

html[data-theme="dark"] .divider {
  background: linear-gradient(
    180deg,
    transparent,
    rgba(201, 168, 76, 0.22),
    transparent
  ) !important;
}

html[data-theme="dark"] .empty-hint {
  color: rgba(236, 231, 220, 0.65) !important;
}

html[data-theme="dark"] .toggle-row {
  background: rgba(12, 13, 18, 0.55) !important;
  border-color: rgba(201, 168, 76, 0.14) !important;
}

html[data-theme="dark"] .toggle-row label {
  color: #ece7dc !important;
}

html[data-theme="dark"] .admin-footer {
  color: rgba(236, 231, 220, 0.55) !important;
  border-top-color: rgba(201, 168, 76, 0.12) !important;
}

/* Drawer (history sidebar) — dark mode */
html[data-theme="dark"] .drawer-search {
  background: rgba(12, 13, 16, 0.55) !important;
  border-color: rgba(201, 168, 76, 0.18) !important;
  color: #ece7dc !important;
}

html[data-theme="dark"] .drawer-search::placeholder {
  color: rgba(236, 231, 220, 0.4) !important;
}

html[data-theme="dark"] .drawer-section-label {
  color: rgba(236, 231, 220, 0.5) !important;
}

html[data-theme="dark"] .history-item {
  background: rgba(201, 168, 76, 0.05) !important;
  border-color: rgba(201, 168, 76, 0.14) !important;
}

html[data-theme="dark"] .history-item:hover {
  background: rgba(201, 168, 76, 0.1) !important;
  border-color: rgba(201, 168, 76, 0.22) !important;
}

html[data-theme="dark"] .drawer-link-item {
  color: rgba(236, 231, 220, 0.9) !important;
}

html[data-theme="dark"] .drawer-link-item:hover {
  background: rgba(201, 168, 76, 0.1) !important;
  color: #f5ecd4 !important;
}

html[data-theme="dark"] .drawer-divider {
  background: linear-gradient(
    90deg,
    transparent,
    rgba(201, 168, 76, 0.22),
    transparent
  ) !important;
}

html[data-theme="dark"] .account-card {
  background: linear-gradient(
    135deg,
    rgba(201, 168, 76, 0.12),
    rgba(160, 120, 48, 0.06)
  ) !important;
  border-color: rgba(201, 168, 76, 0.22) !important;
}

html[data-theme="dark"] .account-name {
  color: #ece7dc !important;
}

html[data-theme="dark"] .account-status {
  color: rgba(236, 231, 220, 0.6) !important;
}

html[data-theme="dark"] .account-login-btn {
  background: rgba(12, 13, 16, 0.65) !important;
  border-color: rgba(201, 168, 76, 0.3) !important;
  color: #e9d18a !important;
}

html[data-theme="dark"] .account-login-btn:hover {
  background: rgba(201, 168, 76, 0.15) !important;
}

/* Dark mode - Credit Display */
html[data-theme="dark"] .account-credit {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.15), rgba(180, 140, 60, 0.1)) !important;
  border-color: rgba(201, 168, 76, 0.3) !important;
  box-shadow: 0 2px 12px rgba(201, 168, 76, 0.2) !important;
}

html[data-theme="dark"] .credit-coin {
  color: #e9d18a !important;
}

html[data-theme="dark"] .credit-label {
  color: rgba(236, 231, 220, 0.7) !important;
}

html[data-theme="dark"] .credit-amount {
  color: #f5ecd4 !important;
}

html[data-theme="dark"] .drawer-credits {
  color: rgba(236, 231, 220, 0.5) !important;
}

html[data-theme="dark"] .drawer-credits strong {
  color: #e9d18a !important;
}

/* User Dropdown — dark mode */
html[data-theme="dark"] .user-dropdown-menu {
  background: linear-gradient(135deg, #2a2520 0%, #1f1a15 100%);
  border-color: rgba(201, 168, 76, 0.3);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(201, 168, 76, 0.15);
}

html[data-theme="dark"] .user-dropdown-menu::before {
  background: #2a2520;
  border-left-color: rgba(201, 168, 76, 0.3);
  border-top-color: rgba(201, 168, 76, 0.3);
}

html[data-theme="dark"] .user-dropdown-header {
  border-bottom-color: rgba(201, 168, 76, 0.2);
}

html[data-theme="dark"] .user-dropdown-name {
  color: #e8dcc8;
}

html[data-theme="dark"] .user-dropdown-contact {
  color: #a09078;
}

html[data-theme="dark"] .user-dropdown-item {
  color: rgba(236, 231, 220, 0.9);
}

html[data-theme="dark"] .user-dropdown-item:hover {
  background: rgba(201, 168, 76, 0.12);
  color: #f5ecd4;
}

html[data-theme="dark"] .user-dropdown-item svg {
  color: #e9d18a;
}

html[data-theme="dark"] .user-dropdown-item.logout {
  color: #ff9999;
  border-top-color: rgba(201, 168, 76, 0.2);
}

html[data-theme="dark"] .user-dropdown-item.logout:hover {
  background: rgba(204, 68, 68, 0.12);
  color: #ffaaaa;
}

html[data-theme="dark"] .user-dropdown-item.logout svg {
  color: #ff7777;
}

html[data-theme="dark"] .divider {
  background: linear-gradient(180deg, transparent, rgba(201, 168, 76, 0.22), transparent);
}

/* ===== Responsive — shared components ===== */

/* ── Tablet ── */
@media (max-width: 900px) {
  .header {
    padding: 14px 24px;
  }
  .header-right {
    gap: 14px;
  }
  .header-left {
    gap: 6px;
  }
  .site-footer-inner {
    padding: 4px 12px;
  }
  .header-btn.primary.logged-in {
    min-width: 180px;
  }
  .header-btn.primary.logged-in .auth-profile-name,
  .header-btn.primary.logged-in .auth-profile-contact {
    max-width: 120px;
  }
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .header {
    padding: 10px 14px;
  }
  .header-title {
    font-size: 12px;
  }
  .header-right {
    gap: 10px;
  }
  .header-left {
    gap: 4px;
  }
  .header-btn {
    padding: 5px 10px;
    font-size: 11px;
  }
  .header-btn.primary.logged-in {
    min-width: auto;
    width: 42px;
    padding: 6px;
    justify-content: center;
  }
  .header-btn.primary.logged-in .auth-profile-meta,
  .header-btn.primary.logged-in .auth-profile-role,
  .header-btn.primary.logged-in svg:not(.auth-profile-avatar svg) {
    display: none;
  }
  .header-btn.primary.logged-in .auth-profile-avatar {
    width: 28px;
    height: 28px;
  }
  .header-btn.primary.logged-in .auth-profile-avatar svg {
    width: 16px;
    height: 16px;
  }
  .header-lang-select {
    max-width: 95px;
    font-size: 11px;
    padding: 5px 26px 5px 8px;
  }
  [dir="rtl"] .header-lang-select {
    padding: 5px 8px 5px 26px;
  }
  .header-lang-icon {
    width: 14px;
    height: 14px;
    right: 6px;
    left: auto;
  }
  [dir="rtl"] .header-lang-icon {
    right: auto;
    left: 6px;
  }
  .theme-toggle {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
  .theme-toggle svg {
    width: 16px;
    height: 16px;
  }
  .menu-btn {
    width: 32px;
    height: 32px;
  }
  .menu-icon {
    width: 16px;
    height: 10px;
  }
  .divider {
    height: 16px;
  }
  .user-dropdown-menu {
    min-width: 180px;
    left: -10px;
  }
  .user-dropdown-item {
    padding: 10px 12px;
    font-size: 13px;
    gap: 10px;
  }
  .user-dropdown-item svg {
    width: 16px;
    height: 16px;
  }
  .site-footer-inner {
    padding: 4px 14px;
    gap: 4px;
    flex-direction: column;
    align-items: stretch;
    min-height: 36px;
  }
  .site-footer-nav {
    justify-content: center;
  }
  .site-footer-meta {
    justify-content: center;
  }
  .site-footer-link-donate span {
    font-size: 11px;
  }
  .input-box.has-sources {
    padding-right: 100px !important;
  }
  .sources-btn {
    height: 26px;
    padding: 0 8px;
    font-size: 11px;
  }
  .sources-menu {
    min-width: 200px;
  }
  .sources-item {
    padding: 8px 8px;
    font-size: 12px;
  }
  .account-card {
    flex-wrap: wrap;
    gap: 8px;
  }
  .account-credit {
    width: 100%;
  }
}

/* ── Small mobile ── */
@media (max-width: 400px) {
  .header {
    padding: 8px 10px;
  }
  .header-title {
    font-size: 11px;
  }
  .header-btn {
    padding: 4px 8px;
    font-size: 10px;
  }
  .header-btn.primary.logged-in {
    min-width: auto;
    width: 38px;
    padding: 5px;
    justify-content: center;
  }
  .header-btn.primary.logged-in .auth-profile-meta,
  .header-btn.primary.logged-in .auth-profile-role,
  .header-btn.primary.logged-in svg:not(.auth-profile-avatar svg) {
    display: none;
  }
  .header-btn.primary.logged-in .auth-profile-avatar {
    width: 26px;
    height: 26px;
  }
  .header-btn.primary.logged-in .auth-profile-avatar svg {
    width: 14px;
    height: 14px;
  }
  .header-lang-select {
    max-width: 80px;
    font-size: 10px;
    padding: 4px 22px 4px 6px;
  }
  [dir="rtl"] .header-lang-select {
    padding: 4px 6px 4px 22px;
  }
  .header-lang-icon {
    width: 12px;
    height: 12px;
    right: 5px;
    left: auto;
  }
  [dir="rtl"] .header-lang-icon {
    right: auto;
    left: 5px;
  }
  .theme-toggle {
    width: 30px;
    height: 30px;
  }
  .theme-toggle svg {
    width: 14px;
    height: 14px;
  }
  .input-box.has-sources {
    padding-right: 88px !important;
  }
  .sources-btn {
    height: 24px;
    padding: 0 6px;
    font-size: 10px;
    gap: 4px;
  }
  .sources-btn-label {
    font-size: 10px;
  }
}

/* Text alignment and direction based on language direction */
[dir="ltr"] .input-box textarea,
[dir="ltr"] textarea {
  text-align: left;
  direction: ltr;
}

[dir="rtl"] .input-box textarea,
[dir="rtl"] textarea {
  text-align: right;
  direction: rtl;
}
