/* Design base: every colour, font, size, radius and shadow of the site lives here as a CSS
   variable (the only file with colour values), plus the shared components. Page layouts are in
   styles.css and use only these variables. No web fonts, no icon fonts, no external files:
   system fonts and the local /icons.svg sprite (Ghana networks are slow and unstable).

   Components: buttons (.primary / .secondary / .danger / .link), inputs and selects, .card,
   tables (.table-wrap > table: zebra, hover, sticky header), .badge (+ .ok .warn .off .info and
   one .st-<status> per order status), alerts (p.form-error / p.form-ok from UI.message, .notice,
   .alert-*), .modal, .pager, .empty-state, loading (.loading, body.is-loading top bar), .progress. */

:root {
  /* brand */
  --c-primary: #1f6f5c;
  --c-primary-hover: #195b4b;
  --c-primary-active: #144a3d;
  --c-primary-soft: #e4f0eb;
  --c-primary-softer: #f1f7f4;
  --c-on-primary: #ffffff;

  /* neutrals */
  --c-bg: #f3f5f4;
  --c-surface: #ffffff;
  --c-surface-2: #f8faf9;
  --c-surface-3: #eef2f0;
  --c-border: #dde3e0;
  --c-border-strong: #c3ccc8;
  --c-text: #1b2420;
  --c-text-2: #4d5955;
  --c-text-3: #6b7672;
  --c-overlay: rgba(16, 24, 21, 0.45);

  /* states: text / background / border */
  --c-success: #17663f;
  --c-success-bg: #e3f3ea;
  --c-success-border: #a9d9be;
  --c-warning: #7a4d00;
  --c-warning-bg: #fff4d6;
  --c-warning-border: #f0d184;
  --c-error: #b3261e;
  --c-error-bg: #fdecea;
  --c-error-border: #f2b8b3;
  --c-info: #1c4f86;
  --c-info-bg: #e6eff9;
  --c-info-border: #b4cde9;
  --c-whatsapp: #128c4a;
  --c-alt: #4b6b8a;

  /* the 9 order statuses merchants see; the staff-only ones reuse the nearest colour */
  --st-pending: #8a5a00;        --st-pending-bg: #fff1cc;
  --st-contact-failed: #a1360b; --st-contact-failed-bg: #fde6d8;
  --st-confirmed: #1c4f86;      --st-confirmed-bg: #e3edf9;
  --st-out-of-stock: #6c3d99;   --st-out-of-stock-bg: #efe6f8;
  --st-in-delivery: #0b6b7a;    --st-in-delivery-bg: #dff2f4;
  --st-delivered: #17663f;      --st-delivered-bg: #e0f2e8;
  --st-rejected: #b3261e;       --st-rejected-bg: #fbe4e2;
  --st-cancelled: #59625e;      --st-cancelled-bg: #eceeed;
  --st-settled: #ffffff;        --st-settled-bg: #1f6f5c;

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;     /* tables, hints */
  --fs-base: 14px;   /* body text */
  --fs-md: 16px;
  --fs-lg: 18px;     /* h3 */
  --fs-xl: 22px;     /* h2, page titles */
  --fs-2xl: 28px;    /* big numbers */
  --lh: 1.55;

  /* shape and space (multiples of 8; 4 only inside small parts) */
  --sp-half: 4px;
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 32px;
  --sp-5: 40px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 21, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 21, 0.08), 0 1px 2px rgba(16, 24, 21, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 21, 0.18);
  --focus: 0 0 0 3px rgba(31, 111, 92, 0.28);
  --control-h: 40px;
  --control-h-touch: 48px;
  --content-max: 1280px;
  --nav-w: 232px;
  --topbar-h: 56px;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--c-bg); color: var(--c-text);
  font-family: var(--font-sans); font-size: var(--fs-base); line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.3; color: var(--c-text); }
