/* Theme = dataviz skill's validated default palette, both modes.
   Light is always the default — no OS/prefers-color-scheme lookup. Dark only
   applies when an account explicitly picks it in Settings > Appearance. */
:root {
  color-scheme: light;

  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f2ef;
  --surface-3: #ebebe7;
  --border: rgba(11, 11, 11, 0.10);
  --ink: #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  --accent: #1baf7a;
  --accent-hover: #159163;
  --accent-soft: rgba(27, 175, 122, 0.14);
  --accent-glow-1: rgba(27, 175, 122, 0.40);
  --accent-glow-2: rgba(27, 175, 122, 0.16);
  --series-blue: #2a78d6;
  --series-blue-soft: rgba(42, 120, 214, 0.16);
  --series-orange: #eb6834;
  --series-orange-soft: rgba(235, 104, 52, 0.16);
  --series-yellow: #eda100;
  --series-purple: #8b5cf6;
  --series-purple-soft: rgba(139, 92, 246, 0.16);

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --on-warning-ink: #1a1a19; /* text on a warning-yellow fill; near-black in both modes */

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 76px;
  --topbar-h: 64px;
}

/* Dark mode: only when an account explicitly picks it in Settings. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.10);
  --ink: #ffffff;
  --ink-secondary: #c3c2b7;
  --ink-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;

  --accent: #199e70;
  --accent-hover: #22b982;
  --accent-soft: rgba(25, 158, 112, 0.16);
  --accent-glow-1: rgba(25, 158, 112, 0.45);
  --accent-glow-2: rgba(25, 158, 112, 0.18);
  --series-blue: #3987e5;
  --series-blue-soft: rgba(57, 135, 229, 0.18);
  --series-orange: #d95926;
  --series-orange-soft: rgba(217, 89, 38, 0.18);
  --series-yellow: #c98500;
  --series-purple: #a78bfa;
  --series-purple-soft: rgba(167, 139, 250, 0.18);
}

* { box-sizing: border-box; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---- Shell layout ---- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--page);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  transition: width 0.15s ease;
}
.app-shell.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  color: var(--ink);
  font-weight: 600;
  font-size: 1.05rem;
}
.sidebar-brand .bi { font-size: 1.4rem; color: var(--accent); }
.app-shell.sidebar-collapsed .label-text { display: none; }

.sidebar-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}
.sidebar-toggle:hover { color: var(--ink); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink-secondary);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-link .bi { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-link:hover { background: var(--surface-2); color: var(--ink); }
.sidebar-link.active {
  background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
  color: #ffffff;
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--page);
}
.topbar-title { font-size: 1.3rem; font-weight: 600; }
.topbar-spacer { flex: 1; }
.topbar-date { color: var(--ink-muted); font-size: 0.9rem; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--ink-muted);
  width: 220px;
}
.topbar-search input {
  background: none;
  border: none;
  color: var(--ink);
  outline: none;
  width: 100%;
  font-size: 0.88rem;
}

.topbar-icon-btn {
  background: none;
  border: none;
  color: var(--ink-secondary);
  font-size: 1.15rem;
  position: relative;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.topbar-icon-btn:hover { color: var(--ink); background: var(--surface-2); }

.notif-wrap { position: relative; }
/* The span always exists (for htmx's oob-swap to target); only rendered with
   a visible count badge when it actually carries this class. */
