/* =====================================================================
   UK ASSET ERP — "Wired" editorial design system
   Strict black-on-white duet · square corners · hairline rules ·
   serif display headlines · sans UI labels · zero drop-shadows.
   See DESIGN-wired.md for the full token reference.
   ===================================================================== */

:root {
  /* ---- Brand & ink ---- */
  --ink: #000000;            /* primary — wordmark, headlines, CTAs, footer */
  --ink-soft: #1a1a1a;       /* near-black emphasis */
  --body: #757575;           /* secondary metadata, bylines, timestamps */
  --on-primary: #ffffff;

  /* ---- Surface ---- */
  --canvas: #ffffff;
  --canvas-soft: #f5f5f5;    /* table headers, hover rows, soft panels */
  --hairline: #e0e0e0;       /* the brand's only line */

  /* ---- The single accent ---- */
  --link: #057dbc;           /* inline links only, used sparingly */

  /* ---- Type families (open-source substitutes per DESIGN-wired.md) ---- */
  --font-display: "Playfair Display", "Times New Roman", Georgia, serif;
  --font-serif: "Lora", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;

  /* ---- Spacing scale (4px base) ---- */
  --sp-xxs: 2px;  --sp-xs: 4px;  --sp-sm: 8px;  --sp-md: 12px;
  --sp-lg: 16px;  --sp-xl: 20px; --sp-2xl: 24px; --sp-3xl: 32px; --sp-4xl: 48px;

  --sidebar-width: 264px;

  /* Bootstrap variable overrides — kill the rounded corners globally */
  --bs-border-radius: 0;
  --bs-border-radius-sm: 0;
  --bs-border-radius-lg: 0;
  --bs-border-radius-xl: 0;
  --bs-border-radius-pill: 9999px;
  --bs-body-font-family: var(--font-sans);
  --bs-body-color: var(--ink-soft);
  --bs-link-color: var(--link);
  --bs-link-hover-color: var(--ink);
}

/* ---------------------------------------------------------------------
   Base
   --------------------------------------------------------------------- */
*,
*::before,
*::after { border-radius: 0; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-soft);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

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

.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

::selection { background: var(--ink); color: var(--on-primary); }

/* Headings default to the display serif */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--ink);
  letter-spacing: -0.01em;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--canvas);
  border-right: 1px solid var(--hairline);
  color: var(--ink);
  padding: var(--sp-2xl) var(--sp-lg);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 1040;
}

/* Masthead wordmark — the signature black block */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding-bottom: var(--sp-lg);
  margin-bottom: var(--sp-xl);
  border-bottom: 2px solid var(--ink);
}

.brand-logo {
  width: 44px;
  height: 44px;
  background: var(--ink);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand-logo.large { width: 60px; height: 60px; font-size: 20px; }

.brand-title {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.1;
}

.brand-subtitle {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--body);
}

.sidebar-nav { display: block; }

.sidebar-group { margin-bottom: var(--sp-xl); }

.sidebar-group-title {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: var(--sp-sm);
  padding: 0 var(--sp-md);
}

.sidebar-links { display: grid; gap: 0; }

.sidebar-link {
  /* Explicit, not inherited from the parent's layout mode. Relying on the
     grid parent to blockify these anchors meant that the moment anything
     changed .sidebar-links to display:block they reverted to inline, their
     padding boxes overlapped, and clicks landed on the wrong link. */
  display: block;
  color: var(--ink-soft);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 10px var(--sp-md);
  border-left: 3px solid transparent;
  transition: background 0.12s ease;
}

.sidebar-link:hover {
  background: var(--canvas-soft);
  color: var(--ink);
}

.sidebar-link.active {
  background: var(--canvas-soft);
  color: var(--ink);
  border-left-color: var(--ink);
  font-weight: 700;
}

.sidebar-link.standalone {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-xl);
}

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

/* ---------------------------------------------------------------------
   Topbar
   --------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-lg);
  padding: var(--sp-md) var(--sp-2xl);
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--sp-md); }

.sidebar-toggle { display: none; }

.search-form {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 9px var(--sp-lg);
  min-width: min(420px, 50vw);
  border: 1px solid var(--ink);
  background: var(--canvas);
  color: var(--ink);
}

.search-form input {
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
}

.search-form input::placeholder { color: var(--body); }

.icon-button {
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--ink);
  position: relative;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover { border-color: var(--ink); }

.icon-button .badge {
  position: absolute;
  top: -6px;
  right: -6px;
}

.profile-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 6px var(--sp-md) 6px 6px;
  border: 1px solid var(--hairline);
  background: var(--canvas);
  color: var(--ink);
}

.profile-pill:hover { border-color: var(--ink); }

.profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--on-primary);
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.profile-avatar.xl { width: 84px; height: 84px; font-size: 30px; }

.profile-name { font-family: var(--font-sans); font-weight: 700; font-size: 14px; line-height: 1.1; }
.profile-role {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--body);
}

.main-content { padding-bottom: var(--sp-4xl); flex: 1; }

/* ---------------------------------------------------------------------
   Page header (editorial masthead for each page)
   --------------------------------------------------------------------- */
