/* ─────────────────────────────────────────────────────────────────────
   Africa Coffee Park · Management OS · Component Library
   Reusable components — ALL colors via var(--*). Never hard-code.
   ───────────────────────────────────────────────────────────────────── */

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s, filter .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); color: #001828; border-color: transparent; }
.btn.primary:hover { background: var(--primary-2); }
.btn.accent  { background: var(--accent); color: #1a1208; border-color: transparent; }
.btn.accent:hover { filter: brightness(1.07); }
.btn.danger  { background: var(--err); color: #fff; border-color: transparent; }
.btn.danger:hover { filter: brightness(1.1); }
.btn.ghost   { background: transparent; }
.btn[disabled], .btn.loading {
  opacity: .55; cursor: not-allowed; pointer-events: none;
}
.btn.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn.btn-xs { padding: 2px 8px; font-size: 11px; }

/* Inline spinner for .btn.loading */
.btn.loading::after {
  content: '';
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

/* ── Toast notifications ────────────────────────────────────────────── */
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 280px;
  max-width: 420px;
}
.toast.toast-in { animation: toast-in .18s ease; }
.toast.toast-out { animation: toast-out .18s ease forwards; }
.toast-msg { flex: 1; font-size: 13px; line-height: 1.4; }
.toast-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--primary);
}
.toast.ok  .toast-icon { color: var(--ok); }
.toast.err .toast-icon { color: var(--err); }
.toast.warn .toast-icon { color: var(--warn); }
.toast-dismiss {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  opacity: .65;
}
.toast-dismiss:hover { opacity: 1; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(8px); opacity: 0; } }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
  /* Same surface stack as sidebar — avoids brown/green panel mismatch */
}
.card.table-wrap,
.table-wrap.card {
  background: var(--surface);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.card-title { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }

/* ── KPI cards ────────────────────────────────────────────────────── */
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: grid; gap: var(--space-1);
  position: relative; overflow: hidden;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: color-mix(in oklab, var(--primary) 28%, var(--line));
}
.kpi::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}
.kpi .label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .07em; font-weight: 600;
  user-select: none;
  touch-action: manipulation;
  /* Prevent long labels from overflowing narrow cards on mobile */
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  line-height: 1.3;
}
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.kpi .trend {
  font-size: 12px; color: var(--text-muted);
  /* Prevent long trend text from overflowing */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi .trend.up   { color: var(--ok); }
.kpi .trend.down { color: var(--err); }

/* KPI status tones — explicit semantic framing */
.kpi.tone-ok  { border-color: color-mix(in oklab, var(--ok)  30%, var(--line)); }
.kpi.tone-ok::before  { background: linear-gradient(180deg, var(--ok), color-mix(in oklab, var(--ok) 50%, var(--accent))); }
.kpi.tone-warn{ border-color: color-mix(in oklab, var(--warn) 30%, var(--line)); }
.kpi.tone-warn::before{ background: linear-gradient(180deg, var(--warn), color-mix(in oklab, var(--warn) 50%, var(--accent))); }
.kpi.tone-err { border-color: color-mix(in oklab, var(--err)  30%, var(--line)); }
.kpi.tone-err::before { background: linear-gradient(180deg, var(--err), color-mix(in oklab, var(--err) 50%, var(--accent-2))); }

.kpi-grid {
  display: grid; gap: var(--space-4);
  /* Desktop: auto-fit with 200px floor — collapses naturally above ~768px.
     Explicit mobile overrides below handle the sub-768px cases where the
     minmax alone cannot guarantee no-overflow at 360px viewport. */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: var(--space-5);
}

/* 2-up grid on small tablets / large phones (≤768px down to 361px) */
@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 1-up grid only on very small phones (≤360px CSS viewport).
   360px gives each card ~160px width which is tight but functional with
   word-break applied to .kpi .label (above). 390px gets ~175px — fine
   at 2-up. Threshold is 360 not 420 so that 390px devices stay 2-up. */
@media (max-width: 360px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Pills (tab pills used by Capture Hub + every _reports/* sub-module) ─
   Inactive: muted dark chip on the surface; cyan accent on hover.
   Active:   filled with --primary, contrast text from --pill-fg.
   Wraps cleanly at 360px (guardrail §9 #9). */
.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 var(--space-4) 0;
}
.pill {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.pill .icon { flex: 0 0 auto; }
.pill:hover {
  color: var(--text);
  border-color: color-mix(in oklab, var(--primary) 50%, var(--line));
}
.pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 40%, transparent);
}
.pill.active {
  color: var(--pill-fg, #001828);
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
.pill.active:hover { color: var(--pill-fg, #001828); }
.pill[disabled],
.pill.disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ── Module sub-tabs (.subnav) — finance/hr/infrastructure/procurement/stores ──
   These render as default white buttons without this rule; theme them to a
   pill-style segmented control consistent with .pill above. */
.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 18px;
}
.subnav-btn {
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.subnav-btn:hover { color: var(--text); border-color: var(--primary); }
.subnav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--pill-fg, #001828);
}
.subnav-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── Tables ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table th, .table td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.table th {
  background: var(--surface-2); color: var(--text-muted);
  text-transform: uppercase; font-size: 11px; letter-spacing: .06em;
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.table tr:hover td { background: color-mix(in oklab, var(--primary) 5%, transparent); }
.table tr.hoverable {
  cursor: pointer;
  touch-action: manipulation;
}
.table tr.hoverable:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
/* Stock-status row indicators (Stores) */
.table tr.row-ok   td:first-child { border-left: 3px solid var(--ok); }
.table tr.row-warn td:first-child { border-left: 3px solid var(--warn); }
.table tr.row-err  td:first-child { border-left: 3px solid var(--err); }

/* Empty state row */
.table .empty-row td {
  text-align: center; padding: 36px 14px;
  color: var(--text-muted); border-bottom: none;
}
.empty-state {
  display: grid; place-items: center; gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  color: var(--text-muted); text-align: center;
}
.empty-state .icon-xl { opacity: .35; }
.empty-state p { font-size: 13px; margin: 0; max-width: 280px; }

/* ── Activity feed rows (home dashboard) ─────────────────────────── */
.activity-feed-modal {
  max-height: 70vh;
  margin-top: 70px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
}
.activity-feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.activity-feed-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.activity-feed-scroll {
  max-height: 380px;
  overflow-y: auto;
}
.activity-feed-empty {
  color: var(--text-muted);
  padding: var(--space-6);
  text-align: center;
  font-size: 13px;
}
.activity-feed-group + .activity-feed-group {
  margin-top: var(--space-4);
}
.activity-feed-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.activity-row {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
}
.activity-row-clickable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding-left: var(--space-2);
  padding-right: var(--space-2);
  margin-left: calc(-1 * var(--space-2));
  margin-right: calc(-1 * var(--space-2));
}
.activity-row-clickable:hover {
  background: color-mix(in oklab, var(--primary) 8%, transparent);
}
.activity-row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 6px;
}
.activity-row-msg {
  font-size: 13px;
  font-weight: 600;
}
.activity-row-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
/* home.js emits an inline grid-template-columns: 108px 1fr auto.
   At narrow viewports the 108px chip + auto timestamp columns leave too
   little space for the content column. Restack to two rows on mobile.
   !important is required to win over the inline style on the element. */
@media (max-width: 540px) {
  .activity-row {
    grid-template-columns: 1fr auto !important;
    grid-template-rows: auto auto;
    row-gap: 4px !important;
    gap: 6px 8px !important;
  }
  /* Chip stays top-left */
  .activity-row > *:first-child { grid-column: 1; grid-row: 1; }
  /* Title/sub spans full width on row 2 */
  .activity-row > *:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  /* Timestamp sits top-right */
  .activity-row > *:last-child  { grid-column: 2; grid-row: 1; }
}

/* ── Responsive table → card-per-row at small screens */
@media (max-width: 720px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); margin-bottom: var(--space-2);
    padding: var(--space-2);
  }
  .table td {
    display: grid;
    grid-template-columns: 130px 1fr;
    padding: 6px var(--space-3);
    border-bottom: none;
    align-items: start;
  }
  .table td::before {
    content: attr(data-label);
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); font-weight: 600;
    padding-top: 2px;
  }
  .table tr.row-ok td:first-child,
  .table tr.row-warn td:first-child,
  .table tr.row-err td:first-child { border-left: none; border-top: 3px solid var(--ok); }
  .table tr.row-warn td:first-child { border-top-color: var(--warn); }
  .table tr.row-err td:first-child  { border-top-color: var(--err); }
  .table .empty-row { display: block; }
}

