/* =====================================================================
   Electro Engineers — Portfolio Tracker
   DESIGN SYSTEM + app stylesheet (one file, one source of truth).
   Components are documented in docs/DESIGN_SYSTEM.md.

   Order:  1 Tokens · 2 Base · 3 Shell (top bar, sidebar, main)
           4 Page header · 5 Surfaces (card, KPI, alert, meter)
           6 Tables · 7 Forms & buttons · 8 Badges · 9 Tabs
           10 Utilities · 11 Feature sections (tender costing, settings…)
           12 Login · 13 Responsive · 14 Print

   Rule: change a colour, size or radius by editing a TOKEN below. Do not
   add one-off colours or spacing to individual pages.
   ===================================================================== */

/* ------------------------------------------------------------------ */
/* 1. Tokens                                                            */
/* ------------------------------------------------------------------ */
:root {
  /* Brand */
  --navy-900: #102B4E;      /* sidebar */
  --navy-800: #12315B;      /* headings */
  --blue-600: #1677E8;      /* primary action, active nav */
  --blue-700: #0F62C7;      /* hover */
  --blue-50:  #EAF2FE;
  --blue-100: #D7E7FC;

  /* Surfaces */
  --bg:       #F3F7FC;
  --surface:  #FFFFFF;
  --surface-2:#F7FAFD;      /* table header, subtle panels */
  --border:   #E2EAF3;
  --border-strong: #CBD7E5;

  /* Text */
  --text:     #172B4D;
  --text-2:   #64748B;
  --text-3:   #8A9BB0;

  /* Status accents (solid) + readable text + light tint */
  --green-500:#10B981; --green-700:#047857; --green-50:#E6F7F1;
  --teal-500: #0D9488; --teal-700: #0F766E; --teal-50: #E4F5F3;
  --violet-500:#7C5CFC; --violet-700:#5B3FD6; --violet-50:#F0ECFF;
  --amber-500:#F59E0B; --amber-700:#B45309; --amber-50:#FEF3DC;
  --red-500:  #EF4444; --red-700:  #B91C1C; --red-50:  #FDECEC;

  /* Type */
  --font: Inter, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs-base: 0.875rem; --fs-md: 0.9375rem; --fs-lg: 1.125rem;

  /* Space (8px scale) */
  --sp-1: 0.5rem; --sp-2: 1rem; --sp-3: 1.5rem; --sp-4: 2rem;

  /* Shape & depth */
  --r-card: 12px; --r-input: 8px; --r-nav: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 43, 78, 0.05), 0 1px 3px rgba(16, 43, 78, 0.04);
  --shadow-md: 0 6px 20px rgba(16, 43, 78, 0.10);
  --focus-ring: 0 0 0 3px rgba(22, 119, 232, 0.25);

  /* Layout */
  --topbar-h: 72px;
  --sidebar-w: 268px;
  --content-max: 1320px;
}

/* ------------------------------------------------------------------ */
/* 2. Base                                                              */
/* ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body { min-height: 100%; }   /* min-height, not height: keeps sticky bars working on long pages */
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-md); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-700); text-decoration: underline; }
a:focus-visible, button:focus-visible, .btn:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 6px; }
h1, h2, h3 { color: var(--navy-800); margin: 0; }
[hidden] { display: none !important; }
.icon { flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.icon--inline { width: 15px; height: 15px; margin-left: 0.15rem; vertical-align: -2px; }

/* ------------------------------------------------------------------ */
/* 3. Shell — top bar, sidebar, content area                            */
/* ------------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 0 var(--sp-2);
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.menu-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
  background: transparent; color: var(--navy-800); border: 1px solid var(--border); border-radius: var(--r-input); cursor: pointer; flex: 0 0 auto;
}
.menu-toggle:hover { background: var(--blue-50); }
.brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; color: var(--navy-800); }
.brand:hover { text-decoration: none; color: var(--navy-800); }
.brand__logo { height: 42px; width: auto; max-width: 150px; object-fit: contain; flex: 0 0 auto; }
.brand__mark {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: 10px; background: var(--navy-800); color: #fff; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em;
  box-shadow: inset 0 -3px 0 var(--blue-600);
}
.brand__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand__name { font-weight: 700; font-size: 1.1rem; color: var(--navy-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand__sub { display: none; font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex: 0 0 auto; }
.topbar-user { display: flex; align-items: center; gap: 0.55rem; font-size: var(--fs-base); color: var(--text); white-space: nowrap; }
.topbar-user__avatar { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: var(--blue-50); color: var(--blue-600); }
.topbar-user__name { display: none; font-weight: 500; }
.topbar-user-group { color: var(--text-2); font-weight: 400; }
.env-badge { background: var(--blue-50); color: var(--blue-700); font-size: var(--fs-xs); font-weight: 700; padding: 0.3rem 0.65rem; border-radius: 8px; text-transform: uppercase; letter-spacing: 0.03em; }
.logout-link { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; padding: 0 0.4rem; color: var(--text); font-size: var(--fs-base); font-weight: 500; white-space: nowrap; }
.logout-link:hover { color: var(--blue-600); text-decoration: none; }
.logout-link__text { display: none; }

.app-body { display: flex; position: relative; }

/* Sidebar: off-canvas drawer on small screens, fixed column from 861px */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w); max-width: 86vw;
  background: var(--navy-900); transform: translateX(-100%); transition: transform 0.22s ease;
  z-index: 50; overflow-y: auto; padding: var(--sp-2) 0.9rem var(--sp-3);
}
body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 8px 0 24px rgba(8, 20, 40, 0.35); }
.sidebar-backdrop { display: none; position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; background: rgba(10, 24, 46, 0.5); z-index: 45; }
body.sidebar-open .sidebar-backdrop { display: block; }