.page-header {
  padding-bottom: var(--sp-lg);
  border-bottom: 2px solid var(--ink);
}

.page-eyebrow {
  text-transform: uppercase;
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink);
  margin-bottom: var(--sp-sm);
  font-weight: 700;
}

.page-title {
  font-family: var(--font-display);
  font-size: 44px;
  line-height: 1.04;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.page-subtitle {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.5;
  color: var(--body);
  max-width: 680px;
}

/* ---------------------------------------------------------------------
   Cards & containers — flat, hairline-bordered, square
   --------------------------------------------------------------------- */
.erp-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  box-shadow: none;
  padding: var(--sp-2xl);
}

.erp-card:hover { transform: none; box-shadow: none; }

.card-head { margin-bottom: var(--sp-lg); padding-bottom: var(--sp-md); border-bottom: 1px solid var(--hairline); }

.card-head h3, .erp-card h3 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
}

.dashboard-chart-card { overflow: hidden; }
.dashboard-chart-wrap { position: relative; width: 100%; }
.dashboard-chart-wrap-line { height: 340px; }
.dashboard-chart-wrap-donut { height: 320px; max-width: 320px; margin: 0 auto; }
.dashboard-chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ---------------------------------------------------------------------
   Stat cards — magazine "by the numbers" boxes
   --------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-lg);
}

.stats-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat-card {
  border: 1px solid var(--hairline);
  border-top: 3px solid var(--ink);
  position: relative;
  overflow: hidden;
  padding: var(--sp-xl);
}

/* Variants keep the strict duet — differentiation comes from the top rule
   weight + label, never a chromatic fill. Accent is the single link blue. */
.stat-card.success { border-top-color: var(--ink); }
.stat-card.danger  { border-top-color: var(--body); }
.stat-card.accent  { border-top-color: var(--link); }

.stat-label {
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--sp-md);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1.05;
  font-weight: 400;
  color: var(--ink);
  position: relative;
  z-index: 1;
}

/* Neutralise the old red/green helpers from Bootstrap on stat values */
.stat-value.text-success, .stat-value.text-danger { color: var(--ink) !important; }

.stat-meta {
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 13px;
  margin-top: var(--sp-md);
  position: relative;
  z-index: 1;
}

/* ---------------------------------------------------------------------
   Tables — editorial ledger with hairline rows
   --------------------------------------------------------------------- */
.erp-table { width: 100%; border-collapse: collapse; }

.erp-table thead {
  background: var(--canvas-soft);
  color: var(--ink);
}

.erp-table thead th {
  padding: var(--sp-md) var(--sp-lg);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink);
  border: none;
  border-bottom: 2px solid var(--ink);
  text-align: left;
}

.erp-table tbody td {
  padding: var(--sp-md) var(--sp-lg);
  vertical-align: middle;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--hairline);
}

.erp-table tbody tr:hover { background: var(--canvas-soft); }

.table-actions { display: flex; gap: var(--sp-sm); flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Buttons — square, monochrome
   --------------------------------------------------------------------- */
.btn {
  border-radius: 0 !important;
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.btn-erp-primary,
.btn-primary {
  background: var(--ink);
  color: var(--on-primary);
  border: 1px solid var(--ink);
  padding: 11px var(--sp-xl);
  font-size: 15px;
  font-weight: 700;
  box-shadow: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-erp-primary:hover,
.btn-primary:hover {
  background: var(--canvas);
  color: var(--ink);
  border-color: var(--ink);
  transform: none;
}

/* All outline variants collapse to the ink-on-white square button.
   Hover inverts to a solid black fill. */
.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-success,
.btn-outline-danger,
.btn-outline-dark,
.btn-outline-info,
.btn-outline-warning {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--ink);
}

.btn-outline-primary:hover,
.btn-outline-secondary:hover,
.btn-outline-success:hover,
.btn-outline-danger:hover,
.btn-outline-dark:hover,
.btn-outline-info:hover,
.btn-outline-warning:hover {
  background: var(--ink);
  color: var(--on-primary);
  border-color: var(--ink);
}

/* Destructive actions: same square geometry, signalled by a heavy 2px rule
   (Elevation Level 2) rather than colour. */
.btn-outline-danger { border-width: 2px; }

.btn-secondary { background: var(--canvas); color: var(--ink); border: 1px solid var(--ink); }
.btn-secondary:hover { background: var(--ink); color: var(--on-primary); }

.btn-success { background: var(--ink); color: var(--on-primary); border: 1px solid var(--ink); }
.btn-success:hover { background: var(--canvas); color: var(--ink); }

.btn-sm { padding: 6px var(--sp-md); font-size: 13px; }
.btn-lg { padding: 14px var(--sp-2xl); font-size: 16px; }

.btn-link { color: var(--link); font-weight: 700; text-decoration: none; }
.btn-link:hover { color: var(--ink); text-decoration: underline; }

/* ---------------------------------------------------------------------
   Forms — square inputs, 1px ink border
   --------------------------------------------------------------------- */
.form-label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: var(--sp-xs);
  letter-spacing: 0.01em;
}

.form-control,
.form-select {
  border: 1px solid var(--ink);
  border-radius: 0 !important;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 10px var(--sp-lg);
  box-shadow: none;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
  outline: none;
}

.form-control::placeholder { color: var(--body); }

.form-text { color: var(--body); font-size: 13px; font-family: var(--font-sans); }
.form-text a { color: var(--link); }

.invalid-feedback { color: var(--ink-soft); font-weight: 600; }
.is-invalid { border-color: var(--ink) !important; border-width: 2px !important; }

kbd {
  background: var(--ink);
  color: var(--on-primary);
  border-radius: 0;
  padding: 1px 6px;
  font-family: var(--font-sans);
  font-size: 11px;
}

/* ---------------------------------------------------------------------
   Badges, alerts, pills — monochrome
   --------------------------------------------------------------------- */
.badge {
  border-radius: 0 !important;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
}

.badge.bg-danger,
.badge.bg-success,
.badge.bg-warning,
.badge.bg-info,
.badge.bg-primary,
.badge.bg-secondary {
  background: var(--ink) !important;
  color: var(--on-primary) !important;
}

.badge.rounded-pill { border-radius: 9999px !important; }

.alert {
  border-radius: 0;
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--ink);
  background: var(--canvas-soft);
  color: var(--ink-soft);
  font-family: var(--font-sans);
}