/* ── Chips ────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.ok   { color: var(--ok);   border-color: color-mix(in oklab, var(--ok)   40%, transparent); background: color-mix(in oklab, var(--ok)   10%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 40%, transparent); background: color-mix(in oklab, var(--warn) 10%, transparent); }
.chip.err  { color: var(--err);  border-color: color-mix(in oklab, var(--err)  40%, transparent); background: color-mix(in oklab, var(--err)  10%, transparent); }
.chip.info { color: var(--info); border-color: color-mix(in oklab, var(--info) 40%, transparent); background: color-mix(in oklab, var(--info) 10%, transparent); }

/* Pulse-on-low-stock / critical CTA */
@keyframes pulse-cta {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--err) 50%, transparent); }
  50%       { box-shadow: 0 0 0 6px transparent; }
}
.chip.err.pulse {
  animation: pulse-cta 1.6s ease infinite;
}
@media (prefers-reduced-motion: reduce) {
  .chip.err.pulse { animation: none; }
}

/* ── Form fields — unified on-theme controls (no white browser defaults) ─── */
.field { display: grid; gap: 6px; }
.field label,
.form-grid > label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Base control styling shared across field, form-grid, modals, and utilities */
.field input, .field select, .field textarea,
.form-grid > label input, .form-grid > label select, .form-grid > label textarea,
.input, .form-control {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid color-mix(in oklab, var(--line) 85%, var(--text-muted));
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color-scheme: dark;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: inset 0 1px 0 color-mix(in oklab, var(--text) 4%, transparent);
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.field input::placeholder,
.field textarea::placeholder,
.form-grid > label input::placeholder,
.form-grid > label textarea::placeholder,
.input::placeholder, .form-control::placeholder {
  color: var(--text-muted);
  opacity: .65;
}

.field input:hover, .field select:hover, .field textarea:hover,
.form-grid > label input:hover, .form-grid > label select:hover, .form-grid > label textarea:hover,
.input:hover, .form-control:hover {
  border-color: color-mix(in oklab, var(--primary) 28%, var(--line));
  background: color-mix(in oklab, var(--surface-2) 92%, var(--surface-3));
}

.field input:focus, .field select:focus, .field textarea:focus,
.form-grid > label input:focus, .form-grid > label select:focus, .form-grid > label textarea:focus,
.input:focus, .form-control:focus,
.input:focus-visible, .form-control:focus-visible {
  outline: none;
  border-color: var(--primary);
  background: var(--surface-2);
  box-shadow:
    inset 0 1px 0 color-mix(in oklab, var(--text) 4%, transparent),
    0 0 0 3px color-mix(in oklab, var(--primary) 22%, transparent);
}

.field input:read-only, .field input:disabled,
.form-grid > label input:read-only, .form-grid > label input:disabled,
.form-grid > label select:disabled, .form-grid > label textarea:disabled,
.input:disabled, .form-control:disabled {
  opacity: .72;
  cursor: not-allowed;
  background: var(--surface-3);
  border-style: dashed;
}

.field textarea, .form-grid > label textarea, textarea.form-control, textarea.input {
  min-height: 80px;
  resize: vertical;
}

.field select, .form-grid > label select, select.form-control, select.input {
  cursor: pointer;
  padding-right: 36px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--primary) 50%),
    linear-gradient(135deg, var(--primary) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.field select option, .form-grid > label select option,
select.form-control option, select.input option {
  background: var(--surface);
  color: var(--text);
}

.field input[aria-invalid="true"],
.field input.error,
.field select.error,
.field textarea.error,
.form-grid > label input[aria-invalid="true"],
.form-grid > label input.error,
.input[aria-invalid="true"], .input.error,
.form-control.form-control--error {
  border-color: var(--err);
}

.field input[aria-invalid="true"]:focus,
.field input.error:focus,
.form-control.form-control--error:focus {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--err) 22%, transparent);
}

.field .field-error {
  font-size: 11px; color: var(--err); margin-top: 2px;
}
.field .field-hint {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}

/* Mail reply form inputs (public-message detail modal) */
#rp-subject, #rp-body {
  width: 100%; box-sizing: border-box;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; font-size: 14px;
}
#rp-body { min-height: 120px; resize: vertical; line-height: 1.5; }
#rp-subject::placeholder, #rp-body::placeholder { color: var(--text-muted); opacity: .65; }
#rp-subject:focus, #rp-body:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 22%, transparent);
}

@media (max-width: 720px) {
  .field { gap: 6px; }
  .field label, .form-grid > label { font-size: 11px; }
}

/* ── Layout helpers ──────────────────────────────────────────────── */
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.col { display: grid; gap: var(--space-3); }
.spacer { flex: 1; }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr 1fr; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Modals — standardised sizes ─────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: grid; place-items: center; z-index: 50;
  padding: var(--space-4);
  animation: backdrop-in .15s ease;
}
@keyframes backdrop-in { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-6);
  width: 100%; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-3);
  animation: modal-in .18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.97) translateY(8px); }
}
/* Size modifiers */
.modal.modal-sm { max-width: 400px;  }
.modal.modal-md { max-width: 580px;  }
.modal.modal-lg { max-width: 760px;  }
.modal.modal-xl { max-width: 1000px; }
/* Default (no size class) → md */
.modal:not(.modal-sm):not(.modal-lg):not(.modal-xl) { max-width: 640px; }

/* ── Form controls ─ used by stakeholders, account-approvals, etc. ───────── */
.form-group { margin-bottom: var(--space-4); }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .02em;
  margin-bottom: 6px;
}
.form-group label[for] { cursor: pointer; }
.form-row { display: grid; gap: var(--space-3); }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 480px) {
  .form-row, .form-row.cols-2 { grid-template-columns: 1fr; }
}

.form-control:disabled { opacity: .72; cursor: not-allowed; }

textarea.form-control { min-height: 80px; resize: vertical; line-height: 1.5; }

select.form-control {
  cursor: pointer;
  padding-right: 36px;
}

.form-control.form-control--error { border-color: var(--err); }
.form-control.form-control--error:focus {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--err) 22%, transparent);
}

.form-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; }
.form-error { font-size: 12px; color: var(--err); margin-top: 4px; line-height: 1.5; }

/* Drawer — slides from right */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 50; display: flex; justify-content: flex-end;
}
.drawer {
  background: var(--surface); border-left: 1px solid var(--line);
  height: 100%; overflow-y: auto; padding: var(--space-6);
  box-shadow: -8px 0 32px rgba(0,0,0,.4);
  animation: drawer-in .22s cubic-bezier(.25,.46,.45,.94);
}
@keyframes drawer-in { from { transform: translateX(20px); opacity: 0; } }
.drawer.drawer-sm { width: min(420px, 95vw); }
.drawer.drawer-md { width: min(560px, 95vw); }
.drawer.drawer-lg { width: min(720px, 95vw); }
.drawer.drawer-xl { width: min(900px, 95vw); }
.drawer:not(.drawer-sm):not(.drawer-lg):not(.drawer-xl) { width: min(640px, 95vw); }

@media (max-width: 720px) {
  .modal { padding: var(--space-4); }
  .drawer { padding: var(--space-4); }
  .modal-backdrop { padding: var(--space-2); }
}

