:root {
  /* Brand. A working emerald, deep enough to carry solid fills and body text. */
  --brand: #0a7d5a;
  --brand-strong: #065f45;
  --brand-tint: #e6f4ee;
  --brand-ring: rgba(10, 125, 90, 0.16);

  /* Neutrals, biased a touch green so they sit with the brand. */
  --ink: #16211d;
  --ink-2: #4b5b55;
  --ink-3: #7b8b85;
  --line: #e3e9e6;
  --line-soft: #eef2f0;
  --surface: #ffffff;
  --canvas: #f3f6f4;

  /* Semantic. Kept apart from the brand hue on purpose. */
  --ok: #067647;
  --warn: #b45309;
  --bad: #b42318;
  --info: #175cd3;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 33, 29, 0.05), 0 1px 3px rgba(16, 33, 29, 0.04);
  --shadow-lift: 0 6px 16px rgba(16, 33, 29, 0.08);

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Archivo', 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Older names kept so nothing that still references them breaks. */
  --primary-color: var(--brand);
  --primary-hover: var(--brand-strong);
  --primary: var(--brand);
  --bg-color: var(--canvas);
  --surface-color: var(--surface);
  --glass-border: var(--line);
  --text-dark: var(--ink);
  --text-light: var(--ink-2);
  --success: var(--ok);
  --danger: var(--bad);
  --warning: var(--warn);
}

html, body {
  overflow-x: hidden;
  position: relative;
  width: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  background: var(--canvas);
  color: var(--ink);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

a { color: var(--brand-strong); }

/* Identifiers, money and dates read better on a mono face. */
.mono, td.num, .tdr-stat .v, .ref {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.glass-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

/* Navigation & Header Overhaul */
/* The element selector loses to .glass-panel, which the markup also puts on
   the header, so the bar kept its 12px radius and full border. */
header, header.glass-panel {
  padding: 0 1.75rem;
  height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
  z-index: 1000;
  position: sticky;
  top: 0;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex: 0 0 auto;
  margin-right: 1.5rem;
}

.logo-img {
  height: 34px !important;
  width: auto;
  filter: none !important;
  border-radius: 6px;
}

header .logo {
  font-family: var(--font-display);
  font-size: 1.15rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em;
  color: var(--ink) !important;
  background: none !important;
  -webkit-text-fill-color: currentColor !important;
  margin: 0;
  line-height: 1.15;
}

header .logo-sub {
  font-family: var(--font-ui);
  font-size: 0.6rem !important;
  letter-spacing: 0.08em !important;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-3) !important;
  line-height: 1.3;
}

/* DESKTOP Navigation Section */
.desktop-nav-container {
  display: flex;
  flex: 1;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

@media (max-width: 768px) {
  .desktop-nav-container {
    display: none;
  }
}

nav.main-nav {
  flex: 1;
  display: flex;
  justify-content: center;
}

nav.main-nav ul {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
}

nav.main-nav { justify-content: flex-start; }

nav.main-nav ul { gap: 0.15rem; }

nav.main-nav > ul > li > a {
  text-decoration: none;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
  display: block;
  white-space: nowrap;
}

nav.main-nav > ul > li > a:hover {
  background: var(--brand-tint);
  color: var(--brand-strong);
}

/* A drawn caret, so the dropdown arrow is not a glyph in the markup. */
nav.main-nav .dropbtn::after {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  margin-left: 7px;
  vertical-align: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.55;
}

/* User Zone */
.user-zone {
  flex: 0 0 240px;
  display: flex;
  justify-content: flex-end;
}

/* Hamburger Menu Toggle */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  z-index: 3000;
}

/* Mobile drawer: hidden by default on desktop */
.mobile-drawer {
  display: none;
}

/* Close button inside mobile drawer */
.mobile-drawer-close {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
  color: var(--text-dark);
  z-index: 9100;
  padding: 0.5rem;
  transition: color 0.2s;
}
.mobile-drawer-close:hover {
  color: var(--primary-color);
}

.hamburger-box { width: 30px; height: 24px; display: inline-block; position: relative; }
.hamburger-inner { width: 100%; height: 2px; background-color: var(--primary-color); position: absolute; left: 0; top: 50%; transform: translateY(-50%); transition: all 0.3s; }
.hamburger-inner::before, .hamburger-inner::after { content: ""; width: 100%; height: 2px; background-color: var(--primary-color); position: absolute; transition: all 0.3s; }
.hamburger-inner::before { top: -8px; }
.hamburger-inner::after { top: 8px; }

.mobile-menu-toggle.active .hamburger-inner { background-color: transparent; }
.mobile-menu-toggle.active .hamburger-inner::before { top: 0; transform: rotate(45deg); background-color: var(--danger); }
.mobile-menu-toggle.active .hamburger-inner::after { top: 0; transform: rotate(-45deg); background-color: var(--danger); }

/* Professional Dropdown */
.dropdown {
  position: relative;
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lift);
  padding: 0.3rem;
  z-index: 2000;
  margin-top: 0;
}