.alert-warning,
.alert-danger,
.alert-success,
.alert-info {
  background: var(--canvas-soft);
  color: var(--ink-soft);
  border-left-color: var(--ink);
}

.soft-alert { border: 1px solid var(--hairline); border-left: 3px solid var(--ink); background: var(--canvas-soft); }

/* Bootstrap text-colour helpers → ink (keep the strict duet) */
.text-success, .text-danger, .text-primary, .text-info, .text-warning { color: var(--ink) !important; }
.text-muted { color: var(--body) !important; }

/* ---------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: var(--sp-4xl) var(--sp-xl);
  color: var(--body);
  background: var(--canvas-soft);
}

.empty-state h5 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--ink);
  margin-bottom: var(--sp-sm);
}

/* ---------------------------------------------------------------------
   Domain cards (projects / resources / workers)
   --------------------------------------------------------------------- */
.project-card, .resource-card, .worker-card { height: 100%; }

.project-code {
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--body);
  font-weight: 700;
}

.resource-icon, .worker-avatar, .shape-box {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--on-primary);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  margin-bottom: var(--sp-lg);
}

.worker-avatar { border-radius: 9999px; }

.shape-preview { display: flex; align-items: center; justify-content: center; min-height: 260px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-lg);
}

.detail-grid .full { grid-column: 1 / -1; }

.detail-grid strong {
  display: block;
  margin-bottom: var(--sp-xs);
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-grid span { font-family: var(--font-serif); font-size: 17px; font-weight: 400; color: var(--ink); }

.mini-stat {
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  padding: var(--sp-lg);
}

.mini-stat span {
  display: block;
  color: var(--body);
  margin-bottom: var(--sp-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mini-stat strong { font-family: var(--font-display); font-size: 24px; font-weight: 400; color: var(--ink); }

.narrow-card { max-width: 520px; }

/* ---------------------------------------------------------------------
   Search results
   --------------------------------------------------------------------- */
.search-result-item {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: var(--sp-lg) 0;
  border-bottom: 1px solid var(--hairline);
}

.search-result-item:hover { background: var(--canvas-soft); color: var(--ink); }

/* ---------------------------------------------------------------------
   Reports hub
   --------------------------------------------------------------------- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-lg);
}

.report-link {
  text-decoration: none;
  color: var(--ink);
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: background 0.12s ease;
}

.report-link:hover { background: var(--canvas-soft); color: var(--ink); }
.report-link i { font-size: 28px; color: var(--ink); }

/* ---------------------------------------------------------------------
   Area calculator
   --------------------------------------------------------------------- */
.calculator-result {
  background: var(--ink);
  color: var(--on-primary);
  padding: var(--sp-xl) var(--sp-2xl);
}

.calculator-result span { display: block; color: rgba(255, 255, 255, 0.7); font-family: var(--font-sans); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.calculator-result strong { font-family: var(--font-display); font-size: 40px; font-weight: 400; }

.setup-box {
  padding: var(--sp-xl);
  background: var(--canvas-soft);
  border: 1px dashed var(--ink);
}

/* ---------------------------------------------------------------------
   Notifications dropdown
   --------------------------------------------------------------------- */
.dropdown-menu {
  border-radius: 0;
  border: 1px solid var(--ink);
  box-shadow: none;
  font-family: var(--font-sans);
}

.dropdown-item { font-family: var(--font-sans); font-size: 14px; color: var(--ink-soft); }
.dropdown-item:hover { background: var(--canvas-soft); color: var(--ink); }
.dropdown-header { font-family: var(--font-sans); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; color: var(--ink); }
.dropdown-divider { border-color: var(--hairline); }

.notification-menu { width: 360px; padding: var(--sp-sm); }
.notification-item { padding: var(--sp-md); white-space: normal; border-bottom: 1px solid var(--hairline); }
.notification-item:last-child { border-bottom: none; }

/* ---------------------------------------------------------------------
   Login page — Wired masthead
   --------------------------------------------------------------------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--canvas);
  padding: var(--sp-lg);
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  padding: var(--sp-4xl);
  background: var(--canvas);
  border: 1px solid var(--ink);
  box-shadow: none;
}

.login-brand { display: flex; align-items: center; gap: var(--sp-lg); padding-bottom: var(--sp-lg); border-bottom: 2px solid var(--ink); margin-bottom: var(--sp-xl); }
.login-brand h1 { font-family: var(--font-display); font-size: 34px; font-weight: 400; margin-bottom: 2px; color: var(--ink); }
.login-brand p { color: var(--body); margin-bottom: 0; font-family: var(--font-sans); font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }

/* ---------------------------------------------------------------------
   Third-party widget overrides
   --------------------------------------------------------------------- */

/* DataTables */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--ink) !important;
  border-radius: 0 !important;
  padding: 6px var(--sp-md);
  font-family: var(--font-sans);
}
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_info { font-family: var(--font-sans); font-size: 13px; color: var(--body); }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: 0 !important;
  border: 1px solid var(--hairline) !important;
  color: var(--ink) !important;
  background: var(--canvas) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--ink) !important;
  color: var(--on-primary) !important;
  border-color: var(--ink) !important;
}

