/* ══════════════════════════════════════════════════════
   Dashboard Layout
══════════════════════════════════════════════════════ */

*,
*::before,
*::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  background: #f0f0eb;
  color: var(--text, #0f172a);
  direction: rtl;
  font-size: 14px;
}

.dash-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════
   Sidebar Nav
══════════════════════════════════════════════════════ */

.dash-nav {
  background: #fff;
  border-left: 1px solid rgba(0,0,0,.07);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.dash-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.dash-nav-logo-img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
}

.dash-nav-brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dash-nav-app-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-1, #1a1a2e);
}

.dash-nav-app-sub {
  font-size: 10px;
  color: var(--text-2, #64748b);
  font-weight: 400;
}

.dash-nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2, #94a3b8);
  padding: 14px 16px 4px;
}

.dash-nav-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.dash-nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2, #64748b);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.dash-nav-item:hover:not(.disabled):not(.active) {
  background: var(--bg, #f4f6f9);
  color: var(--text-1, #1a1a2e);
}

.dash-nav-item.active {
  background: var(--accent-soft, #dcfce7);
  color: var(--accent, #2563eb);
  font-weight: 600;
}

[data-theme="dark"] .dash-nav-item.active {
  background: rgba(37, 99, 235, 0.15);
}

.dash-nav-item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.dash-nav-soon {
  margin-right: auto;
  font-size: 9px;
  font-weight: 600;
  background: var(--border, #e2e8f0);
  color: var(--text-2, #64748b);
  border-radius: 20px;
  padding: 1px 7px;
  letter-spacing: 0.04em;
}

.dash-nav-footer {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid var(--border, #e2e8f0);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-nav-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.dash-nav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-nav-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.dash-nav-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1, #1a1a2e);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-nav-user-role {
  font-size: 10px;
  color: var(--text-2, #64748b);
}

.dash-nav-theme-btn,
.dash-nav-logout-btn {
  background: none;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
  color: var(--text-2, #64748b);
  font-size: 13px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.dash-nav-theme-btn:hover,
.dash-nav-logout-btn:hover {
  background: var(--bg, #f4f6f9);
  color: var(--text-1, #1a1a2e);
}

/* ══════════════════════════════════════════════════════
   Main Content
══════════════════════════════════════════════════════ */

.dash-main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0 0 24px;
  overflow: auto;
}

/* ══════════════════════════════════════════════════════
   Header
══════════════════════════════════════════════════════ */

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px 10px;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,.07);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.dash-mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2, #64748b);
  padding: 4px;
  border-radius: 6px;
}

.dash-header-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #0f172a);
  margin: 0;
}

.dash-header-sub {
  font-size: 12px;
  color: var(--text-2, #64748b);
  margin: 2px 0 0;
}

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

.dash-header-status {
  font-size: 11px;
  color: var(--text-2, #94a3b8);
}

.dash-refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-1, #1a1a2e);
  transition: background 0.15s, border-color 0.15s;
}

.dash-refresh-btn:hover {
  background: var(--bg, #f4f6f9);
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}

.dash-refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

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

/* ══════════════════════════════════════════════════════
   KPI Strip
══════════════════════════════════════════════════════ */

.dash-kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 24px 0;
}

@keyframes dash-card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dash-kpi-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px 12px;
  border: 1px solid rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
  transition: box-shadow 0.2s, transform 0.2s;
  animation: dash-card-in 0.3s ease-out both;
}

.dash-kpi-card:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,.06), 0 8px 20px rgba(0,0,0,.06);
  transform: translateY(-1px);
}

.dash-kpi-card:nth-child(1) { animation-delay: 0ms; }
.dash-kpi-card:nth-child(2) { animation-delay: 70ms; }
.dash-kpi-card:nth-child(3) { animation-delay: 140ms; }
.dash-kpi-card:nth-child(4) { animation-delay: 210ms; }

/* Header: label left, icon badge right */
.dash-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.dash-kpi-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted, #64748b);
}

.dash-kpi-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-kpi-badge.kpi-green { background: #dcfce7; color: #16a34a; }
.dash-kpi-badge.kpi-amber { background: #fef3c7; color: #d97706; }
.dash-kpi-badge.kpi-red   { background: #fee2e2; color: #dc2626; }
.dash-kpi-badge.kpi-blue  { background: #dbeafe; color: #2563eb; }

/* Value */
.dash-kpi-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text, #0f172a);
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer: change + meta */
.dash-kpi-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.dash-kpi-change {
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  padding: 1px 6px;
  white-space: nowrap;
}

.dash-kpi-change.pos { color: #16a34a; background: #dcfce7; }
.dash-kpi-change.neg { color: #dc2626; background: #fee2e2; }

.dash-kpi-meta {
  font-size: 11px;
  color: var(--muted-light, #94a3b8);
}

/* Sparkline — compact, sits under footer */
.dash-kpi-sparkline {
  display: block;
  width: 100%;
  height: 28px;
  margin-top: 6px;
}

[data-theme="dark"] .dash-kpi-change.pos { background: rgba(22,163,74,.2); }
[data-theme="dark"] .dash-kpi-change.neg { background: rgba(220,38,38,.2); }

/* Skeleton inside KPI cards */
.dash-skel {
  display: block;
  background: linear-gradient(90deg,
    var(--border, #e2e8f0) 25%,
    var(--bg, #f4f6f9) 50%,
    var(--border, #e2e8f0) 75%);
  background-size: 200% 100%;
  animation: dash-shimmer 1.4s infinite;
  border-radius: 5px;
  width: 80%;
  height: 22px;
}

@keyframes dash-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ══════════════════════════════════════════════════════
   Content Cards
══════════════════════════════════════════════════════ */

.dash-row {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 12px;
  padding: 12px 24px 0;
}

/* Mid row: trend chart | donut | forecast */
.dash-mid-row {
  display: grid;
  grid-template-columns: 1fr 220px 210px;
  gap: 12px;
  padding: 12px 24px 0;
}

/* Bot row: reps | clients | quick actions */
.dash-bot-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 12px 24px 0;
}

/* Full-width row */
.dash-full-row {
  padding: 12px 24px 0;
}

.dash-card {
  background: #fff;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 6px 16px rgba(0,0,0,.04);
  overflow: hidden;
  animation: dash-card-in 0.35s ease-out both;
}

.dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px 9px;
  border-bottom: 1px solid rgba(0,0,0,.06);
}

.dash-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-1, #1a1a2e);
}

.dash-card-sub {
  font-size: 11px;
  color: var(--text-2, #94a3b8);
}

.dash-card-action {
  font-size: 12px;
  color: var(--accent, #2563eb);
  text-decoration: none;
  font-weight: 500;
}

.dash-card-action:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════════
   Trend Chart
══════════════════════════════════════════════════════ */

.dash-chart-wrap {
  padding: 8px 14px 10px;
  min-height: 170px;
}

.dash-chart-sm {
  min-height: 130px;
  padding: 6px 10px 8px;
}

.dash-chart-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-2, #64748b);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.legend-dot.green { background: var(--accent, #16a34a); }
.legend-dot.amber { background: #f59e0b; }

/* ══════════════════════════════════════════════════════
   Top Reps
══════════════════════════════════════════════════════ */

.dash-reps-list {
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dash-rep-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dash-rep-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dash-rep-rank {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-rep-rank.r1 { background: #fde68a; color: #92400e; }
.dash-rep-rank.r2 { background: #e2e8f0; color: #475569; }
.dash-rep-rank.r3 { background: #fed7aa; color: #9a3412; }
.dash-rep-rank.rx { background: var(--bg, #f4f6f9); color: var(--text-2, #64748b); }

.dash-rep-name {
  flex: 1;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-1, #1a1a2e);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-rep-amount {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2, #64748b);
  white-space: nowrap;
}

.dash-rep-bar-wrap {
  height: 4px;
  background: var(--border, #e2e8f0);
  border-radius: 99px;
  overflow: hidden;
  margin-right: 26px;
}

.dash-rep-bar-fill {
  height: 100%;
  background: var(--accent, #16a34a);
  border-radius: 99px;
  transition: width 0.65s cubic-bezier(.4,0,.2,1);
  width: 0;
}

.dash-rep-bar-amber { background: #f59e0b; }

/* ══════════════════════════════════════════════════════
   Donut Ring Card
══════════════════════════════════════════════════════ */

.dash-donut-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 10px 16px;
  gap: 10px;
}

.dash-donut-svg {
  width: 108px;
  height: 108px;
  display: block;
  color: var(--text, #0f172a);
}

.dash-donut-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--text-2, #64748b);
}

.donut-leg {
  display: flex;
  align-items: center;
  gap: 5px;
}

.donut-leg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════
   Forecast Card
══════════════════════════════════════════════════════ */

.dash-forecast-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dash-forecast-projected {
  font-size: 19px;
  font-weight: 700;
  color: var(--text, #0f172a);
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-forecast-label {
  font-size: 11px;
  color: var(--text-2, #94a3b8);
  font-weight: 500;
  margin-bottom: 2px;
}

.dash-forecast-daily {
  font-size: 12px;
  color: var(--text-2, #64748b);
}

.dash-forecast-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.dash-forecast-progress {
  flex: 1;
  height: 6px;
  background: var(--border, #e2e8f0);
  border-radius: 99px;
  overflow: hidden;
}

.dash-forecast-bar {
  height: 100%;
  background: var(--accent, #16a34a);
  border-radius: 99px;
  transition: width 0.7s cubic-bezier(.4,0,.2,1);
  width: 0;
}

.dash-forecast-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent, #16a34a);
  white-space: nowrap;
  min-width: 30px;
  text-align: left;
}

.dash-forecast-foot {
  font-size: 11px;
  color: var(--muted-light, #94a3b8);
  margin-top: 2px;
}

/* ══════════════════════════════════════════════════════
   Unpaid Table
══════════════════════════════════════════════════════ */

.dash-table-wrap {
  overflow-x: auto;
  padding: 0;
}

.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  direction: rtl;
}

.dash-table th {
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2, #64748b);
  background: var(--bg, #f8fafc);
  text-align: right;
  border-bottom: 1px solid var(--border, #e2e8f0);
  white-space: nowrap;
}

.dash-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border, #f1f5f9);
  color: var(--text-1, #1a1a2e);
  vertical-align: middle;
}

.dash-table tbody tr:last-child td { border-bottom: none; }

.dash-table tbody tr:hover td { background: var(--bg, #f8fafc); }

.dash-table-loading {
  text-align: center;
  color: var(--text-2, #94a3b8);
  padding: 24px 14px !important;
}

.dash-inv-amount {
  font-weight: 600;
  color: #dc2626;
}

.dash-inv-date {
  color: var(--text-2, #64748b);
  font-size: 11.5px;
}

.dash-inv-num {
  color: var(--text-2, #64748b);
  font-family: monospace;
  font-size: 11.5px;
}

/* ══════════════════════════════════════════════════════
   Quick Actions
══════════════════════════════════════════════════════ */

.dash-quick-actions {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dash-qa-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--bg, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  text-decoration: none;
  color: var(--text-1, #1a1a2e);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
  cursor: pointer;
}

.dash-qa-btn:hover {
  background: var(--accent-soft, #dcfce7);
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
  transform: translateX(-2px);
}

.dash-qa-icon { font-size: 16px; flex-shrink: 0; }

.dash-qa-text { flex: 1; }

.dash-qa-arrow {
  font-size: 14px;
  opacity: 0.4;
  transition: opacity 0.15s, transform 0.15s;
}

.dash-qa-btn:hover .dash-qa-arrow {
  opacity: 1;
  transform: translateX(-3px);
}

/* ══════════════════════════════════════════════════════
   Dark theme overrides
══════════════════════════════════════════════════════ */

[data-theme="dark"] body {
  background: #111318;
  color: #e2e8f0;
}

[data-theme="dark"] .dash-nav,
[data-theme="dark"] .dash-header {
  background: #1a1f2e;
  border-color: #2d3348;
}

[data-theme="dark"] .dash-kpi-card,
[data-theme="dark"] .dash-card {
  background: #1a1f2e;
  border-color: rgba(255,255,255,.06);
  box-shadow: 0 1px 3px rgba(0,0,0,.2), 0 6px 16px rgba(0,0,0,.15);
}

[data-theme="dark"] .dash-table th {
  background: #131720;
}

[data-theme="dark"] .dash-table tbody tr:hover td {
  background: #131720;
}

[data-theme="dark"] .dash-qa-btn {
  background: #131720;
  border-color: #2d3348;
}

[data-theme="dark"] .dash-skel {
  background: linear-gradient(90deg, #2d3348 25%, #1a1f2e 50%, #2d3348 75%);
  background-size: 200% 100%;
  animation: dash-shimmer 1.4s infinite;
}

/* ══════════════════════════════════════════════════════
   Mobile (< 768px)
══════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .dash-layout {
    grid-template-columns: 1fr;
  }

  .dash-nav {
    position: fixed;
    top: 0;
    right: -220px;
    height: 100vh;
    width: 220px;
    transition: right 0.25s ease;
    z-index: 200;
  }

  .dash-nav.open { right: 0; }

  .dash-mobile-menu-btn { display: flex; }

  .dash-kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .dash-row {
    grid-template-columns: 1fr;
  }

  .dash-mid-row,
  .dash-bot-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1200px) {
  .dash-mid-row {
    grid-template-columns: 1fr 200px;
  }

  .dash-mid-row > .dash-card:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .dash-kpi-strip {
    grid-template-columns: 1fr;
  }
}