.nav-group { margin-bottom: 1.15rem; }
.nav-group-label { font-size: 0.6875rem; letter-spacing: 0.1em; text-transform: uppercase; color: #8FA6C4; font-weight: 700; padding: 0 0.75rem; margin-bottom: 0.4rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.75rem; min-height: 44px; padding: 0.55rem 0.75rem; margin-bottom: 2px;
  color: #C9D8EC; font-size: var(--fs-md); font-weight: 500; border-radius: var(--r-nav); text-decoration: none;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.nav-link:focus-visible { box-shadow: 0 0 0 2px #fff; }
.nav-link.active { background: var(--blue-600); color: #fff; font-weight: 600; }
.nav-link .icon { opacity: 0.9; }

.main-wrap { flex: 1; min-width: 0; width: 100%; }
main { position: relative; padding: var(--sp-3) var(--sp-2) 3rem; max-width: var(--content-max); }

/* ------------------------------------------------------------------ */
/* 4. Page header                                                       */
/* ------------------------------------------------------------------ */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); position: relative; }
.page-header__text { min-width: 0; flex: 1 1 18rem; position: relative; z-index: 1; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; position: relative; z-index: 1; }
h1.page-title { font-size: 1.5rem; line-height: 1.2; font-weight: 700; color: var(--navy-800); margin: 0 0 0.35rem; letter-spacing: -0.01em; }
.page-sub { color: var(--text-2); font-size: var(--fs-base); margin: 0; max-width: 62ch; }
.page-title + .page-sub { margin-top: 0; }
.page-header__art { display: none; }
.page-sub strong { color: var(--text); }

/* Blue accent rule under the page title on the dashboard welcome */
.page-header--accent .page-title::after { content: ""; display: block; width: 36px; height: 3px; margin-top: 0.5rem; background: var(--teal-500); border-radius: 2px; }