/* Bootstrap5-integrated DataTables pagination */
.page-link {
  border-radius: 0 !important;
  color: var(--ink) !important;
  border-color: var(--hairline) !important;
  font-family: var(--font-sans);
  font-weight: 600;
}
.page-link:hover { background: var(--canvas-soft) !important; color: var(--ink) !important; }
.page-item.active .page-link {
  background: var(--ink) !important;
  border-color: var(--ink) !important;
  color: var(--on-primary) !important;
}
.page-item.disabled .page-link { color: var(--body) !important; }

/* Select2 — match the square ink input */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
  border: 1px solid var(--ink) !important;
  border-radius: 0 !important;
  min-height: 44px;
  font-family: var(--font-sans);
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 42px;
  color: var(--ink);
  padding-left: var(--sp-lg);
}
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 42px; }
.select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--ink) !important; color: var(--on-primary); }
.select2-dropdown { border: 1px solid var(--ink) !important; border-radius: 0 !important; }
.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: var(--ink) !important;
  color: var(--on-primary) !important;
  border: none !important;
  border-radius: 0 !important;
}

/* Flatpickr */
.flatpickr-calendar { border-radius: 0; box-shadow: 0 0 0 1px var(--ink); }
.flatpickr-day.selected { background: var(--ink); border-color: var(--ink); border-radius: 0; }

/* Toastr — square monochrome toasts */
#toast-container > div {
  border-radius: 0 !important;
  box-shadow: 0 0 0 1px var(--ink) !important;
  opacity: 1 !important;
  font-family: var(--font-sans);
  background-color: var(--ink) !important;
}
#toast-container > .toast-success,
#toast-container > .toast-error,
#toast-container > .toast-warning,
#toast-container > .toast-info { background-image: none !important; padding-left: var(--sp-lg); }

/* SweetAlert */
.swal2-popup { border-radius: 0 !important; border: 1px solid var(--ink); font-family: var(--font-sans); }
.swal2-title { font-family: var(--font-display); font-weight: 400; }
.swal2-styled { border-radius: 0 !important; }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 1199px) {
  .stats-grid,
  .stats-grid.compact,
  .report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 991px) {
  .sidebar { position: fixed; transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,0.3); }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .search-form { min-width: 0; flex: 1; }
  .topbar { padding: var(--sp-md) var(--sp-lg); }
  .detail-grid,
  .report-grid,
  .stats-grid,
  .stats-grid.compact { grid-template-columns: 1fr; }
  .page-title { font-size: 36px; }
}

