@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;900&display=swap');

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #6366f1;
  --primary-dark:   #4f46e5;
  --primary-soft:   #e0e7ff;
  --primary-light:  rgba(99,102,241,.08);
  --bg:             #f5f7ff;
  --card:           #ffffff;
  --border:         #e8eaf6;
  --text:           #1e1b4b;
  --text-secondary: #7c7ca8;
  --shadow-sm:      0 1px 4px rgba(99,102,241,.07), 0 0 0 1px rgba(99,102,241,.05);
  --shadow-md:      0 4px 16px rgba(99,102,241,.10), 0 1px 4px rgba(99,102,241,.06);
  --shadow-lg:      0 12px 40px rgba(99,102,241,.14), 0 2px 8px rgba(99,102,241,.08);
  --sidebar-w:      244px;
  --topbar-h:       58px;
  --danger:         #f43f5e;
  --success:        #10b981;
  --warning:        #f59e0b;
  --radius:         14px;
  --radius-sm:      9px;
  --radius-lg:      18px;
  --transition:     .18s cubic-bezier(.4,0,.2,1);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  line-height: 1.6;
}

/* ── App Shell ────────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  /* Solid background instead of blur — "backdrop-filter" on a sticky
     element is a known Chromium/Windows GPU-compositing bug: it can leave
     a stuck blurred "ghost" rectangle over page content while scrolling,
     especially on some Intel/integrated GPUs. */
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 14px;
  box-shadow: 0 1px 8px rgba(99,102,241,.06);
}

.brand {
  font-size: 1.18rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: .01em;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.top-actions .item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: .72rem;
  line-height: 1.2;
  color: var(--text-secondary);
}
.top-actions .item span:last-child {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text);
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}
.icon-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ── Layout ───────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition);
  box-shadow: -2px 0 12px rgba(99,102,241,.04);
}

.sidebar.collapsed { width: 58px; }
.sidebar.collapsed .sidebar-header .title,
.sidebar.collapsed .nav-item span:not(.icon),
.sidebar.collapsed .nav-group-header span:not(.icon):not(.nav-arrow),
.sidebar.collapsed .nav-group-header .nav-arrow,
.sidebar.collapsed .nav-group-items { display: none; }
.sidebar.collapsed .nav-item,
.sidebar.collapsed .nav-group-header { justify-content: center; padding: 10px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-header .title { font-weight: 700; font-size: .84rem; color: var(--text-secondary); letter-spacing: .04em; text-transform: uppercase; }

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-secondary);
  padding: 4px 7px;
  border-radius: 8px;
  line-height: 1;
  transition: all var(--transition);
}
.sidebar-toggle:hover { background: var(--primary-soft); color: var(--primary); }

/* ── Nav ──────────────────────────────────────────────────── */
.nav { padding: 10px 6px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: .87rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 10px;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: right;
}
.nav-item:hover  { background: var(--primary-light); color: var(--primary); transform: translateX(-2px); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-item .icon  { font-size: 1.05rem; flex-shrink: 0; width: 22px; text-align: center; }
.nav-sub { padding: 7px 12px 7px 18px; font-size: .83rem; }

.nav-group { margin: 0 2px; }
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: .87rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 10px;
  transition: all var(--transition);
  user-select: none;
}
.nav-group-header:hover { background: var(--primary-light); color: var(--primary); }
.nav-group-header .icon { font-size: 1.05rem; flex-shrink: 0; width: 22px; text-align: center; }
.nav-group-header span:nth-child(2) { flex: 1; }
.nav-arrow { font-size: .8rem; transition: transform .2s; display: inline-block; }
.nav-group-header.open .nav-arrow { transform: rotate(-90deg); }

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-right: 8px;
  border-right: 2px solid transparent;
  margin-right: 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s ease, margin .22s ease, border-color .22s ease;
}
.nav-group-items.open {
  max-height: 400px;
  border-right-color: var(--primary-soft);
  margin-top: 2px;
  margin-bottom: 4px;
}

/* ── Content ──────────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 22px 26px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* The page-enter fade/slide animation that used to live here was removed —
   it caused two separate rendering bugs (a dropdown trapped behind a later
   sibling card via a stacking context leak, and a suspected ghost/blur
   artifact tied to elements re-entering the DOM mid-session). It was purely
   decorative, so it's not worth carrying that risk. */

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

/* ── Page title ───────────────────────────────────────────── */
.page-title    { font-size: 1.28rem; font-weight: 900; color: var(--text); }
.page-subtitle { font-size: .84rem; color: var(--text-secondary); margin-top: 3px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-danger, .btn-daftra {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.30);
}
.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,.40);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-secondary:active { transform: translateY(0); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(244,63,94,.25);
}
.btn-danger:hover {
  opacity: .88;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(244,63,94,.35);
}

button:disabled { opacity: .42; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-daftra {
  background: #0d9488;
  color: #fff;
  box-shadow: 0 2px 8px rgba(13,148,136,.30);
}
.btn-daftra:hover { background: #0f766e; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(13,148,136,.40); }
.btn-daftra:active { transform: translateY(0); }
.btn-daftra.linked { background: #16a34a; cursor: default; }
.btn-daftra.linked:hover { transform: none; box-shadow: 0 2px 8px rgba(22,163,74,.30); }
/* Partial fulfilment — order has short items, invoices prepared qty only */
.btn-daftra.partial-invoice { background: #ea580c; box-shadow: 0 2px 8px rgba(234,88,12,.30); }
.btn-daftra.partial-invoice:hover { background: #c2410c; box-shadow: 0 4px 16px rgba(234,88,12,.40); }

/* ── Tables ───────────────────────────────────────────────── */
.table, .entity-list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.table th, .entity-list-table th {
  background: var(--bg);
  padding: 11px 14px;
  text-align: right;
  font-size: .79rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.table td, .entity-list-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f0f2ff;
  vertical-align: middle;
}
.table tr:last-child td,
.entity-list-table tr:last-child td { border-bottom: none; }
.table tbody tr,
.entity-list-table tbody tr {
  transition: background var(--transition);
}
.table tbody tr:hover,
.entity-list-table tbody tr:hover { background: var(--primary-light); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: .02em;
}

.badge.pending   { background: #fef9c3; color: #92400e; }
.badge.preparing { background: #dbeafe; color: #1e40af; }
.badge.ready     { background: #dcfce7; color: #14532d; }
.badge.delivered { background: #ede9fe; color: #5b21b6; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }

/* Inventory badges */
.qty-zero { color: #b91c1c; font-weight: 800; }
.qty-low  { color: #b45309; font-weight: 800; }
.qty-ok   { color: #15803d; font-weight: 800; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30,27,75,.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open,
.modal-overlay[style*="flex"] { display: flex; }

.modal-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 28px 30px;
  width: 100%;
  max-width: 490px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  direction: rtl;
  animation: modalIn .22s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.93) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-size: 1.08rem;
  font-weight: 800;
  margin-bottom: 18px;
  color: var(--text);
}
.modal-text {
  font-size: .9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.75;
}
.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ── Form fields ──────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: .82rem; font-weight: 700; color: var(--text-secondary); }

.form-group input,
.form-group select,
.form-group textarea,
input.form-control,
select.form-control,
textarea.form-control {
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .9rem;
  background: #fafbff;
  color: var(--text);
  outline: none;
  transition: all var(--transition);
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
input.form-control:focus,
select.form-control:focus {
  border-color: var(--primary);
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(99,102,241,.10);
}
textarea { resize: vertical; min-height: 72px; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-lg) !important;
  animation: toastIn .25s cubic-bezier(.34,1.4,.64,1) both !important;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Print ────────────────────────────────────────────────── */
.print-header { display: none; }

@media print {
  .topbar, .sidebar, .no-print { display: none !important; }
  .content { padding: 0 !important; overflow: visible !important; }
  .layout  { height: auto !important; }
  .print-header { display: block; text-align: center; margin-bottom: 20px; direction: rtl; }
  .print-header .company-name { font-size: 18pt; font-weight: 900; }
  .print-header .doc-title    { font-size: 13pt; margin: 4pt 0; }
  .print-header .doc-date     { font-size: 10pt; color: #555; }
  .print-header hr            { border: none; border-top: 2px solid #000; margin: 8pt 0 14pt; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .table th, .entity-list-table th {
    background: #1e293b !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d4f0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a5b4fc; }

/* ── Utility ──────────────────────────────────────────────── */
.text-primary   { color: var(--primary); }
.text-danger    { color: var(--danger); }
.text-success   { color: #16a34a; }
.text-secondary { color: var(--text-secondary); }
.fw-bold        { font-weight: 700; }
.fw-black       { font-weight: 900; }
.d-flex         { display: flex; }
.gap-2          { gap: 8px; }
.gap-3          { gap: 12px; }
.align-center   { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1         { flex: 1; }
.w-100          { width: 100%; }
.mt-1           { margin-top: 6px; }
.mt-2           { margin-top: 12px; }
.mt-3           { margin-top: 18px; }
.mb-2           { margin-bottom: 12px; }
.mb-3           { margin-bottom: 18px; }
.text-center    { text-align: center; }
.small          { font-size: .82rem; }
.mono           { font-family: monospace; }

/* ── Logout button ────────────────────────────────────────── */
.logout-btn { color: #f43f5e !important; border-color: #fecdd3 !important; }
.logout-btn:hover { background: #fff1f2 !important; border-color: #f43f5e !important; }

/* ── Stat chips ───────────────────────────────────────────── */
.stat-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-chip:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.stat-chip-count { font-size: 1.5rem; font-weight: 900; color: var(--text); }
.stat-chip-label { font-size: .78rem; font-weight: 600; color: var(--text-secondary); }

/* ── Order cards ──────────────────────────────────────────── */
.order-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.order-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
  opacity: 0;
  transition: opacity var(--transition);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.order-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #c7d2fe;
}
.order-card:hover::before { opacity: 1; }

/* ── Bulk bar ──────────────────────────────────────────────── */
.bulk-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: #fff;
  border-radius: 999px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  transition: all .28s cubic-bezier(.34,1.4,.64,1);
  white-space: nowrap;
}
.bulk-bar.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Input / Search ───────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
  transition: all var(--transition);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  box-shadow: 0 0 0 3px rgba(99,102,241,.10);
}

/* ── Section card (create order) ─────────────────────────── */
.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.section-card:hover { box-shadow: var(--shadow-md); }
.section-title {
  font-size: .92rem;
  font-weight: 800;
  margin-bottom: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Login page ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #eef2ff 0%, #e0e7ff 50%, #ede9fe 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 36px 38px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .35s cubic-bezier(.34,1.4,.64,1) both;
}
.login-logo {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slides in from right on mobile */
  .sidebar {
    position: fixed; top: var(--topbar-h); right: 0;
    height: calc(100dvh - var(--topbar-h)); z-index: 200;
    transform: translateX(100%);
    transition: transform .28s ease;
    will-change: transform;
    width: min(var(--sidebar-w), 84vw) !important;
    box-shadow: -4px 0 32px rgba(99,102,241,.18);
  }
  .sidebar.mobile-open { transform: translateX(0); }

  /* Neutralize desktop "collapsed" state on mobile (full width + labels visible) */
  .sidebar.collapsed { width: min(var(--sidebar-w), 84vw) !important; }
  .sidebar.collapsed .sidebar-header .title,
  .sidebar.collapsed .nav-item span:not(.icon),
  .sidebar.collapsed .nav-group-header span:not(.icon):not(.nav-arrow),
  .sidebar.collapsed .nav-group-header .nav-arrow { display: inline !important; }
  .sidebar.collapsed .nav-group-items.open { display: block !important; }
  .sidebar.collapsed .nav-item,
  .sidebar.collapsed .nav-group-header { justify-content: flex-start !important; padding: 10px 16px !important; }

  /* Body scrolls instead of .content — better for iOS Safari */
  .layout { overflow: visible; height: auto; min-height: calc(100vh - var(--topbar-h)); }
  .content { overflow: visible; padding: 14px 14px calc(24px + env(safe-area-inset-bottom, 0px)); }

  .topbar { padding: 0 12px; gap: 8px; }
  .top-actions .item { display: none; }   /* hide datetime/user — too cramped */
  .brand { font-size: 1rem; }
  .page-title { font-size: 1.08rem; }

  /* Touch-friendly targets */
  .nav-item, .nav-group-header { min-height: 44px; }
  .icon-btn { width: 40px; height: 40px; }
  .btn-primary, .btn-secondary, .btn-danger { min-height: 40px; }

  /* Stat chips — horizontal scroll row */
  .stats-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 8px;
    scrollbar-width: none;
  }
  .stats-row::-webkit-scrollbar { display: none; }
  .stat-chip { min-width: 95px; padding: 11px 13px; flex-shrink: 0; }
  .stat-chip-count { font-size: 1.2rem; }

  /* Tables — horizontal scroll inside card */
  .card { overflow-x: auto; }
  .entity-list-table, .table { min-width: 480px; }
  .orders-toolbar { gap: 8px; }

  /* Modals */
  .modal-card { padding: 22px 16px; max-height: 92vh; }
  .modal-overlay { padding: 10px; align-items: flex-end; }

  /* Bulk bar — full width on mobile */
  .bulk-bar { min-width: calc(100vw - 32px) !important; border-radius: 14px; padding: 10px 14px; }
}

/* ── Card-reflow tables (opt-in via .card-table) ─────────
   On phones a wide data table (many columns) is turned into a
   stack of labelled cards instead of a horizontally-scrolling grid.
   Each <td data-label="…"> becomes a "label : value" row; cells with
   .card-title-cell act as the card header and .card-actions-cell span
   full width for buttons/inputs. */
@media (max-width: 640px) {
  .card-table { min-width: 0 !important; width: 100%; }
  .card-table thead { display: none; }
  .card-table, .card-table tbody, .card-table tfoot, .card-table tr, .card-table td { display: block; width: 100%; }
  .card-table tr {
    border: 1px solid var(--border);
    border-radius: 14px;
    margin: 0 0 12px;
    padding: 6px 12px 10px;
    background: var(--card);
    box-shadow: 0 1px 3px rgba(15,23,42,.05);
  }
  .card-table tr:hover { background: var(--card); }
  .card-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    padding: 7px 0;
    border: none;
    border-bottom: 1px dashed var(--border);
    min-height: 0;
  }
  .card-table td:last-child { border-bottom: none; }
  .card-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: .78rem;
    flex-shrink: 0;
  }
  /* Title cell — the product name, spans the card as a header */
  .card-table td.card-title-cell {
    display: block;
    font-size: .95rem !important;
    font-weight: 700;
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  /* Action cell — buttons/inputs stack full width, no label */
  .card-table td.card-actions-cell {
    display: block;
    border-bottom: none;
    padding-top: 10px;
  }
  .card-table td.card-actions-cell .prep-actions { justify-content: stretch; }
  .card-table td.card-actions-cell .prep-actions .prep-btn { flex: 1; }
  /* Hide the always-empty print-only spacer cell in card mode */
  .card-table td.print-only-td { display: none; }
}

/* Mobile hamburger — hidden on desktop, shown on mobile */
.mobile-hamburger { display: none !important; }
@media (max-width: 768px) {
  .mobile-hamburger { display: flex !important; font-size: 1.25rem; }
}

/* ── Sidebar backdrop (mobile) ─────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.visible { display: block; }

@media (max-width: 480px) {
  :root { --topbar-h: 52px; }
  .topbar { padding: 0 10px; }
  .icon-btn { width: 36px; height: 36px; font-size: .95rem; }
  .content { padding: 10px 10px calc(20px + env(safe-area-inset-bottom, 0px)); }
  .btn-primary, .btn-secondary, .btn-danger { padding: 9px 14px; font-size: .84rem; }
  .modal-card { padding: 18px 14px; }
  .modal-overlay { padding: 8px; }
  .page-title { font-size: .98rem; }
  .card { padding: 12px 13px; }
  .entity-list-table, .table { font-size: .82rem; }
  .entity-list-table th, .table th { padding: 8px 10px; }
  .entity-list-table td, .table td { padding: 8px 10px; }
  /* Inputs — slightly larger for touch */
  .form-group input, .form-group select, input.form-control, select.form-control {
    min-height: 44px; font-size: .95rem;
  }
  .stat-chip { min-width: 80px; }
  .stat-chip-count { font-size: 1.05rem; }
  .stat-chip-label { font-size: .68rem; }
}

/* ── CESRO Brand Background Art ────────────────────────── */
.cesro-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  user-select: none;
}
.cesro-bg svg { position: absolute; inset: 0; width: 100%; height: 100%; }
@media print { .cesro-bg { display: none !important; } }
