/* CBEX Logistics Design System */
:root {
  --navy-900: #1a2540;
  --navy-800: #223054;
  --navy-700: #2d3e5c;
  --navy-600: #3a4d6e;
  --navy-500: #5a6b86;
  --navy-400: #8594ab;
  --navy-300: #b5bfcf;
  --navy-200: #dde2ea;
  --navy-100: #eef1f6;
  --navy-50:  #f6f8fb;

  --red-600: #c62836;
  --red-500: #e63946;
  --red-400: #ef5d68;
  --red-100: #fde4e6;
  --red-50:  #fef1f2;

  --green-500: #2d9d5f;
  --green-50:  #e8f5ec;
  --amber-500: #e7a02a;
  --amber-50:  #fbf3e2;
  --blue-500:  #2d6fd9;
  --blue-50:   #e6efff;

  --ink: #1a2540;
  --ink-2: #4a5870;
  --ink-3: #7a8699;
  --line: #e5e9f0;
  --line-2: #eef1f6;
  --bg: #f3f5f9;
  --bg-card: #ffffff;

  --shadow-sm: 0 1px 2px rgba(26, 37, 64, 0.04), 0 1px 1px rgba(26, 37, 64, 0.02);
  --shadow-md: 0 4px 12px rgba(26, 37, 64, 0.06), 0 2px 4px rgba(26, 37, 64, 0.04);
  --shadow-lg: 0 12px 28px rgba(26, 37, 64, 0.10), 0 4px 8px rgba(26, 37, 64, 0.04);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --topbar-h: 60px;
  --domainbar-h: 46px;
  --sidebar-w: 276px;
  --sidebar-w-collapsed: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: 'Tajawal', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font-family: inherit; }
svg { flex-shrink: 0; }

/* ============ TOPBAR ============ */
.topbar {
  position: fixed;
  top: 0; right: 0; left: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  gap: 20px;
}
/* Domain strip (second row under topbar) */
.domainbar {
  position: fixed;
  top: var(--topbar-h);
  right: 0; left: 0;
  height: var(--domainbar-h);
  background: var(--navy-900);
  display: flex;
  align-items: center;
  padding: 0 14px;
  z-index: 99;
  overflow-x: auto;
  scrollbar-width: none;
}
.domainbar::-webkit-scrollbar { display: none; }
.domain-tab {
  height: 34px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(255,255,255,0.72);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;
  position: relative;
  transition: all 0.15s;
  flex-shrink: 0;
}
.domain-tab:hover { color: #fff; background: rgba(255,255,255,0.06); }
.domain-tab.active {
  color: #fff;
  background: rgba(255,255,255,0.08);
}
.domain-tab.active::after {
  content: "";
  position: absolute;
  bottom: -10px;
  right: 20%; left: 20%;
  height: 3px;
  background: var(--red-500);
  border-radius: 3px 3px 0 0;
}
.domain-tab .d-badge {
  background: var(--red-500);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}
.tb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: calc(var(--sidebar-w) - 20px);
  padding-left: 16px;
  border-left: 1px solid var(--line-2);
  height: 100%;
}
.tb-brand .logo-mark {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--navy-700);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  position: relative;
  overflow: hidden;
}
.tb-brand .logo-mark::after {
  content: "";
  position: absolute;
  bottom: 6px;
  right: 6px; left: 6px;
  height: 2px;
  background: var(--red-500);
  border-radius: 2px;
}
.tb-brand .brand-text { line-height: 1.1; }
.tb-brand .brand-name { font-weight: 800; font-size: 15px; color: var(--navy-900); letter-spacing: 0.2px; }
.tb-brand .brand-sub { font-size: 10.5px; color: var(--ink-3); font-weight: 500; }

.tb-search {
  flex: 1;
  max-width: 520px;
  position: relative;
}
.tb-search input {
  width: 100%;
  height: 38px;
  padding: 0 38px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--navy-50);
  outline: none;
  font-size: 13.5px;
  transition: all 0.15s;
}
.tb-search input:focus {
  background: #fff;
  border-color: var(--navy-400);
  box-shadow: 0 0 0 3px rgba(45, 62, 92, 0.08);
}
.tb-search .icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
}
.tb-search .kbd {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--ink-3);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, monospace;
}