h1 { font-size: var(--fs-xl); font-weight: 700; }
h2 { font-size: var(--fs-xl); font-weight: 700; }
h3 { font-size: var(--fs-lg); font-weight: 600; }
h4 { font-size: var(--fs-md); font-weight: 600; }
a { color: var(--c-primary); }
a:hover { color: var(--c-primary-hover); }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--c-surface-3); padding: 1px 4px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-2) 0; }
.muted { color: var(--c-text-3); }
.small { font-size: var(--fs-sm); }
.strong-text { font-weight: 700; }
.danger-text { color: var(--c-error) !important; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; }
button.primary, button.secondary, button.danger, a.button, a.secondary-link {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1);
  min-height: var(--control-h); padding: 0 var(--sp-2); border-radius: var(--radius);
  font-size: var(--fs-base); font-weight: 600; line-height: 1.2; text-decoration: none;
  border: 1px solid transparent; transition: background-color .12s, border-color .12s, color .12s;
}
button.primary, a.button { background: var(--c-primary); color: var(--c-on-primary); border-color: var(--c-primary); }
button.primary:hover:not(:disabled), a.button:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); color: var(--c-on-primary); }
button.primary:active:not(:disabled) { background: var(--c-primary-active); }
button.secondary, a.secondary-link { background: var(--c-surface); color: var(--c-primary); border-color: var(--c-border-strong); }
button.secondary:hover:not(:disabled), a.secondary-link:hover { border-color: var(--c-primary); background: var(--c-primary-softer); color: var(--c-primary); }
button.danger { background: var(--c-error); color: #fff; border-color: var(--c-error); }
button.danger:hover:not(:disabled) { filter: brightness(0.92); }
button.link {
  background: none; border: 0; color: var(--c-primary); padding: var(--sp-half) var(--sp-1);
  min-height: 32px; border-radius: var(--radius-sm); font-weight: 500;
}
button.link:hover:not(:disabled) { background: var(--c-primary-softer); text-decoration: underline; }
button.link.active { font-weight: 700; }
button:disabled, button[disabled] { opacity: 0.5; cursor: not-allowed; }
button.small-btn { min-height: 32px; padding: 0 12px; font-size: var(--fs-sm); }

/* ---------- inputs ---------- */
input, select, textarea {
  font: inherit; font-size: var(--fs-base); color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius); min-height: var(--control-h);
  padding: 0 12px; max-width: 100%; transition: border-color .12s, box-shadow .12s;
}
textarea { padding: var(--sp-1) 12px; min-height: 88px; line-height: var(--lh); resize: vertical; }
input[type=file] { padding: 6px; min-height: var(--control-h); background: var(--c-surface-2); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 18px; height: 18px; padding: 0; accent-color: var(--c-primary); }
input::placeholder, textarea::placeholder { color: var(--c-text-3); }
input:hover, select:hover, textarea:hover { border-color: var(--c-text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c-primary); box-shadow: var(--focus); }
input:disabled, select:disabled, textarea:disabled { background: var(--c-surface-3); color: var(--c-text-3); }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--c-error); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: var(--fs-base); color: var(--c-text); }
label > span:first-child { font-size: var(--fs-sm); color: var(--c-text-2); }
label small { font-weight: 400; color: var(--c-text-3); font-size: var(--fs-xs); line-height: 1.5; }
label.required > span:first-child::after, .required-mark::after,
.form-grid label:has(> input[required], > select[required], > textarea[required]) > span:first-child::after,
.inline-form label:has(> input[required], > select[required], > textarea[required]) > span:first-child::after { content: " *"; color: var(--c-error); }
.field-error { color: var(--c-error); font-size: var(--fs-xs); font-weight: 500; }
fieldset { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px var(--sp-2) var(--sp-2); display: flex; flex-direction: column; gap: 12px; margin: 0; }
legend { font-weight: 600; padding: 0 var(--sp-half); color: var(--c-text-2); }
label.check, label.inline { flex-direction: row; align-items: center; font-weight: 400; gap: var(--sp-1); }
label.check { min-height: 32px; }
label.inline > span:first-child { font-size: var(--fs-sm); }

/* ---------- card ---------- */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: var(--sp-3);
}
.card > h3:first-child, .card > h4:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; margin-bottom: var(--sp-2); }
.card-head h3 { margin: 0 auto 0 0; }

/* ---------- tables ---------- */
.table-wrap {
  overflow: auto; -webkit-overflow-scrolling: touch; background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-sm); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--c-border); vertical-align: top; }
th {
  position: sticky; top: 0; z-index: 1; background: var(--c-surface-2); color: var(--c-text-2);
  font-size: var(--fs-xs); font-weight: 600; text-transform: none; letter-spacing: .02em; white-space: nowrap;
}
.table-wrap tbody tr:nth-child(even) td { background: var(--c-surface-2); }
.table-wrap tbody tr:hover td { background: var(--c-primary-softer); }
.table-wrap tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.strong { font-weight: 700; }
td.empty-cell { padding: 0; }
@media (min-width: 900px) {
  .table-wrap { max-height: calc(100vh - 180px); } /* long tables scroll inside: the header row stays */
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; line-height: 1.5;
  padding: 1px 8px; border-radius: var(--radius-pill); margin: 2px 4px 2px 0; white-space: nowrap;
  background: var(--c-surface-3); color: var(--c-text-2); border: 1px solid transparent;
}
.badge.ok { background: var(--c-success-bg); color: var(--c-success); }
.badge.warn { background: var(--c-warning-bg); color: var(--c-warning); }
.badge.off { background: var(--c-error-bg); color: var(--c-error); }
.badge.info { background: var(--c-info-bg); color: var(--c-info); }
.badge.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.st-pending_confirmation { background: var(--st-pending-bg); color: var(--st-pending); }
.badge.st-contact_failed { background: var(--st-contact-failed-bg); color: var(--st-contact-failed); }
.badge.st-confirmed { background: var(--st-confirmed-bg); color: var(--st-confirmed); }
.badge.st-out_of_stock { background: var(--st-out-of-stock-bg); color: var(--st-out-of-stock); }
.badge.st-in_delivery, .badge.st-dispatched { background: var(--st-in-delivery-bg); color: var(--st-in-delivery); }
.badge.st-delivered, .badge.st-posted { background: var(--st-delivered-bg); color: var(--st-delivered); }
.badge.st-rejected, .badge.st-returned { background: var(--st-rejected-bg); color: var(--st-rejected); }
.badge.st-cancelled { background: var(--st-cancelled-bg); color: var(--st-cancelled); }
.badge.st-settled { background: var(--st-settled-bg); color: var(--st-settled); }

