/* ===== Chat Maintenance Screen — v140 ===== */
/* صفحة "تحت الصيانة" الأنيقة بهوية نظام الطيبات */

/* 🛠️ Anti-Flash: لو HTML عنده class، يخفي الشات فوراً */
html.chat-is-maintenance #chatInterface,
html.chat-is-maintenance .ta-tg-banner,
html.chat-is-maintenance #ta-telegram-banner {
  display: none !important;
}

html.chat-is-maintenance body.chat-page {
  display: block !important;
  height: auto !important;
  overflow: auto !important;
}

html.chat-is-maintenance #maintenanceScreen {
  display: flex !important;
}

/* لما الـ maintenance screen ظاهر، نخفي كل شي ثاني */
body.chat-maintenance-active {
  overflow: auto !important;
  height: auto !important;
  min-height: 100dvh !important;
}

body.chat-maintenance-active .ta-tg-banner,
body.chat-maintenance-active #ta-telegram-banner,
body.chat-maintenance-active .site-header,
body.chat-maintenance-active .chat-header,
body.chat-maintenance-active .chat-messages,
body.chat-maintenance-active .chat-input-area,
body.chat-maintenance-active #chatInterface {
  display: none !important;
}

.maintenance-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none; /* يُفعّل من JavaScript */
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #faf8f2 0%, #f5f1e8 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: 'Tajawal', 'Cairo', system-ui, sans-serif;
  direction: rtl;
}

.maintenance-content {
  max-width: 600px;
  width: 100%;
  margin: auto; /* يحقق التوسيط الأفقي + الرأسي مع flex parent */
  background: #ffffff;
  border-radius: 24px;
  padding: 40px 32px;
  box-shadow: 0 10px 40px rgba(26, 61, 43, 0.12);
  border: 1px solid rgba(26, 61, 43, 0.08);
  text-align: center;
  animation: maintenance-fade-in 0.5s ease-out;
}

@keyframes maintenance-fade-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.maintenance-icon {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 20px;
  animation: maintenance-bounce 2.5s ease-in-out infinite;
  display: inline-block;
}

@keyframes maintenance-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}

.maintenance-title {
  font-size: 28px;
  font-weight: 800;
  color: #1a3d2b;
  margin: 0 0 12px 0;
  line-height: 1.3;
}

.maintenance-subtitle {
  font-size: 16px;
  color: #4a5f4f;
  margin: 0 0 28px 0;
  line-height: 1.8;
}

.maintenance-subtitle strong {
  color: #1a3d2b;
  font-weight: 700;
}

.maintenance-meanwhile {
  font-size: 15px;
  color: #6b7d6f;
  margin: 0 0 18px 0;
  font-weight: 600;
}

/* Links Grid */
.maintenance-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.maintenance-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #faf8f2;
  border: 1.5px solid #e8e2d3;
  border-radius: 14px;
  text-decoration: none;
  color: #1a3d2b;
  transition: all 0.25s ease;
  text-align: right;
}

.maintenance-link:hover {
  background: #f0ead8;
  border-color: #c9a84c;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(201, 168, 76, 0.2);
}

.maintenance-link:active {
  transform: translateY(0);
}

.maintenance-link .ml-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #e8e2d3;
}

.maintenance-link:hover .ml-icon {
  background: #1a3d2b;
}

.maintenance-link .ml-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.maintenance-link .ml-title {
  font-size: 15px;
  font-weight: 700;
  color: #1a3d2b;
  line-height: 1.3;
}

.maintenance-link .ml-desc {
  font-size: 12px;
  color: #6b7d6f;
  line-height: 1.4;
}