.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--status-critical);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--page);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.user-menu-caret { font-size: 0.7rem; color: var(--ink-muted); }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-menu-wrap { position: relative; }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 200px;
  background: var(--surface);
  border-radius: 14px;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.18s ease;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 16px 2px var(--accent-glow-2),
    0 20px 44px rgba(0, 0, 0, 0.35);
  padding: 6px;
}
.user-menu-panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.user-menu-panel form { margin: 0; }

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--ink);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--surface-2); color: var(--ink); }
.user-menu-item i { width: 18px; text-align: center; color: var(--ink-muted); }
.user-menu-item-danger:hover { background: var(--status-critical); color: #fff; }
.user-menu-item-danger:hover i { color: #fff; }

.content { padding: 24px; flex: 1; }

/* ---- Cards / tiles ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--ink);
}
.card-body { padding: 18px 20px; }

.stat-tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 12px;
}
.stat-tile-icon-green { background: var(--accent-soft); color: var(--accent); }
.stat-tile-icon-blue { background: var(--series-blue-soft); color: var(--series-blue); }
.stat-tile-icon-purple { background: var(--series-purple-soft); color: var(--series-purple); }
.stat-tile-icon-orange { background: var(--series-orange-soft); color: var(--series-orange); }
.stat-tile-icon-red { background: rgba(208, 59, 59, 0.14); color: var(--status-critical); }

/* Small inline version of the same icon badge, used next to page titles. */
.page-title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 0.95rem;
  margin-right: 10px;
  vertical-align: middle;
}
.page-title-icon-green { background: var(--accent-soft); color: var(--accent); }
.page-title-icon-blue { background: var(--series-blue-soft); color: var(--series-blue); }
.page-title-icon-purple { background: var(--series-purple-soft); color: var(--series-purple); }
.page-title-icon-orange { background: var(--series-orange-soft); color: var(--series-orange); }
.page-title-icon-neutral { background: var(--surface-3); color: var(--ink-secondary); }

.stat-tile-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.stat-tile-value { font-size: 2rem; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.stat-tile-sub { font-size: 0.8rem; color: var(--ink-secondary); margin-top: 2px; }

/* ---- Empty states (e.g. dashboard receipt log with no rows yet) ---- */

.empty-state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
}
.empty-state-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 16px;
}
.empty-state-title { font-weight: 600; color: var(--ink); }
.empty-state-sub { font-size: 0.85rem; color: var(--ink-muted); margin-top: 2px; }

/* Bootstrap's default .text-muted (#6c757d) is tuned for a light surface —
   ~3.7:1 on our dark card background, under the 4.5:1 AA floor. Re-point it
   at the secondary ink token instead (~9.7:1 on --surface). */
.text-muted { color: var(--ink-secondary) !important; }

/* ---- Contractor picker: searchable combobox + small linked-items table ---- */

.linked-contractors-table-wrap {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.linked-contractors-table-wrap .table { margin-bottom: 0; }
.linked-contractors-table-wrap .table td { border-color: var(--border); }
.linked-contractors-table-wrap .table tr:last-child td { border-bottom: none; }

.combobox { position: relative; }

.combobox-input:focus { z-index: 2; position: relative; }

.combobox-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}
.combobox-panel:empty { display: none; border: none; box-shadow: none; }

.combobox-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  font-size: 0.88rem;
  cursor: pointer;
}
.combobox-item:last-of-type { border-bottom: none; }
.combobox-item:hover, .combobox-item:focus { background: var(--accent-soft); outline: none; }
.combobox-item strong { color: var(--accent); }

.combobox-empty {
  padding: 12px 14px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}
.combobox-hint {
  padding: 7px 14px;
  color: var(--ink-muted);
  font-size: 0.74rem;
  border-top: 1px solid var(--border);
}

/* The real <select> a select-combobox wraps stays in the DOM (still submits
   with the form, still fires "change" for htmx) but is never shown itself —
   the text input + panel are the only visible/interactive parts. */
.select-combobox-native { display: none; }

/* ---- Tables ---- */

.table {
  color: var(--ink);
  border-color: var(--gridline);
  --bs-table-bg: transparent;
}
.table > :not(caption) > * > * {
  background: transparent;
  border-color: var(--gridline);
  color: var(--ink);
}
.table thead th {
  color: var(--ink-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 1px solid var(--baseline);
}
.table tbody tr:hover > * { background: var(--surface-2); }
.table-bordered { border: 1px solid var(--gridline); }
.table-bordered > :not(caption) > * > * { border-width: 1px; }

/* ---- Forms ---- */

.form-control, .form-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}
.form-control:focus, .form-select:focus {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 0 0 0.2rem var(--accent-soft);
}
.form-label { color: var(--ink-secondary); font-size: 0.85rem; margin-bottom: 4px; }
.form-select option { background: var(--surface-2); color: var(--ink); }
.radio-row { height: 38px; }

/* ---- Form footer (separates fields from their submit action) ---- */

.form-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* Lets side-by-side cards (e.g. Settings > Profile / Change password) match
   height even when one has fewer fields — the footer pins to the bottom
   instead of trailing right under the last field, so mismatched field counts
   don't read as mismatched card sizes. */
.card-equal-height { height: 100%; display: flex; flex-direction: column; }
.card-equal-height > .card-body { flex: 1; display: flex; flex-direction: column; }
.card-equal-height > .card-body > form { flex: 1; display: flex; flex-direction: column; }
.card-equal-height .form-footer { margin-top: auto; }

/* ---- Buttons ---- */

.btn-primary {
  background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
  border-color: var(--accent);
  color: #ffffff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  border-color: var(--accent-hover);
}