/* ---------- alerts ---------- */
.form-error { color: var(--c-error); margin: 0; padding-left: 0; list-style: none; }
.form-ok { color: var(--c-success); margin: 0; font-weight: 600; }
p.form-error[role=alert], ul.form-error[role=alert], p.form-ok[role=alert], .alert {
  display: block; margin: var(--sp-1) 0 0; padding: 10px 12px 10px 14px; border-radius: var(--radius);
  border: 1px solid; border-left-width: 4px; font-size: var(--fs-base); font-weight: 500;
}
p.form-error[role=alert], ul.form-error[role=alert], .alert-error { background: var(--c-error-bg); border-color: var(--c-error-border); border-left-color: var(--c-error); color: var(--c-error); }
p.form-ok[role=alert], .alert-success { background: var(--c-success-bg); border-color: var(--c-success-border); border-left-color: var(--c-success); color: var(--c-success); }
ul.form-error[role=alert] li + li { margin-top: 2px; }
.notice, .alert-warning {
  background: var(--c-warning-bg); border: 1px solid var(--c-warning-border); color: var(--c-text);
  border-radius: var(--radius); padding: 10px 14px; margin: 0;
}
.alert-info { background: var(--c-info-bg); border-color: var(--c-info-border); border-left-color: var(--c-info); color: var(--c-info); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: var(--c-overlay);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-2);
}
.modal {
  background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; min-width: 0; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; padding: var(--sp-3);
}
.modal h3 { margin: 0 0 var(--sp-1); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-1); margin-top: var(--sp-3); flex-wrap: wrap; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-1); margin: 12px 0; color: var(--c-text-2); font-size: var(--fs-sm); }
.pager button.link {
  min-width: 32px; min-height: 32px; border: 1px solid var(--c-border-strong); background: var(--c-surface);
  font-size: var(--fs-md); line-height: 1; padding: 0 8px;
}
.pager button.link:hover:not(:disabled) { text-decoration: none; border-color: var(--c-primary); }
.pager > p { margin: 0; }

/* ---------- empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: var(--sp-5) var(--sp-2); color: var(--c-text-3);
}
.empty-state svg { width: 40px; height: 40px; color: var(--c-border-strong); }
.empty-state p { margin: 0; font-size: var(--fs-base); color: var(--c-text-2); }

/* ---------- loading ---------- */
.loading { display: flex; align-items: center; gap: var(--sp-1); color: var(--c-text-3); padding: var(--sp-2) 0; }
.loading::before, .spinner {
  content: ""; width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid var(--c-border); border-top-color: var(--c-primary); animation: spin .8s linear infinite;
}
body::after {
  content: ""; position: fixed; left: 0; top: 0; height: 3px; width: 0; z-index: 200;
  background: var(--c-primary); opacity: 0; transition: opacity .2s;
}
body.is-loading::after { opacity: 1; animation: load-bar 1.2s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes load-bar { 0% { left: 0; width: 0; } 50% { left: 20%; width: 50%; } 100% { left: 100%; width: 0; } }
@media (prefers-reduced-motion: reduce) {
  .loading::before, .spinner { animation: none; }
  body.is-loading::after { animation: none; width: 100%; }
}

/* ---------- progress bar ---------- */
.progress { height: 8px; border-radius: var(--radius-pill); background: var(--c-surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--c-primary); transition: width .3s; }
.progress.success > span { background: var(--c-success); }
.progress.error > span { background: var(--c-error); }

/* ---------- icons (sprite /icons.svg) ---------- */
svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- phones: bigger touch targets ---------- */
@media (max-width: 640px) {
  input, select, textarea { min-height: var(--control-h-touch); font-size: var(--fs-md); } /* 16px stops iOS zooming in */
  button.primary, button.secondary, button.danger, a.button, a.secondary-link { min-height: 44px; }
  button.link { min-height: 40px; }
  .card { padding: var(--sp-2); }
}
