/* ─────────── MediDrop ERP — design tokens & base styles ─────────── */
:root {
  /* Brand */
  --teal: #3FA89A;
  --teal-dark: #2D7268;
  --ink: #1F4D45;
  --teal-light: #EDF7F5;

  /* Warm neutrals (9-step) */
  --n0: #FAFAF8;
  --n50: #F4F4F0;
  --n100: #E8E7E2;
  --n200: #D2D1CA;
  --n300: #A8A79F;
  --n400: #76756D;
  --n500: #53524C;
  --n600: #3A3A35;
  --n700: #131312;

  /* Semantic */
  --success: #1F8A5B;
  --success-soft: #E1F4E9;
  --warn: #B57A14;
  --warn-soft: #FBF3DF;
  --danger: #C0322E;
  --danger-soft: #FBE6E4;
  --info: #2A6FDB;
  --info-soft: #E4ECF9;
  --sale: #E25C2E;
  --sale-soft: #FBE6DA;

  /* Radii */
  --r-chip: 8px;
  --r-card: 16px;
  --r-pill: 9999px;

  /* Type */
  --font-ui: "Inter", -apple-system, system-ui, sans-serif;
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  /* Density (set via tweak) */
  --row-h: 38px;
  --row-py: 8px;
  --body-fs: 13px;

  /* Sidebar tone (set via tweak) */
  --side-bg: #FAFAF8;
  --side-border: #E8E7E2;

  /* Layout */
  --sidebar-w: 232px;
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: var(--body-fs);
  color: var(--n700);
  background: var(--n50);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
}

#root { min-height: 100vh; }

/* ─── Density variants ─── */
.density-compact { --row-h: 32px; --row-py: 6px; --body-fs: 12px; }
.density-regular { --row-h: 38px; --row-py: 8px; --body-fs: 13px; }
.density-comfy   { --row-h: 46px; --row-py: 12px; --body-fs: 14px; }

/* ─── Sidebar tones ─── */
.side-light { --side-bg: #FAFAF8; --side-border: #E8E7E2; }
.side-cream { --side-bg: #F4F4F0; --side-border: #E8E7E2; }
.side-white { --side-bg: #FFFFFF; --side-border: #E8E7E2; }

/* ─── App frame ─── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  min-height: 100vh;
  background: var(--n0);
}
.app.app-collapsed { --sidebar-w: 64px; }
.app.mobile {
  --sidebar-w: 0px;
  grid-template-columns: 1fr;
}

/* ─── Sidebar ─── */
.sidebar {
  background: var(--side-bg);
  border-right: 1px solid var(--side-border);
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; height: var(--header-h);
  border-bottom: 1px solid var(--side-border);
  flex-shrink: 0;
}
.brand-logo {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--teal);
  display: grid; place-items: center;
  box-shadow: 0 1px 2px rgba(63,168,154,.3);
}
.brand-logo svg { color: #fff; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; color: var(--n700); font-size: 14px; }
.brand-sub { font-size: 10px; color: var(--n400); margin-top: -2px; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500; }

.side-nav {
  flex: 1; overflow-y: auto; padding: 10px 8px 16px;
  scrollbar-width: thin; scrollbar-color: var(--n200) transparent;
}
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: var(--n200); border-radius: 3px; }

/* ─── Featured Rx tile (pinned at top of sidebar) ───
   Pharmacist's primary workspace — the verification queue. Pinned so
   it's always visible without scrolling or expanding a nav group. */
.rx-featured {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  margin: 0 4px 12px;
  background: linear-gradient(135deg, var(--danger-soft) 0%, #fff 100%);
  border: 1px solid rgba(192,50,46,0.18);
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
  position: relative;
}
.rx-featured:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(192,50,46,0.10); }
.rx-featured.active { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(192,50,46,0.12); }
.rx-featured-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.rx-featured-icon svg { width: 16px; height: 16px; }
.rx-featured-body { flex: 1; min-width: 0; }
.rx-featured-label {
  font-size: 13px; font-weight: 600; color: var(--n700);
  line-height: 1.1;
}
.rx-featured-sub {
  font-size: 10px; color: var(--n500); margin-top: 2px;
  letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500;
}
.rx-featured-count {
  background: var(--danger);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  min-width: 24px; height: 24px;
  padding: 0 6px;
  border-radius: 9999px;
  display: grid; place-items: center;
  box-shadow: 0 1px 2px rgba(192,50,46,0.3);
}
.rx-featured-count.zero {
  background: var(--n100);
  color: var(--n400);
  box-shadow: none;
}
.app.app-collapsed .rx-featured-body,
.app.app-collapsed .rx-featured-count { display: none; }
.app.app-collapsed .rx-featured { justify-content: center; }

/* ─── Header Rx quick-link chip ─── */
.rx-header-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 11px; font-weight: 600;
  text-decoration: none;
  border: 1px solid rgba(192,50,46,0.15);
  transition: background 0.1s;
}
.rx-header-chip:hover { background: var(--danger); color: #fff; }
.rx-header-chip svg { width: 12px; height: 12px; }
.rx-header-chip .n {
  font-family: var(--font-mono);
  font-weight: 700;
}
.rx-header-chip.zero {
  background: var(--n50);
  color: var(--n500);
  border-color: var(--n100);
}
.rx-header-chip.zero:hover { background: var(--n100); color: var(--n700); }
.rx-header-chip.pulse {
  animation: rxPulse 2s ease-in-out infinite;
}
@keyframes rxPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,50,46,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(192,50,46,0); }
}