.dropdown-content::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 0;
  width: 100%;
  height: 20px;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-content a {
  padding: 0.5rem 0.7rem !important;
  font-size: 0.855rem !important;
  color: var(--ink-2);
  border-radius: 6px !important;
  font-weight: 500 !important;
  text-decoration: none;
}

.dropdown-content a:hover {
  background: var(--brand-tint) !important;
  color: var(--brand-strong) !important;
}

.dropdown-content form button {
  padding: 0.5rem 0.7rem !important;
  font-size: 0.855rem !important;
  border-radius: 6px !important;
  color: var(--danger);
  border-radius: 0 !important;
  font-weight: 700 !important;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
}

.dropdown-content form button:hover {
  background: var(--danger) !important;
  color: #fff !important;
}

.user-zone { flex: 0 0 auto; }

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: transparent;
  padding: 0.3rem 0.5rem 0.3rem 0.35rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-profile-trigger:hover {
  background: var(--line-soft);
}

.user-avatar {
  width: 30px;
  height: 30px;
  background: var(--primary-color);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-meta .username {
  font-weight: 600;
  font-size: 0.83rem;
}

.user-meta .institution {
  font-size: 0.7rem;
  color: var(--ink-3);
  font-weight: 500;
}

.user-dropdown-content {
  right: 0 !important;
  left: auto !important;
  transform: none !important;
  min-width: 240px;
}

.dropdown:hover .user-dropdown-content {
  display: block;
}

.dropdown-header {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  margin-bottom: 0.5rem;
}

.dropdown-header .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-light);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.dropdown-header .value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--brand-strong);
  font-family: var(--font-mono);
}

/* Ensure the divider is clean */
.dropdown-divider {
  height: 1px;
  background: rgba(0,0,0,0.05);
  margin: 0.5rem 0;
}

/* Main Container */
main {
  flex: 1;
  padding: 1.75rem 2rem 3rem;
  max-width: 1320px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* Dashboard Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  padding: 1.25rem 1.4rem;
  text-align: left;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: #cfdcd7;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 100%; height: 3px;
  background: var(--brand);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.stat-card:hover::before { opacity: 1; }

.stat-card h3 {
  margin: 0; font-family: var(--font-ui);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-3);
}
.stat-card p {
  margin: 0.35rem 0 0; font-family: var(--font-display);
  font-size: 2rem; font-weight: 700; color: var(--ink);
  line-height: 1.05; font-variant-numeric: tabular-nums;
}

/* Tables */
.table-container {
  overflow-x: auto;
  padding: 0;
  margin-top: 1.25rem;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

th {
  padding: 0.6rem 0.9rem;
  color: var(--ink-3);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  background: var(--line-soft);
  border-bottom: 1px solid var(--line);
}

td {
  padding: 0.7rem 0.9rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.15s ease;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fbf9; }

/* Status Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.685rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  line-height: 1.55;
}
.badge.pending, .badge.draft { background: #fef3c7; color: #92400e; }
.badge.approved, .badge.fulfilled { background: #d5f2e3; color: #065f46; }
.badge.rejected, .badge.cancelled { background: #fde7e5; color: #991b1b; }

/* Forms */
.form-group { margin-bottom: 1.1rem; }
.form-group > label {
  display: block; margin-bottom: 0.3rem;
  font-size: 0.775rem; font-weight: 600; color: var(--ink-2);
}
.form-input, .form-select,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="url"],
input[type="search"], input[type="date"], input[type="datetime-local"],
input[type="time"], input[type="month"], input[type="week"],
input[type="file"], textarea, select {
  width: 100%;
  padding: 0.44rem 0.65rem;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}