@media (max-width: 767px) {
  .erp-card { padding: var(--sp-lg); }
  .dashboard-chart-wrap-line, .dashboard-chart-wrap-donut { height: 280px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-left, .topbar-right { justify-content: space-between; }
  .erp-table { display: block; overflow-x: auto; }
  .page-title { font-size: 30px; }
}

@media print {
  .sidebar,
  .topbar,
  .page-actions,
  .btn,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_paginate { display: none !important; }
  .app-main, .main-content, .container-fluid { margin: 0 !important; padding: 0 !important; }
  .erp-card { box-shadow: none; border: 1px solid var(--hairline); }
}

/* =====================================================================
   NEW COMPONENTS
   Everything below was added for the rebuilt shell: pagination, form
   errors, destructive-action confirmations, error pages, the guest
   (login) shell, and a mobile layout a site foreman can actually use.
   ===================================================================== */

:root {
  /* The one deliberate exception to the black-on-white duet. A validation
     error rendered in near-black is indistinguishable from help text, so
     users re-submitted the same broken form over and over. */
  --error: #b3261e;
  --error-soft: #fdf3f2;
  --ok: #1b6b3a;
}

/* ---------------------------------------------------------------------
   Page header — layout moved out of Bootstrap utility classes so the
   component owns its own responsive behaviour.
   --------------------------------------------------------------------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--sp-lg);
}

.page-header-main { min-width: 0; }

.page-actions { display: flex; flex-wrap: wrap; gap: var(--sp-sm); }

/* ---------------------------------------------------------------------
   Sidebar — <details> groups, active item, mobile drawer
   --------------------------------------------------------------------- */
.sidebar-brand-text { min-width: 0; }

/* The group header is a <summary>: focusable and toggled by Enter/Space
   with no JavaScript and no ARIA state to keep in sync. */
summary.sidebar-group-title {
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 10px var(--sp-md);
  margin-bottom: var(--sp-xxs);
  min-height: 44px;              /* comfortable touch target */
}

summary.sidebar-group-title::-webkit-details-marker { display: none; }
summary.sidebar-group-title::marker { content: ""; }
summary.sidebar-group-title:hover { background: var(--canvas-soft); color: var(--ink); }

.sidebar-chevron {
  margin-left: auto;
  font-size: 11px;
  transition: transform 0.15s ease;
}

details.sidebar-group[open] > summary .sidebar-chevron { transform: rotate(180deg); }

.sidebar-empty {
  color: var(--body);
  font-size: 13px;
  padding: var(--sp-md);
  border: 1px dashed var(--hairline);
}

/* Keyboard focus must be obvious everywhere in the nav. */
.sidebar a:focus-visible,
.sidebar summary:focus-visible,
.topbar button:focus-visible,
.topbar a:focus-visible,
.btn:focus-visible,
.page-link:focus-visible {
  outline: 3px solid var(--link);
  outline-offset: 2px;
}

/* The mobile drawer dims the page behind it. */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1035;
  border: 0;
}

.sidebar-backdrop[hidden] { display: none; }

/* The toggle was btn-outline-light on a white topbar — invisible, so on a
   phone there was no way to open the menu at all. */
.sidebar-toggle {
  border: 1px solid var(--ink);
  background: var(--canvas);
  color: var(--ink);
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus { background: var(--ink); color: var(--on-primary); }

/* ---------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------- */
.erp-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  margin-top: var(--sp-xl);
  padding-top: var(--sp-lg);
  border-top: 1px solid var(--hairline);
}

.erp-pagination .pagination { flex-wrap: wrap; gap: var(--sp-xxs); }

.erp-pagination .page-link {
  min-width: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
}

.pagination-summary {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--body);
  margin-top: var(--sp-md);
}

.erp-pagination .pagination-summary { margin-top: 0; }
.pagination-summary strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   Form errors — the one place colour carries meaning
   --------------------------------------------------------------------- */
.field-error {
  display: block;
  margin-top: var(--sp-xs);
  padding: 6px var(--sp-sm);
  border-left: 3px solid var(--error);
  background: var(--error-soft);
  color: var(--error);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
}

/* Help text sits directly above errors, so the two must never look alike. */
.form-text { font-weight: 400; }

.invalid-feedback,
.errorlist { color: var(--error); font-weight: 600; list-style: none; padding-left: 0; }

.is-invalid,
.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--error) !important;
  border-width: 2px !important;
}

.alert-danger {
  border-left-color: var(--error);
  color: var(--error);
  background: var(--error-soft);
}

/* ---------------------------------------------------------------------
   Destructive-action confirmation
   --------------------------------------------------------------------- */
.delete-warning {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-lg);
  padding: var(--sp-lg);
  margin-bottom: var(--sp-xl);
  border: 1px solid var(--error);
  border-left-width: 4px;
  background: var(--error-soft);
}

.delete-warning > i { font-size: 22px; color: var(--error); line-height: 1.3; }

.delete-target-type {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--error);
  margin-bottom: var(--sp-xs);
}

.delete-target-label {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
  color: var(--ink);
  word-break: break-word;
}

.confirm-facts {
  display: grid;
  grid-template-columns: minmax(0, 140px) minmax(0, 1fr);
  gap: var(--sp-sm) var(--sp-lg);
  margin: 0 0 var(--sp-xl);
  padding-bottom: var(--sp-lg);
  border-bottom: 1px solid var(--hairline);
}

.confirm-facts dt {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--body);
}

.confirm-facts dd { margin: 0; font-family: var(--font-serif); font-size: 16px; color: var(--ink); }

.btn-danger {
  background: var(--error);
  border: 1px solid var(--error);
  color: var(--on-primary);
}

.btn-danger:hover { background: var(--canvas); color: var(--error); border-color: var(--error); }

.btn-outline-danger { border-color: var(--error); color: var(--error); }
.btn-outline-danger:hover { background: var(--error); border-color: var(--error); color: var(--on-primary); }

