/* ============================================================
   CHAB Internal App — Global Styles
   ============================================================ */
:root {
  --navy:       #1B3A5C;
  --navy-dark:  #122840;
  --blue:       #2E75B6;
  --blue-light: #D5E8F0;
  --blue-mid:   #5B9FD4;
  --teal:       #1A6B5C;
  --teal-light: #E0F4F0;
  --green:      #3A6B25;
  --green-light:#E8F4E8;
  --purple:     #6A0572;
  --purple-light:#F3E5F5;
  --amber:      #B87333;
  --amber-light:#FFF3E0;
  --red:        #C0392B;
  --red-light:  #FDEDEC;
  --gray-50:    #F8F9FA;
  --gray-100:   #F0F4F8;
  --gray-200:   #E2E8F0;
  --gray-300:   #CBD5E0;
  --gray-500:   #718096;
  --gray-600:   #475569;
  --gray-700:   #2D3748;
  --gray-900:   #0F172A;
  --white:      #FFFFFF;
  --sidebar-w:  240px;
  --header-h:   56px;
  --radius:     10px;
  --shadow:     0 2px 8px rgba(0,0,0,.09);
  --shadow-lg:  0 8px 28px rgba(0,0,0,.14);
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:  'Cascadia Code', 'Consolas', monospace;

  /* ─────────────────────────────────────────────────────────────
     SEMANTIC THEME CONTRACT (2026-05-04)
     Default values match the existing bright palette so unmigrated
     rules look identical. Themes override via [data-theme="..."].
     ─────────────────────────────────────────────────────────── */
  --bg-page:           #F0F4F8;
  --bg-card:           #FFFFFF;
  --bg-secondary:      #F8FAFC;
  --bg-input:          #FFFFFF;
  --bg-hover:          #F1F5F9;

  --text-primary:      #1F2937;
  --text-secondary:    #475569;
  --text-tertiary:     #94A3B8;
  --text-on-brand:     #FFFFFF;

  --border-default:    #E2E8F0;
  --border-strong:     #CBD5E0;
  --border-divider:    #F1F5F9;

  --brand-primary:     #1B3A5C;
  --brand-accent:      #1E40AF;

  --sidebar-bg:        #1B3A5C;
  --sidebar-fg:        #FFFFFF;
  --topbar-bg:         #FFFFFF;
}

/* ─── CREAM — warm off-white (Light Dim) ───────────────────── */
[data-theme="cream"] {
  /* Legacy palette overrides — these power the bulk of the app
     because every existing page uses var(--gray-N) and var(--navy). */
  --gray-50:           #F0EBE0;
  --gray-100:          #F5F1E8;
  --gray-200:          #E5E0D5;
  --gray-300:          #D4CFC2;
  --gray-500:          #9A9385;
  --gray-600:          #6B6358;
  --gray-700:          #2C2A26;
  --gray-900:          #1A1815;
  --white:             #FAF8F2;
  --navy:              #2A5278;
  --blue:              #2A5C8C;
  --blue-light:        #E8E3D5;
  /* Semantic theme contract — for newer themed components */
  --bg-page:           #F5F1E8;
  --bg-card:           #FAF8F2;
  --bg-secondary:      #F0EBE0;
  --bg-input:          #FCFBF6;
  --bg-hover:          #EDE7DA;
  --text-primary:      #2C2A26;
  --text-secondary:    #6B6358;
  --text-tertiary:     #9A9385;
  --border-default:    #E5E0D5;
  --border-strong:     #D4CFC2;
  --border-divider:    #EDE9DC;
  --brand-accent:      #1F4A75;
  --topbar-bg:         #FAF8F2;
}

/* ─── SLATE — dimmed dark (GitHub Dim aesthetic) ───────────── */
[data-theme="slate"] {
  /* Legacy palette overrides — values INVERT vs default theme:
     gray-50 is the LIGHTEST surface in light mode → it's a slightly
     RAISED dark surface in dark mode. gray-700 was darkest (text);
     in dark mode it's a near-white text colour. The variable's
     SEMANTIC meaning is preserved; the literal value flips. */
  --gray-50:           #2D333B;
  --gray-100:          #373E47;
  --gray-200:          #444C56;
  --gray-300:          #545D68;
  --gray-500:          #768390;
  --gray-600:          #909DAB;
  --gray-700:          #ADBAC7;
  --gray-900:          #CDD9E5;
  --white:             #22272E;
  --navy:              #316DCA;
  --blue:              #539BF5;
  --blue-light:        #2D3F52;
  /* Semantic theme contract */
  --bg-page:           #1A1F26;
  --bg-card:           #22272E;
  --bg-secondary:      #2D333B;
  --bg-input:          #2D333B;
  --bg-hover:          #373E47;
  --text-primary:      #ADBAC7;
  --text-secondary:    #768390;
  --text-tertiary:     #545D68;
  --border-default:    #373E47;
  --border-strong:     #444C56;
  --border-divider:    #2D333B;
  --brand-primary:     #316DCA;
  --brand-accent:      #539BF5;
  --sidebar-bg:        #161B22;
  --sidebar-fg:        #ADBAC7;
  --topbar-bg:         #22272E;
}

/* ─── SAGE — neutral green-gray (peak eye sensitivity) ─────── */
[data-theme="sage"] {
  /* Legacy palette overrides */
  --gray-50:           #DFE6DF;
  --gray-100:          #E8EDE8;
  --gray-200:          #C8D4C8;
  --gray-300:          #B0BFB0;
  --gray-500:          #889088;
  --gray-600:          #5A6B5A;
  --gray-700:          #1F2A1F;
  --gray-900:          #0F1A0F;
  --white:             #F4F8F3;
  --navy:              #2D5A3C;
  --blue:              #2D5A3C;
  --blue-light:        #D5E0D5;
  /* Semantic theme contract */
  --bg-page:           #E8EDE8;
  --bg-card:           #ECF2EC;
  --bg-secondary:      #DFE6DF;
  --bg-input:          #F4F8F3;
  --bg-hover:          #D8E0D8;
  --text-primary:      #1F2A1F;
  --text-secondary:    #5A6B5A;
  --text-tertiary:     #889088;
  --border-default:    #C8D4C8;
  --border-strong:     #B0BFB0;
  --border-divider:    #D5DDD5;
  --brand-accent:      #2D5A3C;
  --topbar-bg:         #ECF2EC;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; font-family: var(--font); background: var(--bg-page); color: var(--text-primary); font-size: 15px; }

/* ─── Theme-aware shell rules ──────────────────────────────────
   Override the existing hard-coded surface rules so they pick up
   theme variables. Anything still using --gray-100 / #fff for
   background looks fine on default but won't react to themes. */
.sidebar             { background: var(--sidebar-bg) !important; color: var(--sidebar-fg); }
.topbar              { background: var(--topbar-bg);     border-bottom: 1px solid var(--border-default); }
.card,
.config-card         { background: var(--bg-card);       border-color: var(--border-default); color: var(--text-primary); }
.btn-secondary       { background: var(--bg-secondary);  color: var(--text-secondary);
                       border-color: var(--border-default); }
.btn-secondary:hover { background: var(--bg-hover); }
.form-input,
.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea             { background: var(--bg-input); color: var(--text-primary);
                       border-color: var(--border-default); }
table thead          { background: var(--bg-secondary); color: var(--text-secondary); }
table tbody tr:hover { background: var(--bg-hover) !important; }
.modal               { background: var(--bg-card);   color: var(--text-primary); }
.empty-state         { color: var(--text-secondary); }
.text-muted, .text-sm.text-muted { color: var(--text-secondary); }

/* ── LAYOUT ──────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--navy); color: #fff;
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden; transition: width .25s ease;
  z-index: 200;
}
.sidebar-logo {
  padding: 0;
  background: #2C4A7C;
  border-bottom: 1px solid rgba(255,255,255,.1);
  text-align: center;
  flex-shrink: 0;
}
.sidebar-logo-mark {
  width: 100%; height: auto; display: block;
}
.sidebar-logo-img {
  width: 100%; max-width: 200px; height: auto;
}
.logo-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--blue); display: flex; align-items: center;
  justify-content: center; font-weight: 900; font-size: 16px;
  color: #fff; flex-shrink: 0;
}
.logo-text h2 { font-size: .95rem; font-weight: 700; line-height: 1.2; }
.logo-text p  { font-size: .68rem; color: rgba(255,255,255,.55); margin-top: 2px; }

.nav-section-label {
  font-size: .62rem; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: rgba(255,255,255,.35);
  padding: 14px 16px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; font-size: .84rem; font-weight: 500;
  color: rgba(255,255,255,.7); cursor: pointer;
  border-radius: 0; transition: all .15s; text-decoration: none;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--blue-mid); }
.nav-item .nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--blue); color: #fff;
  border-radius: 20px; padding: 1px 7px; font-size: .65rem; font-weight: 700;
}
.nav-item.disabled { opacity: .35; pointer-events: none; }

/* Collapsible nav group */
.nav-group-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; font-size: .84rem; font-weight: 500;
  color: rgba(255,255,255,.7); cursor: pointer;
  border-left: 3px solid transparent;
  text-decoration: none; transition: all .15s;
}
.nav-group-toggle:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-group-toggle .nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
.nav-group-chevron {
  margin-left: auto; font-size: .6rem; opacity: .5;
  transition: transform .2s;
}
.nav-group.open .nav-group-chevron { transform: rotate(90deg); }
.nav-group-toggle.has-active { color: #fff; background: rgba(255,255,255,.05); }
.nav-group-items { overflow: hidden; }
.nav-sub-item { padding-left: 34px !important; font-size: .8rem !important; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .72rem; color: rgba(255,255,255,.35);
}

/* Main area */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Top bar */
.topbar {
  height: var(--header-h); background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; padding: 0 24px;
  gap: 12px; flex-shrink: 0;
}
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--navy); }
.topbar-sub   { font-size: .8rem; color: var(--gray-500); margin-left: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.menu-btn {
  display: none; background: none; border: none;
  font-size: 1.3rem; cursor: pointer; color: var(--navy); padding: 4px;
}

/* Content area */
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── CARDS & PANELS ──────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 10px;
}
.card-header h3 { font-size: .95rem; font-weight: 700; color: var(--navy); }
.card-body { padding: 20px; }