textarea { min-height: 64px; line-height: 1.5; padding: 0.5rem 0.65rem; }
input::placeholder, textarea::placeholder { color: #a4b2ac; }
input[type="date"], input[type="datetime-local"], input[type="number"] {
  font-variant-numeric: tabular-nums;
}
input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px; min-height: 0; padding: 0;
  accent-color: var(--brand); vertical-align: middle; cursor: pointer;
}
.form-input:focus, .form-select:focus,
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus,
input[type="number"]:focus, input[type="tel"]:focus, input[type="url"]:focus,
input[type="search"]:focus, input[type="date"]:focus, input[type="datetime-local"]:focus,
input[type="time"]:focus, input[type="month"]:focus, input[type="week"]:focus,
input[type="file"]:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

/* Tom Select — global searchable dropdown styling matched to .form-input */
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  width: 100%;
  padding: 0.44rem 1.6rem 0.44rem 0.65rem;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
  box-shadow: none;
}
.ts-wrapper.focus .ts-control,
.ts-wrapper.dropdown-active .ts-control {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.ts-wrapper .ts-control > input {
  font-family: inherit;
  font-size: 0.875rem;
}
.ts-wrapper.single .ts-control::after {
  border-color: var(--ink-3) transparent transparent !important;
}
.ts-dropdown {
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  padding: 0.25rem;
}
.ts-dropdown .option {
  padding: 0.45rem 0.7rem;
  font-size: 0.865rem;
  border-radius: 6px;
  transition: background 0.15s ease;
}
.ts-dropdown .option:hover,
.ts-dropdown .active {
  background: var(--brand-tint);
  color: var(--brand-strong);
}
.ts-dropdown .option.selected {
  background: var(--brand-tint);
  color: var(--brand-strong);
  font-weight: 600;
}
.ts-dropdown .no-results {
  padding: 0.75rem 0.9rem;
  font-style: italic;
}
/* Compact variant for inline table cells */
#itemsTable .ts-wrapper.single .ts-control { min-height: 38px; padding: 0.4rem 0.6rem; }

/* Compact icon-only button — use `title=""` for tooltip */
.btn-icon {
  padding: 6px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1;
  border-radius: 6px;
}
.btn-icon svg { display: block; }
.btn-icon-group { display: inline-flex; gap: 4px; align-items: center; }

/* Buttons */
/* A bare `.btn` used to have no background at all, which is why Cancel
   rendered as floating text. The quiet button is now the default. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.45rem 0.9rem; min-height: 38px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 0.855rem;
  cursor: pointer; text-decoration: none; box-sizing: border-box;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--line-soft); color: var(--ink); border-color: #cfdcd7; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }

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

/* Actions */
.action-forms { display: flex; gap: 0.5rem; }
.btn-sm { padding: 0.25rem 0.6rem; min-height: 30px; font-size: 0.78rem; }
.btn-success { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-success:hover { background: #05603a; border-color: #05603a; color: #fff; }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-danger:hover { background: #912018; border-color: #912018; color: #fff; }

/* Micro animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn 0.5s ease forwards; }

.messages {
  padding: 1rem 2rem 0; max-width: 1320px;
  margin: 0 auto; width: 100%; box-sizing: border-box;
}
.messages:empty { padding: 0; }
.alert {
  padding: 0.7rem 0.95rem; border-radius: var(--radius-sm);
  margin-bottom: 0.6rem; font-weight: 500; font-size: 0.875rem;
  border: 1px solid transparent; box-shadow: none;
}
.alert-success { background: #eafaf1; color: #05603a; border-color: #b6e6cd; }
.alert-warning { background: #fdeceb; color: #912018; border-color: #f5cfcb; }
.alert-error { background: #fdeceb; color: #912018; border-color: #f5cfcb; }
.alert-info { background: #eff4ff; color: #1849a9; border-color: #cddcfb; }

/* --- Mobile Responsiveness Overhaul --- */
@media (max-width: 768px) {
  header, header.glass-panel {
    height: 56px;
    margin: 0;
    padding: 0 1rem;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  
  header .logo-link {
    flex: none;
    gap: 8px;
  }

  header .logo-img {
    height: 30px !important;
  }

  header .logo {
    flex: none;
    font-size: 1.05rem !important;
  }

  header .logo-sub { display: none; }

  .messages { padding: 0.75rem 1rem 0; }

  .mobile-menu-toggle {
    display: block;
  }

  /* --- The New Full-Page Mobile Drawer --- */
  .mobile-drawer {
    display: block; /* Override global display:none for mobile */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    z-index: 9000; /* Sit above everything */
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    visibility: hidden;
    pointer-events: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-drawer.active {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-drawer-content {
    padding: 100px 2rem 5rem;
    display: flex;
    flex-direction: column;
    gap: 3rem;
    min-height: 100%;
    box-sizing: border-box;
  }

  .mobile-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }

  .mobile-nav a {
    text-decoration: none;
    color: var(--text-dark);
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
    transition: color 0.2s ease;
  }

  .mobile-nav a:hover {
    color: var(--primary-color);
  }

  /* Handle Dropdowns in Mobile (Flatten them) */
  .mobile-nav .dropdown-content {
    display: block;
    position: static;
    box-shadow: none;
    padding: 1rem 0 0 1.5rem;
    background: none;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .mobile-nav .dropdown-content a {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--text-light);
  }

  .mobile-nav .dropbtn {
    /* Match regular nav link style */
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    text-decoration: none;
    display: block;
    pointer-events: none; /* Label only, not clickable */
    padding: 0;
    background: none;
    border: none;
    text-transform: none;
    letter-spacing: normal;
  }

  .mobile-lang-zone, .mobile-user-zone {
    border-top: 1px solid var(--glass-border);
    padding-top: 2rem;
  }

  body.menu-open {
    overflow: hidden; /* Prevent background scroll without position:fixed jump */
  }
  main {
    padding: 1rem;
  }
  
  .glass-panel {
    border-radius: 12px;
  }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  
  div[style*="grid-template-columns: 1fr 1fr"], 
  div[style*="grid-template-columns:1fr 1fr"], 
  div[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .messages {
    padding: 0 1rem;
  }

  .table-container {
    padding: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }
  
  th, td {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
  }
  
  .btn {
    padding: 0.6rem 1rem;
  }

  /* --- BOQ Table → Card Layout on Mobile --- */
  #itemsTable thead {
    display: none; /* Hide the header row */
  }

  #itemsTable tr {
    display: block;
    background: rgba(255,255,255,0.6);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
  }

  #itemsTable td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
  }

  #itemsTable td:last-child {
    border-bottom: none;
    padding-top: 0.75rem;
    justify-content: flex-end;
  }

  /* Show data-label as the left label */
  #itemsTable td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex: 0 0 auto;
    min-width: 80px;
  }

  #itemsTable td .form-input {
    flex: 1;
    min-width: 0;
  }

  #itemsTable td[data-label=" "]::before {
    display: none; /* No label for the remove button cell */
  }

  /* Autocomplete dropdown should still work in card layout */
  #itemsTable td[style*="position: relative"] {
    position: relative !important;
    flex-direction: column;
    align-items: stretch;
  }

  #itemsTable td[style*="position: relative"]::before {
    align-self: flex-start;
  }
}