.nav-group { margin-bottom: 14px; }
.nav-group-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--n400);
  padding: 6px 12px 4px; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.nav-group-label .chev { transition: transform 0.15s; opacity: 0.5; }
.nav-group.collapsed .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-items { display: none; }

.nav-items { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--n600); font-size: 13px; font-weight: 500;
  cursor: pointer; user-select: none;
  text-decoration: none;
  transition: background 0.1s;
  position: relative;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--n400); }
.nav-item:hover { background: rgba(0,0,0,0.035); color: var(--n700); }
.nav-item:hover svg { color: var(--n500); }
.nav-item.active {
  background: var(--teal-light);
  color: var(--ink);
  font-weight: 600;
}
.nav-item.active svg { color: var(--teal-dark); }
.nav-item .badge {
  margin-left: auto;
  background: var(--teal);
  color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 9999px;
  min-width: 18px; text-align: center;
}
.nav-item.active .badge { background: var(--teal-dark); }
.nav-item .badge-muted { background: var(--n200); color: var(--n600); }
.nav-item.active .badge-muted { background: rgba(45,114,104,0.15); color: var(--teal-dark); }

/* Collapsed sidebar */
.app.app-collapsed .nav-group-label,
.app.app-collapsed .brand-name,
.app.app-collapsed .brand-sub,
.app.app-collapsed .nav-item span:not(.badge),
.app.app-collapsed .side-footer { display: none; }
.app.app-collapsed .nav-item { justify-content: center; padding: 8px; }
.app.app-collapsed .brand { justify-content: center; padding: 14px 8px; }

.side-footer {
  padding: 10px 14px; border-top: 1px solid var(--side-border);
  font-size: 11px; color: var(--n400);
  display: flex; align-items: center; justify-content: space-between;
}
.side-footer .status-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); margin-right: 6px;
  box-shadow: 0 0 0 2px rgba(31,138,91,0.15);
}

/* ─── Main area ─── */
.main { display: flex; flex-direction: column; min-width: 0; }

/* ─── Header ─── */
.header {
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  border-bottom: 1px solid var(--n100);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.header-icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 7px; cursor: pointer;
  color: var(--n500); background: transparent; border: 0;
}
.header-icon-btn:hover { background: var(--n50); color: var(--n700); }
.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--n400); }
.breadcrumbs .crumb { color: var(--n400); cursor: pointer; }
.breadcrumbs .crumb:hover { color: var(--n700); }
.breadcrumbs .crumb.current { color: var(--n700); font-weight: 500; }
.breadcrumbs .sep { color: var(--n200); }

.search {
  flex: 1; max-width: 480px; position: relative;
  display: flex; align-items: center;
}
.search input {
  width: 100%; height: 32px;
  background: var(--n50);
  border: 1px solid var(--n100);
  border-radius: 8px;
  padding: 0 12px 0 32px;
  font: inherit; font-size: 13px;
  color: var(--n700);
  outline: none;
}
.search input::placeholder { color: var(--n300); }
.search input:focus { border-color: var(--teal); background: #fff; box-shadow: 0 0 0 3px rgba(63,168,154,0.12); }
.search .s-icon { position: absolute; left: 10px; color: var(--n300); pointer-events: none; }
.search .kbd {
  position: absolute; right: 8px;
  display: flex; gap: 2px;
  font-family: var(--font-mono); font-size: 10px;
  color: var(--n400);
}
.search .kbd span {
  padding: 1px 5px; background: var(--n0);
  border: 1px solid var(--n100); border-radius: 4px;
  box-shadow: 0 1px 0 var(--n100);
}

.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.shop-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 11px; font-weight: 600;
}
.shop-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 3px rgba(31,138,91,0.18);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(31,138,91,0.18); }
  50% { box-shadow: 0 0 0 5px rgba(31,138,91,0.05); }
}
.shop-pill.closed { background: var(--n100); color: var(--n500); }
.shop-pill.closed .dot { background: var(--n400); animation: none; }