/* ── STAT CARDS ──────────────────────────────────────────────────────── */
.stat-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin-bottom: 24px;
}
.stat-card {
  background: #fff; border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  border-left: 4px solid var(--blue);
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); }
.stat-card .stat-label { font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--gray-500); }
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--navy);
  line-height: 1.1; margin: 4px 0; }
.stat-card .stat-sub   { font-size: .75rem; color: var(--gray-500); }

/* ── BUTTONS ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: .84rem;
  font-weight: 600; cursor: pointer; border: 1px solid var(--gray-300);
  background: var(--gray-100); color: var(--gray-700);
  transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--gray-200); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--navy); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover { background: #2a5018; }
.btn-danger   { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn-icon { padding: 6px 10px; }

/* ── TABLE ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  background: var(--gray-50); color: var(--gray-700);
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; padding: 10px 14px;
  border-bottom: 2px solid var(--gray-200);
  text-align: left; white-space: nowrap;
}

/* ── LEADS TABLE: Scrollable + Sticky Header + Frozen Columns ─────── */
.leads-scroll-container {
  max-height: calc(100vh - 230px);
  min-height: 400px;
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  position: relative;
}
.leads-scroll-container table {
  border-collapse: separate;
  border-spacing: 0;
}

/* Sticky header */
.leads-scroll-container thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-300);
}

/* Frozen columns: col 0 = expand toggle (32px), col 1 = Project ID (~120px) */
.leads-scroll-container .col-freeze-0 {
  position: sticky;
  left: 0;
  z-index: 2;
  background: inherit;
  min-width: 32px;
  max-width: 32px;
}
.leads-scroll-container .col-freeze-1 {
  position: sticky;
  left: 32px;
  z-index: 2;
  background: inherit;
  min-width: 110px;
  border-right: 2px solid var(--gray-200);
}

/* Frozen header cells need highest z-index (sticky both ways) */
.leads-scroll-container thead .col-freeze-0,
.leads-scroll-container thead .col-freeze-1 {
  z-index: 5;
}