/* --- Global Page Loader --- */
.global-loader {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--brand-tint);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  box-shadow: none;
}

.loader-text {
  margin-top: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  font-size: 1.1rem;
  letter-spacing: 1px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin { 
  to { transform: rotate(360deg); } 
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}

/* ============================================================
   Custom Autocomplete Dropdown (BOQ Item Descriptions)
   ============================================================ */
.ac-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--glass-border);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 5000;
  max-height: 220px;
  overflow-y: auto;
}

.ac-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dark);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.15s;
}

.ac-item:last-child {
  border-bottom: none;
  border-radius: 0 0 10px 10px;
}

.ac-item:hover, .ac-item.ac-active {
  background: var(--brand-tint);
  color: var(--brand-strong);
}

.ac-item mark {
  background: var(--brand-tint);
  color: var(--brand-strong);
  font-weight: 700;
  border-radius: 2px;
  padding: 0 2px;
}


/* ============================================================
   Attachment Cards
   ============================================================ */
.att-card {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.att-preview {
  height: 140px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.04);
}

.att-icon-card {
  flex-direction: column;
  gap: 0.5rem;
}

.att-ext-badge {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
}

.att-filename {
  font-size: 0.8rem;
  font-weight: 600;
  word-break: break-all;
  color: var(--text-dark);
  margin: 0;
  line-height: 1.4;
}

/* ============================================================
   Tender management (phases 1-3)
   ============================================================ */