/* ------------------------------------------------------------------ */
/* 5. Surfaces                                                          */
/* ------------------------------------------------------------------ */
.card {
  background: var(--surface); padding: 1.25rem; border-radius: var(--r-card);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: var(--sp-3);
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.card__head-action { font-size: var(--fs-sm); font-weight: 500; }
.section-title { display: flex; align-items: center; gap: 0.6rem; font-size: 1.0625rem; font-weight: 650; color: var(--navy-800); margin: 0 0 var(--sp-2); }
.card__head .section-title { margin: 0; }
.section-title__icon { display: inline-flex; color: var(--navy-800); }
.subsection-title { font-size: var(--fs-md); font-weight: 650; color: var(--navy-800); margin: 1.25rem 0 0.75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.empty { color: var(--text-2); margin: 0; font-size: var(--fs-base); }

/* KPI cards */
.kpi-grid, .summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.kpi {
  position: relative; display: flex; align-items: center; gap: 0.85rem; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); overflow: hidden;
  container-type: inline-size;   /* lets the value shrink with the card instead of wrapping mid-number */
}
.kpi::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--kpi-accent, var(--blue-600)); }
.kpi__icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; flex: 0 0 auto; border-radius: 50%; background: var(--kpi-tint, var(--blue-50)); color: var(--kpi-accent, var(--blue-600)); }
.kpi__body { min-width: 0; }
.kpi__label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.kpi__value { font-size: 1.5rem; font-size: clamp(1.05rem, 7.2cqw, 1.5rem); line-height: 1.25; font-weight: 700; color: var(--navy-800); white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: var(--fs-sm); color: var(--text-2); }
.kpi--blue   { --kpi-accent: var(--blue-600);   --kpi-tint: var(--blue-50); }
.kpi--green  { --kpi-accent: var(--green-500);  --kpi-tint: var(--green-50); }
.kpi--teal   { --kpi-accent: var(--teal-500);   --kpi-tint: var(--teal-50); }
.kpi--violet { --kpi-accent: var(--violet-500); --kpi-tint: var(--violet-50); }
.kpi--amber  { --kpi-accent: var(--amber-500);  --kpi-tint: var(--amber-50); }
.kpi--red    { --kpi-accent: var(--red-500);    --kpi-tint: var(--red-50); }
.kpi__value--lg { font-size: 1.5rem; }
.kpi.is-compact { padding: 0.9rem 1rem; }
.kpi.is-compact .kpi__icon { width: 42px; height: 42px; }
.kpi.is-compact .kpi__value { font-size: 1.2rem; }

/* Older summary boxes (project hub, reports) share the KPI look without an icon */
.summary-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 0.9rem 1.1rem; box-shadow: var(--shadow-sm); min-width: 0; }
.summary-box .label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); margin: 0 0 0.25rem; }
.summary-box .value { font-size: 1.25rem; font-weight: 700; color: var(--navy-800); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary-box .value.value-text { font-size: 1rem; }
.summary-box .muted { margin-top: 0.15rem; }
.summary-strip { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }

/* Needs attention */
.alert-card { border-left: 4px solid var(--blue-600); }
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { border-top: 1px solid var(--border); }
.alert-list li:first-child { border-top: 0; }
.alert-list a { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0; color: var(--text); font-size: var(--fs-md); }
.alert-list a:hover { color: var(--blue-600); text-decoration: none; }
.alert-list a::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--blue-600); flex: 0 0 auto; }
.alert-list li.is-warn a::before { background: var(--amber-500); }
.alert-list li.is-bad a::before { background: var(--red-500); }
.alert-list a .icon { margin-left: auto; color: var(--text-3); width: 16px; height: 16px; }
.alert-card .section-title__icon { color: var(--blue-600); }