/* ---------------------------------------------------------------------
   Error pages (base_error.html + 403 / 404 / 500)
   --------------------------------------------------------------------- */
.error-page { background: var(--canvas); }

.error-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-xl);
}

.error-card {
  width: min(560px, 100%);
  border: 1px solid var(--ink);
  border-top: 6px solid var(--ink);
  background: var(--canvas);
  padding: var(--sp-4xl);
}

.error-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding-bottom: var(--sp-lg);
  margin-bottom: var(--sp-xl);
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink);
}

.error-brand .brand-logo { width: 36px; height: 36px; font-size: 13px; }

.error-code {
  font-family: var(--font-display);
  font-size: 72px;
  line-height: 1;
  color: var(--ink);
  margin-bottom: var(--sp-sm);
}

.error-title {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: var(--sp-lg);
}

.error-text {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--body);
  margin-bottom: var(--sp-md);
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-top: var(--sp-xl);
  padding-top: var(--sp-lg);
  border-top: 1px solid var(--hairline);
}

/* ---------------------------------------------------------------------
   Guest shell (login and other anonymous screens)
   --------------------------------------------------------------------- */
.guest-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--canvas);
  padding: var(--sp-xl) var(--sp-lg);
}

.guest-card {
  width: min(440px, 100%);
  padding: var(--sp-4xl);
  background: var(--canvas);
  border: 1px solid var(--ink);
}

.guest-lede {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.55;
  color: var(--body);
  margin-bottom: var(--sp-xl);
}

.guest-footnote {
  margin: var(--sp-xl) 0 0;
  padding-top: var(--sp-lg);
  border-top: 1px solid var(--hairline);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--body);
}

/* ---------------------------------------------------------------------
   Avatars, status chips, filter bars
   --------------------------------------------------------------------- */
.profile-avatar { overflow: hidden; }

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 9999px;
  display: block;
}

.profile-card .profile-avatar.xl { margin-bottom: var(--sp-sm); }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--ink);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-chip.status-on { background: var(--ink); color: var(--on-primary); border-color: var(--ink); }
.status-chip.status-off { background: var(--canvas); color: var(--body); border-color: var(--body); }

.row-inactive td { color: var(--body); }
.row-inactive td .fw-semibold { text-decoration: line-through; }

.filter-bar { padding: var(--sp-lg) var(--sp-xl); }

.search-summary {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--body);
  margin-bottom: var(--sp-lg);
}

.done-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--on-primary);
  font-size: 26px;
}

/* ---------------------------------------------------------------------
   Mobile — a foreman checks stock on a phone, in daylight, one-handed.
   --------------------------------------------------------------------- */
@media (min-width: 992px) {
  /* Desktop shows every nav group expanded, so the disclosure control is
     noise. The groups are genuinely `open` (the template always emits it) —
     forcing display on a CLOSED <details> instead left the links painted but
     not hit-testable, so the whole sidebar looked fine and clicked nowhere. */
  summary.sidebar-group-title { cursor: default; }
  summary.sidebar-group-title:hover { background: none; color: var(--ink-soft); }
  .sidebar-chevron { display: none; }
}