/* Give project rows a white background so frozen columns look solid */
.leads-scroll-container .project-row td { background: #fff; }
.leads-scroll-container .project-row:hover td { background: var(--blue-50, #eff6ff); }
.leads-scroll-container .inquiry-subrow td { background: var(--gray-50); }
.leads-scroll-container .inquiry-subrow:hover td { background: var(--gray-100); }
.leads-scroll-container tbody tr:hover .col-freeze-0,
.leads-scroll-container tbody tr:hover .col-freeze-1 { background: inherit; }

/* Region and city full-span headers — sticky vertically but not frozen horizontally */
.leads-scroll-container .region-header-row td,
.leads-scroll-container .city-header-row td {
  position: sticky;
  left: 0;
  z-index: 1;
}

/* Shadow hint on frozen column edge when scrolled */
.leads-scroll-container .col-freeze-1::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: -6px;
  width: 6px;
  background: linear-gradient(to right, rgba(0,0,0,.06), transparent);
  pointer-events: none;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); cursor: pointer; }

/* Project table rows */
.region-header-row { transition: background .15s; }
.region-header-row:hover { opacity: .85; }
.region-header-row td { user-select: none; }
.city-header-row { transition: background .15s; }
.city-header-row:hover { opacity: .9; }
.city-header-row td { user-select: none; }
.project-row { transition: background .1s; }
.project-row:hover { background: var(--blue-50, #eff6ff) !important; }
.project-row .expand-toggle { transition: color .15s; }
.project-row:hover .expand-toggle { color: var(--navy) !important; }
.inquiry-subrow { transition: background .1s; }
.inquiry-subrow:hover { background: var(--gray-100) !important; }
.inquiry-subrow td { padding-top: 8px !important; padding-bottom: 8px !important; font-size: .82rem; }

/* Sortable column headers */
th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
th.sortable:hover { color: var(--blue); }
.sort-icon { font-size: .6rem; margin-left: 3px; opacity: .35; }
.sort-icon.active { opacity: 1; color: var(--blue); }

/* ── BADGES / PILLS ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: .7rem; font-weight: 700; white-space: nowrap;
}
.badge-blue   { background: var(--blue-light);   color: var(--blue); }
.badge-teal   { background: var(--teal-light);   color: var(--teal); }
.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-amber  { background: var(--amber-light);  color: var(--amber); }
.badge-red    { background: var(--red-light);    color: var(--red); }
.badge-gray   { background: var(--gray-200);     color: var(--gray-500); }
.badge-navy   { background: var(--navy);         color: #fff; }

/* ── STAGE PROGRESS BAR ──────────────────────────────────────────────── */
.stage-progress {
  display: flex; align-items: center; gap: 0;
  overflow-x: auto; padding: 4px 0;
}
.stage-dot {
  display: flex; flex-direction: column; align-items: center;
  flex-shrink: 0; position: relative;
}
.stage-dot .dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 800; border: 2px solid var(--gray-300);
  background: #fff; color: var(--gray-500); z-index: 1; position: relative;
}
.stage-dot.done .dot   { background: var(--green); border-color: var(--green); color: #fff; }
.stage-dot.active .dot { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 0 0 3px rgba(46,117,182,.2); }
.stage-dot.pending .dot{ background: #fff; border-color: var(--gray-300); color: var(--gray-500); }
.stage-dot .dot-label  { font-size: .58rem; color: var(--gray-500); margin-top: 4px; max-width: 52px; text-align: center; line-height: 1.2; }
.stage-dot.active .dot-label { color: var(--blue); font-weight: 700; }
.stage-dot.done .dot-label   { color: var(--green); }
.stage-connector {
  flex: 1; min-width: 12px; height: 2px;
  background: var(--gray-200); margin-bottom: 20px; flex-shrink: 0;
}
.stage-connector.done { background: var(--green); }

/* ── FORMS ───────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: .78rem; font-weight: 700; color: var(--gray-700); }
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--gray-300);
  border-radius: 8px; font-size: .88rem; font-family: var(--font);
  color: var(--gray-700); background: #fff; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}
textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: .72rem; color: var(--gray-500); }

/* ── MODAL ───────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 500;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px;
  max-width: 640px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
  animation: modalIn .2s ease;
}
.modal-lg { max-width: 840px; }
@keyframes modalIn {
  from { transform: translateY(12px) scale(.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; color: var(--navy); flex: 1; }
.modal-close {
  background: var(--gray-100); border: none; border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-500); transition: all .15s;
}
.modal-close:hover { background: var(--gray-200); color: var(--gray-700); }
.modal-body    { padding: 20px 24px; }
.modal-footer  {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── ENTITY BADGE ────────────────────────────────────────────────────── */
.entity-chab      { background: #e8f0f8; color: var(--navy); }
.entity-cleantech { background: var(--teal-light); color: var(--teal); }

/* ── SEARCH BAR ──────────────────────────────────────────────────────── */
.search-bar { position: relative; }
.search-bar input { padding-left: 36px; }
.search-bar .search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--gray-500); font-size: .95rem; pointer-events: none;
}

/* ── FILTER ROW ──────────────────────────────────────────────────────── */
.filter-row {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; align-items: center;
}
.filter-row select { width: auto; font-size: .82rem; padding: 7px 10px; }

/* ── FILTER DROPDOWNS (autocomplete) ──────────────────────────────────── */
.filter-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto;
  margin-top: 2px;
}
.filter-dd-item {
  padding: 8px 12px; font-size: .82rem; cursor: pointer;
  border-bottom: 1px solid var(--gray-100); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.filter-dd-item:last-child { border-bottom: none; }
.filter-dd-item:hover { background: var(--gray-50); color: var(--navy); }

/* ── STAGE TIMELINE (detail view) ────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: ""; position: absolute; left: 9px; top: 0; bottom: 0;
  width: 2px; background: var(--gray-200);
}
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before {
  content: ""; position: absolute; left: -23px; top: 5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--gray-200); border: 2px solid var(--gray-300);
}
.tl-item.done::before    { background: var(--green); border-color: var(--green); }
.tl-item.active::before  { background: var(--blue); border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,117,182,.2); }
.tl-title   { font-size: .85rem; font-weight: 700; color: var(--navy); }
.tl-meta    { font-size: .75rem; color: var(--gray-500); margin-top: 2px; }
.tl-notes   { font-size: .8rem; color: var(--gray-700); margin-top: 4px;
  background: var(--gray-50); border-radius: 6px; padding: 6px 10px; }

/* ── TABS ────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab-btn {
  padding: 8px 16px; font-size: .84rem; font-weight: 600;
  color: var(--gray-500); background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  cursor: pointer; transition: all .15s;
}
.tab-btn:hover { color: var(--blue); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── EMPTY STATE ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--gray-500);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 1rem; font-weight: 700; color: var(--gray-700); margin-bottom: 6px; }
.empty-state p  { font-size: .85rem; margin-bottom: 16px; }

/* ── ALERT / TOAST ───────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff; border-radius: 10px;
  padding: 12px 18px; font-size: .85rem; font-weight: 600;
  box-shadow: var(--shadow-lg); animation: toastIn .25s ease;
  display: flex; align-items: center; gap: 10px; min-width: 240px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── LOADING ─────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--gray-200); border-top-color: var(--blue);
  animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESPONSIVE ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; height: 100%; transition: left .25s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: flex; }
  .content  { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 16px; }
  .modal { margin: 0; border-radius: 14px 14px 0 0; max-height: 92vh; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row select, .filter-row .search-bar { width: 100%; }
}

/* ── UTILS ───────────────────────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.flex  { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.ml-auto { margin-left: auto; }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.text-muted { color: var(--gray-500); }
.text-navy  { color: var(--navy); }
.fw-bold { font-weight: 700; }
.w-full { width: 100%; }
.overlay-bg { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 199; display: none; }
.overlay-bg.open { display: block; }

/* ── ATTACHMENT GRID ────────────────────────────────────────────────── */
.att-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.att-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--gray-50);
  border-radius: 10px; border: 1px solid var(--gray-200);
  transition: box-shadow .15s;
}
.att-card:hover { box-shadow: var(--shadow); }
.att-icon { font-size: 1.6rem; flex-shrink: 0; }
.att-info { flex: 1; min-width: 0; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.att-actions { display: flex; gap: 6px; flex-shrink: 0; }
.att-actions .btn { padding: 4px 8px; font-size: .78rem; }

/* ── DROP ZONE ──────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--gray-300); border-radius: 10px;
  padding: 28px; text-align: center; cursor: pointer;
  transition: all .2s; background: var(--gray-50);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--blue); background: var(--blue-light);
}
.drop-zone-text { font-size: .85rem; color: var(--gray-500); }
.drop-zone.drag-over .drop-zone-text { color: var(--blue); font-weight: 600; }

/* ── BADGE RED (for Hot leads) ──────────────────────────────────────── */
.badge-red { background: var(--red-light); color: var(--red); }

/* ── QS SPECIFICATION SHEET ─────────────────────────────────────────── */
.qs-back-row { margin-bottom: 16px; }

.qs-chute-tabs {
  display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; align-items: center;
}
.qs-chute-tab {
  padding: 7px 16px; font-size: .82rem; font-weight: 600;
  border: 1px solid var(--gray-200); border-radius: 8px;
  background: #fff; color: var(--gray-500); cursor: pointer; transition: all .15s;
}
.qs-chute-tab:hover { border-color: var(--blue); color: var(--blue); }
.qs-chute-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Main section (e.g. "1. DUCT") */
.qs-main-section {
  margin-bottom: 16px; border: 1.5px solid var(--navy); border-radius: 10px; overflow: hidden;
}
.qs-main-header {
  background: var(--navy); color: #fff; padding: 10px 18px;
  display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none;
}
.qs-main-header:hover { background: #1a3352; }
.qs-main-num {
  font-size: 1rem; font-weight: 800; min-width: 28px; text-align: center;
  background: rgba(255,255,255,.18); border-radius: 6px; padding: 2px 8px;
}
.qs-main-label { font-size: .82rem; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; flex: 1; }
.qs-main-toggle { font-size: .7rem; opacity: .7; transition: transform .2s; }
.qs-main-section.collapsed .qs-main-body { display: none; }
.qs-main-section.collapsed .qs-main-toggle { transform: rotate(-90deg); }
.qs-main-body { padding: 0; }

/* Sub-section (e.g. "1.1 Duct Pipe") */
.qs-sub-section { border-bottom: 1px solid var(--gray-200); }
.qs-sub-section:last-child { border-bottom: 0; }
.qs-sub-header {
  background: var(--gray-50); padding: 8px 18px;
  display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--gray-200);
}
.qs-sub-header:hover { background: var(--gray-100); }
.qs-sub-num {
  font-size: .75rem; font-weight: 700; color: var(--navy); min-width: 28px;
}
.qs-sub-label { font-size: .76rem; font-weight: 600; color: var(--navy); flex: 1; }
.qs-sub-toggle { font-size: .65rem; color: var(--gray-400); transition: transform .2s; }
.qs-sub-section.collapsed .qs-sub-body { display: none; }
.qs-sub-section.collapsed .qs-sub-toggle { transform: rotate(-90deg); }
.qs-sub-body { padding: 12px 18px; }

.qs-section-title {
  font-size: .78rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 1px; color: var(--navy); padding: 12px 0 6px;
  border-bottom: 2px solid var(--navy); margin: 20px 0 12px;
}
.qs-section-title:first-of-type { margin-top: 0; }

.qs-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 16px; margin-bottom: 8px;
}

.qs-field {
  display: flex; flex-direction: column; gap: 3px;
  /* Bottom-align inputs so labels with long subtitle spans (e.g.
     "USERNAME — editing this signs the user out…") don't push their
     input out of row alignment with sibling fields. Single-line labels
     reserve a bit of extra space above so the visual stays consistent. */
  justify-content: flex-end;
}
.qs-field label {
  font-size: .72rem; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: .5px;
  /* Soft minimum so single-line labels are visually similar to those
     with a short subtitle span. Two-line labels grow naturally. */
  min-height: 1.4em;
}
.qs-field input,
.qs-field select,
.qs-field textarea {
  padding: 7px 10px; font-size: .84rem; border-radius: 6px;
  border: 1px solid var(--gray-300);
}
.qs-field input:focus,
.qs-field select:focus {
  border-color: var(--blue); box-shadow: 0 0 0 2px rgba(46,117,182,.12);
}

.qs-num {
  text-align: right; font-family: var(--font-mono); font-size: .84rem;
}

.qs-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 0; border-top: 1px solid var(--gray-200); margin-top: 20px;
}

/* Floor measurement table */
.qs-floor-table { width: 100%; border-collapse: collapse; font-size: .82rem; margin-top: 8px; }
.qs-floor-table th {
  background: var(--gray-50); font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; padding: 8px 10px;
  border-bottom: 2px solid var(--gray-200); text-align: left;
}
.qs-floor-table td { padding: 6px 8px; border-bottom: 1px solid var(--gray-200); }
.qs-floor-table input {
  width: 100%; padding: 5px 8px; font-size: .82rem; border-radius: 4px;
  border: 1px solid var(--gray-300);
}
.qs-floor-table .floor-num { font-family: var(--font-mono); text-align: right; }
.qs-floor-actions { display: flex; gap: 8px; margin-top: 8px; }