.btn-secondary { background: var(--surface-3); border-color: var(--border); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border); color: var(--ink); }

.btn-outline-secondary { color: var(--ink-secondary); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border); }

.btn-outline-danger { color: var(--status-critical); border-color: var(--status-critical); }
.btn-outline-danger:hover { background: var(--status-critical); color: #fff; }

.btn-outline-warning { color: var(--status-warning); border-color: var(--status-warning); }
.btn-outline-warning:hover { background: var(--status-warning); color: var(--on-warning-ink); }

.btn-outline-primary { color: var(--accent); border-color: var(--accent); }
.btn-outline-primary:hover { background: var(--accent); color: #fff; }

/* ---- Status chips ---- */

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip.good { background: rgba(12, 163, 12, 0.16); color: var(--status-good); }
.status-chip.muted { background: rgba(137, 135, 129, 0.16); color: var(--ink-muted); }
.status-chip.warning { background: rgba(250, 178, 25, 0.18); color: var(--status-warning); }

/* ---- Entity detail pages (contractor/distributor/dealer) ---- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
}
.back-link:hover { color: var(--accent-hover); text-decoration: underline; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px 24px;
  margin-top: 18px;
}
.detail-item { display: flex; align-items: flex-start; gap: 12px; }
.detail-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.detail-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 2px;
}
.detail-value { font-size: 0.95rem; font-weight: 500; color: var(--ink); word-break: break-word; }

.subpanel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-top: 14px;
}
.subpanel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.subpanel-title i { color: var(--accent); }

.btn-icon {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: none;
  color: var(--ink-secondary);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
}
.btn-icon:hover { background: var(--surface-3); color: var(--ink); }
.btn-icon-danger:hover { background: var(--status-critical); color: #fff; border-color: var(--status-critical); }
.btn-icon-warning:hover { background: var(--status-warning); color: var(--on-warning-ink); border-color: var(--status-warning); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.supplied-products-list { display: flex; flex-direction: column; gap: 8px; }
.supplied-product-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.supplied-product-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.supplied-product-name { flex: 1; font-weight: 500; font-size: 0.9rem; color: var(--ink); }

.section-icon-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
}
.section-icon-btn:hover { background: var(--accent); color: #fff; }

.empty-state {
  padding: 16px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.85rem;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ---- Tabs (e.g. Operations: Entry book / Dispatch book) ---- */

.tab-bar {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  background: none;
  border: none;
  padding: 4px 2px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  position: relative;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Mini charts (server-rendered inline SVG, see dashboard) ---- */

.mini-chart text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.mini-chart .axis-label { fill: var(--ink-muted); font-size: 9px; }

/* ---- Operations: current-stock tile + per-contractor breakdown ---- */
/* Fixed single-line height so it always matches the .form-select/.form-control
   controls beside it in the row — the breakdown lives in a popover instead of
   stacking inline, so the tile's box never changes shape as data changes. */

.stock-tile {
  position: relative;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stock-tile-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
}
.stock-tile-value { font-size: 1rem; font-weight: 600; line-height: 1.5; color: var(--ink); white-space: nowrap; }
.stock-tile-label {
  font-size: 1rem;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-tile-empty {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-secondary);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-tile-info-btn {
  margin-left: auto;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
}
.stock-tile-info-btn:hover { color: var(--accent); background: var(--accent-soft); }

.stock-breakdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.16s ease, transform 0.16s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.16s ease;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 14px 2px var(--accent-glow-2),
    0 16px 34px rgba(0, 0, 0, 0.35);
}
.stock-breakdown-panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.stock-breakdown-title {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.stock-breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.78rem;
  padding: 2px 0;
}
.stock-breakdown-code { color: var(--ink-secondary); font-weight: 500; }
.stock-breakdown-qty {
  font-weight: 600;
  font-size: 0.74rem;
  color: var(--ink);
  background: var(--surface-3);
  padding: 1px 9px;
  border-radius: 999px;
}

/* ---- Form validation feedback ---- */

.invalid-feedback { color: var(--status-critical); }
.form-control.is-invalid, .form-select.is-invalid {
  border-color: var(--status-critical);
  background-image: none; /* drop Bootstrap's default light-mode error icon */
}
.form-control.is-invalid:focus, .form-select.is-invalid:focus {
  box-shadow: 0 0 0 0.2rem rgba(208, 59, 59, 0.18);
}

/* ---- Modal: blurred backdrop + a soft neon-green ring in the app accent ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.32s ease, visibility 0.32s ease, backdrop-filter 0.32s ease, -webkit-backdrop-filter 0.32s ease;
}
.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  transform: scale(0.92) translateY(18px);
  opacity: 0;
  will-change: transform, opacity;
  transition:
    transform 0.38s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.28s ease,
    box-shadow 0.38s ease;
  box-shadow:
    0 0 0 1px transparent,
    0 0 0 0 transparent,
    0 0 0 0 transparent,
    0 25px 60px rgba(0, 0, 0, 0.45);
}
.modal-overlay.open .modal-box {
  transform: scale(1) translateY(0);
  opacity: 1;
  box-shadow:
    0 0 0 1px var(--accent-glow-1),
    0 0 22px 3px var(--accent-glow-1),
    0 0 70px 16px var(--accent-glow-2),
    0 25px 60px rgba(0, 0, 0, 0.45);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 1.05rem;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
}
.modal-close:hover { color: var(--ink); background: var(--surface-2); }

.modal-box h5 { margin-bottom: 1.25rem; }

/* ---- Notification panel (bell dropdown) ---- */

.notif-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.18s ease;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 16px 2px var(--accent-glow-2),
    0 20px 44px rgba(0, 0, 0, 0.35);
}
.notif-panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.notif-panel:empty { box-shadow: none; }

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--ink);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.notif-clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 2px;
}
.notif-clear-btn:hover { color: var(--accent-hover); text-decoration: underline; }

