/* ============================================================
   ELHASSANE STUDIO - Modern Design System
   A single refresh layer applied to every module.
   Loaded LAST so equal-specificity rules win over style.css.
   ============================================================ */

/* ---------- Cards ---------- */
.card {
  border-radius: 1rem;
  border-color: rgb(229 231 235 / 1);
  box-shadow: 0 1px 2px rgb(16 24 40 / 0.04), 0 8px 24px -8px rgb(16 24 40 / 0.08);
}
.card:is(.dark *) {
  border-color: rgb(51 65 85 / 1);
  background-color: rgb(24 33 52 / 1);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -8px rgb(0 0 0 / 0.4);
}

/* ---------- Stats (clean professional) ---------- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color 200ms ease, box-shadow 200ms ease, transform 200ms ease;
}
.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card:is(.dark *) { background: var(--bg-card); }
.stat-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  border: 1px solid transparent;
}
.stat-icon-blue,
.stat-icon-emerald,
.stat-icon-amber,
.stat-icon-purple { background: #E0F2FE; border-color: #BAE6FD; }
.dark .stat-icon-blue,
.dark .stat-icon-emerald,
.dark .stat-icon-amber,
.dark .stat-icon-purple { background: rgba(14, 165, 233, 0.16); border-color: rgba(56, 189, 248, 0.35); }
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}
.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}
.stat-delta.up   { background: var(--brand-success-light); color: var(--brand-success); }
.stat-delta.down { background: var(--brand-danger-light); color: var(--brand-danger); }

/* Chart cards: consistent, clean */
.chart-card { padding: 20px; }
.chart-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.chart-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}
.chart-chip {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.chart-chip-blue,
.chart-chip-emerald,
.chart-chip-amber,
.chart-chip-purple { background: #E0F2FE; border: 1px solid #BAE6FD; }
.dark .chart-chip-blue,
.dark .chart-chip-emerald,
.dark .chart-chip-amber,
.dark .chart-chip-purple { background: rgba(14, 165, 233, 0.16); border-color: rgba(56, 189, 248, 0.35); }
.chart-card-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-page);
  border: 1px solid var(--border-default);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Insights: compact stat blocks */
.insight-card {
  background: var(--bg-page);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
  transition: border-color 200ms ease;
}
.insight-card:hover { border-color: var(--border-strong); }
.insight-card .insight-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.insight-card .insight-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--brand-secondary);
  font-variant-numeric: tabular-nums;
}
.insight-card.is-warning .insight-value { color: var(--brand-warning); }
.insight-card .insight-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Tables ---------- */
.card table,
.card .overflow-x-auto table {
  border-collapse: separate;
  border-spacing: 0;
}
.card thead th,
.card table thead th {
  padding: 0.7rem 1rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgb(107 114 128 / 1);
  background: rgb(249 250 251 / 1);
  border-bottom: 1px solid rgb(229 231 235 / 1);
}
.card:is(.dark *) thead th,
.card table thead th:is(.dark *) {
  color: rgb(156 163 175 / 1);
  background: rgb(17 24 39 / 1);
  border-bottom: 1px solid rgb(51 65 85 / 1);
}
.card thead th:first-child { border-top-left-radius: 0.75rem; }
.card thead th:last-child { border-top-right-radius: 0.75rem; }
.card tbody td,
.card table tbody td {
  padding: 0.7rem 1rem;
}
.card tbody tr {
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.card tbody tr:hover {
  background: rgb(249 250 251 / 0.9);
}
.card:is(.dark *) tbody tr:hover {
  background: rgb(31 41 55 / 0.8);
}
.card tbody tr + tr td {
  border-top: 1px solid rgb(243 244 246 / 1);
}
.card:is(.dark *) tbody tr + tr td {
  border-top: 1px solid rgb(51 65 85 / 0.6);
}

/* ---------- Buttons ---------- */
.btn-primary,
.btn-success,
.btn-danger,
.btn-warning,
.btn-brand {
  border-radius: 0.65rem;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12), 0 4px 12px -4px rgb(0 0 0 / 0.25);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.btn-primary:hover,
.btn-success:hover,
.btn-danger:hover,
.btn-brand:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.12), 0 8px 20px -6px rgb(0 0 0 / 0.28);
}
.btn-outline {
  border-radius: 0.65rem;
  font-weight: 600;
}
.btn-outline:hover {
  transform: translateY(-1px);
}

