:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e7eaf3;
  --blue: #2f6bff;
  --blue-soft: #e8efff;
  --green: #12b76a;
  --amber: #f79009;
  --red: #f04438;
  --violet: #7a5af8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 32px -18px rgba(16, 24, 40, .25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }
p { margin: 0; }
button, input, select { font-family: inherit; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: #0f1729;
  color: #cfd6e6;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--violet));
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 20px;
}
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand span { font-size: 12px; color: #8c98b4; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: #b7c0d6; text-decoration: none; font-size: 14.5px;
  transition: .18s;
}
.sidebar nav a:hover { background: #1a2338; color: #fff; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.ic { font-size: 15px; }
.side-note {
  margin-top: auto; background: #1a2338; border-radius: 12px;
  padding: 14px; font-size: 12.5px; color: #98a3bd;
}
.side-note strong { color: #fff; display: block; margin-bottom: 4px; font-size: 13px; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 26px 30px 40px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.topbar h1 { font-size: 24px; }
.topbar p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer; transition: .15s;
}
.seg button.on { background: var(--blue); color: #fff; font-weight: 600; }
.btn-ghost {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; cursor: pointer; transition: .15s;
}
.btn-ghost:hover { background: var(--blue-soft); border-color: #cddcff; color: var(--blue); }

/* ---------- KPIs ---------- */
.kpis {
  display: grid; gap: 16px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.kpi .foot { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.chip { padding: 3px 8px; border-radius: 20px; font-weight: 600; font-size: 12px; }
.chip.up { background: #e7f7ef; color: var(--green); }
.chip.down { background: #feecea; color: var(--red); }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-head h2 { font-size: 16.5px; }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 3px; }
.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.blue { background: var(--blue); }
.dot.faint { background: #cbd5e6; margin-right: 8px; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { flex: 0 0 190px; max-width: 190px; }
.cat-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 160px; display: grid; gap: 11px; }
.cat-legend li { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.cat-legend .nm { flex: 1; color: #344054; }
.cat-legend .vl { font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-legend .pc { color: var(--muted); font-size: 12px; width: 42px; text-align: left; }

/* top products */
.top-products { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.top-products li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13.5px; }
.top-products .nm { font-weight: 600; }
.top-products .vl { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 7px; background: #eef1f8; border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--blue), var(--violet)); }

/* ---------- Table ---------- */
.table-tools { display: flex; gap: 9px; flex-wrap: wrap; }
.table-tools input, .table-tools select {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-size: 13px; background: #fff; color: var(--ink); outline: none;
}
.table-tools input { min-width: 230px; }
.table-tools input:focus, .table-tools select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
thead th {
  text-align: right; color: var(--muted); font-weight: 600; font-size: 12.5px;
  padding: 10px 12px; background: #f8f9fc; border-bottom: 1px solid var(--line);
}
thead th:first-child { border-radius: 0 10px 10px 0; }
thead th:last-child { border-radius: 10px 0 0 10px; }
tbody td { padding: 13px 12px; border-bottom: 1px solid #f0f2f8; }
tbody tr:hover { background: #fafbff; }
td.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.cust { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.mono { font-variant-numeric: tabular-nums; color: var(--muted); }
.status { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-done { background: #e7f7ef; color: #067647; }
.s-ship { background: #e8efff; color: #2b52c9; }
.s-wait { background: #fff4e5; color: #b54708; }
.s-cancel { background: #feecea; color: #b42318; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; }
.table-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding-top: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px 0 0; }

/* ---------- Chart bits ---------- */
.grid-line { stroke: #eceff6; stroke-width: 1; }
.axis-text { fill: #98a2b3; font-size: 11px; }
.area-fill { fill: url(#revGrad); }
.line-path { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.avg-line { stroke: #cbd5e6; stroke-width: 1.5; stroke-dasharray: 5 5; }
.pt { fill: #fff; stroke: var(--blue); stroke-width: 2.5; opacity: 0; transition: opacity .15s; }
.pt.show { opacity: 1; }
.hot { fill: transparent; cursor: pointer; }
.bar-rect { fill: #cddcff; transition: fill .15s; cursor: pointer; }
.bar-rect:hover, .bar-rect.hot-on { fill: var(--blue); }
.arc { transition: opacity .15s; cursor: pointer; }
.arc:hover { opacity: .82; }
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: #0f1729; color: #fff; padding: 8px 11px; border-radius: 9px;
  font-size: 12.5px; line-height: 1.6; box-shadow: 0 10px 25px -10px rgba(0,0,0,.5);
  transform: translate(-50%, -115%); white-space: nowrap;
}
.tooltip b { font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 14px;
    padding: 12px 16px; overflow-x: auto;
  }
  .sidebar nav { flex-direction: row; gap: 6px; }
  .sidebar nav a { padding: 8px 11px; white-space: nowrap; font-size: 13px; }
  .side-note { display: none; }
  .brand span { display: none; }
  .main { padding: 18px 16px 30px; }
  .topbar h1 { font-size: 20px; }
  .table-tools input { min-width: 0; flex: 1; }
  .table-tools { width: 100%; }
  .donut { margin: 0 auto; }
}
@media (max-width: 620px) {
  /* على الموبايل نخفي عمودي المنتج والتاريخ عشان الجدول يظهر كامل بدون سحب */
  table { min-width: 0; font-size: 12.5px; }
  thead th:nth-child(3), tbody td:nth-child(3),
  thead th:nth-child(4), tbody td:nth-child(4) { display: none; }
  tbody td { padding: 11px 8px; }
  thead th { padding: 9px 8px; }
  .avatar { width: 26px; height: 26px; font-size: 11px; }
}