.notif-btn { position: relative; }
.notif-btn .ncount {
  position: absolute; top: 2px; right: 2px;
  background: var(--danger); color: #fff;
  font-size: 9px; font-weight: 700;
  min-width: 14px; height: 14px;
  border-radius: 9999px;
  display: grid; place-items: center;
  padding: 0 3px;
  border: 1.5px solid #fff;
}

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff; display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
}

/* ─── Content area ─── */
.content {
  flex: 1;
  padding: 24px 28px 48px;
  overflow-x: auto;
  background: var(--n0);
}

/* ─── Page heading ─── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-serif);
  font-size: 28px; font-weight: 500; line-height: 1.1;
  color: var(--n700);
  letter-spacing: -0.01em;
  margin: 0;
}
.page-subtitle {
  color: var(--n400); font-size: 13px; margin-top: 4px;
}
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 8px;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; user-select: none;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-ghost { background: transparent; color: var(--n600); border-color: var(--n100); }
.btn-ghost:hover { background: var(--n50); border-color: var(--n200); }
.btn-soft { background: var(--n50); color: var(--n600); }
.btn-soft:hover { background: var(--n100); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn-sm svg { width: 12px; height: 12px; }
.btn-icon { padding: 0; width: 32px; justify-content: center; }
.btn-icon.btn-sm { width: 26px; }

/* ─── KPI cards ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi {
  background: #fff;
  border: 1px solid var(--n100);
  border-radius: var(--r-card);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}
.kpi:hover { border-color: var(--n200); }
.kpi-label {
  font-size: 11px; font-weight: 600;
  color: var(--n400);
  text-transform: uppercase; letter-spacing: 0.06em;
  display: flex; align-items: center; gap: 6px;
}
.kpi-label svg { width: 13px; height: 13px; }
.kpi-value {
  font-family: var(--font-serif);
  font-size: 38px; font-weight: 500;
  color: var(--n700);
  letter-spacing: -0.02em; line-height: 1;
  margin-top: 8px;
  font-feature-settings: "ss01", "tnum";
  font-variant-numeric: tabular-nums;
}
.kpi-value .unit { font-size: 22px; color: var(--n300); margin-right: 2px; font-weight: 400; }
.kpi-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--n400);
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}
.kpi-delta.up { background: var(--success-soft); color: var(--success); }
.kpi-delta.down { background: var(--danger-soft); color: var(--danger); }
.kpi-delta svg { width: 10px; height: 10px; }
.kpi-spark {
  position: absolute; bottom: 0; right: 0;
  width: 100%; height: 36px;
  opacity: 0.18;
  pointer-events: none;
}
.kpi.accent { background: linear-gradient(170deg, #fff 0%, var(--teal-light) 100%); border-color: rgba(63,168,154,0.18); }
.kpi.accent .kpi-value { color: var(--teal-dark); }
.kpi.danger { background: linear-gradient(170deg, #fff 0%, var(--danger-soft) 100%); border-color: rgba(192,50,46,0.15); }
.kpi.danger .kpi-value { color: var(--danger); }

/* KPI style variants */
.kpi-functional .kpi { padding: 14px 16px; }
.kpi-functional .kpi-value { font-family: var(--font-ui); font-size: 24px; font-weight: 600; }
.kpi-functional .kpi-spark { display: none; }