.tdr-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}

.faint { color: var(--text-light, #6b7280); font-size: 0.82rem; }

.tdr-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.85rem; margin-bottom: 1.25rem; }
.tdr-stat {
  background: #fff; border: 1px solid rgba(0,0,0,0.06); border-radius: 14px;
  padding: 0.9rem 1.1rem; display: flex; flex-direction: column; gap: 0.15rem;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
.tdr-stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-light, #6b7280); }
.tdr-stat .v { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.tdr-stat.warn { background: #fffaf0; border-color: #f5d9a8; }
.tdr-stat.warn .v { color: #b45309; }

.tdr-filters { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }

.chip-link {
  display: inline-block; padding: 0.22rem 0.7rem; border-radius: 999px;
  background: #eef2f6; color: #374151; font-size: 0.8rem; text-decoration: none;
}
.chip-link:hover { background: #e2e8f0; text-decoration: none; }
.chip-link.on { background: #10b981; color: #fff; }
.chip-link.warn { background: #fde8c8; color: #92400e; }

.tdr-keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.85rem; margin-bottom: 1.25rem; }
.tdr-key {
  background: #fff; border: 1px solid rgba(0,0,0,0.06); border-radius: 14px; padding: 0.9rem 1.1rem;
}
.tdr-key .k { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-light, #6b7280); }
.tdr-key .v { display: block; font-size: 1.05rem; font-weight: 700; margin-top: 0.15rem; }
.tdr-key .s { display: block; font-size: 0.78rem; color: var(--text-light, #6b7280); }
.tdr-key .s.urgent { color: #b91c1c; font-weight: 600; }

.tdr-bar { height: 7px; border-radius: 999px; background: #eef2f6; margin-top: 0.5rem; overflow: hidden; }
.tdr-bar span { display: block; height: 100%; background: linear-gradient(90deg, #10b981, #059669); }

.tdr-alert {
  background: #fef2f2; border: 1px solid #fbcfcf; color: #991b1b;
  border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 1rem; font-size: 0.88rem;
}
.tdr-alert.soft { background: #fffaf0; border-color: #f5d9a8; color: #92400e; }

.tdr-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.5rem; }
.inline-form { display: inline-flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form .form-input, .inline-form .form-select { max-width: 230px; padding: 0.35rem 0.6rem; font-size: 0.85rem; }

.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin: 1rem 1.5rem;
}

.tdr-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; margin-top: 1.25rem; }

.tdr-section {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-light, #6b7280); margin: 1.4rem 0 0.6rem;
  border-bottom: 1px solid rgba(0,0,0,0.06); padding-bottom: 0.35rem;
}

.tdr-due { font-size: 0.75rem; font-weight: 600; }
.tdr-due.soon { color: #b45309; }
.tdr-due.over { color: #b91c1c; }
.tdr-ok { color: #059669; font-weight: 700; }
.tdr-unassigned { color: #b45309; font-weight: 600; font-size: 0.85rem; }

.tdr-outstanding { margin-top: 0.7rem; display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }

.tdr-timeline { list-style: none; padding: 0; margin: 1rem 0 0; }
.tdr-timeline li { padding: 0.6rem 0; border-bottom: 1px solid rgba(0,0,0,0.06); font-size: 0.88rem; }
.tdr-timeline li:last-child { border-bottom: none; }

.tdr-event-form { display: flex; flex-direction: column; gap: 0.5rem; }
.tdr-event-form .frow { display: flex; gap: 0.5rem; }

table.mini { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.mini td { padding: 0.35rem 0; border-bottom: 1px solid rgba(0,0,0,0.05); }
table.mini td.num { text-align: right; font-variant-numeric: tabular-nums; }

tr.row-past { opacity: 0.55; }
tr.row-soon { background: #fffaf0; }

/* Stage and status badges */
.badge.stage-registered  { background: #e5edff; color: #1e40af; }
.badge.stage-go_no_go    { background: #ede9fe; color: #5b21b6; }
.badge.stage-packaging   { background: #e0f2fe; color: #075985; }
.badge.stage-preparation { background: #fef3c7; color: #92400e; }
.badge.stage-submitted   { background: #dbeafe; color: #1d4ed8; }
.badge.stage-evaluation  { background: #ede9fe; color: #5b21b6; }
.badge.stage-won         { background: #d1fae5; color: #065f46; }
.badge.stage-lost        { background: #fee2e2; color: #991b1b; }
.badge.stage-no_bid      { background: #e5e7eb; color: #374151; }
.badge.stage-cancelled   { background: #e5e7eb; color: #374151; }

.badge.pk-invited    { background: #e5e7eb; color: #374151; }
.badge.pk-accepted   { background: #e0f2fe; color: #075985; }
.badge.pk-submitting { background: #fef3c7; color: #92400e; }
.badge.pk-complete   { background: #d1fae5; color: #065f46; }
.badge.pk-withdrawn  { background: #fee2e2; color: #991b1b; }

.badge.it-pending   { background: #e5e7eb; color: #374151; }
.badge.it-submitted { background: #dbeafe; color: #1d4ed8; }
.badge.it-accepted  { background: #d1fae5; color: #065f46; }
.badge.it-rejected  { background: #fee2e2; color: #991b1b; }
.badge.it-waived    { background: #f3f4f6; color: #6b7280; }

/* ==== layout layer =========================================================
   Form rows, page headers and the filter bar. `.frow` / `.f` were used all
   over the tender templates but only ever defined inside .tdr-event-form,
   so every field fell back to a full-width block.
   ========================================================================= */

/* --- Form grid --- */
.frow {
  display: grid;
  /* auto-fill, not auto-fit: auto-fit collapses the empty track on a
     two-field row, so every row would resolve to a different width. */
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.85rem 1.1rem;
  margin-bottom: 0.85rem;
  align-items: start;
}

.f, .frow > label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  margin-bottom: 0.85rem;
  min-width: 0;
}

.frow > .f, .frow > label { margin-bottom: 0; }

.f > span:first-child {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--ink-2);
}

/* Optional per-field hint, sits under the control. */
.f > .hint, .f small {
  font-size: 0.72rem;
  color: var(--ink-3);
  line-height: 1.4;
}

.f.wide { grid-column: span 2; }
.f.full { grid-column: 1 / -1; }
.f .errorlist {
  list-style: none; margin: 0.2rem 0 0; padding: 0;
  color: var(--bad); font-size: 0.74rem; font-weight: 500;
}

/* A checkbox reads as a row, not as a label stacked over a tick. */
.f.check { flex-direction: row; align-items: center; gap: 0.5rem; min-height: 38px; }
.f.check > span:first-child { order: 2; font-weight: 500; }

/* The form's own footer. Buttons sit on a rule, not floating. */
.form-actions {
  display: flex; gap: 0.6rem; align-items: center;
  margin-top: 1.4rem; padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}
.form-actions .spacer { flex: 1; }

/* Inputs inside a form card should not exceed a readable measure when
   they are alone on a row. */
.f textarea { min-height: 72px; }

/* --- Page header --- */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-head h2, .page-head h1 {
  margin: 0; font-size: 1.5rem; font-weight: 700; line-height: 1.2;
}
.page-head .sub { color: var(--ink-2); font-size: 0.875rem; margin-top: 0.2rem; }
.page-head .acts { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.crumb {
  font-size: 0.76rem; color: var(--ink-3); margin-bottom: 0.35rem;
  letter-spacing: 0.01em;
}
.crumb a { color: var(--ink-2); text-decoration: none; }
.crumb a:hover { color: var(--brand-strong); text-decoration: underline; }

/* --- Card interior --- */
.card-pad { padding: 1.25rem 1.4rem; }
.card-title {
  font-family: var(--font-display); font-size: 1rem; font-weight: 700;
  margin: 0 0 0.9rem;
}

/* A card that holds nothing but a table needs its corners clipped so the
   tinted header row follows the radius. */
.table-card { overflow: hidden; padding: 0; }
.table-card > .panel-head { margin: 1rem 1.25rem; }

.empty-state {
  padding: 2.5rem 1rem; text-align: center;
  color: var(--ink-3); font-size: 0.9rem;
}

/* ==== tender surfaces, retuned ============================================ */

.faint { color: var(--ink-3); font-size: 0.8rem; }

.tdr-head { margin-bottom: 1.25rem; align-items: flex-end; }

.tdr-stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem; margin-bottom: 1.1rem;
}
.tdr-stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.8rem 1rem; box-shadow: var(--shadow); gap: 0.2rem;
}
.tdr-stat .k {
  font-size: 0.68rem; letter-spacing: 0.07em; color: var(--ink-3); font-weight: 600;
}
.tdr-stat .v {
  font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; color: var(--ink);
}
.tdr-stat.warn { background: #fffbf2; border-color: #f3ddb4; }
.tdr-stat.warn .v { color: var(--warn); }

/* Filters live on one row: scope chips, then the controls. */
.tdr-filters {
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.tdr-filters .inline-form { gap: 0.5rem; }

.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form .form-input,
.inline-form .form-select,
.inline-form input,
.inline-form select { width: auto; min-width: 200px; }
/* Tom Select replaces the <select> with a wrapper, so the width cap has to
   land on the wrapper or the control stretches the whole row. */
.inline-form .ts-wrapper { width: auto !important; min-width: 200px; max-width: 260px; }
.inline-form .ts-wrapper .ts-control { min-height: 34px; padding-top: 0.28rem; padding-bottom: 0.28rem; }
.inline-form .btn { min-height: 34px; padding: 0.25rem 0.75rem; font-size: 0.8rem; }
.inline-form input, .inline-form select { min-height: 34px; font-size: 0.83rem; }

.chip-link {
  display: inline-block; padding: 0.25rem 0.7rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-2); font-size: 0.79rem; font-weight: 500; text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip-link:hover { background: var(--line-soft); text-decoration: none; color: var(--ink); }
.chip-link.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-link.warn { background: #fdf3e3; border-color: #f3ddb4; color: var(--warn); }

.tdr-keys { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.75rem; }
.tdr-key {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.8rem 1rem;
}
.tdr-key .k { font-size: 0.68rem; letter-spacing: 0.07em; color: var(--ink-3); font-weight: 600; }
.tdr-key .v { font-size: 1rem; font-weight: 700; margin-top: 0.15rem; }
.tdr-key .s { font-size: 0.76rem; color: var(--ink-3); }
.tdr-key .s.urgent { color: var(--bad); font-weight: 600; }

.tdr-bar { background: var(--line-soft); height: 6px; }
.tdr-bar span { background: var(--brand); }

.tdr-alert {
  background: #fdeceb; border-color: #f5cfcb; color: #912018;
  border-radius: var(--radius-sm); font-size: 0.855rem; padding: 0.7rem 0.95rem;
}
.tdr-alert.soft { background: #fffbf2; border-color: #f3ddb4; color: var(--warn); }

.tdr-section {
  font-size: 0.7rem; letter-spacing: 0.08em; font-weight: 600;
  color: var(--ink-3); margin: 1.5rem 0 0.8rem;
  border-bottom: 1px solid var(--line); padding-bottom: 0.4rem;
}
.tdr-section:first-child { margin-top: 0; }

.tdr-actions { gap: 0.5rem; margin-bottom: 0.75rem; }

.panel-head { margin: 1.1rem 1.4rem; align-items: center; }
.panel-head h3 { margin: 0; font-size: 1rem; font-weight: 700; }

.tdr-columns { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; margin-top: 1rem; }

.tdr-due { font-size: 0.73rem; font-weight: 600; }
.tdr-timeline li { font-size: 0.855rem; border-bottom-color: var(--line-soft); }
.tdr-event-form .frow { display: flex; gap: 0.5rem; margin-bottom: 0; }
.tdr-event-form .frow > .f { margin-bottom: 0; }

table.mini td { border-bottom-color: var(--line-soft); font-size: 0.855rem; }
tr.row-soon { background: #fffbf2; }

/* Reference numbers are identifiers; give them the mono face. */
td .ref, a.ref { font-family: var(--font-mono); font-size: 0.82rem; letter-spacing: -0.01em; }

@media (max-width: 640px) {
  .frow { grid-template-columns: 1fr; }
  .f.wide, .f.full { grid-column: auto; }
  main { padding: 1rem 1rem 2rem; }
  .page-head { align-items: flex-start; }
  .inline-form .ts-wrapper,
  .inline-form input,
  .inline-form select { min-width: 0; width: 100%; max-width: none; }
  .inline-form { width: 100%; }
}

/* --- Brand block and language switcher --- */
.brand-text { display: flex; flex-direction: column; }

.lang-switcher-zone { margin-right: 0.5rem; }

.lang-btn {
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.28rem 0.6rem; font-family: inherit; font-size: 0.78rem; font-weight: 600;
  color: var(--ink-2); cursor: pointer; display: flex; align-items: center; gap: 0.35rem;
  letter-spacing: 0.04em; transition: background 0.15s ease;
}
.lang-btn:hover { background: var(--line-soft); color: var(--ink); }
.lang-btn::after {
  content: ""; width: 4px; height: 4px; vertical-align: 1px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px); opacity: 0.6;
}

.lang-menu { min-width: 160px; right: 0; left: auto; transform: none; }
.lang-menu a.is-current {
  font-weight: 600; color: var(--brand-strong) !important; background: var(--brand-tint);
}

/* Mobile drawer language grid uses .btn now, so let it fill its cell. */
.mobile-lang-zone .btn { width: 100%; }

/* Scope chips group, then the search controls, on one filter row. */
.chip-group { display: inline-flex; gap: 0.3rem; align-items: center; }
.tdr-filters .inline-form { margin-left: auto; }
@media (max-width: 760px) {
  .tdr-filters .inline-form { margin-left: 0; }
}

/* Document forms render one field per loop iteration, so the grid lives on
   the wrapper. Anything with a textarea takes the full width. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0 1.1rem;
}
.form-grid .form-group { min-width: 0; }
.form-grid .form-group:has(textarea) { grid-column: 1 / -1; }

.field-error { color: var(--bad); font-size: 0.75rem; margin-top: 0.3rem; font-weight: 500; }
.field-error ul { list-style: none; margin: 0; padding: 0; }
.hint { font-size: 0.72rem; color: var(--ink-3); margin-top: 0.25rem; line-height: 1.4; }

/* Tom Select copies the original select's classes onto its wrapper, so
   .form-select landed on both the wrapper and the control and every
   dropdown rendered as a box inside a box. */
.ts-wrapper.form-select,
.ts-wrapper.form-input,
.ts-wrapper.form-control {
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: none !important;
  min-height: 0 !important;
  box-shadow: none !important;
}

.ts-wrapper .ts-control > .item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ts-wrapper.disabled .ts-control { background: var(--line-soft); color: var(--ink-3); }

/* Two more semantic buttons the templates were reaching for with inline
   colours: a warning action and an informational one. */
.btn-warn { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn-warn:hover { background: #92400e; border-color: #92400e; color: #fff; }
.btn-info { background: var(--info); color: #fff; border-color: var(--info); }
.btn-info:hover { background: #1849a9; border-color: #1849a9; color: #fff; }

/* Draw our own caret. Tom Select hides its own once the control is styled,
   and the arrow is the only thing that says a field is a dropdown. */
.ts-wrapper.single .ts-control { padding-right: 1.8rem !important; }
.ts-wrapper.single .ts-control::after {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  top: 50% !important;
  right: 0.75rem !important;
  left: auto !important;
  width: 6px !important;
  height: 6px !important;
  margin: 0 !important;
  border: 0 !important;
  border-right: 1.5px solid var(--ink-3) !important;
  border-bottom: 1.5px solid var(--ink-3) !important;
  transform: translateY(-70%) rotate(45deg) !important;
  transition: transform 0.15s ease;
}
.ts-wrapper.single.dropdown-active .ts-control::after {
  transform: translateY(-25%) rotate(-135deg) !important;
}

/* Everything a checklist row can do, on one line. */
.row-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row-actions .inline-form { margin: 0; }
.form-input.file-sm { max-width: 190px; min-height: 30px; padding: 0.15rem 0.3rem; font-size: 0.78rem; }
.row-actions .form-input[name="reason"] { max-width: 150px; min-width: 0; min-height: 30px; font-size: 0.78rem; }

/* File inputs generally: the native button should match our button scale. */
input[type="file"] { padding: 0.28rem 0.5rem; font-size: 0.83rem; }
input[type="file"]::file-selector-button {
  font-family: inherit; font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink-2);
  padding: 0.2rem 0.6rem; margin-right: 0.6rem; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--line-soft); color: var(--ink); }

/* A reference number is one token; never let it wrap mid-identifier. */
.ref, td .ref, a.ref { white-space: nowrap; }

/* Links inside a table read as text until you reach for them. */
tbody td a { color: var(--ink); text-decoration: none; }
tbody td a:hover { color: var(--brand-strong); text-decoration: underline; }
tbody td a.ref { color: var(--brand-strong); font-weight: 600; }
