/* =========================================================
   Accountant Cloud — طبقة الدخول والمزامنة والموبايل
   ========================================================= */

/* ---------- شاشة الدخول ---------- */
.cloud-gate {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 10%, rgba(56, 189, 248, 0.18), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(45, 212, 191, 0.14), transparent 45%),
    linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #0b3b4a 100%);
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  direction: rtl;
}

.cloud-gate[hidden] {
  display: none !important;
}

.cloud-gate-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 22px;
  padding: 34px 28px 26px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.45);
  text-align: center;
  animation: cloudGateIn 0.35s ease;
}

@keyframes cloudGateIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cloud-gate-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 30px;
  background: linear-gradient(135deg, #0ea5e9, #14b8a6);
  box-shadow: 0 12px 26px rgba(14, 165, 233, 0.35);
}

.cloud-gate-card h1 {
  font-size: 1.32rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0 0 6px;
}

.cloud-gate-card p {
  color: #64748b;
  font-size: 0.92rem;
  margin: 0 0 22px;
}

.cloud-input-wrap {
  position: relative;
  margin-bottom: 12px;
}

.cloud-input-wrap input {
  width: 100%;
  height: 52px;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
  padding: 0 46px 0 16px;
  font-size: 1.05rem;
  font-family: inherit;
  color: #0f172a;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  letter-spacing: 2px;
}

.cloud-input-wrap input:focus {
  border-color: #0ea5e9;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.14);
}

.cloud-input-wrap input::placeholder {
  letter-spacing: 0;
  color: #94a3b8;
}

.cloud-eye {
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #64748b;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.05rem;
}

.cloud-eye:hover {
  background: #eef2f7;
  color: #0f172a;
}

.cloud-submit {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #0284c7, #0d9488);
  color: #fff;
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 12px 24px rgba(2, 132, 199, 0.28);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}

.cloud-submit:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(2, 132, 199, 0.34);
}

.cloud-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}

.cloud-error {
  min-height: 22px;
  margin: 2px 0 10px;
  color: #dc2626;
  font-size: 0.85rem;
  font-weight: 600;
}

.cloud-gate-foot {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed #e2e8f0;
  color: #94a3b8;
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cloud-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: cloudSpin 0.7s linear infinite;
}

@keyframes cloudSpin {
  to { transform: rotate(360deg); }
}

.cloud-shake {
  animation: cloudShake 0.4s ease;
}

@keyframes cloudShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

/* ---------- مؤشر حالة الحفظ ---------- */
.cloud-status {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 2000;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  color: #e2e8f0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.25);
  backdrop-filter: blur(8px);
  max-width: calc(100vw - 36px);
  direction: rtl;
}

.cloud-status[data-visible="true"] {
  display: inline-flex;
}

.cloud-status::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  flex: 0 0 auto;
}

.cloud-status[data-state="saving"]::before {
  background: #f59e0b;
  animation: cloudPulse 1s ease infinite;
}

.cloud-status[data-state="error"]::before,
.cloud-status[data-state="offline"]::before,
.cloud-status[data-state="conflict"]::before {
  background: #ef4444;
}

@keyframes cloudPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

/* ---------- أدوات الحساب في الشريط الجانبي ---------- */
.cloud-account-card {
  border: 1px solid rgba(148, 163, 184, 0.25) !important;
}

.cloud-account-card .btn {
  font-family: inherit;
}