/* ─── Section card ─── */
.card {
  background: #fff;
  border: 1px solid var(--n100);
  border-radius: var(--r-card);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--n50);
}
.card-title {
  font-family: var(--font-serif);
  font-size: 16px; font-weight: 500;
  color: var(--n700);
  letter-spacing: -0.005em;
  margin: 0;
}
.card-sub { color: var(--n400); font-size: 12px; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.card-link {
  color: var(--teal-dark);
  font-size: 12px; font-weight: 500;
  cursor: pointer; text-decoration: none;
}
.card-link:hover { color: var(--ink); }

/* ─── Alert strip ─── */
.alerts-strip {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.alert-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--n100);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  font-size: 12px;
  color: var(--n600);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.alert-chip:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.alert-chip svg { color: var(--warn); width: 14px; height: 14px; }
.alert-chip.danger { border-left-color: var(--danger); }
.alert-chip.danger svg { color: var(--danger); }
.alert-chip.info { border-left-color: var(--info); }
.alert-chip.info svg { color: var(--info); }
.alert-chip strong { font-weight: 600; color: var(--n700); }
.alert-chip .arr { color: var(--n300); margin-left: 4px; }

/* ─── Status pill ─── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill-placed { background: var(--info-soft); color: var(--info); }
.pill-picking { background: var(--warn-soft); color: var(--warn); }
.pill-packed { background: #E7E3F8; color: #5A3DBA; }
.pill-out { background: var(--teal-light); color: var(--teal-dark); }
.pill-delivered { background: var(--success-soft); color: var(--success); }
.pill-cancelled { background: var(--n100); color: var(--n500); }
.pill-pending { background: var(--warn-soft); color: var(--warn); }
.pill-verified { background: var(--success-soft); color: var(--success); }
.pill-rejected { background: var(--danger-soft); color: var(--danger); }
.pill-rx { background: var(--danger-soft); color: var(--danger); }
.pill-paid { background: var(--success-soft); color: var(--success); }
.pill-unpaid { background: var(--n100); color: var(--n500); }
.pill-cod { background: var(--warn-soft); color: var(--warn); }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; }
.tbl {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  font-size: var(--body-fs);
}
.tbl th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--n400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  background: var(--n0);
  border-bottom: 1px solid var(--n100);
  white-space: nowrap;
  position: sticky; top: 0;
  z-index: 1;
}
.tbl td {
  padding: var(--row-py) 12px;
  border-bottom: 1px solid var(--n50);
  vertical-align: middle;
  color: var(--n600);
}
.tbl tr:hover td { background: var(--n0); }
.tbl tr.selected td { background: var(--teal-light); }
.tbl .mono { font-family: var(--font-mono); font-size: calc(var(--body-fs) - 1px); color: var(--n700); }
.tbl .strong { color: var(--n700); font-weight: 500; }
.tbl .muted { color: var(--n400); font-size: 11px; }
.tbl .num { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.tbl tr.click-row { cursor: pointer; }

.checkbox {
  appearance: none;
  width: 14px; height: 14px;
  border: 1.5px solid var(--n200);
  border-radius: 4px;
  cursor: pointer;
  display: inline-grid; place-items: center;
  vertical-align: middle;
  position: relative;
  transition: background 0.1s, border-color 0.1s;
}
.checkbox:hover { border-color: var(--n300); }
.checkbox:checked {
  background: var(--teal);
  border-color: var(--teal);
}
.checkbox:checked::after {
  content: "";
  width: 8px; height: 4px;
  border-left: 1.5px solid #fff;
  border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* ─── Filter bar ─── */
.filter-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--n50);
  background: #fff;
  flex-wrap: wrap;
}
.filter-tabs { display: flex; gap: 2px; padding: 2px; background: var(--n50); border-radius: 8px; }
.filter-tab {
  padding: 4px 10px; border-radius: 6px;
  font-size: 12px; color: var(--n500); font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.filter-tab:hover { color: var(--n700); }
.filter-tab.active {
  background: #fff;
  color: var(--n700);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.filter-tab .count {
  background: var(--n100); color: var(--n500);
  padding: 0 5px; border-radius: 9999px;
  font-size: 10px; font-weight: 600;
  font-family: var(--font-mono);
}
.filter-tab.active .count { background: var(--teal-light); color: var(--teal-dark); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  background: var(--n50);
  border: 1px solid var(--n100);
  border-radius: 8px;
  font-size: 11px;
  color: var(--n600);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--n100); }
.chip svg { width: 11px; height: 11px; color: var(--n400); }
.chip .x { cursor: pointer; color: var(--n400); margin-left: 2px; }
.chip .x:hover { color: var(--n700); }
.chip.active { background: var(--teal-light); border-color: rgba(63,168,154,0.3); color: var(--teal-dark); }

/* ─── Bulk action bar ─── */
.bulk-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--n700);
  color: #fff;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  animation: slideDown 0.18s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.bulk-bar .count {
  background: rgba(255,255,255,0.12);
  padding: 2px 8px; border-radius: 6px;
  font-family: var(--font-mono); font-weight: 600;
}
.bulk-bar .bulk-btns { display: flex; gap: 4px; margin-left: auto; }
.bulk-bar .bulk-btn {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 0;
  padding: 5px 10px;
  font-size: 12px; font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  font-family: inherit;
}
.bulk-bar .bulk-btn:hover { background: rgba(255,255,255,0.16); }
.bulk-bar .bulk-btn svg { width: 12px; height: 12px; }

/* ─── Empty state ─── */
.empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--n400);
}
.empty .empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 12px;
  border-radius: 12px;
  background: var(--n50);
  display: grid; place-items: center;
  color: var(--n300);
}
.empty .empty-icon svg { width: 22px; height: 22px; }
.empty h4 {
  font-family: var(--font-serif);
  margin: 0 0 4px; font-size: 16px; font-weight: 500;
  color: var(--n600);
}
.empty p { margin: 0 0 14px; font-size: 12px; }

/* ─── Timeline ─── */
.timeline {
  padding: 8px 0;
}
/* Today's queue row.
   Was grid-based and several layout bugs ago — when the body column got
   squeezed on narrow cards, long order IDs / customer names spilled into
   the status-pill column and the dot's outer margin pushed it into the
   time + body columns. The whole thing looked "jumbled and overlapping".
   This rewrite uses a single flex row with explicit widths/flex factors
   per child, plus per-line ellipsis truncation, so no element can ever
   visually collide with its neighbour regardless of content length. */
.timeline-row {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  font-size: var(--body-fs);
  border-bottom: 1px solid var(--n50);
  text-decoration: none;
  color: inherit;
  width: 100%;
  box-sizing: border-box;
}
.timeline-row:last-child { border-bottom: none; }
.timeline-row:hover { background: var(--n0); }
.timeline-time {
  flex: 0 0 70px;          /* fixed 70px slot — comfortably fits "12:30 PM" */
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--n400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.timeline-dot {
  flex: 0 0 8px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-light);
}
.timeline-row.delivered .timeline-dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.timeline-row.cancelled .timeline-dot { background: var(--n300); box-shadow: 0 0 0 3px var(--n100); }
.timeline-row.warn .timeline-dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.timeline-body {
  flex: 1 1 auto;          /* takes remaining width, can shrink */
  min-width: 0;            /* MUST be 0 so ellipsis works on flex children */
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
/* Per-line ellipsis. Without nowrap + overflow + ellipsis, a long order ID
   like "APP-12345678 · android" or a long customer name wrapped to a second
   line, squashing the row height and looking jumbled against neighbouring
   rows. */
.timeline-body .id,
.timeline-body .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.timeline-body .id { font-family: var(--font-mono); font-size: 11px; color: var(--n400); }
.timeline-body .name { color: var(--n700); font-weight: 500; }
.timeline-body .name .meta { color: var(--n400); font-weight: 400; }
.timeline-row > .pill { flex: 0 0 auto; }

/* ─── Quick actions ─── */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  padding: 14px 18px;
}
.qa-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--n0);
  border: 1px solid var(--n100);
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px; font-weight: 500;
  color: var(--n700);
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
}
.qa-btn:hover { border-color: var(--teal); background: #fff; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(63,168,154,0.08); }
.qa-btn svg { width: 16px; height: 16px; color: var(--teal-dark); flex-shrink: 0; }
.qa-btn .qa-sub { font-size: 10px; color: var(--n400); font-weight: 400; }

/* ─── Order detail ─── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
}
.detail-col { display: flex; flex-direction: column; gap: 16px; }

.order-banner {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 18px;
  background: linear-gradient(90deg, rgba(63,168,154,0.04) 0%, transparent 100%);
  border: 1px solid var(--n100);
  border-radius: var(--r-card);
}
.order-banner .order-id {
  font-family: var(--font-mono);
  font-size: 18px; font-weight: 600;
  color: var(--n700);
}
.order-banner .order-meta {
  display: flex; align-items: center; gap: 14px;
  margin-left: auto; flex-wrap: wrap;
}
.order-banner .meta-item { font-size: 12px; color: var(--n400); display: flex; align-items: center; gap: 6px; }
.order-banner .meta-item strong { color: var(--n700); font-weight: 500; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 12px; }
.kv dt { color: var(--n400); }
.kv dd { color: var(--n700); margin: 0; font-weight: 500; }
.kv dd.mono { font-family: var(--font-mono); }

.rx-preview {
  background: var(--n50);
  border: 1px dashed var(--n200);
  border-radius: 10px;
  padding: 14px;
  display: flex; gap: 12px; align-items: center;
}
.rx-preview .rx-thumb {
  width: 64px; height: 80px;
  background: repeating-linear-gradient(45deg, var(--n100), var(--n100) 4px, var(--n0) 4px, var(--n0) 8px);
  border: 1px solid var(--n200);
  border-radius: 4px;
  flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--n300);
}
.rx-preview .ocr {
  flex: 1; font-size: 11px; color: var(--n500);
  line-height: 1.5; font-family: var(--font-mono);
}
.rx-preview .ocr strong { color: var(--n700); font-weight: 600; }

/* Audit timeline */
.audit {
  list-style: none; margin: 0; padding: 14px 18px;
  position: relative;
}
.audit::before {
  content: ""; position: absolute;
  left: 26px; top: 18px; bottom: 18px;
  width: 1px; background: var(--n100);
}
.audit li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px; align-items: start;
  padding: 6px 0;
  font-size: 12px;
  position: relative;
}
.audit li .a-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--n200);
  margin-top: 5px; margin-left: 5px;
  z-index: 1; position: relative;
  outline: 3px solid #fff;
}
.audit li.now .a-dot { background: var(--teal); outline-color: var(--teal-light); }
.audit li .a-body strong { color: var(--n700); font-weight: 500; }
.audit li .a-body .who { color: var(--n400); margin-left: 4px; }
.audit li .a-time { color: var(--n300); font-family: var(--font-mono); font-size: 10px; }