/* ---------- Inputs ---------- */
.input-field {
  border-radius: 0.6rem;
  border-width: 1px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.input-field:focus {
  border-color: rgb(37 99 235 / 0.7);
  outline: none;
  box-shadow: 0 0 0 3.5px rgb(37 99 235 / 0.14);
}
.input-field:is(.dark *):focus {
  border-color: rgb(96 165 250 / 0.7);
  box-shadow: 0 0 0 3.5px rgb(96 165 250 / 0.14);
}

/* ---------- Badges ---------- */
.badge,
.badge-blue,
.badge-green,
.badge-red,
.badge-yellow,
.badge-gray,
.badge-purple {
  border-radius: 9999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ---------- Section titles inside modules ---------- */
.report-section-title,
.home-section-title {
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Modal ---------- */
.modal-content,
#modalContent, .modal-box {
  border-radius: 1rem;
  box-shadow: 0 25px 60px -12px rgb(15 23 42 / 0.4);
}

/* ---------- Progress bars ---------- */
.progress-track {
  border-radius: 9999px;
  overflow: hidden;
}
.progress-fill {
  border-radius: 9999px;
}

/* ---------- Thumb scrollbars (app) ---------- */
.main-content::-webkit-scrollbar, #view::-webkit-scrollbar { width: 8px; height: 8px; }
.main-content::-webkit-scrollbar-thumb, #view::-webkit-scrollbar-thumb {
  background: #d1d5db; border-radius: 9999px; border: 2px solid transparent; background-clip: padding-box;
}
.dark .main-content::-webkit-scrollbar-thumb, .dark #view::-webkit-scrollbar-thumb { background: #4b5563; background-clip: padding-box; }

/* ---------- View enter ---------- */
.view-enter { animation: modernViewIn 0.38s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes modernViewIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Guided tour ---------- */
.tour-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: #0b1220;
  opacity: 0; transition: opacity 300ms ease;
}
.tour-highlight {
  position: fixed; z-index: 95; display: none;
  border-radius: 14px;
  box-shadow: 0 0 0 3px #f59e0b, 0 0 0 9999px rgba(11, 18, 32, 0);
  animation: tourPulse 1.8s ease-in-out infinite;
}
@keyframes tourPulse {
  0%, 100% { box-shadow: 0 0 0 3px #f59e0b, 0 0 0 0 rgba(245, 158, 11, 0.25); }
  50%      { box-shadow: 0 0 0 3px #f59e0b, 0 0 0 12px rgba(245, 158, 11, 0.12); }
}
.tour-card {
  position: fixed; z-index: 96;
  left: 50%; bottom: 5vh;
  transform: translateX(-50%);
  width: min(540px, calc(100vw - 32px));
  background: #ffffff; border-radius: 16px;
  box-shadow: 0 24px 60px -12px rgba(2, 6, 23, 0.55);
  padding: 20px 22px;
  font-family: inherit;
}
.tour-card:is(.dark *) { background: #1e293b; color: #e2e8f0; }
.tour-dots { display: flex; gap: 5px; margin-bottom: 12px; }
.tour-dot { width: 7px; height: 7px; border-radius: 9999px; background: #cbd5e1; transition: all 200ms ease; }
.tour-dot.active { width: 22px; background: #f59e0b; }
.tour-card:is(.dark *) .tour-dot { background: #475569; }
.tour-card:is(.dark *) .tour-dot.active { background: #fbbf24; }
.tour-title { font-size: 1.05rem; font-weight: 800; color: #0f172a; margin-bottom: 6px; }
.tour-card:is(.dark *) .tour-title { color: #f1f5f9; }
.tour-body { font-size: 0.9rem; line-height: 1.65; color: #475569; }
.tour-card:is(.dark *) .tour-body { color: #cbd5e1; }
.tour-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; gap: 8px; }
.tour-step { font-size: 0.75rem; color: #94a3b8; font-weight: 600; }
.tour-btn {
  border: 1px solid #e2e8f0; background: #f8fafc; color: #334155;
  border-radius: 10px; padding: 7px 16px; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; transition: all 150ms ease;
}
.tour-btn:hover { background: #eef2f7; transform: translateY(-1px); }
.tour-btn.tour-next { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.tour-btn.tour-next:hover { background: #d97706; }
.tour-card:is(.dark *) .tour-btn { background: #334155; border-color: #475569; color: #e2e8f0; }
.tour-card:is(.dark *) .tour-btn:hover { background: #475569; }
.tour-card:is(.dark *) .tour-btn.tour-next { background: #f59e0b; color: #0f172a; }

/* ---------- Horizontal Top Bar (replaces sidebar) ---------- */
.topbar {
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  z-index: 50;
  padding: 0 12px;
  gap: 8px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
  box-sizing: border-box;
}
.topbar:is(.dark *) {
  background: #1e293b;
  border-bottom-color: #334155;
}
#topNav {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  padding-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  flex: 1 1 0;
  min-width: 0;
}
#topNav.hidden { display: none !important; }
#topNav::-webkit-scrollbar { height: 4px; }
#topNav::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9999px; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: thin; }

.topbar .brand-logo { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  border-radius: 9999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  border: 1px solid transparent;
  transition: all 150ms ease;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}
.topbar-link:hover {
  background: rgb(30 64 175 / 0.06);
  color: rgb(30 64 175);
}
.topbar-link:is(.dark *) { color: #cbd5e1; }
.topbar-link:hover:is(.dark *) { background: #334155; color: #93c5fd; }
.topbar-link.active {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  color: #ffffff;
  box-shadow: 0 2px 8px -2px rgb(30 64 175 / 0.5);
}
.topbar-link.active:is(.dark *) { color: #ffffff; }

.topbar-icon {
  font-size: 17px;
  padding: 5px;
  border-radius: 8px;
  color: #475569;
  transition: all 150ms ease;
  cursor: pointer;
  flex-shrink: 0;
  background: none;
  border: none;
  font-family: inherit;
}
.topbar-icon:hover { background: rgb(30 64 175 / 0.08); color: #1e3a8a; transform: translateY(-1px); }
.topbar-icon:is(.dark *) { color: #cbd5e1; }
.topbar-icon:hover:is(.dark *) { background: #334155; color: #93c5fd; }

.topbar-lang select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: transparent;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
}
.topbar-lang select:is(.dark *) { background: #1e293b; color: #e2e8f0; border-color: #475569; }
.topbar-lang select:focus { outline: none; border-color: #2563eb; }

/* ---------- Topbar Dropdowns ---------- */
.topbar-dd {
  position: relative;
  flex-shrink: 0;
}
.topbar-dd-toggle {
  cursor: pointer;
}
.topbar-dd.open .topbar-dd-toggle {
  background: rgb(30 64 175 / 0.08);
  color: #1e3a8a;
}
.topbar-dd.open .topbar-dd-toggle:is(.dark *) {
  background: #334155;
  color: #93c5fd;
}
.topbar-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: auto;
  min-width: 230px;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 20px 50px -12px rgb(15 23 42 / 0.25);
  padding: 6px;
  z-index: 80;
  display: none;
  animation: ddFadeIn 140ms ease;
}
[dir="rtl"] .topbar-dd-menu {
  left: auto;
  right: 0;
}
.topbar-dd:is(.dark *) .topbar-dd-menu {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 20px 50px -12px rgb(0 0 0 / 0.6);
}
.topbar-dd.open .topbar-dd-menu {
  display: block;
}
@keyframes ddFadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
.topbar-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 120ms ease;
  font-family: inherit;
}
[dir="rtl"] .topbar-dd-item { text-align: right; }
.topbar-dd-item:hover {
  background: rgb(30 64 175 / 0.06);
  color: #1e3a8a;
}
.topbar-dd-item:is(.dark *) { color: #cbd5e1; }
.topbar-dd-item:hover:is(.dark *) { background: #334155; color: #93c5fd; }
.topbar-dd-item.active {
  background: rgb(30 64 175 / 0.1);
  color: #1e3a8a;
  font-weight: 700;
}
.topbar-dd-item.active:is(.dark *) { background: rgb(30 58 138 / 0.3); color: #93c5fd; }

.topbar .topbar-user { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; padding-right: 0; }
body:not(.sidebar-closed) .topbar .topbar-user { padding-left: 8px; border-left: 1px solid #e2e8f0; }
.topbar:is(.dark *) .topbar-user { border-left-color: #334155; }
[dir="ltr"] .topbar .topbar-user { padding-left: 8px; border-left: 1px solid #e2e8f0; }

/* Main content clears the fixed topbar */
.main-content { margin-left: 0 !important; margin-right: 0 !important; }
.main-content { padding-top: 56px; box-sizing: border-box; }
/* keep page header offset below topbar */
.main-content > header { top: 56px !important; }
/* زر القائمة (☰) مخفي على الشاشات العريضة */
.app-menu-btn.hidden { display: none !important; }
/* مساحة المستخدم لا تأكل مساحة التنقل على الشاشات المتوسطة */
@media (max-width: 1400px) {
  .topbar-user .sm\:block { display: none !important; }
}
@media (max-width: 1160px) {
  #topNav { gap: 2px; }
  .topbar-link { padding: 4px 7px; font-size: 11.5px; gap: 4px; }
  .topbar .topbar-user { gap: 4px; }
  .topbar-lang select { padding: 3px 6px; font-size: 11px; }
  .topbar-user .w-8.h-8 { display: none !important; }
}
/* الشاشات المتوسطة والصغيرة: شريط التنقل يتحول لقائمة جانبية رأسية (Accordion) */
@media (max-width: 1023px) {
  #topNav {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 10px 12px 16px;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border-default);
    box-shadow: 0 14px 30px -12px rgb(15 23 42 / 0.18);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 90;
  }
  #topNav .topbar-link { justify-content: flex-start; width: 100%; padding: 9px 12px; font-size: 13px; border-radius: 10px; }
  #topNav .topbar-dd { flex-shrink: 1; }
  #topNav .topbar-dd-toggle { width: 100%; }
  #topNav .topbar-dd-menu {
    position: static;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 2px 0 2px 14px;
    background: transparent;
    animation: none;
  }
  [dir="rtl"] #topNav .topbar-dd-menu { right: auto; left: auto; padding-left: 0; padding-right: 14px; }
}

/* ---------- App page header ---------- */
.app-header {
  position: sticky;
  top: 56px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border-default);
  backdrop-filter: blur(8px);
}
.app-page-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.app-datetime {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.app-menu-btn {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.app-menu-btn:hover { border-color: var(--border-strong); background: var(--bg-card-hover); }

/* Topbar brand divider */
.topbar .brand-logo { padding-right: 12px; }
.topbar .brand-logo span.divider {
  width: 1px; height: 22px;
  background: var(--border-default);
  margin-left: 4px;
}
.topbar .topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-left: 12px;
  border-left: 1px solid var(--border-default);
}