/* ---------- الموبايل ---------- */
@media (max-width: 767.98px) {
  body {
    padding-bottom: calc(88px + env(safe-area-inset-bottom)) !important;
  }

  .dark-mode-toggle {
    top: auto !important;
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: 14px !important;
    z-index: 1000;
  }

  .tools-toggle-btn {
    top: auto !important;
    bottom: calc(14px + env(safe-area-inset-bottom));
    right: 14px !important;
    z-index: 1000;
  }

  .dark-mode-toggle .btn,
  .tools-toggle-btn .btn {
    height: 48px;
    padding: 0 16px;
    border-radius: 14px;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.28);
  }

  .tools-sidebar {
    width: 100% !important;
    max-width: 100vw !important;
    padding: 16px !important;
  }

  .cloud-status {
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 14px;
    font-size: 0.72rem;
    padding: 6px 12px;
  }

  input,
  select,
  textarea,
  .form-control,
  .form-select {
    font-size: 16px !important;
  }

  .modal-dialog {
    margin: 0.5rem;
  }

  .modal-content {
    border-radius: 18px;
  }

  .table {
    font-size: 0.82rem;
  }

  .btn {
    touch-action: manipulation;
  }

  .cloud-gate-card {
    padding: 28px 20px 22px;
    border-radius: 18px;
  }

  /* ---------- تحسينات تنظيم الشاشة على الموبايل ---------- */

  /* الشريط الجانبي بعرض الشاشة الكامل */
  .tools-sidebar.open {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-width: none !important;
  }

  /* الهيدر: مساحة أقل */
  .header {
    padding: 18px 12px !important;
    margin-bottom: 18px !important;
    border-radius: 0 0 16px 16px !important;
  }

  .header h1 {
    font-size: 1.28rem !important;
    margin-bottom: 6px !important;
  }

  .header .lead {
    font-size: 0.86rem !important;
    margin-bottom: 10px !important;
  }

  .header .btn {
    padding: 7px 14px !important;
    font-size: 0.82rem !important;
    margin-top: 4px !important;
  }

  /* الإحصائيات: شبكة 2×2 بدل 4 صناديق طولية */
  .summary-row {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.75rem;
  }

  .summary-row > [class*="col-"] {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }

  .summary-box {
    height: 100%;
    min-height: 96px;
    padding: 12px 8px !important;
    margin-bottom: 0 !important;
  }

  .summary-box i {
    font-size: 1.25rem !important;
    margin-bottom: 4px !important;
  }

  .summary-box h5 {
    font-size: 0.76rem !important;
    margin: 6px 0 4px !important;
  }

  .summary-box h4 {
    font-size: 1.02rem !important;
  }

  /* قائمة العملاء قبل "أحدث المعاملات" */
  .main-content-row {
    display: flex;
    flex-direction: column;
  }

  .main-content-row > .col-md-5 {
    order: 2;
  }

  .main-content-row > .col-md-7 {
    order: 1;
  }

  /* خيارات الترتيب: صف مضغوط */
  .sort-options .row > [class*="col-"] {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }

  .sort-options .row > [class*="col-"]:first-child {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  .sort-options .row > [class*="col-"]:last-child .form-label {
    display: none !important;
  }

  .sort-options .form-label {
    font-size: 0.78rem !important;
    margin-bottom: 4px !important;
  }

  .sort-options .form-select,
  .sort-options .btn {
    font-size: 0.85rem !important;
  }

  /* تابات العملاء أفقية */
  #customersTabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
  }

  #customersTabs::-webkit-scrollbar {
    display: none;
  }

  #customersTabs .nav-link {
    white-space: nowrap;
    font-size: 0.8rem !important;
    padding: 7px 9px !important;
  }

  /* أزرار بطاقة العميل: أهداف لمس أكبر */
  .customer-card .actions {
    gap: 8px;
  }

  .customer-card .actions .btn {
    min-height: 40px;
    font-size: 0.82rem !important;
  }

  .customer-card .actions .favorite-toggle {
    flex: 0 0 46px;
    width: 46px;
    padding: 0;
  }

  .customer-card .actions .btn-outline-info,
  .customer-card .actions .btn-outline-primary {
    flex: 1 1 0;
  }

  .card-header .card-title {
    font-size: 0.95rem !important;
  }
}

@media (max-width: 380px) {
  .cloud-gate-card h1 {
    font-size: 1.15rem;
  }

  .cloud-gate-card {
    padding: 24px 16px 18px;
  }
}

/* ---------- تنبيه عائم ---------- */
.cloud-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 10050;
  transform: translate(-50%, -18px);
  opacity: 0;
  pointer-events: none;
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  border-radius: 14px;
  background: #0f172a;
  color: #f1f5f9;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.35);
  transition: opacity 0.25s ease, transform 0.25s ease;
  direction: rtl;
}

.cloud-toast[data-visible="true"] {
  opacity: 1;
  transform: translate(-50%, 0);
}

.cloud-toast[data-kind="error"] {
  background: #991b1b;
}

.cloud-toast[data-kind="success"] {
  background: #065f46;
}

/* ---------- الطباعة ---------- */
@media print {
  .cloud-gate,
  .cloud-status,
  .cloud-toast {
    display: none !important;
  }
}