/* Meters (<progress>) */
.meter { display: block; width: 100%; height: 8px; margin: 0.45rem 0 0.35rem; border: 0; border-radius: 999px; overflow: hidden; background: #E7EEF7; appearance: none; -webkit-appearance: none; }
.meter::-webkit-progress-bar { background: #E7EEF7; border-radius: 999px; }
.meter::-webkit-progress-value { background: var(--blue-600); border-radius: 999px; }
.meter::-moz-progress-bar { background: var(--blue-600); border-radius: 999px; }
.meter--ok::-webkit-progress-value, .meter--teal::-webkit-progress-value { background: var(--teal-500); }
.meter--ok::-moz-progress-bar, .meter--teal::-moz-progress-bar { background: var(--teal-500); }
.meter--blue::-webkit-progress-value { background: var(--blue-600); }
.meter--blue::-moz-progress-bar { background: var(--blue-600); }
.meter--warn::-webkit-progress-value, .meter--amber::-webkit-progress-value { background: var(--amber-500); }
.meter--warn::-moz-progress-bar, .meter--amber::-moz-progress-bar { background: var(--amber-500); }
.meter--over::-webkit-progress-value, .meter--red::-webkit-progress-value { background: var(--red-500); }
.meter--over::-moz-progress-bar, .meter--red::-moz-progress-bar { background: var(--red-500); }

/* Meter rows (bank guarantee limits, ageing) */
.limit-card { margin-bottom: 1.15rem; }
.limit-card:last-child { margin-bottom: 0.25rem; }
.card.limit-card { margin-bottom: var(--sp-3); }
.limit-row .muted { white-space: nowrap; }
.limit-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.limit-name { font-weight: 600; color: var(--navy-800); min-width: 0; }
.limit-amount { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.limit-meta { display: flex; flex-wrap: wrap; gap: 0.15rem 1.4rem; font-size: var(--fs-sm); color: var(--text-2); font-variant-numeric: tabular-nums; }
.limit-note { display: flex; align-items: center; gap: 0.5rem; margin: 1rem 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.limit-note .icon { width: 16px; height: 16px; }

.mini-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
.mini-stats .label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.value-sm { font-size: 1.2rem; font-weight: 700; color: var(--navy-800); font-variant-numeric: tabular-nums; }
.list-line { margin: 0 0 0.5rem; font-size: var(--fs-base); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--sp-3); }
.dash-grid > * { min-width: 0; }

/* ------------------------------------------------------------------ */
/* 6. Tables                                                            */
/* ------------------------------------------------------------------ */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; padding: 0 0.25rem; }
table { width: 100%; min-width: 480px; border-collapse: collapse; font-size: var(--fs-base); }
th, td { text-align: left; padding: 0.75rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; border-bottom: 1px solid var(--border-strong); }
thead th:first-child { border-top-left-radius: 8px; }
thead th:last-child { border-top-right-radius: 8px; }
tbody tr:hover { background: #F9FBFE; }
tbody tr:last-child td { border-bottom: 0; }
td a { font-weight: 500; }
td.num, th.num, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.total-row td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
tr.row-flag td { background: var(--amber-50); }
tr.row-current td { background: var(--blue-50); }
td.desc { min-width: 220px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.table-scroll.spaced { margin-top: 1rem; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix th:first-child, .perm-matrix td:first-child { text-align: left; }
.list-table { min-width: 0; }
.list-table td { padding: 0.4rem 0.45rem; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* 7. Forms & buttons                                                   */
/* ------------------------------------------------------------------ */
label { display: block; font-size: var(--fs-sm); color: var(--text); font-weight: 600; margin-bottom: 0.4rem; }
input[type=text], input[type=tel], input[type=date], input[type=month], input[type=email], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; min-height: 42px; padding: 0.6rem 0.8rem; margin-bottom: var(--sp-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-input); background: #fff; color: var(--text);
  font-size: var(--fs-md); font-family: inherit;
}
textarea { min-height: 92px; font-family: inherit; line-height: 1.5; }
select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.7rem center / 16px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue-600); box-shadow: var(--focus-ring); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-3); }
input[type=file] { width: 100%; margin-bottom: 0.9rem; font-size: var(--fs-base); }
input[type=checkbox], input[type=radio] { accent-color: var(--blue-600); }
label.check { display: flex; gap: 0.55rem; align-items: flex-start; font-weight: 400; margin-bottom: 0.9rem; }
label.check input { width: auto; min-height: 0; margin: 0.2rem 0 0; }
.hint { color: var(--text-2); font-size: var(--fs-sm); margin-top: -0.7rem; margin-bottom: var(--sp-2); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
form.inline { display: inline; }

.grid-2, .grid-3 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; min-height: 42px;
  padding: 0.55rem 1.15rem; background: var(--blue-600); color: #fff; border: 1px solid transparent;
  border-radius: var(--r-input); font-size: var(--fs-base); font-weight: 600; font-family: inherit; line-height: 1.2;
  cursor: pointer; text-decoration: none; transition: background 0.15s ease, border-color 0.15s ease;
}
button:hover, .btn:hover { background: var(--blue-700); color: #fff; text-decoration: none; }
.btn.secondary, button.secondary { background: #fff; color: var(--navy-800); border-color: var(--border-strong); }
.btn.secondary:hover, button.secondary:hover { background: var(--blue-50); border-color: var(--blue-600); color: var(--blue-700); }
.btn.danger, button.danger { background: var(--red-500); color: #fff; border-color: transparent; }
.btn.danger:hover, button.danger:hover { background: var(--red-700); color: #fff; }
.btn.small, button.small { min-height: 36px; padding: 0.3rem 0.8rem; font-size: var(--fs-sm); }
button:disabled { opacity: 0.45; cursor: default; }
.btn .icon, button .icon { width: 16px; height: 16px; }

/* Filter bar: a GET form of selects/dates plus an Apply button */
.filter-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--sp-2); align-items: end; }
.filter-bar > div { min-width: 0; }
.filter-bar__actions { padding-bottom: var(--sp-2); }
.filter-row { margin-bottom: 0.4rem; }

.flash { padding: 0.8rem 1rem; border-radius: 10px; font-size: var(--fs-base); margin-bottom: var(--sp-3); font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--green-50); color: var(--green-700); border-color: #BDE9D8; }
.flash.error { background: var(--red-50); color: var(--red-700); border-color: #F6C7C7; }
.action-bar { margin-bottom: var(--sp-2); display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.report-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: var(--sp-2); }

/* ------------------------------------------------------------------ */
/* 8. Badges                                                            */
/* ------------------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.65rem; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em; background: #E9EEF5; color: #475569; white-space: nowrap; }
.badge.active, .badge.full, .badge.status-on_track, .badge.status-complete, .badge.received, .badge.tender-won { background: var(--green-50); color: var(--green-700); }
.badge.inactive, .badge.none, .badge.status-delayed, .badge.tender-lost, .badge.tender-cancelled { background: var(--red-50); color: var(--red-700); }
.badge.view, .badge.status-at_risk, .badge.partial, .badge.pending, .badge.expiring, .badge.tender-submitted { background: var(--amber-50); color: var(--amber-700); }
.badge.released, .badge.expired, .badge.status-on_hold, .badge.tender-draft { background: #E9EEF5; color: #475569; }
.count-pill { display: inline-block; min-width: 1.3rem; padding: 0 0.45rem; border-radius: 999px; background: var(--blue-600); color: #fff; font-size: var(--fs-xs); font-weight: 700; text-align: center; }

/* ------------------------------------------------------------------ */
/* 9. Tabs                                                              */
/* ------------------------------------------------------------------ */
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-3); }
.tab-link { padding: 0.7rem 1rem; font-size: var(--fs-base); font-weight: 600; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tab-link:hover { color: var(--blue-600); text-decoration: none; }
.tab-link.active { color: var(--blue-600); border-bottom-color: var(--blue-600); }

/* ------------------------------------------------------------------ */
/* 10. Utilities                                                        */
/* ------------------------------------------------------------------ */
.muted { color: var(--text-2); font-size: var(--fs-sm); }
.text-warn { color: var(--amber-700); font-weight: 600; }
.text-over { color: var(--red-700); font-weight: 600; }
.text-good, .pos { color: var(--green-700); font-weight: 600; }
.spaced-top { margin-top: 1rem; }
.mb-3 { margin-bottom: var(--sp-3); }
.print-only { display: none; }
.unsaved { color: var(--red-700); font-weight: 700; }

/* ------------------------------------------------------------------ */
/* 11. Feature sections                                                 */
/* ------------------------------------------------------------------ */
/* Project hub */
.stage-row { border-top: 1px solid var(--border); padding: 0.9rem 0 0.4rem; }
.stage-name { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; }
details.sched { border-top: 1px solid var(--border); padding: 0.6rem 0; }
details.sched summary { cursor: pointer; font-weight: 650; color: var(--navy-800); }

/* Tender costing */
.cost-bar { position: sticky; top: var(--topbar-h); z-index: 5; background: var(--bg); display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; padding: 0.4rem 0 0.5rem; margin-bottom: 0.8rem; }
.cost-box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.45rem 0.55rem; min-width: 0; box-shadow: var(--shadow-sm); }
.cost-box .label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); font-weight: 600; margin: 0; }
.cost-box .value { font-size: 0.85rem; font-weight: 700; color: var(--navy-800); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.cost-box .sub { display: none; font-size: var(--fs-xs); color: var(--text-2); }
.cost-box-bid { border-color: var(--blue-600); }
.cost-box-bid .value { color: var(--blue-700); }
.cost-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0 1rem; font-size: var(--fs-xs); color: var(--text-2); }
.bar-save { margin-left: auto; }
ol.how { margin: 0 0 1rem 1.1rem; padding: 0; font-size: var(--fs-base); }
ol.how li { margin-bottom: 0.3rem; }
.cost-sched { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 0.7rem 0.9rem; margin-bottom: 0.8rem; box-shadow: var(--shadow-sm); }
.cost-sched summary { cursor: pointer; font-size: var(--fs-sm); margin-top: 0.4rem; }
.sched-title { font-weight: 600; color: var(--navy-800); margin-bottom: 0.4rem; }
.sched-figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem 0.8rem; }
.fig { min-width: 0; }
.fig-l { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); font-weight: 600; margin: 0 0 0.1rem; }
.fig b { display: block; font-size: var(--fs-sm); color: var(--navy-800); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fig-input input { margin: 0; padding: 0.4rem 0.5rem; min-height: 38px; max-width: 8rem; text-align: right; }
.fig-total b { color: var(--blue-700); font-size: var(--fs-base); }
.cv-block { border: 1px solid var(--red-600, #c0392b); background: #fdf3f2; border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.6rem 0; font-size: var(--fs-sm, 0.9rem); }
.cv-override { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--border); }
.th-sub { display: block; font-size: 0.65rem; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-2); }
tr.gst-line td { background: #f6f7f9; color: var(--text-2); }
.gst-choice { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; margin: 0.8rem 0; }
.gst-choice legend { font-size: var(--fs-sm); font-weight: 600; color: var(--navy-800); padding: 0 0.3rem; }
.gst-choice .check { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.3rem 0; font-weight: 400; }
.gst-choice .check input { width: auto; margin: 0.25rem 0 0; flex: 0 0 auto; min-height: 0; }
.gst-choice input[type=number] { max-width: 8rem; }
.save-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin: 0.8rem 0; }
.cost-table input { margin-bottom: 0; padding: 0.5rem 0.55rem; font-size: var(--fs-base); min-width: 6.5rem; min-height: 38px; }

/* Settings, enquiries, paging */
.inline-edit { display: flex; gap: 0.5rem; align-items: center; }
.inline-edit input[type=text] { margin-bottom: 0; flex: 1; min-width: 0; }
.logo-preview { max-height: 64px; max-width: 220px; border: 1px solid var(--border); border-radius: 8px; padding: 0.3rem; background: #fff; }
.enquiry { border-top: 1px solid var(--border); padding: 0.9rem 0; }
.enquiry.unread { border-left: 3px solid var(--blue-600); padding-left: 0.8rem; }
.enquiry-head { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; }
.enquiry-body { margin: 0.4rem 0 0.6rem; font-size: var(--fs-base); }
.pager { display: flex; align-items: center; gap: 0.8rem; margin-top: 1rem; }

/* ------------------------------------------------------------------ */
/* 12. Login                                                            */
/* ------------------------------------------------------------------ */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-2); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-md); padding: 2rem; }
.auth-card .brand { margin-bottom: 1.5rem; }
.auth-card .brand__sub { display: block; }
.auth-card h1 { font-size: 1.25rem; margin: 0 0 1.25rem; }
.auth-card button { width: 100%; }
.auth-env { text-align: center; color: var(--text-3); font-size: var(--fs-xs); margin-top: 1rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* ------------------------------------------------------------------ */
/* 13. Responsive                                                       */
/* ------------------------------------------------------------------ */
@media (min-width: 640px) {
  .brand__sub { display: block; }
  .topbar-user__name { display: inline; }
  .logout-link__text { display: inline; }
  .filter-bar { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
}

@media (max-width: 860px) {
  /* Cost table collapses into stacked cards */
  .cost-table { min-width: 0; display: block; }
  .cost-table thead { display: none; }
  .cost-table tbody, .cost-table tr { display: block; }
  .cost-table tr { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; margin: 0.6rem 0; background: #fff; }
  .cost-table td { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; border: 0; padding: 0.3rem 0; text-align: right; }
  .cost-table td::before { content: attr(data-label); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; text-align: left; flex: 0 0 38%; }
  .cost-table td.desc { display: block; min-width: 0; text-align: left; padding-bottom: 0.4rem; }
  .cost-table td.desc::before { display: block; margin-bottom: 0.15rem; }
  .cost-table td input { width: 55%; text-align: right; }
  .cost-table tbody tr:hover { background: #fff; }
}

@media (min-width: 861px) {
  .menu-toggle { display: none; }
  .topbar { padding: 0 var(--sp-3); }
  .topbar-right { gap: 1rem; }

  .sidebar {
    position: sticky; top: var(--topbar-h); transform: none; width: var(--sidebar-w); max-width: none; flex: 0 0 var(--sidebar-w);
    height: calc(100vh - var(--topbar-h)); box-shadow: none; padding: var(--sp-3) 1rem var(--sp-3);
  }
  .sidebar-backdrop { display: none !important; }

  main { padding: var(--sp-4) 2.25rem 3.5rem; }
  h1.page-title { font-size: 1.875rem; }
  .card { padding: 1.5rem; }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-3); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--sp-3); }
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-actions a, .row-actions button, .row-actions form { margin-right: 0.2rem; }

  .sched-figs { grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); }
  .cost-bar { gap: 0.6rem; padding: 0.5rem 0 0.6rem; }
  .cost-box { padding: 0.6rem 0.9rem; }
  .cost-box .sub { display: block; }
  .cost-box .value { font-size: 1.2rem; }
  .cost-box-bid .value { font-size: 1.3rem; }
  .cost-meta { font-size: var(--fs-sm); }
  #defaultPct { max-width: 11rem; }
  .cost-table { min-width: 0; font-size: var(--fs-sm); }
  .cost-table th, .cost-table td { padding: 0.5rem 0.4rem; }
  .cost-table td.desc { min-width: 170px; }
  .cost-table input { width: 6rem; min-width: 0; padding: 0.4rem 0.45rem; }
  .cost-table input.in-pct { width: 4.5rem; }
  .cost-table td.o-cost, .cost-table td.o-diff, .cost-table td.o-brate, .cost-table td.o-bamt { white-space: nowrap; }
}