/* ─── Login (when in login mode) ─── */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--n0);
}
.login-page .left {
  background: linear-gradient(170deg, var(--teal) 0%, var(--ink) 100%);
  color: #fff;
  padding: 56px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-page .left::before {
  content: ""; position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
  bottom: -200px; right: -150px;
}
.login-page .left::after {
  content: ""; position: absolute;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  top: -80px; left: 80px;
}
.login-page .left-content { position: relative; z-index: 1; }
.login-page .hero-title {
  font-family: var(--font-serif);
  font-size: 56px; line-height: 1.05;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 80px 0 24px;
}
.login-page .hero-title em { font-style: italic; color: rgba(255,255,255,0.7); }
.login-page .hero-sub {
  font-size: 15px; line-height: 1.6;
  color: rgba(255,255,255,0.8);
  max-width: 420px;
}
.login-page .stats {
  display: flex; gap: 32px; position: relative; z-index: 1;
}
.login-page .stat .n {
  font-family: var(--font-serif);
  font-size: 32px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.login-page .stat .l { font-size: 11px; color: rgba(255,255,255,0.6); text-transform: uppercase; letter-spacing: 0.08em; }
.login-page .right {
  padding: 56px;
  display: flex; flex-direction: column; justify-content: center;
}
.login-card { max-width: 360px; width: 100%; margin: 0 auto; }
.login-card h2 { font-family: var(--font-serif); font-size: 28px; margin: 0 0 6px; color: var(--n700); font-weight: 500; letter-spacing: -0.01em; }
.login-card .sub { color: var(--n400); font-size: 13px; margin-bottom: 28px; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 600; color: var(--n500); text-transform: uppercase; letter-spacing: 0.04em; }
.field input {
  height: 38px;
  border: 1px solid var(--n100);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit; font-size: 14px;
  outline: none;
  background: #fff;
}
.field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(63,168,154,0.12); }

/* ─── Notif panel ─── */
.notif-panel {
  position: absolute; top: calc(var(--header-h) - 4px); right: 60px;
  width: 360px; max-width: calc(100vw - 32px);
  background: #fff;
  border: 1px solid var(--n100);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  z-index: 100;
  overflow: hidden;
}
.notif-panel-head { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--n50); }
.notif-panel-head strong { font-size: 13px; }
.notif-panel-head a { font-size: 11px; color: var(--teal-dark); cursor: pointer; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 10px 14px; cursor: pointer; align-items: flex-start; border-bottom: 1px solid var(--n50); }
.notif-item:hover { background: var(--n0); }
.notif-item:last-child { border-bottom: 0; }
.notif-item .ndot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); margin-top: 6px; flex-shrink: 0; }
.notif-item.read .ndot { background: var(--n200); }
.notif-item .ntext { font-size: 12px; color: var(--n700); }
.notif-item .ntext .ntime { color: var(--n400); font-size: 10px; margin-top: 3px; font-family: var(--font-mono); }
.notif-item strong { font-weight: 600; }