.notif-panel-list { padding: 4px 0; }

.notif-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 16px;
  border-left: 3px solid transparent;
}
.notif-item + .notif-item { border-top: 1px solid var(--border); }
.notif-item-success { border-left-color: var(--status-good); }
.notif-item-error { border-left-color: var(--status-critical); }
.notif-item .bi-check-circle-fill { color: var(--status-good); margin-top: 2px; }
.notif-item .bi-exclamation-triangle-fill { color: var(--status-critical); margin-top: 2px; }
.notif-item-body { min-width: 0; }
.notif-item-message { font-size: 0.86rem; color: var(--ink); word-wrap: break-word; }
.notif-item-time { font-size: 0.72rem; color: var(--ink-muted); margin-top: 2px; }

.notif-empty { padding: 24px 16px; text-align: center; color: var(--ink-muted); font-size: 0.85rem; }

/* ---- Toasts ---- */

.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 340px;
  max-width: calc(100vw - 40px);
  pointer-events: none;
}

.toast-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px;
  background: var(--surface);
  border-radius: 12px;
  border-left: 4px solid var(--status-good);
  color: var(--ink);
  font-size: 0.88rem;
  pointer-events: auto;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow:
    0 0 0 1px var(--border),
    0 0 20px 2px var(--accent-glow-2),
    0 14px 34px rgba(0, 0, 0, 0.3);
}
.toast-item.show { opacity: 1; transform: translateX(0); }
.toast-item.hide { opacity: 0; transform: translateX(24px) scale(0.98); }
.toast-item.toast-error { border-left-color: var(--status-critical); }
.toast-item .bi-check-circle-fill { color: var(--status-good); font-size: 1.05rem; margin-top: 1px; }
.toast-item .bi-exclamation-triangle-fill { color: var(--status-critical); font-size: 1.05rem; margin-top: 1px; }
.toast-message { flex: 1; line-height: 1.4; padding-top: 1px; }
.toast-close {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--ink); }

/* ============================================================================
   Dashboard
   One header shape for every panel (title / hint / optional count badge) so
   the eye doesn't re-learn the layout on each card, plus the small data
   graphics the panels are built from. Semantic colour (good/warning/critical)
   is kept separate from the accent — the accent means "this app", the status
   colours mean "this number needs you".
   ========================================================================= */

.dash-section { display: grid; gap: 14px; }
.dash-section + .dash-section { margin-top: 14px; }
.dash-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dash-split-wide { grid-template-columns: 1.6fr 1fr; }
.dash-split-even { grid-template-columns: 1fr 1fr; }