.tb-actions { display: flex; align-items: center; gap: 4px; margin-right: auto; }
.tb-btn {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--navy-600);
  transition: background 0.15s;
}
.tb-btn:hover { background: var(--navy-50); color: var(--navy-800); }
.tb-btn .dot {
  position: absolute;
  top: 8px; left: 8px;
  width: 8px; height: 8px;
  background: var(--red-500);
  border: 2px solid #fff;
  border-radius: 50%;
}
.tb-new {
  height: 38px;
  padding: 0 16px;
  background: var(--navy-700);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s;
}
.tb-new:hover { background: var(--navy-900); }
.tb-divider { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }

.tb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 10px;
  transition: background 0.15s;
}
.tb-user:hover { background: var(--navy-50); }
.tb-user .avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--navy-700), var(--navy-500));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}
.tb-user .u-name { font-weight: 600; font-size: 13px; color: var(--navy-900); line-height: 1.1; }
.tb-user .u-role { font-size: 11px; color: var(--ink-3); }

/* ============ SIDEBAR ============ */
.sidebar {
  position: fixed;
  top: calc(var(--topbar-h) + var(--domainbar-h));
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.sb-workspace {
  padding: 14px 14px;
  margin: 14px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--navy-800), var(--navy-700));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.sb-workspace::before {
  content: "";
  position: absolute;
  right: -20px; top: -20px;
  width: 80px; height: 80px;
  background: radial-gradient(circle, rgba(230,57,70,0.3), transparent 70%);
  border-radius: 50%;
}
.sb-workspace .ws-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--red-500);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.sb-workspace .ws-text { position: relative; z-index: 1; }
.sb-workspace .ws-name { font-weight: 700; font-size: 14px; }
.sb-workspace .ws-sub { font-size: 11px; opacity: 0.75; }

.sb-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--navy-200) transparent;
}
.sb-scroll::-webkit-scrollbar { width: 6px; }
.sb-scroll::-webkit-scrollbar-thumb { background: var(--navy-200); border-radius: 6px; }

.sb-section-title {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 14px 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sb-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-2);
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--ink-2);
  font-weight: 500;
  margin-bottom: 1px;
  position: relative;
  transition: all 0.12s;
  cursor: pointer;
}
.sb-item:hover { background: var(--navy-50); color: var(--navy-900); }
.sb-item.active {
  background: var(--navy-50);
  color: var(--navy-900);
  font-weight: 700;
}
.sb-item.active::before {
  content: "";
  position: absolute;
  right: -10px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--red-500);
  border-radius: 3px 0 0 3px;
}
.sb-item .ico { color: var(--navy-500); flex-shrink: 0; }
.sb-item.active .ico { color: var(--red-500); }
.sb-item .label { flex: 1; }
.sb-item .badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--navy-100);
  color: var(--navy-800);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sb-item .badge.red { background: var(--red-500); color: #fff; }
.sb-item .badge.amber { background: var(--amber-50); color: var(--amber-500); }

.sb-footer {
  border-top: 1px solid var(--line-2);
  padding: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.sb-mini-btn {
  flex: 1;
  height: 36px;
  border-radius: 9px;
  background: var(--navy-50);
  color: var(--navy-700);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}
.sb-mini-btn:hover { background: var(--navy-100); }

/* ============ MAIN ============ */
.main {
  margin-top: calc(var(--topbar-h) + var(--domainbar-h));
  margin-right: var(--sidebar-w);
  padding: 24px 28px 40px;
  min-height: calc(100vh - var(--topbar-h) - var(--domainbar-h));
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 16px;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.breadcrumb .sep { opacity: 0.5; }
.breadcrumb .cur { color: var(--navy-800); font-weight: 600; }
.page-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--navy-900);
  letter-spacing: -0.3px;
}
.page-title .date {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  margin-right: 10px;
}
.page-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary { background: var(--navy-700); color: #fff; }
.btn-primary:hover { background: var(--navy-900); }
.btn-danger { background: var(--red-500); color: #fff; }
.btn-danger:hover { background: var(--red-600); }
.btn-ghost { background: #fff; color: var(--navy-700); border-color: var(--line); }
.btn-ghost:hover { background: var(--navy-50); border-color: var(--navy-300); }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

/* Generic grid utilities (used by sub-pages) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-2-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.kpi .row1 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.kpi .kpi-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kpi.blue .kpi-icon { background: var(--blue-50); color: var(--blue-500); }
.kpi.green .kpi-icon { background: var(--green-50); color: var(--green-500); }
.kpi.amber .kpi-icon { background: var(--amber-50); color: var(--amber-500); }
.kpi.red .kpi-icon { background: var(--red-50); color: var(--red-500); }
.kpi .trend {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.kpi .trend.up { background: var(--green-50); color: var(--green-500); }
.kpi .trend.down { background: var(--red-50); color: var(--red-500); }
.kpi .label { font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 800; color: var(--navy-900); letter-spacing: -0.5px; margin-top: 2px; line-height: 1.1; }
.kpi .sub { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }

/* Layout grid */
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* Cards */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-2);
}
.card-title { font-size: 15px; font-weight: 700; color: var(--navy-900); }
.card-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--navy-50);
  padding: 3px;
  border-radius: 8px;
  align-items: center;
}
/* Style both <button> and <a> so list-page filters (which navigate via
   href to preserve back/forward + bookmarkable URLs) get the same pill
   treatment as in-page tab toggles. */