@media (max-width: 991px) {
  .sidebar { width: min(300px, 86vw); z-index: 1040; }
  .sidebar.is-open { box-shadow: none; }
  .page-header { align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .erp-pagination { justify-content: center; }
}

@media (max-width: 767px) {
  body { font-size: 15px; }

  /* Keep the search box and the menu button on one row; the topbar used to
     stack into three full-width blocks and pushed all content off-screen. */
  .topbar { flex-direction: row; flex-wrap: wrap; gap: var(--sp-sm); padding: var(--sp-sm) var(--sp-md); }
  .topbar-left { flex: 1 1 100%; order: 1; }
  .topbar-right { order: 2; flex: 1 1 100%; justify-content: flex-end; }
  .search-form { flex: 1; padding: 7px var(--sp-md); }
  .profile-meta { display: none; }

  .container-fluid { padding-left: var(--sp-md) !important; padding-right: var(--sp-md) !important; }

  .page-title { font-size: 27px; }
  .page-subtitle { font-size: 15px; }
  .stat-value { font-size: 28px; }
  .card-head h3, .erp-card h3 { font-size: 20px; }

  /* Full-width, thumb-sized controls. */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .form-control, .form-select { font-size: 16px; }  /* stops iOS zoom-on-focus */

  .filter-bar .btn { width: 100%; }
  .table-actions .btn { flex: 1 1 auto; text-align: center; }

  /* Tables scroll inside their own container; the page body never does. */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .erp-table { display: table; min-width: 560px; }

  .guest-card, .error-card { padding: var(--sp-xl); }
  .error-code { font-size: 56px; }
  .confirm-facts { grid-template-columns: 1fr; gap: var(--sp-xxs); }
  .confirm-facts dd { margin-bottom: var(--sp-sm); }
  .notification-menu { width: min(340px, calc(100vw - 24px)); }
}

/* ---------------------------------------------------------------------
   Print — a clean ledger on A4, no chrome
   --------------------------------------------------------------------- */
@media print {
  @page { margin: 14mm; }

  body { font-size: 11pt; color: #000; background: #fff; }

  .sidebar,
  .sidebar-backdrop,
  .topbar,
  .sidebar-toggle,
  .filter-bar,
  .erp-pagination,
  .page-actions,
  .table-actions,
  .empty-state .btn,
  #toast-container,
  #message-store,
  .error-actions { display: none !important; }

  .app-shell { display: block; }

  .erp-card {
    border: 1px solid #999;
    padding: 8pt;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .page-header { border-bottom: 2px solid #000; }
  .page-title { font-size: 20pt; }

  .erp-table { min-width: 0; width: 100%; }
  .erp-table thead { display: table-header-group; }
  .erp-table tbody tr { break-inside: avoid; page-break-inside: avoid; }
  .erp-table thead th { border-bottom: 1.5pt solid #000; background: #fff; }

  .dashboard-chart-wrap { height: auto; }
  .dashboard-chart-wrap canvas { max-height: 220pt; }

  /* Print the destination of a link nobody can click on paper. */
  .search-result-item[href]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; }

  a { color: #000; text-decoration: none; }
}

/* Empty state shown in place of a chart when the selected period has no data.
   A blank canvas reads as a broken page. */
.chart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 220px;
    padding: 1.5rem;
    text-align: center;
    color: var(--gray-600, #6c757d);
}

.chart-empty i {
    font-size: 2rem;
    opacity: 0.35;
}

.chart-empty p {
    margin: 0;
    font-size: 0.9rem;
}

/* =====================================================================
   MOBILE
   The people who use this on a phone are on site: a foreman checking
   whether cement is in stock, a manager approving a payment between
   meetings. They are one-handed, outdoors, and in a hurry.

   Three rules drive everything below:
     1. The number is the point. A finance row whose amount is off-screen
        is worse than no row at all.
     2. Never make them scroll sideways to read a record.
     3. Anything tappable is at least 44px and reachable with a thumb.
   ===================================================================== */

@media (max-width: 767px) {

  /* ---- Tables become cards -------------------------------------------
     A 6-column table cannot fit 375px. Horizontal scroll hid exactly the
     columns that mattered (Miqdor, Foyda), so every row is restacked as a
     label/value card. Labels come from the <th> at runtime (app.js), so
     they can never drift out of step with the header. */

  /* Overrides the horizontal-scroll fallback above: a card layout must be
     free to shrink to the viewport, and min-width:560px pushed every value
     off-canvas while leaving its label visible. */
  .erp-table.as-cards {
    display: block;
    overflow: visible;
    min-width: 0;
    width: 100%;
  }
  .table-responsive:has(> .erp-table.as-cards) { overflow-x: visible; }
  .erp-table.as-cards thead { display: none; }
  .erp-table.as-cards tbody,
  .erp-table.as-cards tr,
  .erp-table.as-cards td { display: block; width: 100%; }

  /* A flex column so the identifying cell can be lifted to the top and the
     buttons pushed to the bottom, whatever order the columns sit in. */
  .erp-table.as-cards tr {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--hairline);
    padding: var(--sp-md) var(--sp-lg);
    margin-bottom: var(--sp-md);
    background: var(--canvas);
  }
  .erp-table.as-cards tr:hover { background: var(--canvas); }

  .erp-table.as-cards td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--sp-lg);
    padding: var(--sp-xs) 0;
    border: 0;
    text-align: left !important;
  }

  .erp-table.as-cards td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--body);
  }

  /* The first cell is the record's identity — promote it to a heading and
     drop its label, which would only repeat the column name. */
  .erp-table.as-cards td.is-title {
    order: -1;
    display: block;
    font-family: var(--font-serif);
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    padding-bottom: var(--sp-sm);
    margin-bottom: var(--sp-sm);
    border-bottom: 1px solid var(--hairline);
  }
  .erp-table.as-cards td.is-title::before { content: none; }

  /* Money reads as the answer, not as another field. */
  .erp-table.as-cards td.is-money { font-size: 16px; font-weight: 700; }

  /* A field with nothing in it earns no line. */
  .erp-table.as-cards td.is-empty { display: none; }
  .erp-table.as-cards td.is-empty.is-title { display: block; }

  /* Row actions sit last, on their own line, full width and thumb-sized. */
  .erp-table.as-cards td.is-actions {
    order: 99;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-sm);
    padding-top: var(--sp-md);
    margin-top: var(--sp-sm);
    border-top: 1px solid var(--hairline);
  }
  .erp-table.as-cards td.is-actions::before { content: none; }
  .erp-table.as-cards td.is-actions .btn { flex: 1 1 auto; min-height: 40px; }
  /* Some tables wrap their buttons in a div; let that wrapper wrap too. */
  .erp-table.as-cards td.is-actions > div {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-sm);
    width: 100%;
  }

  /* An empty state must not be restacked into a label/value pair. */
  .erp-table.as-cards td[colspan] { display: block; text-align: center !important; }
  .erp-table.as-cards td[colspan]::before { content: none; }

  /* ---- Stat cards: 2-up, not a 700px stack -------------------------
     .stats-grid.compact is also matched: the ≤991px block above collapses
     it to a single column with (0,2,0) specificity, which outranks a bare
     .stats-grid selector and left four cards stacked full-width. */
  .stats-grid,
  .stats-grid.compact {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-md);
  }
  .stats-grid .stat-card { padding: var(--sp-md); }
  .stats-grid .stat-label { font-size: 10px; letter-spacing: 0.05em; }
  .stats-grid .stat-value { font-size: 19px; line-height: 1.2; word-break: break-word; }
  .stats-grid .stat-hint { font-size: 11px; }
  /* The headline figure of a page earns the full width. */
  .stats-grid .stat-card.is-primary { grid-column: 1 / -1; }
  .stats-grid .stat-card.is-primary .stat-value { font-size: 26px; }

  @media (max-width: 359px) {
    .stats-grid,
    .stats-grid.compact { grid-template-columns: 1fr; }
  }

  /* ---- Filters collapse behind one control -------------------------
     Seven stacked selects pushed the first record ~1300px down the page.
     app.js wraps the panel; without JS it simply stays open. */
  .filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-sm);
    width: 100%;
    min-height: 44px;
    padding: var(--sp-md) var(--sp-lg);
    background: var(--canvas);
    border: 1px solid var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
  }
  .filter-toggle[aria-expanded="true"] { border-bottom-color: var(--hairline); }
  .filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: var(--ink);
    color: var(--on-primary);
    font-size: 12px;
    font-weight: 700;
  }
  .filter-panel[hidden] { display: none; }
  .filter-panel {
    border: 1px solid var(--ink);
    border-top: 0;
    padding: var(--sp-lg);
  }
  /* The card the form already lives in would double the border. */
  .erp-card.has-filter-toggle { border: 0; padding: 0; }

  /* ---- Density ------------------------------------------------------ */
  .erp-card { margin-bottom: var(--sp-md) !important; }
  .page-header { margin-bottom: var(--sp-lg) !important; }
  .detail-grid { grid-template-columns: 1fr; gap: var(--sp-sm); }
  .detail-grid > div { display: flex; justify-content: space-between; gap: var(--sp-lg); }

  /* Charts are decoration on a phone; keep them, but not half the screen. */
  .dashboard-chart-wrap-line, .dashboard-chart-wrap-donut { height: 220px; }

  /* ---- Tap targets -------------------------------------------------- */
  .sidebar-link, .dropdown-item { min-height: 44px; display: flex; align-items: center; }
  .table-actions .btn { min-height: 40px; }
}