@media (max-width: 1100px) {
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-split-wide, .dash-split-even { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dash-kpis { grid-template-columns: 1fr; }
}

/* ---- panel header ---- */
.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.panel-title { font-size: 0.98rem; font-weight: 600; color: var(--ink); margin: 0; }
.panel-count {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}
.panel-count.is-critical { background: rgba(208, 59, 59, 0.14); color: var(--status-critical); }
.panel-hint { font-size: 0.76rem; color: var(--ink-muted); margin: 0 0 12px; }
.panel-link { margin-left: auto; }

/* ---- KPI tile ---- */
.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.kpi-value.is-outstanding { color: var(--status-critical); }
.kpi-value.is-good { color: var(--accent); }
.kpi-foot { font-size: 0.78rem; color: var(--ink-secondary); margin-top: 3px; }

.dash-meter {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 11px;
}
.dash-meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.dash-meter > span.is-blue { background: var(--series-blue); }

/* ---- stacked bar (ageing, order pipeline) ---- */
.dash-stack { display: flex; height: 30px; border-radius: 8px; overflow: hidden; background: var(--surface-3); }
.dash-stack > span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.dash-stack-good { background: var(--accent); }
.dash-stack-warn { background: var(--status-warning); color: var(--on-warning-ink) !important; }
.dash-stack-crit { background: var(--status-critical); }
.dash-stack-blue { background: var(--series-blue); }

.dash-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 0.76rem; color: var(--ink-secondary); }
.dash-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dash-legend i { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ---- rows (debtors, stock, alerts) ---- */
.dash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.87rem;
}
.dash-row:last-child { border-bottom: none; }
.dash-row-amount { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash-row-amount.is-critical { color: var(--status-critical); font-weight: 600; }

.dash-trackbar { flex: 1; max-width: 96px; height: 4px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.dash-trackbar > span { display: block; height: 100%; background: var(--series-orange); }

/* ---- alert row: severity carried by a stripe as well as the number ---- */
.dash-alert {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.87rem;
  text-decoration: none;
  color: inherit;
}
.dash-alert:last-child { border-bottom: none; }
.dash-alert:hover .dash-alert-who { text-decoration: underline; }
.dash-alert-stripe { width: 3px; border-radius: 2px; flex-shrink: 0; background: var(--ink-muted); }
.dash-alert-body { flex: 1; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.dash-alert-who { font-weight: 600; color: var(--ink); }
.dash-alert-what { color: var(--ink-secondary); }
.dash-alert-value { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.dash-alert.sev-critical .dash-alert-stripe { background: var(--status-critical); }
.dash-alert.sev-critical .dash-alert-value { color: var(--status-critical); }
.dash-alert.sev-warning .dash-alert-stripe { background: var(--status-warning); }
.dash-alert.sev-warning .dash-alert-value { color: var(--status-warning); }
.dash-alert.sev-info .dash-alert-stripe { background: var(--series-blue); }
.dash-alert.sev-info .dash-alert-value { color: var(--series-blue); }

/* ---- quiet footer line for master-data counts ---- */
.dash-footnote {
  margin-top: 18px;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- all-clear state inside a panel ---- */
.dash-clear { display: flex; align-items: center; gap: 10px; padding: 14px 0; color: var(--ink-secondary); font-size: 0.87rem; }
.dash-clear i { color: var(--accent); font-size: 1.1rem; }

/* Narrow screens: let row content wrap rather than push the amount out of the
   card. (The app shell's fixed-width sidebar is what actually forces sideways
   scrolling below ~560px, on every page — this just stops the dashboard from
   making it worse.) */
.dash-row { flex-wrap: wrap; }
.dash-row > a { min-width: 0; overflow-wrap: anywhere; }
/* Without min-width:0 a flex child refuses to shrink past its content width,
   which pushes the trailing amount outside the card. */
.dash-alert-body { min-width: 0; }
.dash-alert-body > span { overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .dash-trackbar { display: none; }
  .dash-row-amount, .dash-alert-value { margin-left: 0; }
}

/* Settings > Dashboard: one switch per optional panel. The whole row is a
   <label>, so clicking the text toggles it too, not just the switch itself. */
.settings-panel-toggle {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.settings-panel-toggle:last-of-type { border-bottom: none; }
.settings-panel-label { font-weight: 500; color: var(--ink); }
.settings-panel-hint { display: block; font-size: 0.78rem; font-weight: 400; color: var(--ink-muted); margin-top: 1px; }

/* macOS/iOS-style switch: a real checkbox, visually hidden but still in the
   tab order and screen-reader-visible, laid over a pill track + sliding knob
   built from plain spans so the look isn't tied to any one browser's
   checkbox rendering. */
.switch { position: relative; flex-shrink: 0; width: 40px; height: 24px; margin-top: 1px; }
.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.switch input:checked ~ .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked ~ .switch-track .switch-knob { transform: translateX(16px); }
.switch input:focus-visible ~ .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }
