:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e3e6ea;
  --primary: #1f7a4d;
  --primary-ink: #ffffff;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --ok: #1f7a4d;
  --ok-bg: #e7f4ec;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #171c24;
    --text: #e7ebf0;
    --muted: #97a0ad;
    --border: #262d38;
    --primary: #2e9d63;
    --danger: #e5695b;
    --danger-bg: #3a201d;
    --ok-bg: #16281f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.who:hover { color: var(--text); }
.inline { display: inline; margin: 0; }

/* Layout */
.container { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 8px 0 16px; }
h3 { margin: 0 0 6px; font-size: 1.05rem; }
.muted { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* Auth card */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 380px;
  margin: 48px auto;
}
.auth-card h1 { text-align: center; }

/* Forms */
label { display: block; margin: 0 0 14px; font-size: 0.92rem; color: var(--muted); }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

/* Buttons — large tap targets for phones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 6px; }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 0.95rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }

/* Stat tiles */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}
.stat-num { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.82rem; color: var(--muted); }

/* Sections */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.section h2 { margin: 0 0 12px; font-size: 1.1rem; }

/* Sub-navigation links */
.subnav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.subnav a {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}
.backlink { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }

/* Inline form rows (label above input already; here for horizontal groups) */
.form-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) {
  .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr auto; align-items: end; }
}
.form-row label { margin-bottom: 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
.qty { font-weight: 700; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }

/* Simple list */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: none; }

.badge { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.badge-off { color: var(--danger); }
.muted-empty { color: var(--muted); padding: 12px 0; }

/* Delivery status badges */
.badge-pending { background: #fff4e0; color: #a86400; border-color: #f0d9a8; }
.badge-claimed { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-parse_failed { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge-cancelled { background: var(--bg); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .badge-pending { background: #3a2e16; color: #e2b264; border-color: transparent; }
}
.delivery.status-cancelled { opacity: 0.6; }

/* Warehouse availability table shown above the "load a messenger" form */
.stock-avail { margin: 0 0 16px; }
.stock-avail table { font-size: 0.9rem; }

/* htmx live-swap: gentle fade so refreshed regions don't flash */
.htmx-swapping { opacity: 0.55; transition: opacity 0.12s ease-out; }
.htmx-settling { opacity: 1; transition: opacity 0.12s ease-in; }

/* Toasts — fixed to the top, above the sticky topbar */
.toast-wrap {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(94vw, 480px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  font-size: 0.95rem;
  cursor: pointer;
  animation: toast-in 0.25s ease;
}
.toast-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.toast-error { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.toast-hide { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* WhatsApp captured-group rows */
.wa-group-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.wa-group-row:last-child { border-bottom: none; }