/* Wide screens: decorative skyline + tagline at the right of every page header */
@media (min-width: 1180px) {
  .page-header__art {
    display: flex; align-items: center; gap: 1rem; flex: 0 0 auto; margin-left: auto; pointer-events: none;
    padding-right: 0.25rem;
  }
  .page-header__art img { width: 300px; height: auto; }
  .page-header__art span { border-left: 1px solid var(--navy-800); padding-left: 1rem; max-width: 9.5rem; font-size: var(--fs-sm); line-height: 1.5; color: var(--text-2); }
  .page-header__actions { order: 3; }
  .kpi-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 640px) and (max-width: 1179px) {
  .kpi-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 639px) {
  .kpi-grid.cols-4, .kpi-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ------------------------------------------------------------------ */
/* 14. Print — tender amount and our bid only, never our cost           */
/* ------------------------------------------------------------------ */
@media print {
  .topbar, .sidebar, .sidebar-backdrop, .tabs, .summary-strip, .kpi-grid, .flash, .internal, .menu-toggle, button, .btn, form .save-bar, .page-header__art, .report-nav { display: none !important; }
  .print-only { display: block !important; }
  .print-head h2 { margin: 0 0 0.2rem; font-size: 1.2rem; }
  .print-head p { margin: 0 0 0.2rem; font-size: 0.9rem; }
  body, .app-body, main { background: #fff !important; display: block !important; padding: 0 !important; max-width: none !important; }
  .card, .cost-sched, .cost-box { border: 0 !important; box-shadow: none !important; padding: 0 !important; }
  .cost-bar { position: static; grid-template-columns: 1fr 1fr; }
  .cost-box-bid { grid-column: auto; }
  .cost-sched { break-inside: auto; margin-bottom: 1rem; }
  .cost-sched summary { font-size: 1rem; }
  .table-scroll { overflow: visible !important; }
  .cost-table { min-width: 0 !important; display: table !important; font-size: 0.78rem; }
  .cost-table thead { display: table-header-group !important; }
  .cost-table tbody { display: table-row-group !important; }
  .cost-table tr { display: table-row !important; border: 0 !important; padding: 0 !important; margin: 0 !important; break-inside: avoid; }
  .cost-table td:not(.internal) { display: table-cell !important; border-bottom: 1px solid #bbb !important; padding: 0.25rem 0.3rem !important; text-align: left !important; }
  .cost-table td::before { content: none !important; }
  .cost-table td.internal, .cost-table th.internal, .cost-sched .sched-figs .internal { display: none !important; }
  .cost-sched .sched-figs { grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); }
  .cost-sched summary { display: none !important; }
  .cost-sched details > * { display: block; }
  tr.gst-line td { background: none !important; }
  .cost-summary { break-inside: avoid; margin-top: 1rem; }
  .sum-table { display: table !important; min-width: 0 !important; width: 100%; font-size: 0.85rem; }
  .sum-table thead { display: table-header-group !important; }
  .sum-table tbody, .sum-table tfoot { display: table-row-group !important; }
  .sum-table tr { display: table-row !important; border: 0 !important; padding: 0 !important; margin: 0 !important; }
  .sum-table td, .sum-table th { display: table-cell !important; border-bottom: 1px solid #bbb !important; padding: 0.3rem 0.4rem !important; }
  .sum-table td::before { content: none !important; }
  .sum-table .num { text-align: right !important; }
  .sum-table td.internal, .sum-table th.internal { display: none !important; }
  .sum-table td:first-child { width: 40%; }
  .cost-table tr.row-flag td { background: none !important; }
  h1.page-title, .page-sub { display: none !important; }
  .alert-card a { text-decoration: none; }
}

/* ------------------------------------------------------------------ */
/* 15. Version history, selected rows                                   */
/* ------------------------------------------------------------------ */
.version-item { border-left: 3px solid var(--border-strong); padding: 6px 0 6px 14px; margin: 0 0 14px; }
.version-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.version-reason { margin: 2px 0 4px; color: var(--navy-800); }
.version-changes { margin: 4px 0 4px 18px; padding: 0; }
.version-changes li { margin: 2px 0; }
.version-files { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 4px; }
tr.row-selected td { background: var(--blue-50); }
.meter-wrap { margin: 4px 0 8px; }
.table-scroll + .hint, .table-scroll + p.hint { margin-top: 12px; }

/* 16 · Bill documents preview */
.doc-preview { border: 1px solid var(--border); border-radius: 12px; padding: var(--sp-3); margin-bottom: var(--sp-3); background: var(--surface-2, transparent); }
.doc-preview input[readonly] { background: transparent; font-weight: 600; }

.summary-strip--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary-strip--4 .summary-box { padding: 0.75rem 0.8rem; }
.summary-strip--4 .summary-box .value { font-size: 0.92rem; white-space: nowrap; overflow-wrap: normal; }
@media (max-width: 760px) { .summary-strip--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .summary-strip--4 .summary-box .value { font-size: 1rem; } }

.small-note { font-size: var(--fs-xs); margin-top: 0.2rem; max-width: 22rem; white-space: normal; }
.status-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.9rem; }
.status-actions input[type=text] { flex: 1 1 16rem; min-width: 0; }
.status-actions .hint { flex: 1 1 100%; margin: 0; }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: 0.55rem 0; border-bottom: 1px solid var(--border, #E2E8F0); font-size: var(--fs-sm, 0.9rem); }
.kv-label { color: #475569; flex: 1 1 55%; min-width: 0; }
.kv-value { text-align: right; flex: 0 1 45%; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kv { margin-bottom: 0.9rem; }
.summary-strip + .dash-grid, .dash-grid + .dash-grid { margin-top: 1rem; }

a.topbar-user { color: inherit; text-decoration: none; }
a.topbar-user:hover .topbar-user__name { text-decoration: underline; }

/* Tenders list: live search */
.list-search { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 12px; }
.list-search input[type="search"] { flex: 1 1 260px; max-width: 520px; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
tr[hidden] { display: none; }

/* Tender costing: schedule-wise summary */
.sum-table td.num, .sum-table th.num { text-align: right; white-space: nowrap; }
.sum-table tr.sum-total td { font-weight: 700; border-top: 2px solid var(--border, #cfd6e0); }

/* Reading a scanned PDF in the browser (OCR) */
.ocr-box { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--border, #cfd6e0); border-radius: 10px; background: #f4f8ff; }
.ocr-box .ocr-msg { margin: 0 0 8px; }
.ocr-box progress { width: 100%; height: 10px; }

/* Money held by the client: highlighted, but not styled as profit */
.held-card { border-left: 4px solid var(--red-500); background: var(--red-50); }
.held-figure { font-size: 1.6rem; font-weight: 700; color: var(--red-700); margin: 0.25rem 0 0.5rem; }
.held-pct { font-size: 0.85rem; font-weight: 500; color: var(--text-2); margin-left: 0.4rem; }
.summary-box--held { border-left: 4px solid var(--red-500); }
.sd-table .sd-target th, .sd-table .sd-target td { background: var(--bg); }
.sd-table .sd-held th, .sd-table .sd-held td { font-weight: 700; border-top: 2px solid var(--border); }
.check-list { list-style: none; margin: 0.4rem 0; padding: 0; font-size: var(--fs-sm, 0.9rem); }
.check-list li { padding: 0.15rem 0; }
.ck-ok { color: var(--green-700, #1e7a46); }
.ck-bad { color: var(--red-600, #c0392b); font-weight: 600; }
.held-missing .inline-form { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.4rem; }
.held-missing .inline-form input { max-width: 14rem; }