/* Mobile preview */
.app.mobile-preview-on {
  display: flex; flex-direction: column;
  background: var(--n50);
  padding: 24px; min-height: 100vh;
  align-items: center; gap: 18px;
}
.app.mobile-preview-on .desktop-area { display: none; }
.mobile-phone {
  width: 390px;
  background: #fff;
  border: 8px solid #131312;
  border-radius: 36px;
  overflow: hidden;
  box-shadow: 0 20px 48px rgba(0,0,0,0.18);
  height: 760px;
  display: flex; flex-direction: column;
}
.mobile-phone .m-status {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 22px 4px;
  font-size: 12px; font-weight: 600;
  color: var(--n700);
}
.mobile-phone .m-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 12px;
  border-bottom: 1px solid var(--n50);
}
.mobile-phone .m-header .m-burger { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; }
.mobile-phone .m-header .m-title { font-family: var(--font-serif); font-size: 17px; font-weight: 500; color: var(--n700); flex: 1; }
.mobile-phone .m-body { flex: 1; overflow-y: auto; padding: 14px; background: var(--n0); }

/* Tasks card (mobile picker) */
.task-card {
  background: #fff;
  border: 1px solid var(--n100);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.task-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.task-card .t-id { font-family: var(--font-mono); font-weight: 600; color: var(--n700); font-size: 13px; }
.task-card .t-items { font-size: 12px; color: var(--n400); margin-bottom: 8px; }
.task-card .t-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 8px; border-top: 1px solid var(--n50); }
.task-card .t-foot .bin { font-family: var(--font-mono); font-size: 11px; color: var(--n500); }
.task-card .t-foot .age { font-size: 11px; color: var(--warn); font-weight: 600; }

/* ─── Misc ─── */
.divider { height: 1px; background: var(--n100); margin: 16px 0; }
.text-muted { color: var(--n400); }
.text-ink { color: var(--ink); }
.text-teal { color: var(--teal-dark); }
.font-mono { font-family: var(--font-mono); }
.font-serif { font-family: var(--font-serif); }

/* selected row checkbox visibility */
.row-check {
  opacity: 0; transition: opacity 0.1s;
}
.tbl tr:hover .row-check,
.tbl tr.selected .row-check,
.tbl tr .row-check:checked { opacity: 1; }
.tbl thead .row-check { opacity: 1; }

/* ─────────────────────────────────────────────────────────────────────
 * Responsive — explicit mobile/tablet rules.
 *
 * The base.html JS has historically toggled the sidebar via inline-style
 * mutation in checkDesktop(). That worked but couldn't address the rest
 * of the chrome — header crowding, table overflow, kpi-grid wrapping,
 * tap-target sizing. The block below picks up where the JS leaves off
 * so the ERP is actually usable on a phone (primary use stays laptop —
 * mobile is a fallback for "I'm at the counter and need to check X").
 * ────────────────────────────────────────────────────────────────── */

/* Tablet (768 – 1023) — sidebar already auto-hides via JS */
@media (max-width: 1023px) {
  .content { padding: 18px; }
  .header { padding: 0 12px; gap: 8px; }
  .breadcrumbs { font-size: 12px; }
  .search { max-width: 320px; }
  /* Hide the heaviest header chrome before we lose it entirely on phone */
  .search .kbd { display: none; }
}