/* ── Module head + breadcrumbs ────────────────────────────────────── */
.module-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-5); flex-wrap: wrap; gap: var(--space-3);
}
.module-head-left { display: grid; gap: 2px; }
.module-title {
  font-size: 22px; font-weight: 800; letter-spacing: -.02em;
  display: flex; align-items: center; gap: var(--space-3);
}
.module-title .icon-lg { color: var(--primary); }
.module-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.module-head-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--line);
  margin-bottom: var(--space-5); overflow-x: auto; flex-wrap: nowrap;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 14px; font-size: 13px; font-weight: 600;
  color: var(--text-muted); background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer;
  white-space: nowrap; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Meter / progress bars ────────────────────────────────────────── */
.meter {
  background: var(--surface-2); border-radius: 999px;
  overflow: hidden; height: 8px;
}
.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width .5s ease;
}
.meter-fill.ok   { background: var(--ok); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.err  { background: var(--err); }

/* Fuel order CTA — pulse on low stock */
.order-cta.urgent {
  animation: pulse-cta 1.6s ease infinite;
}
@media (prefers-reduced-motion: reduce) {
  .order-cta.urgent { animation: none; }
}

/* ── Section separators ───────────────────────────────────────────── */
.section-title {
  font-size: 13px; font-weight: 700; color: var(--text);
  letter-spacing: -.01em; margin-bottom: var(--space-3);
  margin-top: var(--space-5);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}

/* ── Print styles ─────────────────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .tabs, .module-head-actions,
  .btn, .icon-btn, .user-chip, .modal-backdrop,
  .toast-root, .breadcrumb { display: none !important; }
  body { display: block; background: #fff; color: #000; font-size: 11pt; }
  .workspace { padding: 0; overflow: visible; }
  .card { border: 1px solid #ddd; box-shadow: none; page-break-inside: avoid; }
  .table th { background: #f5f5f5; color: #333; }
  .kpi::before { display: none; }
  a { color: inherit; text-decoration: none; }
}

/* ── Attach widget [hidden] overrides (specificity guard — §9 anti-pattern 6) */
.attach-lightbox[hidden] { display: none; }
.attach-dropzone[hidden] { display: none; }
.attach-error[hidden]    { display: none; }
.attach-lightbox-prev[hidden],
.attach-lightbox-next[hidden] { display: none; }

/* ─────────────────────────────────────────────────────────────────────────
   Pass 6 — Table-utils helpers
   All colors via var(--*). Never hard-code.
   ─────────────────────────────────────────────────────────────────────── */

/* ── Inline-edit cell ─────────────────────────────────────────────────── */
.cell-editable { cursor: pointer; }
.cell-editable:hover {
  background: color-mix(in oklab, var(--primary) 6%, transparent);
}
.cell-editing > input,
.cell-editing > select {
  width: 100%; padding: 4px 8px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--primary); border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 18%, transparent);
}
/* Transient error flash on failed save */
.cell-edit-err {
  background: color-mix(in oklab, var(--err) 12%, transparent) !important;
  transition: background .4s;
}

/* ── Bulk-action toolbar ──────────────────────────────────────────────── */
.bulk-toolbar {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  backdrop-filter: blur(8px);
  z-index: 50;
  animation: modal-in .18s ease;
}
/* Specificity guard — must pair with [hidden] toggle */
.bulk-toolbar[hidden] { display: none; }

.bulk-count {
  font-size: 13px; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}

/* Collapse to full-width bottom sheet on mobile */
@media (max-width: 720px) {
  .bulk-toolbar {
    left: 0; right: 0; bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
    justify-content: center;
  }
}

/* ── Sortable column headers ──────────────────────────────────────────── */
.sortable { cursor: pointer; user-select: none; }
.sort-asc::after,
.sort-desc::after {
  font-size: 10px; margin-left: 4px; opacity: .7;
}
.sort-asc::after  { content: '\25B2'; } /* ▲ */
.sort-desc::after { content: '\25BC'; } /* ▼ */

/* ── Filter popover ───────────────────────────────────────────────────── */
.filter-icon-btn {
  background: none; border: none; cursor: pointer;
  padding: 0 0 0 4px; line-height: 1;
  color: var(--text-muted); opacity: .55;
  vertical-align: middle;
  transition: color .15s, opacity .15s;
}
.filter-icon-btn:hover { opacity: 1; color: var(--primary); }