.tabs button,
.tabs a {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.tabs button:hover,
.tabs a:hover {
  background: rgba(255, 255, 255, 0.55);
  color: var(--navy-900);
}
.tabs button.on,
.tabs a.on {
  background: #fff;
  color: var(--navy-900);
  box-shadow: var(--shadow-sm);
}
/* Count pill after the label, e.g. "نشطون 23". Muted by default,
   inherits the navy ink when its parent chip is active. */
.tabs .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: rgba(11, 35, 66, 0.08);
  color: var(--ink-2);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tabs button.on .tab-count,
.tabs a.on .tab-count {
  background: var(--navy-50);
  color: var(--navy-900);
}

/* Table */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: right;
  padding: 12px 18px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-3);
  background: var(--navy-50);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--line-2);
}
.tbl td {
  padding: 14px 18px;
  font-size: 13px;
  color: var(--ink);
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; transition: background 0.1s; }
.tbl tr.clickable:hover { background: var(--navy-50); }
.tbl .track-id { font-family: ui-monospace, 'Courier New', monospace; font-weight: 700; color: var(--navy-900); font-size: 12.5px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}
.status .s-dot { width: 6px; height: 6px; border-radius: 50%; }
.status.delivered { background: var(--green-50); color: var(--green-500); }
.status.delivered .s-dot { background: var(--green-500); }
.status.in-transit { background: var(--blue-50); color: var(--blue-500); }
.status.in-transit .s-dot { background: var(--blue-500); }
.status.pending { background: var(--amber-50); color: var(--amber-500); }
.status.pending .s-dot { background: var(--amber-500); }
.status.cancelled { background: var(--red-50); color: var(--red-500); }
.status.cancelled .s-dot { background: var(--red-500); }