@media (max-width: 767px) {
  /* ---- Roster / catalogue cards -------------------------------------
     The worker list rendered 25 cards of ~380px each — a 10,500px page to
     scroll past 25 people. Reflowing the meta lines two-up and pulling the
     name alongside the avatar roughly halves that without hiding a field. */
  .worker-card,
  .resource-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-xs) var(--sp-md);
    padding: var(--sp-md) var(--sp-lg);
  }

  .worker-card .worker-avatar,
  .resource-card .resource-icon {
    order: -1;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    margin: 0;
    font-size: 15px;
  }

  .worker-card > h3,
  .resource-card > h3 {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    font-size: 17px;
    line-height: 1.25;
  }

  /* The badge rides on the name row rather than claiming a line of its own. */
  .worker-card > .badge,
  .resource-card > .badge { flex: 0 0 auto; order: 1; }

  /* Job title / category: full width, directly under the name. */
  .worker-card > p.text-muted,
  .resource-card > p.text-muted {
    flex: 1 1 100%;
    order: 2;
    margin: 0 0 var(--sp-xs);
    font-size: 13px;
  }

  /* Everything else pairs up two-per-row. */
  .worker-card > p.small,
  .resource-card > p.small {
    flex: 1 1 calc(50% - var(--sp-md));
    min-width: 0;
    order: 3;
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .worker-card > p.small i,
  .resource-card > p.small i { width: 14px; color: var(--body); }

  /* The action row only — NOT .worker-avatar, which is also a direct div
     child and was being ordered to the bottom-right of the card. */
  .worker-card > div.d-flex,
  .resource-card > div.d-flex {
    flex: 1 1 100%;
    order: 4;
    margin-top: var(--sp-sm) !important;
  }
  .worker-card > div.d-flex .btn,
  .resource-card > div.d-flex .btn { flex: 1 1 auto; }
}

/* The card/filter hooks are added by JS once, at load. If the window is then
   widened past the mobile breakpoint — or a phone is simply rotated — the
   markup must fall back to the desktop layout on CSS alone, or a filter panel
   collapsed on mobile would stay hidden on a desktop that has no toggle. */
@media (min-width: 768px) {
  .filter-toggle { display: none; }
  .filter-panel { display: block !important; border: 0; padding: 0; }
  .erp-card.has-filter-toggle { border: 1px solid var(--hairline); padding: var(--sp-2xl); }
}