.filter-pop {
  position: absolute; top: 100%; left: 0; min-width: 180px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 8px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2); z-index: 30;
}
/* Specificity guard */
.filter-pop[hidden] { display: none; }

/* ── Checkbox selection column ────────────────────────────────────────── */
.sel-col {
  width: 40px; text-align: center; padding: 6px !important;
}
.sel-col input[type="checkbox"] { cursor: pointer; accent-color: var(--primary); }

/* ── Mobile-first responsive sweep (≤768px / ≤420px) ──────────────────
   Prevents horizontal overflow on 360–390px viewports. Applies broadly
   to all dashboard and module content without breaking desktop layout.
   These are additive — they only activate at narrow breakpoints. */

/* 1. Flex panels (home dashboard, any .row with .card children).
      home.js emits cards with inline `flex:1 1 360px` and `flex:1 1 320px`.
      Below 768px those minimums exceed the available viewport, so override
      them to a full-width stack via !important. */
@media (max-width: 768px) {
  /* Force all flex-based card panels to fill the row and stack */
  .row > .card {
    flex-basis: 100% !important;
    min-width: 0 !important;
    flex-shrink: 1 !important;
  }

  /* Ensure flex rows themselves wrap and don't overflow */
  .row {
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
  }

  /* Workspace tables and cards must not produce a horizontal scrollbar on
     the page. They have their own .table-wrap overflow-x:auto. */
  .workspace > * {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Module title — prevent very long names from causing overflow */
  .module-title {
    font-size: 18px;
    flex-wrap: wrap;
    word-break: break-word;
  }

  /* Subnav pill rows already flex-wrap, but ensure they never overflow */
  .subnav, .pill-row {
    max-width: 100%;
  }

  /* Subnav / pill buttons: minimum 40px tap target height */
  .subnav-btn, .pill {
    min-height: 40px;
    min-width: 0;
  }

  /* General buttons: 40px minimum tap target */
  .btn {
    min-height: 40px;
  }

  /* Icon buttons: already 38px — nudge to 40px */
  .icon-btn {
    width: 40px;
    height: 40px;
  }

  /* Cards inside workspace — remove any fixed widths */
  .card {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  /* Modal full-screen at narrow viewports — prevent content overflow */
  .modal {
    max-height: 95vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
}

/* 2. Very narrow (≤360px) — additional refinements */
@media (max-width: 360px) {
  /* The KPI value font can overflow its card at the smallest sizes */
  .kpi .value { font-size: 22px; }

  /* Action rows in home dashboard: stack label and count vertically */
  .row > .card .row {
    flex-wrap: wrap;
  }

  /* Modals: full-width, minimal padding */
  .modal.modal-sm, .modal.modal-md, .modal.modal-lg, .modal.modal-xl,
  .modal:not(.modal-sm):not(.modal-lg):not(.modal-xl) {
    max-width: 100%;
    padding: var(--space-3);
  }
  .modal-backdrop {
    padding: var(--space-2);
    align-items: flex-end;
  }

  /* Form grids: always single column */
  .form-row.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Drawer: full width */
  .drawer.drawer-sm, .drawer.drawer-md, .drawer.drawer-lg,
  .drawer.drawer-xl, .drawer { width: 100vw; }
}

/* ─────────────────────────────────────────────────────────────────────────
   Visual Polish Pass — utility classes (all colours via var(*))
   ─────────────────────────────────────────────────────────────────────── */

/* ── Section header with icon ─────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}
.section-header h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 0;
  flex: 1;
}
.section-header .section-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

/* ── KPI card icon accent ─────────────────────────────────────────────── */
.kpi-icon {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  color: color-mix(in oklab, var(--primary) 30%, transparent);
}

/* ── Large empty state (section-level, not table-row) ─────────────────── */
.empty-state-lg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--surface-2) 50%, transparent);
}
.empty-state-lg .es-icon {
  opacity: .3;
  color: var(--primary);
}
.empty-state-lg .es-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.empty-state-lg .es-body {
  font-size: 13px;
  max-width: 300px;
  line-height: 1.5;
}