/* Phone (≤ 767) — the real mobile path */
@media (max-width: 767px) {
  :root { --header-h: 52px; }

  /* Header collapse: hide breadcrumbs + global search; keep brand, Rx
     chip, notif bell, avatar. Search re-surfaces via menu drawer if
     the operator wants it. */
  .header {
    padding: 0 10px;
    gap: 6px;
    height: var(--header-h);
  }
  .header .breadcrumbs { display: none; }
  .header .search { display: none; }
  .header .shop-pill { display: none; }     /* status moves to footer */
  .header .header-right { gap: 4px; }
  .header-right .btn-soft span,
  .header-right .switch-user-label { display: none; }
  .rx-header-chip { padding: 4px 8px; font-size: 12px; }
  .rx-header-chip span { display: none; }   /* keep only the icon + count */
  .rx-header-chip .n { display: inline; }

  /* Make tap targets at least 40 px tall */
  .header-icon-btn,
  .notif-btn,
  .btn,
  .nav-item { min-height: 40px; }
  .header-icon-btn { width: 40px; }

  /* Content padding shrinks */
  .content { padding: 12px; }
  .page-title { font-size: 20px; line-height: 1.25; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head .page-actions { width: 100%; flex-wrap: wrap; gap: 6px; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* KPI grid stacks 2-up on phone */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 10px; }

  /* Cards / shadows lighten — phones are battery-sensitive to repaints */
  .card { border-radius: 10px; }
  .card-head { padding: 12px; flex-wrap: wrap; gap: 8px; }
  .card-title { font-size: 14px; }

  /* Tables: scroll horizontally rather than overflow the layout. Wrap
     every .tbl in its existing .table-wrap parent — that's already in
     most templates. For ad-hoc <table> usage, give them a horizontal
     scroll fallback so cells don't get squashed unreadable. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl { min-width: 640px; }
  .tbl th, .tbl td { padding: 8px 10px; font-size: 12px; white-space: nowrap; }

  /* Order detail two-col layout → stack */
  .detail-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .order-banner { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
  .order-banner .order-meta { margin-left: 0; }

  /* Filter tabs scroll horizontally on phone instead of wrapping into
     three messy rows */
  .filter-tabs {
    display: flex; flex-wrap: nowrap;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    gap: 6px; padding-bottom: 4px;
  }
  .filter-tab { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }

  /* Alerts strip stacks */
  .alerts-strip { flex-direction: column; gap: 8px; }
  .alert-chip { width: 100%; }

  /* Sidebar — drawer width fits narrow phones (was 232 px) */
  #sidebar { width: 260px !important; max-width: 80vw; }

  /* Mobile menu button stays visible + tap-sized */
  #mobileMenuBtn { display: grid !important; min-width: 40px; min-height: 40px; }

  /* Modals — eat the whole screen with breathing room. Even legacy
     dialogs that set their own max-width get overridden so they don't
     end up as 600 px wide on a 360 px screen. */
  dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh; max-height: 100vh;
    margin: 0; border-radius: 0;
    overflow-y: auto;
  }
  dialog .p-6, dialog form { padding: 14px !important; }
  dialog h3, dialog .dialog-title { font-size: 16px; }

  /* Quick actions grid: 2-up not 3-up */
  .quick-actions { grid-template-columns: 1fr 1fr; }

  /* Pills wrap nicely */
  .pill { font-size: 11px; padding: 2px 7px; }

  /* Hide non-essential whitespace */
  .side-footer { font-size: 10px; padding: 8px 12px; }

  /* Inputs comfortable to tap — 16 px font prevents iOS auto-zoom */
  input[type="text"], input[type="number"], input[type="tel"],
  input[type="email"], input[type="date"], input[type="month"],
  input[type="datetime-local"], select, textarea {
    font-size: 16px;
  }

  /* Counter sale + similar two-pane layouts already collapse via
     Tailwind. Tighten the right-pane height cap that's set inline. */
  [style*="max-height: calc(100vh - 200px)"] { max-height: none !important; }
}

/* Generic table escape hatch — any <table> without a .table-wrap parent
   still gets a horizontal scroll on phone instead of breaking the layout.
   Wrapping the outer table in display:block + overflow-x is the standard
   mobile responsive-table trick (header/body keep their grid alignment
   because they stay display:table internally). */
@media (max-width: 767px) {
  table:not(.no-mobile-scroll) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100vw;
  }
  table:not(.no-mobile-scroll) thead,
  table:not(.no-mobile-scroll) tbody,
  table:not(.no-mobile-scroll) tfoot {
    display: table;
    min-width: 100%;
  }
  /* Bigger tap targets in tbody rows (avoids overriding compact .pill or
     thermal-receipt-style tables; those use specific selectors). */
  table:not(.no-mobile-scroll) tbody td { padding: 8px 10px; font-size: 12px; }
}

/* Very small phones (≤ 359) — trim further */
@media (max-width: 359px) {
  .page-title { font-size: 18px; }
  .kpi-value { font-size: 18px; }
  .kpi-grid { grid-template-columns: 1fr; }
}

/* Legacy 900 px break preserved (was here pre-mobile-overhaul) */
@media (max-width: 900px) {
  .content { padding: 16px; }
  .page-title { font-size: 22px; }
  .kpi-value { font-size: 30px; }
  .detail-grid { grid-template-columns: 1fr; }
}