/* Timeline / activity */
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  right: 15px;
  top: 36px;
  bottom: -6px;
  width: 2px;
  background: var(--line);
}
.timeline-item .tl-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--navy-50);
  color: var(--navy-600);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.timeline-item.done .tl-dot { background: var(--green-500); color: #fff; box-shadow: 0 0 0 1px var(--green-500); }
.timeline-item.active .tl-dot { background: var(--red-500); color: #fff; box-shadow: 0 0 0 1px var(--red-500); }
.timeline-item .tl-title { font-weight: 700; font-size: 13px; color: var(--navy-900); }
.timeline-item .tl-meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.timeline-item .tl-desc { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }

/* Mini map */
.mini-map {
  position: relative;
  width: 100%;
  height: 280px;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 30% 40%, rgba(45,111,217,0.08), transparent 40%),
    radial-gradient(circle at 70% 60%, rgba(230,57,70,0.08), transparent 40%),
    linear-gradient(180deg, #f5f7fb, #eef2f8);
  overflow: hidden;
  border: 1px solid var(--line);
}
.mini-map .grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--navy-200) 1px, transparent 1px),
    linear-gradient(90deg, var(--navy-200) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.35;
}
.map-pin {
  position: absolute;
  transform: translate(50%, -50%);
  width: 26px; height: 26px;
  background: var(--red-500);
  border-radius: 50% 50% 50% 0;
  transform: translate(50%, -100%) rotate(-45deg);
  box-shadow: 0 4px 10px rgba(230,57,70,0.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.map-pin::after {
  content: "";
  width: 10px; height: 10px;
  background: #fff;
  border-radius: 50%;
}
.map-pin.navy { background: var(--navy-700); box-shadow: 0 4px 10px rgba(45,62,92,0.4); }
.map-pulse {
  position: absolute;
  transform: translate(50%, -50%);
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(230, 57, 70, 0.2);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { transform: translate(50%, -50%) scale(1); opacity: 0.7; }
  50% { transform: translate(50%, -50%) scale(1.6); opacity: 0; }
}

.route-line {
  position: absolute;
  stroke: var(--navy-700);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
  fill: none;
  animation: dash 20s linear infinite;
}
@keyframes dash { to { stroke-dashoffset: -200; } }

/* Fleet card */
.fleet-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  transition: all 0.15s;
}
.fleet-card:hover { border-color: var(--navy-300); background: var(--navy-50); }
.fleet-card .truck-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--navy-50);
  color: var(--navy-700);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Chart */
.chart-wrap { height: 240px; position: relative; }

/* Sidebar collapsed */
body.sb-collapsed { --sidebar-w: var(--sidebar-w-collapsed); }
body.sb-collapsed .tb-brand { min-width: calc(var(--sidebar-w-collapsed) - 20px); }
body.sb-collapsed .tb-brand .brand-text { display: none; }
body.sb-collapsed .sb-workspace .ws-text,
body.sb-collapsed .sb-section-title,
body.sb-collapsed .sb-item .label,
body.sb-collapsed .sb-item .badge,
body.sb-collapsed .sb-mini-btn span { display: none; }
body.sb-collapsed .sb-workspace { justify-content: center; padding: 10px; }
body.sb-collapsed .sb-item { justify-content: center; padding: 11px; }
body.sb-collapsed .sb-item.active::before { right: -5px; }
body.sb-collapsed .sb-section-title { padding: 10px 0 4px; justify-content: center; }
body.sb-collapsed .sb-section-title::after { display: none; }

/* Responsive */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2-3-1 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); transition: transform 0.2s; }
  body.sb-open .sidebar { transform: translateX(0); }
  .main { margin-right: 0; padding: 16px; }
  .tb-brand { min-width: auto; border-left: none; }
  .tb-search { display: none; }
}

/* Hide elements based on page */
.page-view { display: none; }
.page-view.active { display: block; }

/* ============================================
   FORM SYSTEM — Professional inputs & fields
   ============================================ */

/* Field wrapper */
.fform-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fform-field > label,
.fform-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.1px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fform-label .req { color: var(--red-500); font-weight: 800; }
.fform-label .hint {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  margin-inline-start: auto;
}

/* Base input class — applied via .fld */
.fld,
input.fld,
textarea.fld,
select.fld {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}
textarea.fld {
  height: auto;
  min-height: 80px;
  padding: 12px 14px;
  line-height: 1.6;
  resize: vertical;
}
.fld::placeholder {
  color: #b4bdca;
  font-weight: 400;
}
.fld:hover:not(:disabled):not(:focus) {
  border-color: #ccd4e0;
  background: var(--navy-50);
}
.fld:focus {
  border-color: var(--navy-700);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(26, 37, 64, 0.08);
}
.fld:disabled {
  background: var(--navy-50);
  color: var(--ink-3);
  cursor: not-allowed;
}

/* Select — custom chevron (RTL: chevron on LEFT side) */
select.fld {
  padding-inline-end: 14px;
  padding-inline-start: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8699' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  cursor: pointer;
}
[dir="rtl"] select.fld { background-position: left 14px center; }