.home-body-loaded {
  animation: home-body-in 0.35s ease both;
}

@keyframes home-body-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .home-body-loaded { animation: none; }
  .kpi:hover { transform: none; }
}

.btn:active:not(:disabled):not(.loading) {
  transform: scale(0.98);
}

/* ── Skeleton table (multiple rows as placeholder) ─────────────────────── */
.skeleton-table {
  display: grid;
  gap: 6px;
}
.skeleton-table .skeleton-row {
  height: 44px;
  border-radius: var(--radius-sm);
}
/* First row (header) is slightly shorter */
.skeleton-table .skeleton-row:first-child {
  height: 36px;
  opacity: .5;
}

/* ── Zebra table rows ──────────────────────────────────────────────────── */
.table.zebra tbody tr:nth-child(even) td {
  background: color-mix(in oklab, var(--surface-2) 40%, transparent);
}

/* ── Sticky table header (scroll container must have max-height) ──────── */
.table-container {
  overflow: auto;
  max-height: 420px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.table-container .table th {
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--line);
}

/* ── Badge count (inside card-header) ─────────────────────────────────── */
.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--primary);
  color: var(--pill-fg, #001828);
  margin-left: var(--space-2);
}
.badge-count.badge-err {
  background: var(--err);
  color: #fff;
}
.badge-count.badge-warn {
  background: var(--warn);
  color: var(--pill-fg, #001828);
}

/* ── Action list (Home dashboard action queue) ─────────────────────────── */
.action-list {
  display: grid;
  gap: 0;
}
.action-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  transition: background .12s ease;
  border-radius: 0;
}
.action-list-item:last-child {
  border-bottom: none;
}
.action-list-item:hover {
  background: color-mix(in oklab, var(--primary) 5%, transparent);
  margin: 0 calc(-1 * var(--space-3));
  padding-left: var(--space-3);
  padding-right: var(--space-3);
  border-radius: var(--radius-sm);
}
.action-list-item .al-label {
  flex: 1;
  min-width: 0;
}
.action-list-item .al-count {
  font-size: 18px;
  font-weight: 800;
  flex-shrink: 0;
}
.action-list-item .al-count.ok   { color: var(--ok); }
.action-list-item .al-count.warn { color: var(--warn); }
.action-list-item .al-count.err  { color: var(--err); }

/* ── Detail row (key-value pair, used in drawers / detail panels) ──────── */
.detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid color-mix(in oklab, var(--line) 50%, transparent);
  font-size: 13px;
  align-items: baseline;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .dr-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
@media (max-width: 480px) {
  .detail-row { grid-template-columns: 1fr; gap: var(--space-1); }
}

/* ── Chip with coloured dot indicator ──────────────────────────────────── */
.chip-dot::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Button with icon + label (replaces icon+text combos) ─────────────── */
.btn-icon-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ── Card hover lift ──────────────────────────────────────────────────── */
.card.hoverable {
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.card.hoverable:hover {
  box-shadow: var(--shadow-2);
  border-color: color-mix(in oklab, var(--primary) 40%, var(--line));
  transform: translateY(-1px);
}
.card.hoverable:active {
  transform: translateY(0) scale(0.99);
}
.card.hoverable:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── KPI grid with auto glow on active values ──────────────────────────── */
.kpi.has-value .value:not(:empty) {
  text-shadow: 0 0 30px color-mix(in oklab, var(--primary) 20%, transparent);
}

/* ── Audit log diff viewer ─────────────────────────────────────────────── */
.diff-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.diff-col {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: auto;
  max-height: 200px;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-col.diff-before { border-left: 3px solid var(--err); }
.diff-col.diff-after  { border-left: 3px solid var(--ok); }
@media (max-width: 600px) {
  .diff-panel { grid-template-columns: 1fr; }
}

/* ── Loading overlay (positioned over a card/section while fetching) ──── */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  border-radius: inherit;
  z-index: 5;
}
.loading-overlay[hidden] { display: none; }