.maintenance-footer {
  font-size: 14px;
  color: #6b7d6f;
  margin: 0;
  padding-top: 20px;
  border-top: 1px solid #e8e2d3;
  font-weight: 600;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 600px) {
  .maintenance-screen {
    padding: 16px 12px;
  }

  .maintenance-content {
    padding: 32px 20px;
    border-radius: 20px;
  }

  .maintenance-icon {
    font-size: 60px;
    margin-bottom: 16px;
  }

  .maintenance-title {
    font-size: 22px;
  }

  .maintenance-subtitle {
    font-size: 15px;
    margin-bottom: 24px;
  }

  .maintenance-links {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .maintenance-link {
    padding: 12px 14px;
  }

  .maintenance-link .ml-icon {
    font-size: 24px;
    width: 40px;
    height: 40px;
  }

  .maintenance-link .ml-title {
    font-size: 14px;
  }

  .maintenance-link .ml-desc {
    font-size: 11px;
  }

  .maintenance-footer {
    font-size: 13px;
  }
}

/* ===== Dark Theme Support ===== */
[data-theme="dark"] .maintenance-screen,
.theme-awadi .maintenance-screen {
  background: linear-gradient(135deg, #0f2018 0%, #1a3d2b 100%);
}

[data-theme="dark"] .maintenance-content,
.theme-awadi .maintenance-content {
  background: #1a3d2b;
  border-color: rgba(232, 201, 106, 0.2);
}

[data-theme="dark"] .maintenance-title,
.theme-awadi .maintenance-title {
  color: #e8c96a;
}

[data-theme="dark"] .maintenance-subtitle,
.theme-awadi .maintenance-subtitle {
  color: #d4d8d2;
}

[data-theme="dark"] .maintenance-subtitle strong,
.theme-awadi .maintenance-subtitle strong {
  color: #e8c96a;
}

[data-theme="dark"] .maintenance-meanwhile,
.theme-awadi .maintenance-meanwhile {
  color: #95d5b2;
}

[data-theme="dark"] .maintenance-link,
.theme-awadi .maintenance-link {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(232, 201, 106, 0.2);
  color: #f0ead8;
}

[data-theme="dark"] .maintenance-link:hover,
.theme-awadi .maintenance-link:hover {
  background: rgba(232, 201, 106, 0.1);
  border-color: #c9a84c;
}

[data-theme="dark"] .maintenance-link .ml-icon,
.theme-awadi .maintenance-link .ml-icon {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(232, 201, 106, 0.2);
}

[data-theme="dark"] .maintenance-link .ml-title,
.theme-awadi .maintenance-link .ml-title {
  color: #e8c96a;
}

[data-theme="dark"] .maintenance-link .ml-desc,
.theme-awadi .maintenance-link .ml-desc {
  color: #95d5b2;
}

[data-theme="dark"] .maintenance-footer,
.theme-awadi .maintenance-footer {
  color: #95d5b2;
  border-top-color: rgba(232, 201, 106, 0.2);
}

/* ===== Telegram Invitation Card ===== */
.maintenance-telegram {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: linear-gradient(135deg, #e7f3ff 0%, #d4e9fb 100%);
  border: 2px solid #5dade2;
  border-radius: 18px;
  padding: 22px 20px;
  margin-bottom: 24px;
  text-align: right;
  position: relative;
  overflow: hidden;
}

.maintenance-telegram::before {
  content: '';
  position: absolute;
  top: -40px;
  left: -40px;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(41, 182, 246, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.mt-bell {
  font-size: 36px;
  flex-shrink: 0;
  animation: mt-bell-ring 3s ease-in-out infinite;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
}

@keyframes mt-bell-ring {
  0%, 90%, 100% { transform: rotate(0deg); }
  93% { transform: rotate(-10deg); }
  96% { transform: rotate(10deg); }
}

.mt-content {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.mt-title {
  font-size: 17px;
  font-weight: 800;
  color: #0d4a7d;
  margin-bottom: 6px;
  line-height: 1.4;
}

.mt-desc {
  font-size: 13.5px;
  color: #1a5a8a;
  line-height: 1.7;
  margin-bottom: 14px;
}

.mt-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mt-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: #ffffff;
  border: 1.5px solid transparent;
  border-radius: 12px;
  text-decoration: none;
  transition: all 0.25s ease;
  text-align: right;
}

.mt-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(13, 74, 125, 0.18);
}

.mt-btn-channel {
  border-color: #29b6f6;
}

.mt-btn-channel:hover {
  background: #29b6f6;
  border-color: #29b6f6;
}

.mt-btn-channel:hover .mt-btn-label,
.mt-btn-channel:hover .mt-btn-sub {
  color: #ffffff;
}

.mt-btn-group {
  border-color: #4caf50;
}

.mt-btn-group:hover {
  background: #4caf50;
  border-color: #4caf50;
}

.mt-btn-group:hover .mt-btn-label,
.mt-btn-group:hover .mt-btn-sub {
  color: #ffffff;
}

.mt-btn-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
}

.mt-btn:hover .mt-btn-icon {
  background: rgba(255, 255, 255, 0.95);
}

.mt-btn-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.mt-btn-label {
  font-size: 13.5px;
  font-weight: 700;
  color: #0d4a7d;
  line-height: 1.3;
  transition: color 0.2s;
}

.mt-btn-sub {
  font-size: 11px;
  color: #5a7a95;
  line-height: 1.3;
  transition: color 0.2s;
}

/* Mobile Responsive */
@media (max-width: 600px) {
  .maintenance-telegram {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 18px 16px;
    gap: 10px;
  }

  .mt-content {
    width: 100%;
    text-align: center;
  }

  .mt-bell {
    font-size: 32px;
  }

  .mt-title {
    font-size: 15.5px;
  }

  .mt-desc {
    font-size: 12.5px;
    margin-bottom: 12px;
  }

  .mt-buttons {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .mt-btn {
    text-align: right;
    padding: 10px 12px;
  }
}

/* Dark Theme Support */
[data-theme="dark"] .maintenance-telegram,
.theme-awadi .maintenance-telegram {
  background: linear-gradient(135deg, rgba(41, 182, 246, 0.12) 0%, rgba(41, 182, 246, 0.06) 100%);
  border-color: rgba(41, 182, 246, 0.4);
}

[data-theme="dark"] .mt-title,
.theme-awadi .mt-title {
  color: #93cdf3;
}

[data-theme="dark"] .mt-desc,
.theme-awadi .mt-desc {
  color: #b8d4e8;
}

[data-theme="dark"] .mt-btn,
.theme-awadi .mt-btn {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .mt-btn-label,
.theme-awadi .mt-btn-label {
  color: #93cdf3;
}

[data-theme="dark"] .mt-btn-sub,
.theme-awadi .mt-btn-sub {
  color: #8fa8bc;
}

[data-theme="dark"] .mt-btn-icon,
.theme-awadi .mt-btn-icon {
  background: rgba(0, 0, 0, 0.3);
}