/* Date / time inputs */
input.fld[type="date"],
input.fld[type="time"],
input.fld[type="datetime-local"] {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
}
input.fld[type="date"]::-webkit-calendar-picker-indicator,
input.fld[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.55;
  filter: invert(30%);
}
input.fld[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Number without spin buttons */
input.fld[type="number"]::-webkit-outer-spin-button,
input.fld[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.fld[type="number"] { -moz-appearance: textfield; }

/* Prefix/suffix wrapper (e.g., currency, unit) */
.fld-group {
  position: relative;
  display: flex;
  align-items: center;
}
.fld-group .fld { padding-inline-end: 52px; }
.fld-group .fld-suffix {
  position: absolute;
  inset-inline-end: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-inline-start: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  background: var(--navy-50);
  border-radius: 0 var(--radius) var(--radius) 0;
}
[dir="rtl"] .fld-group .fld-suffix {
  border-radius: var(--radius) 0 0 var(--radius);
}
.fld-group .fld-prefix-icon {
  position: absolute;
  inset-inline-start: 12px;
  color: var(--ink-3);
  pointer-events: none;
  display: flex;
}
.fld-group:has(.fld-prefix-icon) .fld { padding-inline-start: 40px; }

/* Small helper text below a field */
.fform-help {
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.5;
}
.fform-help.err { color: var(--red-500); font-weight: 600; }

/* Section within a form card */
.form-section {
  padding: 22px 24px;
}
.form-section + .form-section {
  border-top: 1px solid var(--line-2);
}
.form-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.form-section-head .ico {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--navy-50);
  color: var(--navy-700);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.form-section-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--navy-900);
  letter-spacing: -0.1px;
}
.form-section-sub {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 1px;
  font-weight: 500;
}

/* Grid for form rows */
.fgrid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.fgrid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px 18px; }
.fgrid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px 18px; }
.fgrid-full { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .fgrid-2, .fgrid-3, .fgrid-4 { grid-template-columns: 1fr; }
}

/* Segmented control (for type pickers) */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--navy-50);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  gap: 2px;
  width: 100%;
}
.seg > button {
  flex: 1;
  height: 34px;
  padding: 0 12px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.seg > button:hover { color: var(--navy-900); }
.seg > button.on {
  background: #fff;
  color: var(--navy-900);
  box-shadow: 0 1px 3px rgba(26,37,64,0.08), 0 0 0 1px var(--line);
  font-weight: 700;
}

/* Choice cards (big radio-style picker) */
.choice-grid {
  display: grid;
  gap: 12px;
}
.choice-card {
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  position: relative;
}
.choice-card:hover {
  border-color: var(--navy-300, #ccd4e0);
  background: var(--navy-50);
}
.choice-card.on {
  border-color: var(--navy-700);
  background: linear-gradient(180deg, rgba(45,111,217,0.05), rgba(45,111,217,0.02));
  box-shadow: 0 2px 8px rgba(26,37,64,0.06);
}
.choice-card.on::after {
  content: '';
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--navy-700) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/10px no-repeat;
}

/* File upload row */
.upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: #fafbfd;
  transition: all 0.15s;
}
.upload-row + .upload-row { margin-top: 10px; }
.upload-row:hover { border-color: var(--navy-300, #b4bdca); background: var(--navy-50); }
.upload-row.done {
  border-style: solid;
  border-color: var(--green-500);
  background: rgba(16, 185, 129, 0.04);
}
.upload-row .ur-ico {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--navy-700);
  flex-shrink: 0;
}
.upload-row.done .ur-ico { background: var(--green-500); color: #fff; border-color: var(--green-500); }
.upload-row .ur-meta { flex: 1; padding: 0 12px; }
.upload-row .ur-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.upload-row .ur-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; }

/* Sticky form footer bar for wizards */
.form-foot {
  position: sticky;
  bottom: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -2px 12px rgba(26,37,64,0.04);
  z-index: 5;
}

/* Stepper (wizard) */
.stepper {
  display: flex;
  align-items: center;
  padding: 22px 26px;
}
.stepper .step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.stepper .step-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink-3);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
  transition: all 0.25s;
}
.stepper .step.done .step-num { background: var(--green-500); border-color: var(--green-500); color: #fff; }
.stepper .step.on .step-num {
  background: var(--navy-900);
  border-color: var(--navy-900);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(26,37,64,0.12);
}
.stepper .step-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  white-space: nowrap;
}
.stepper .step.on .step-label { color: var(--navy-900); font-weight: 800; }
.stepper .step.done .step-label { color: var(--ink); font-weight: 700; }
.stepper .step-line {
  flex: 1;
  height: 2px;
  background: var(--line);
  margin: 0 14px;
  position: relative;
  overflow: hidden;
  border-radius: 2px;
}
.stepper .step-line.done { background: var(--green-500); }