@media (max-width: 768px) {
  .qs-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .qs-grid { grid-template-columns: 1fr; }
}

/* ── QS Sticky Jump Bar ──────────────────────────────────────────── */
.qs-jump-bar {
  position: sticky; top: 0; z-index: 90;
  background: #fff; border-bottom: 2px solid var(--navy);
  padding: 6px 12px; display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.qs-jump-btn {
  font-size: .68rem; font-weight: 600; padding: 4px 10px;
  border-radius: 14px; border: 1.5px solid var(--navy); background: transparent;
  color: var(--navy); cursor: pointer; transition: all .15s; white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
.qs-jump-btn:hover, .qs-jump-btn.active { background: var(--navy); color: #fff; }
.qs-jump-btn .qs-completion-dot {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block;
  border: 1px solid currentColor; flex-shrink: 0;
}
.qs-jump-btn .qs-completion-dot.filled { background: #22c55e; border-color: #22c55e; }
.qs-jump-btn .qs-completion-dot.partial { background: #f59e0b; border-color: #f59e0b; }
.qs-jump-bar-actions {
  margin-left: auto; display: flex; gap: 6px; align-items: center;
}
.qs-jump-bar-actions button {
  font-size: .68rem; font-weight: 600; padding: 4px 10px;
  border-radius: 14px; border: 1.5px solid var(--gray-300); background: var(--gray-50);
  color: var(--gray-600); cursor: pointer; transition: all .15s;
}
.qs-jump-bar-actions button:hover { background: var(--gray-200); }

/* ── QS Floating Save ────────────────────────────────────────────── */
.qs-floating-save {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  display: flex; gap: 8px; align-items: center;
  background: #fff; padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15); border: 1.5px solid var(--gray-200);
  transition: all .2s;
}
.qs-floating-save.has-changes { border-color: #f59e0b; box-shadow: 0 4px 20px rgba(245,158,11,.25); }
.qs-floating-save .qs-save-indicator {
  font-size: .7rem; font-weight: 600; color: var(--gray-400);
  transition: color .2s;
}
.qs-floating-save.has-changes .qs-save-indicator { color: #f59e0b; }
.qs-floating-save button {
  padding: 8px 20px; border-radius: 8px; font-size: .8rem; font-weight: 700;
  border: none; cursor: pointer; transition: all .15s;
}
.qs-floating-save .qs-btn-save {
  background: var(--navy); color: #fff;
}
.qs-floating-save.has-changes .qs-btn-save {
  background: #f59e0b; color: #fff; animation: qs-pulse .8s ease-in-out infinite alternate;
}
.qs-floating-save .qs-btn-print {
  background: var(--gray-100); color: var(--navy); border: 1px solid var(--gray-300);
}
.qs-floating-save .qs-btn-print:hover { background: var(--gray-200); }
@keyframes qs-pulse { from { box-shadow: 0 0 0 0 rgba(239,68,68,.35); } to { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }
@keyframes pr-pulse { from { box-shadow: 0 0 0 0 rgba(239,68,68,.35); } to { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }

/* ── QS Section Summary (collapsed) ─────────────────────────────── */
.qs-section-summary {
  font-size: .68rem; font-weight: 400; color: rgba(255,255,255,.65);
  margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 500px; display: none;
}
.qs-main-section.collapsed .qs-section-summary { display: inline; }

/* ── Fan Calculator Side Panel ───────────────────────────────────── */
.fan-calc-panel {
  position: fixed; top: 0; right: -420px; width: 400px; height: 100vh;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 1000; transition: right .3s ease; overflow-y: auto;
  display: flex; flex-direction: column;
}
.fan-calc-panel.open { right: 0; }
.fan-calc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 2px solid var(--navy);
  background: var(--gray-50); position: sticky; top: 0; z-index: 1;
}
.fan-calc-body { padding: 16px; flex: 1; }
.fan-calc-section {
  margin-bottom: 18px; background: var(--gray-50);
  border-radius: 8px; padding: 14px;
}
.fan-calc-section-title {
  font-size: .8rem; font-weight: 700; color: var(--navy);
  margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px;
}
.fan-calc-note {
  font-size: .72rem; color: var(--gray-500); margin-bottom: 10px; line-height: 1.4;
}
.fan-calc-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; align-items: center;
}
.fan-calc-grid label {
  font-size: .75rem; font-weight: 600; color: var(--gray-600);
}
.fan-calc-input {
  padding: 5px 8px; border: 1px solid var(--gray-300); border-radius: 4px;
  font-size: .82rem; width: 100%; box-sizing: border-box;
}
.fan-calc-input:focus { border-color: var(--blue); outline: none; }
.fan-calc-results-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  font-size: .78rem;
}
.fan-calc-results-grid .fc-label { color: var(--gray-500); }
.fan-calc-results-grid .fc-value { font-weight: 600; color: var(--navy); text-align: right; }
.fan-calc-results-grid .fc-highlight {
  background: #dcfce7; padding: 4px 8px; border-radius: 4px;
  grid-column: 1 / -1; text-align: center; font-weight: 700;
  color: #166534; margin: 6px 0;
}
.fan-calc-results-grid .fc-warning {
  background: #fef2f2; padding: 4px 8px; border-radius: 4px;
  grid-column: 1 / -1; text-align: center; font-weight: 700;
  color: #dc2626; margin: 6px 0;
}
.fan-calc-table {
  width: 100%; border-collapse: collapse; font-size: .78rem;
}
.fan-calc-table th {
  background: var(--navy); color: #fff; padding: 6px 10px;
  text-align: left; font-size: .72rem; text-transform: uppercase;
}
.fan-calc-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--gray-200);
}
.fan-calc-table tr.fc-recommended {
  background: #dcfce7; font-weight: 700;
}
.fan-calc-table tr.fc-too-small {
  color: var(--gray-400);
}
.fan-calc-literature {
  font-size: .74rem; color: var(--gray-600); line-height: 1.6;
}
.fan-calc-literature p { margin: 6px 0; }
.fan-calc-literature ol {
  margin: 4px 0 10px 18px; padding: 0;
}
.fan-calc-literature ol li { margin-bottom: 3px; }
@media (max-width: 600px) {
  .fan-calc-panel { width: 100%; right: -100%; }
}
@media print { .fan-calc-panel { display: none !important; } }

/* ── Chute Height Calculator Side Panel ──────────────────────────── */
.hc-panel {
  position: fixed; top: 0; right: -540px; width: 520px; height: 100vh;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.18);
  z-index: 1001; transition: right .3s ease; overflow-y: auto;
  display: flex; flex-direction: column;
}
.hc-panel.open { right: 0; }
.hc-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 3px solid #d97706;
  background: #fffbeb; position: sticky; top: 0; z-index: 1;
}
.hc-panel-body {
  display: flex; flex: 1; min-height: 0;
}
/* Left side: inputs */
.hc-inputs { flex: 1; padding: 14px; overflow-y: auto; border-right: 1px solid #fde68a; }
/* Right side: building diagram */
.hc-diagram { width: 160px; padding: 10px 8px; overflow-y: auto; background: #fefce8; display: flex; flex-direction: column; }
.hc-section {
  margin-bottom: 12px; background: #fff; border: 1px solid #fde68a;
  border-radius: 8px; padding: 10px 12px;
}
.hc-section-title {
  font-size: .74rem; font-weight: 700; color: #92400e;
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}
.hc-section-note {
  font-size: .68rem; color: #92400e; margin-bottom: 8px; line-height: 1.3;
}
/* Building diagram blocks */
.hc-bldg-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; }
.hc-bldg-label { font-size: .62rem; font-weight: 700; text-align: center; margin-bottom: 4px; color: #92400e; text-transform: uppercase; letter-spacing: .4px; }
.hc-bldg-stack { display: flex; flex-direction: column; border: 2px solid #d97706; border-radius: 6px; overflow: visible; }
.hc-bldg-floor {
  display: flex; align-items: center; justify-content: center; gap: 3px;
  padding: 2px 4px; font-size: .58rem; font-weight: 600;
  border-bottom: 1px solid rgba(0,0,0,.08); min-height: 16px;
  text-align: center; line-height: 1.2; position: relative;
  transition: all .2s;
}
.hc-bldg-floor.hc-typ  { background: #dbeafe; color: #1e40af; }
.hc-bldg-floor.hc-below { background: #dcfce7; color: #166534; }
.hc-bldg-floor.hc-above { background: #fce7f3; color: #9d174d; }
.hc-bldg-floor .hc-intake-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #d97706; flex-shrink: 0;
}
.hc-bldg-floor.hc-offset-floor {
  border-left: 3px solid #7c3aed; background: #f5f3ff !important;
}
.hc-bldg-roof {
  background: #92400e; color: #fff; text-align: center; padding: 3px 4px;
  font-size: .6rem; font-weight: 700; border-radius: 4px 4px 0 0; letter-spacing: .5px;
}
.hc-bldg-ground {
  background: #78716c; color: #fff; text-align: center; padding: 3px 4px;
  font-size: .6rem; font-weight: 700; letter-spacing: .5px;
}
.hc-legend { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; justify-content: center; }
.hc-legend-item { display: flex; align-items: center; gap: 3px; font-size: .56rem; color: #6b7280; }
.hc-legend-swatch { width: 8px; height: 8px; border-radius: 2px; }
/* Footer with totals + buttons */
/* Backdrop that blocks interaction behind the panel */
.hc-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 999;
}
.hc-backdrop.open { display: block; }
.hc-panel-footer {
  padding: 10px 18px; border-top: 2px solid #d97706;
  background: #fffbeb; position: sticky; bottom: 0; z-index: 1;
}
@media (max-width: 700px) {
  .hc-panel { width: 100%; right: -100%; }
  .hc-diagram { width: 120px; }
}
@media print { .hc-panel { display: none !important; } }

/* ── QS Optional Toggle ──────────────────────────────────────────── */
.qs-opt-wrap {
  position: relative;
}
.qs-opt-toggle {
  position: absolute; top: 2px; right: 4px; z-index: 1;
  display: flex; align-items: center; gap: 4px;
  font-size: .68rem; font-weight: 600; letter-spacing: .3px;
  text-transform: uppercase; color: var(--gray-400);
  cursor: pointer; user-select: none;
  padding: 2px 8px; border-radius: 10px;
  background: var(--gray-50); border: 1px solid var(--gray-200);
  transition: all .15s;
}
.qs-opt-toggle:hover { border-color: var(--gray-300); background: #fff; }
.qs-opt-toggle input[type="checkbox"] {
  width: 13px; height: 13px; margin: 0; cursor: pointer;
  accent-color: #d97706;
}
.qs-opt-toggle.is-optional {
  background: #fff7ed; border-color: #d97706; color: #d97706;
}

/* ── QS Validation ───────────────────────────────────────────────── */
.qs-field.qs-invalid select, .qs-field.qs-invalid input {
  border-color: #ef4444 !important; background: #fef2f2 !important;
}
.qs-validation-banner {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;
  padding: 10px 16px; margin-bottom: 12px; display: none;
}
.qs-validation-banner.show { display: block; }
.qs-validation-banner p { font-size: .78rem; color: #dc2626; font-weight: 600; margin: 0; }

/* ── QS Print Styles ─────────────────────────────────────────────── */
@media print {
  .qs-jump-bar, .qs-floating-save, #qs-back, #btn-add-chute,
  #btn-duplicate-chute, #btn-delete-chute, .btn-remove-bin,
  .btn-remove-sbin, .btn-remove-mech, .btn-remove-whe,
  #btn-add-bin, #btn-add-small-bin, #btn-add-mech, #btn-add-whe,
  .qs-validation-banner { display: none !important; }
  .qs-main-section.collapsed .qs-main-body { display: block !important; }
  .qs-sub-section.collapsed .qs-sub-body { display: block !important; }
  .qs-main-section { break-inside: avoid; page-break-inside: avoid; }
  .qs-section-summary { display: none !important; }
}

/* ── Directory Detail ─────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-fields { display: flex; flex-direction: column; gap: 0; }
.detail-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--gray-200); }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-weight: 600; color: var(--gray-500); min-width: 140px; }
.clickable-row:hover { background: var(--gray-100); }

/* ── Global Search ────────────────────────────────────────────────── */
.global-search-wrap { position: relative; margin-left: auto; flex: 0 1 260px; min-width: 120px; }
.global-search-wrap input {
  width: 100%; padding: 6px 12px; border: 1px solid var(--gray-200);
  border-radius: 6px; font-size: .82rem; background: var(--gray-50);
  transition: border-color .2s;
  box-sizing: border-box;
}
.global-search-wrap input:focus {
  outline: none; border-color: var(--blue); background: #fff;
}
.global-search-results {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
  width: 420px; max-height: 420px; overflow-y: auto;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 999;
}
.global-search-results.open { display: block; }
.gs-section { padding: 6px 14px 2px; font-size: .68rem; font-weight: 700;
  color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.gs-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  cursor: pointer; font-size: .82rem; border-bottom: 1px solid var(--gray-100);
}
.gs-item:hover { background: var(--blue-light); }
.gs-item:last-child { border-bottom: none; }
.gs-icon { width: 28px; height: 28px; border-radius: 6px; display: flex;
  align-items: center; justify-content: center; font-size: .9rem;
  background: var(--gray-100); flex-shrink: 0; }
.gs-info { flex: 1; min-width: 0; }
.gs-title { font-weight: 600; color: var(--navy); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.gs-sub { font-size: .72rem; color: var(--gray-500); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.gs-empty { padding: 20px; text-align: center; color: var(--gray-500); font-size: .82rem; }

/* ── Dashboard layout ───────────────────────────────────────────── */
.dash-row { display: flex; gap: 20px; margin-bottom: 12px; }
.dash-col { flex: 1; min-width: 0; }
@media (max-width: 900px) {
  .dash-row { flex-direction: column; }
}

/* Activity feed */
.activity-item {
  display: flex; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--gray-100); cursor: pointer;
  transition: background .15s;
}
.activity-item:hover { background: var(--blue-light); }
.activity-item:last-child { border-bottom: none; }
.activity-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 2px; }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: .85rem; color: var(--gray-700); line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; }

/* ── Contract progress bar ─────────────────────────────────────── */
.progress-bar-wrap { padding: 4px 0; }
.progress-bar-bg {
  position: relative; height: 22px; background: var(--gray-100);
  border-radius: 11px; overflow: hidden;
}
.progress-bar-fill {
  position: absolute; top: 0; left: 0; height: 100%;
  transition: width .4s ease;
}
.progress-bar-fill.paid { background: var(--green); z-index: 2; border-radius: 11px 0 0 11px; }
.progress-bar-fill.invoiced { background: var(--purple); z-index: 1; }
.progress-labels {
  display: flex; gap: 20px; margin-top: 8px; font-size: .78rem; color: var(--gray-500);
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot.paid { background: var(--green); }
.dot.invoiced { background: var(--purple); }
.dot.remaining { background: var(--gray-200); }

/* ── Extra button sizes ─────────────────────────────────────────── */
.btn-xs { padding: 2px 8px; font-size: .72rem; border-radius: 4px; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #a93226; }

/* ── Form grid 2-col ─────────────────────────────────────────────── */
.form-grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.form-grid-2 .full-width { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}

/* ── Login Screen ───────────────────────────────────────────────────── */
#app-shell.login-mode {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  display: flex; align-items: center; justify-content: center;
}

#app-shell.login-mode .sidebar,
#app-shell.login-mode .main-area {
  display: none;
}

.login-container {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
}

.login-card {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 48px 40px; width: 100%; max-width: 400px;
}

.login-header {
  text-align: center; margin-bottom: 32px;
}

.login-logo {
  width: 100%; max-width: 280px; height: auto; margin: 0 auto 16px; display: block;
  object-fit: contain;
}

.login-header h1 {
  font-size: 1.5rem; font-weight: 700; color: var(--navy);
  margin-bottom: 4px;
}

.login-form { margin-top: 24px; }

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form label {
  display: block; font-size: .84rem; font-weight: 600;
  color: var(--gray-700); margin-bottom: 6px;
}

.login-form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
  border-radius: 6px; font-size: .9rem; font-family: var(--font);
  transition: border .15s;
}

.login-form input:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light);
}

.login-error {
  color: var(--red); font-size: .84rem; margin-bottom: 16px;
  padding: 10px 12px; background: var(--red-light); border-radius: 6px;
  display: none;
}

.login-error:not(:empty) {
  display: block;
}

.btn-block {
  width: 100%;
}

.login-footer {
  text-align: center; font-size: .78rem; color: var(--gray-500);
  margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--gray-200);
}

/* ── Pricing Formula Layout ─────────────────────────────────────── */
.pricing-formula {
  display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap;
}
.formula-inputs {
  display: flex; gap: 12px; flex-wrap: wrap; min-width: 200px;
}
.formula-field { display: flex; flex-direction: column; gap: 4px; }
.formula-field label { font-size: .75rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.formula-field input { width: 80px; }
.formula-breakdown { flex: 1; min-width: 300px; }
.formula-table { width: 100%; border-collapse: collapse; }
.formula-table td { padding: 6px 12px; font-size: .88rem; }
.formula-label { color: var(--gray-600); }
.formula-value { text-align: right; font-family: var(--font-mono); font-weight: 500; }
.formula-subtotal td { border-top: 1px solid var(--gray-300); font-weight: 600; color: var(--navy); }
.formula-grand-total td {
  border-top: 2px solid var(--navy); font-weight: 700; font-size: 1.05rem;
  color: var(--navy); background: #f0f4ff; padding: 10px 12px;
}
@media (max-width: 700px) {
  .pricing-formula { flex-direction: column; }
  .formula-inputs { width: 100%; }
}

/* ── Kanban Board ──────────────────────────────────────────────────── */
.kanban-board {
  display: flex; gap: 12px; overflow: auto; padding-bottom: 12px;
  min-height: 400px; max-height: calc(100vh - 180px);
  border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 12px;
}
.kanban-column {
  flex: 0 0 220px;
  background: var(--gray-50); border-radius: var(--radius);
  display: flex; flex-direction: column;
}
.kanban-header {
  padding: 10px 12px; display: flex; align-items: center; justify-content: space-between;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #fff;
}
.kanban-title { font-size: .78rem; font-weight: 700; color: var(--navy); }
.kanban-count {
  background: var(--gray-200); color: var(--gray-700); border-radius: 10px;
  font-size: .68rem; font-weight: 700; padding: 2px 8px;
}
.kanban-cards { flex: 1; padding: 8px; min-height: 60px; transition: background .15s; }
.kanban-cards.kanban-drop-target { background: var(--blue-light); border-radius: 0 0 var(--radius) var(--radius); }
.kanban-card {
  background: #fff; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); cursor: pointer;
  border-left: 3px solid transparent; transition: box-shadow .15s;
}
.kanban-card:hover { box-shadow: 0 3px 10px rgba(0,0,0,.14); }
.kanban-card[draggable="true"] { cursor: grab; }
.kanban-card-ref { font-size: .7rem; font-weight: 700; color: var(--navy); margin-bottom: 2px; }
.kanban-card-project { font-size: .78rem; font-weight: 600; color: var(--gray-700); margin-bottom: 2px; }
.kanban-card-contractor { font-size: .7rem; color: var(--gray-500); margin-bottom: 6px; }
.kanban-card-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: .65rem; color: var(--gray-500); }
.kanban-overdue { color: var(--red); font-weight: 700; }
.kanban-tasks { color: var(--amber); font-weight: 600; }
.kanban-last-act { color: var(--gray-500); }
.kanban-empty { text-align: center; padding: 20px 8px; font-size: .75rem; color: var(--gray-500); }

/* ── JIH TABLE: Scrollable + Sticky Header + Frozen Columns ──────── */
.jih-scroll-container {
  max-height: calc(100vh - 300px);
  min-height: 300px;
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
}
.jih-scroll-container table {
  border-collapse: separate;
  border-spacing: 0;
}
.jih-scroll-container thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-300);
}
/* Frozen col 0 = Ref (~100px), col 1 = Project (~160px) */
.jih-scroll-container .col-freeze-0 {
  position: sticky;
  left: 0;
  z-index: 2;
  background: inherit;
  min-width: 90px;
}
.jih-scroll-container .col-freeze-1 {
  position: sticky;
  left: 90px;
  z-index: 2;
  background: inherit;
  min-width: 140px;
  border-right: 2px solid var(--gray-200);
}
.jih-scroll-container thead .col-freeze-0,
.jih-scroll-container thead .col-freeze-1 {
  z-index: 5;
}
.jih-scroll-container tbody tr td { background: #fff; }
.jih-scroll-container tbody tr:hover td { background: var(--gray-50); }
.jih-scroll-container .col-freeze-1::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: -6px;
  width: 6px;
  background: linear-gradient(to right, rgba(0,0,0,.06), transparent);
  pointer-events: none;
}

/* ── Sales Activity Timeline ──────────────────────────────────────── */
.activity-timeline { padding: 0; }
.activity-item {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue-light);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; flex-shrink: 0;
}
.activity-body { flex: 1; min-width: 0; }
.activity-subject { font-size: .82rem; font-weight: 600; color: var(--gray-700); }
.activity-desc { font-size: .75rem; color: var(--gray-500); margin-top: 2px; }
.activity-meta { font-size: .68rem; color: var(--gray-500); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Task List ────────────────────────────────────────────────────── */
.task-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
}
.task-item:last-child { border-bottom: none; }
.task-check { margin-top: 3px; cursor: pointer; width: 18px; height: 18px; accent-color: var(--green); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: .82rem; font-weight: 600; color: var(--gray-700); }
.task-title.task-done { text-decoration: line-through; color: var(--gray-500); }
.task-meta { font-size: .68rem; color: var(--gray-500); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.task-overdue { color: var(--red); font-weight: 600; }
.task-priority-urgent { border-left: 3px solid var(--red); padding-left: 8px; }
.task-priority-high { border-left: 3px solid var(--amber); padding-left: 8px; }
.text-danger { color: var(--red); }
.text-xs { font-size: .68rem; }

/* ── Quotation Preview ─────────────────────────────────────────────── */
.qt-document {
  max-width: 850px;
  margin: 0 auto;
  background: #fff;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius);
  overflow: hidden;
}
.qt-page {
  padding: 36px 44px;
  border-bottom: 1px dashed var(--gray-300);
}
/* Start every page after the first on a fresh sheet using break-BEFORE.
   break-after would leave a forced break trailing the LAST page and emit a
   blank end sheet. `+ .qt-page` also survives the print-footer <div> being
   the last child of .qt-document, which made the old :last-of-type
   cancel-rule silently dead and let the trailing blank page through. */
.qt-page + .qt-page { break-before: page; page-break-before: always; }
.qt-page:last-of-type { border-bottom: none; }

/* Per-page confidentiality footer */
.qt-page-footer {
  margin-top: 26px;
  padding-top: 8px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  font-size: 0.64rem;
  line-height: 1.45;
  color: var(--gray-500);
}
.qt-page-footer-text { flex: 1; font-style: italic; }
.qt-page-footer-meta { white-space: nowrap; font-weight: 700; color: var(--gray-600); }

/* Fixed confidentiality footer — print only, repeats on every printed page */
.qt-print-footer { display: none; }
.qt-print-footer .qt-pf-text { display: block; font-style: italic; }
.qt-print-footer .qt-pf-meta { display: block; margin-top: 2px; font-weight: 700; color: #4b5563; }

/* Header */
.qt-header { margin-bottom: 16px; }
.qt-company-name {
  font-size: 1.4rem; font-weight: 800; color: var(--navy);
  letter-spacing: 0.5px; margin-bottom: 2px;
}
.qt-company-sub { font-size: 0.72rem; color: var(--gray-500); margin-bottom: 8px; }
.qt-gold-line {
  height: 3px; background: linear-gradient(90deg, #C1A664, #DAC78E, #C1A664);
  border-radius: 2px;
}

/* Ref row */
.qt-ref-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.82rem; color: var(--gray-700); margin: 12px 0 16px;
}

/* Addressed to */
.qt-addressed { margin-bottom: 14px; }
.qt-addressed p { margin: 2px 0; font-size: 0.88rem; color: var(--gray-700); }

/* Subject */
.qt-subject {
  font-size: 0.95rem; color: var(--navy); margin-bottom: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--gray-200);
}

/* Body text */
.qt-body-text { font-size: 0.85rem; color: var(--gray-700); line-height: 1.55; margin-bottom: 8px; }
.qt-urgent { font-size: 0.78rem; color: var(--gray-500); font-style: italic; }

/* Grand total box */
.qt-grand-total-box {
  background: linear-gradient(135deg, var(--navy), #264a6e);
  color: #fff; padding: 16px 24px; border-radius: 8px;
  margin: 14px 0 18px; text-align: center;
}
.qt-grand-amount { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.5px; }
.qt-grand-words { font-size: 0.78rem; opacity: 0.85; margin-top: 4px; }

/* Tables */
.qt-table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-bottom: 16px;
}
.qt-table th {
  background: var(--navy); color: #fff; font-weight: 600; padding: 8px 10px;
  text-align: left; font-size: 0.78rem; letter-spacing: 0.3px;
}
.qt-table td { padding: 7px 10px; border-bottom: 1px solid var(--gray-200); }
.qt-table .qt-alt-row { background: var(--gray-50); }
.qt-table .qt-total-row {
  background: var(--gray-100); border-top: 2px solid var(--navy);
}
.qt-table .qt-total-row td { font-weight: 700; color: var(--navy); }

/* Buildup table */
.qt-buildup-table { max-width: 500px; }
.qt-buildup-table td { padding: 7px 14px; }
.qt-subtotal-row { background: var(--gray-50); }
.qt-subtotal-row td { font-weight: 600; color: var(--navy); border-top: 1px solid var(--gray-300); }
.qt-grand-row {
  background: var(--navy) !important;
}
.qt-grand-row td { color: #fff !important; font-weight: 700; font-size: 0.95rem; border-top: 2px solid var(--navy); padding: 10px 14px; }

/* Material table */
.qt-material-table { font-size: 0.78rem; }

/* Spec sections */
.qt-section-title {
  font-size: 1.05rem; font-weight: 700; color: var(--navy); margin-bottom: 14px;
  padding-bottom: 6px; border-bottom: 2px solid var(--navy);
}
.qt-spec-section { margin-bottom: 16px; }
.qt-spec-heading {
  font-size: 0.9rem; font-weight: 700; color: var(--navy); margin-bottom: 6px;
}
.qt-spec-text { font-size: 0.82rem; color: var(--gray-700); line-height: 1.55; margin-bottom: 6px; }
.qt-note-small { font-size: 0.75rem; color: var(--gray-500); margin-top: 12px; }

/* Technical-specification cards — mirror the PDF card layout.
   NOTE: the cards container must stay a plain block (NOT flex): Chrome's
   print engine ignores `break-inside: avoid` on flex items, which caused
   spec sections to be cut across printed pages. */
.qt-spec-cards { display: block; }
.qt-spec-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
  break-inside: avoid;
  page-break-inside: avoid;
}
.qt-spec-card-head {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  border-left: 3px solid #1B3A5C;
  border-radius: 7px 7px 0 0;
  break-after: avoid;
  page-break-after: avoid;
}
.qt-spec-card-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; color: #475569; flex-shrink: 0;
}
.qt-spec-card-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0;
  background: #e2e8f0; font-size: 0.72rem; font-weight: 700; color: #334155;
}
.qt-spec-card-title { font-weight: 600; font-size: 0.85rem; color: #1e293b; flex: 1; }
.qt-spec-card-body { padding: 8px 14px 10px; }
.qt-spec-row {
  display: flex; gap: 8px; align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px solid #f1f5f9;
  break-inside: avoid;
  page-break-inside: avoid;
}
.qt-spec-row-last { border-bottom: none; }
.qt-spec-dot {
  flex-shrink: 0; width: 4px; height: 4px; border-radius: 50%;
  background: #94a3b8; margin-top: 7px;
}
.qt-spec-row-text { font-size: 0.8rem; color: #475569; line-height: 1.5; }
.qt-spec-row-text b { font-weight: 600; color: #1e293b; }

/* Terms */
.qt-terms-section { margin-bottom: 16px; }
.qt-payment-section { margin-bottom: 16px; padding-top: 8px; border-top: 1px solid var(--gray-200); }

/* Signoff */
.qt-signoff { margin-top: 28px; }
.qt-signoff p { margin: 2px 0; font-size: 0.85rem; color: var(--gray-700); }

/* Footer */
.qt-footer {
  text-align: center; font-size: 0.7rem; color: var(--gray-500);
  padding: 12px; border-top: 1px solid var(--gray-200);
}

/* ── Print styles ──────────────────────────────────────────────────── */
@media print {
  /* margin:0 suppresses the browser's own header/footer (URL, title, date) */
  @page { margin: 0; }
  body { background: #fff !important; }
  .no-print, .sidebar, .topbar, .nav-item { display: none !important; }
  /* Release the app's scroll containers so the quotation flows naturally
     across printed pages instead of being clipped to one screen-height
     box (which also dragged the on-screen scrollbar into the printout). */
  html, body { height: auto !important; overflow: visible !important; }
  .app-shell { display: block !important; height: auto !important; overflow: visible !important; }
  .main-area { display: block !important; height: auto !important; overflow: visible !important; }
  .content { height: auto !important; overflow: visible !important; padding: 0 !important; margin: 0 !important; }
  .qt-document { box-shadow: none !important; max-width: 100%; overflow: visible !important; border-radius: 0; }
  /* page padding gives the print margin (since @page margin is 0); the extra
     bottom padding reserves space for the fixed confidentiality footer. */
  .qt-page { padding: 14mm 14mm 32mm 14mm; border-bottom: none; }
  /* inline per-section footers + the trailing document footer off in print;
     the fixed .qt-print-footer repeats per page instead (and the trailing
     footer would otherwise spill onto a blank end sheet). */
  .qt-page-footer, .qt-footer { display: none !important; }
  .qt-print-footer {
    display: block !important;
    position: fixed; left: 0; right: 0; bottom: 0;
    padding: 4mm 14mm;
    border-top: 1px solid #cbd5e1;
    background: #fff;
    font-size: 7pt; line-height: 1.4; color: #6b7280;
  }
  .qt-grand-total-box { background: var(--navy) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .qt-table th { background: var(--navy) !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .qt-grand-row { background: var(--navy) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .qt-grand-row td { color: #fff !important; }
  /* Keep each Technical-Specification card whole — never cut a section
     (e.g. "6 Hopper Doors") across a page boundary. The card must NOT be
     a flex item and must NOT clip overflow, or Chrome drops break-inside. */
  .qt-spec-cards { display: block !important; }
  .qt-spec-card {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    overflow: visible !important;
  }
  .qt-spec-card-head { break-after: avoid !important; page-break-after: avoid !important; }
  .qt-spec-row { break-inside: avoid !important; page-break-inside: avoid !important; }
  /* keep card backgrounds/borders in the printout */
  .qt-spec-card-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .qt-spec-card-num { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Help Panel (slide-out) ─────────────────────────────────────── */

.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 998;
  transition: opacity .2s;
}

.help-overlay.open { display: block; }

.help-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,.12);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transition: right .25s ease;
}

.help-panel.open { right: 0; }

.help-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--navy);
  color: #fff;
}

.help-panel-header h3 { color: #fff; }

.help-panel-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all .15s;
}

.help-panel-close:hover { background: rgba(255,255,255,.15); color: #fff; }

.help-panel-header .btn { background: rgba(255,255,255,.15); color: #fff; border: none; }
.help-panel-header .btn:hover { background: rgba(255,255,255,.25); }

.help-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.help-section { margin-bottom: 20px; }

.help-section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--navy);
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--navy);
}

.help-overview {
  font-size: .88rem;
  line-height: 1.6;
  color: var(--gray-700);
}

.help-fields-list { display: flex; flex-direction: column; gap: 10px; }

.help-field-item {
  padding: 10px 12px;
  background: var(--gray-50);
  border-radius: 8px;
  border-left: 3px solid var(--navy);
}

.help-field-name {
  font-size: .82rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 2px;
}

.help-field-desc {
  font-size: .8rem;
  color: var(--gray-600);
  line-height: 1.5;
}

.help-tips {
  font-size: .85rem;
  line-height: 1.6;
  color: var(--gray-600);
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 12px 14px;
}

/* Help button in topbar */
.help-btn {
  background: var(--navy);
  border: 1px solid var(--navy);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .82rem;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  z-index: 10;
}

.help-btn:hover { background: #1a3a6b; }
.help-btn.active { background: #1a3a6b; border-color: #2563eb; }

/* Notification bell */
.notif-bell-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.15rem; position: relative; padding: 4px 8px;
  border-radius: 6px; transition: background .15s;
}
.notif-bell-btn:hover { background: rgba(0,0,0,.06); }
.notif-badge {
  position: absolute; top: -2px; right: 0;
  background: #EF4444; color: #fff; font-size: 0.65rem; font-weight: 700;
  min-width: 16px; height: 16px; line-height: 16px;
  border-radius: 8px; text-align: center; padding: 0 4px;
}

/* Notification list page */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-card {
  display: flex; gap: 12px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; transition: box-shadow .15s, border-color .15s;
  align-items: flex-start;
}
.notif-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); border-color: var(--navy); }
.notif-card.unread { border-left: 3px solid var(--navy); background: #f8fafc; }
.notif-severity {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 5px;
}
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: 0.9rem; color: var(--navy); }
.notif-msg { font-size: 0.82rem; color: #64748b; margin-top: 2px; }
.notif-meta { display: flex; gap: 12px; margin-top: 6px; font-size: 0.75rem; color: #94a3b8; }
.notif-module-tag {
  display: inline-block; background: var(--bg); border-radius: 4px;
  padding: 1px 6px; font-size: 0.72rem; color: var(--navy); font-weight: 500;
}
.notif-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
.notif-actions button {
  background: none; border: none; cursor: pointer; font-size: 0.9rem;
  padding: 4px; border-radius: 4px; opacity: 0.5; transition: opacity .15s;
}
.notif-actions button:hover { opacity: 1; background: rgba(0,0,0,.04); }

/* ── Admin Dashboard ──────────────────────────────────────────────── */
.db-wrap { max-width: 1440px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

/* Alert banners */
.db-alert-banner {
  display: flex; align-items: center; gap: 14px; padding: 16px 22px;
  border-radius: 12px; font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.db-alert-banner:hover { opacity: .9; }
.db-alert-danger { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; }
.db-alert-ok { background: #F0FDF4; color: #166534; border: 1px solid #BBF7D0; }
.db-alert-icon { font-size: 1.2rem; }
.db-alert-arrow { margin-left: auto; font-size: 1.2rem; }

/* KPI grid */
.db-kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px;
}
.db-kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.db-kpi {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 14px;
  padding: 22px 20px 28px; display: flex; align-items: flex-start; gap: 16px;
  cursor: pointer; transition: all .2s; position: relative; overflow: hidden;
}
.db-kpi:hover { box-shadow: var(--shadow-lg); border-color: var(--blue); transform: translateY(-2px); }
.db-kpi-icon {
  width: 52px; height: 52px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0;
}
.db-kpi-body { flex: 1; min-width: 0; }
.db-kpi-val { font-size: 2.2rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.db-kpi-val-sm { font-size: 1.4rem; }
.db-kpi-label { font-size: .8rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
.db-kpi-sub {
  position: absolute; bottom: 10px; right: 16px;
  font-size: .75rem; color: var(--gray-500); font-weight: 500;
}
.db-kpi-finance { padding: 20px; }

/* Cards */
.db-card {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 14px;
  overflow: hidden;
}
.db-card-hdr {
  display: flex; align-items: center; gap: 12px; padding: 18px 22px;
  border-bottom: 1px solid var(--gray-100);
}
.db-card-hdr h3 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--navy); }
.db-card-link {
  margin-left: auto; font-size: .8rem; color: var(--blue); cursor: pointer;
  font-weight: 600; transition: color .15s;
}
.db-card-link:hover { color: var(--navy); }
.db-card-body { padding: 20px 22px; }

/* Grids */
.db-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.db-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* Pipeline — horizontal cascade */
.db-pipeline-h {
  display: flex; align-items: center; justify-content: center;
  padding: 18px 12px; gap: 0;
}
.dbp-cell {
  flex: 1; text-align: center; cursor: pointer; padding: 4px 2px;
  border-radius: 8px; transition: all .15s; min-width: 0;
}
.dbp-cell:hover { background: var(--gray-50); transform: translateY(-2px); }
.dbp-cell-active .dbp-cell-count { font-weight: 900; }
.dbp-cell-top {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin: 0 auto 4px; width: 56px; height: 34px; border-radius: 10px;
}
.dbp-cell-icon { font-size: .85rem; }
.dbp-cell-count { font-size: 1.1rem; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.2); }
.dbp-cell-name {
  font-size: .6rem; font-weight: 600; color: var(--gray-500);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.2; padding: 0 2px;
}
.dbp-chevron {
  color: var(--gray-300); font-size: .7rem; flex-shrink: 0; margin: 0 -2px;
  align-self: center; padding-bottom: 14px;
}

/* Lead funnel */
.db-funnel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.db-funnel-label { width: 90px; text-align: right; flex-shrink: 0; }
.db-funnel-track {
  flex: 1; height: 14px; background: var(--gray-100); border-radius: 7px; overflow: hidden;
}
.db-funnel-fill { height: 100%; border-radius: 7px; transition: width .4s ease; }
.db-funnel-val { width: 34px; font-size: .9rem; font-weight: 700; color: var(--navy); }

/* Module cards grid */
.db-module-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 0;
}
.db-module-card {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  border-radius: 10px; cursor: pointer; transition: all .15s;
  border: 1px solid var(--gray-100); overflow: visible;
}
.db-module-card:hover { border-color: var(--blue); background: var(--blue-light); }
.db-mod-active { background: var(--gray-50); }
.db-mod-idle { background: var(--gray-50); opacity: .6; }
.db-mod-icon { font-size: 1.5rem; flex-shrink: 0; }
.db-mod-info { min-width: 0; flex: 1; }
.db-mod-name { font-size: .82rem; font-weight: 700; color: var(--navy); }
.db-mod-val { font-size: 1.15rem; font-weight: 800; color: var(--gray-700); line-height: 1.2; }
.db-mod-label { font-size: .72rem; font-weight: 500; color: var(--gray-500); }

/* QHSE / Fleet strips */
.db-qhse-strip {
  display: flex; gap: 0; padding: 0;
}
.db-qhse-item {
  flex: 1; text-align: center; padding: 20px 14px; cursor: pointer;
  border-right: 1px solid var(--gray-100); transition: background .15s;
}
.db-qhse-item:last-child { border-right: none; }
.db-qhse-item:hover { background: var(--gray-50); }
.db-qhse-num { font-size: 1.7rem; font-weight: 800; color: var(--navy); display: block; }
.db-qhse-lbl { font-size: .74rem; color: var(--gray-500); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; margin-top: 4px; }

/* Activity list */
.db-activity-list { padding: 0; max-height: 380px; overflow-y: auto; }
.db-activity-item {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 22px;
  border-bottom: 1px solid var(--gray-50); cursor: pointer; transition: background .15s;
}
.db-activity-item:hover { background: var(--gray-50); }
.db-activity-item:last-child { border-bottom: none; }
.db-act-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
.db-act-body { flex: 1; min-width: 0; }
.db-act-title { font-size: .88rem; font-weight: 600; color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db-act-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; font-size: .76rem; color: var(--gray-500); }

/* Table wrap inside cards */
.db-table-wrap { max-height: 360px; overflow-y: auto; }
.db-table-wrap table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.db-table-wrap th { background: var(--gray-50); padding: 10px 16px; text-align: left; font-size: .74rem; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; }
.db-table-wrap td { padding: 10px 16px; border-bottom: 1px solid var(--gray-50); }
.db-table-wrap tr:hover { background: var(--gray-50); }

/* Responsive */
@media (max-width: 1024px) {
  .db-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .db-kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .db-grid-2, .db-grid-3 { grid-template-columns: 1fr; }
  .db-module-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .db-kpi-grid, .db-kpi-grid-3 { grid-template-columns: 1fr; }
  .db-module-grid { grid-template-columns: 1fr; }
  .db-qhse-strip { flex-wrap: wrap; }
  .db-qhse-item { min-width: 45%; }
}

/* ============================================================
   Planner Cockpit
   ============================================================ */
.planner-cockpit { max-width: 1440px; }

.planner-kpi-strip {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px;
}
.planner-kpi {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 12px 16px; flex: 1; min-width: 150px;
}
.planner-kpi-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.planner-kpi-value { font-size: 1.3rem; font-weight: 700; color: #111827; line-height: 1.2; }
.planner-kpi-label { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: .3px; }

.planner-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}
.planner-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.planner-card-header h4 { margin: 0; font-size: 15px; font-weight: 600; color: #111827; }
.planner-card-alert { border-left: 3px solid #f59e0b; }

.planner-matrix { font-size: 13px; }
.planner-matrix th {
  background: #f8fafc; font-size: 11px; text-transform: uppercase;
  letter-spacing: .4px; color: #6b7280; padding: 8px 10px; white-space: nowrap;
}
.planner-matrix td { padding: 10px; vertical-align: middle; }
.planner-row { cursor: pointer; transition: background .15s; }
.planner-row:hover { background: #f0f7ff; }

.planner-bottom-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}

.planner-alert-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.planner-alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: 6px; background: #fffbeb;
}
.planner-alert-red { background: #fef2f2; }
.planner-alert-amber { background: #fffbeb; }
.planner-alert-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }

@media (max-width: 1024px) {
  .planner-bottom-grid { grid-template-columns: 1fr; }
  .planner-kpi-strip { gap: 8px; }
  .planner-kpi { min-width: 130px; padding: 10px 12px; }
}
@media (max-width: 640px) {
  .planner-kpi { min-width: 100%; }
}
