:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1d2320;
  --muted: #69736d;
  --line: #e2e5df;
  --brand: #1f4d3a;
  --brand-soft: #e6efe9;
  --go: #1f7a4d;
  --go-soft: #e3f3ea;
  --slow: #a86a00;
  --slow-soft: #fbf0d9;
  --stop: #b3261e;
  --stop-soft: #fbe5e3;
  --info: #2c5a8c;
  --info-soft: #e5eef8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", "Cairo", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, .tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---- الهيدر ---- */
.top {
  background: var(--brand);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.top-in {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 18px; min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; color: #fff; white-space: nowrap; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: rgba(255,255,255,.82); padding: 6px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }
.nav a.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.who { font-size: 13px; color: rgba(255,255,255,.75); white-space: nowrap; }
.who a { color: #fff; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

/* ---- الفلاتر ---- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 18px;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip:hover { text-decoration: none; border-color: var(--brand); }
.filters .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
input, select, textarea, button { font: inherit; }
input[type=date], input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: #fff; color: var(--ink);
  min-width: 0;
}
input[type=number] { width: 110px; }
textarea { width: 100%; min-height: 60px; }
.btn {
  display: inline-block; border: 0; border-radius: 8px; padding: 7px 16px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.danger { background: transparent; color: var(--stop); border: 1px solid var(--stop); }
.btn.sm { padding: 3px 10px; font-size: 13px; }

/* ---- الكروت ---- */
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .g4, .g2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 14px; }
.section { margin-top: 22px; }

.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; margin: 2px 0; }
.kpi .target { font-size: 12px; color: var(--muted); }
.kpi.go { border-top: 3px solid var(--go); }
.kpi.slow { border-top: 3px solid var(--slow); }
.kpi.stop { border-top: 3px solid var(--stop); }
.kpi.none { border-top: 3px solid var(--line); }
.kpi .bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.kpi .bar span { display: block; height: 100%; background: var(--brand); }

.stat { display: flex; flex-direction: column; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .hint { font-size: 12px; color: var(--muted); }

/* ---- الجداول ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: #fafbf9; }
td.num, th.num { text-align: left; direction: ltr; }
tr.total td { font-weight: 700; background: var(--brand-soft); }
tr.strong td { font-weight: 700; }
tbody tr:hover td { background: #fbfcfa; }
td.wrap-text { white-space: normal; min-width: 220px; }

.money td:first-child { color: var(--ink); }
.neg { color: var(--stop); }
.pos { color: var(--go); }

/* ---- شارات ---- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.go { background: var(--go-soft); color: var(--go); }
.badge.slow { background: var(--slow-soft); color: var(--slow); }
.badge.stop { background: var(--stop-soft); color: var(--stop); }
.badge.info, .badge.none { background: var(--info-soft); color: var(--info); }

/* ---- التنبيهات ---- */
.alerts { display: grid; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff;
}
.alert .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; }
.alert.red { background: var(--stop-soft); border-color: #f0c9c5; }
.alert.red .dot { background: var(--stop); }
.alert.amber { background: var(--slow-soft); border-color: #efd9a8; }
.alert.amber .dot { background: var(--slow); }
.alert.info { background: var(--info-soft); border-color: #c8d9ee; }
.alert.info .dot { background: var(--info); }
.alert .t { font-weight: 700; }
.alert .d { font-size: 13px; color: #3b4440; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; }
.flash.ok { background: var(--go-soft); color: var(--go); }
.flash.err { background: var(--stop-soft); color: var(--stop); }

/* ---- الرحلة ---- */
.funnel { display: grid; gap: 6px; }
.frow { display: grid; grid-template-columns: 170px 1fr 90px; gap: 10px; align-items: center; font-size: 14px; }
.frow .track { display: block; background: #f0f2ee; border-radius: 6px; height: 18px; overflow: hidden; }
.frow .fill { display: block; height: 100%; border-radius: 6px; }
.fill.delivered { background: var(--go); }
.fill.returned { background: var(--stop); }
.fill.shipping, .fill.confirmed { background: #6b9a83; }
.fill.pending { background: #b9c4be; }
.fill.lost_noanswer, .fill.lost_cancel, .fill.lost_stock { background: var(--slow); }
.fill.other { background: #a4aeb8; }
@media (max-width: 600px) { .frow { grid-template-columns: 120px 1fr 70px; font-size: 13px; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 20px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.field input[type=number], .field select { width: 100%; }

.note { background: var(--info-soft); color: #23466e; border-radius: 10px; padding: 10px 14px; font-size: 13.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { margin-inline-start: auto; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 14px; }
.chart-box { position: relative; height: 280px; }

/* ---- الدخول ---- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
}
.login form { width: 100%; max-width: 360px; }
.login .field { margin-bottom: 12px; }
.login input { width: 100%; padding: 10px 12px; }
.login .btn { width: 100%; padding: 10px; }

@media (max-width: 720px) {
  .top-in { gap: 8px; padding-top: 8px; }
  .nav { order: 3; width: 100%; flex: none; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .who { margin-inline-start: auto; }
  .kpi .value { font-size: 24px; }
  .wrap { padding-top: 14px; }
}