/* ============================================
   FIDELITY ADDITIONS — round-2 design pass
   These classes are referenced across the surface
   (filter pills, extra status variants, icon-only
   buttons, additional KPI hue) but were missing
   from the original port — Blades were faking them
   with inline styles. Defining them here makes the
   markup match the JSX classes 1:1.
   ============================================ */

/* Filter chip (pill-shaped, used for type/status filters on list pages) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.chip:hover {
  background: var(--navy-50);
  border-color: var(--navy-300);
  color: var(--navy-900);
}
.chip.on,
.chip.chip-active {
  background: var(--navy-900);
  border-color: var(--navy-900);
  color: #fff;
  font-weight: 700;
}
.chip.on:hover,
.chip.chip-active:hover {
  background: var(--navy-800);
  border-color: var(--navy-800);
  color: #fff;
}
.chip.red.on   { background: var(--red-500);   border-color: var(--red-500); }
.chip.green.on { background: var(--green-500); border-color: var(--green-500); }
.chip.amber.on { background: var(--amber-500); border-color: var(--amber-500); }
.chip.blue.on  { background: var(--blue-500);  border-color: var(--blue-500); }

/* Additional status pill variants (returned / draft / paid / picked) */
.status.returned {
  background: rgba(139,92,246,0.10);
  color: #7c3aed;
}
.status.returned .s-dot { background: #7c3aed; }
.status.draft {
  background: var(--navy-100);
  color: var(--navy-700);
}
.status.draft .s-dot { background: var(--navy-500); }
.status.paid {
  background: var(--green-50);
  color: var(--green-500);
}
.status.paid .s-dot { background: var(--green-500); }
.status.unpaid {
  background: var(--red-50);
  color: var(--red-500);
}
.status.unpaid .s-dot { background: var(--red-500); }
.status.picked {
  background: var(--blue-50);
  color: var(--blue-500);
}
.status.picked .s-dot { background: var(--blue-500); }
.status.exception {
  background: var(--red-50);
  color: var(--red-500);
}
.status.exception .s-dot { background: var(--red-500); }

/* Violet KPI variant — kept consistent with the blue/green/amber/red
   palette above. Uses a solid pastel background (Tailwind violet-50)
   instead of the previous translucent rgba so the icon tone matches
   the saturation of the sibling cards on the business entity-detail
   KPI strip (and any other violet-coded KPI). */
.kpi.violet .kpi-icon {
  background: #f5f3ff;
  color: #7c3aed;
}

/* Icon-only ghost button — square, neutral, used in toolbars / row actions */
.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy-700);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover {
  background: var(--navy-50);
  border-color: var(--navy-300);
  color: var(--navy-900);
}

/* Make `.btn-ghost` look right when used as `<a>` (no border-collapsing) */
a.btn,
a.btn-ghost,
a.btn-primary,
a.btn-danger,
a.btn-icon {
  text-decoration: none;
  vertical-align: middle;
}

/* Tighter spacing between sequential `.btn` elements in `.page-actions` */
.page-actions > .btn + .btn,
.page-actions > a.btn + .btn,
.page-actions > .btn + a.btn { margin-inline-start: 0; }

/* Make sure inline SVG icons inside .btn / .chip / .status sit on the
   text baseline cleanly (was visibly offset on long Arabic labels) */
.btn svg,
.chip svg,
.status svg,
.btn-icon svg { display: inline-block; vertical-align: middle; }

/* Misc fallback variables that some Blades reference inline. Map them
   to existing tokens so legacy inline styles render correctly without
   touching the markup. */
:root {
  --bg-0: #ffffff;
  --bg-1: var(--navy-50);
  --ink-1: var(--ink-2);
  --gray-50:  var(--navy-50);
  --gray-100: var(--navy-100);
  --gray-200: var(--navy-200);
  --gray-300: var(--navy-300);
}


