/* ===========================================================================
   app.css — the CRM workspace. Structure is identical across trades;
   only --brand-* and --font-* change.
   =========================================================================== */

/* ============================ 0. Icons ==================================== */
/* Sprite icons default to a sane size; component rules below override it.
   Without this an <svg> with no width/height falls back to 300x150. */
.icon { width: 16px; height: 16px; flex: none; vertical-align: -0.18em; }

/* ============================ 1. Shell ==================================== */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}
.shell.rail-collapsed { grid-template-columns: var(--rail-w-min) minmax(0, 1fr); }

/* ============================ 2. Side rail =============================== */
.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: hidden;
  z-index: 40;
}
.rail-brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-3);
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--brand); color: var(--brand-on);
  font-family: var(--font-display); font-weight: 700; font-size: var(--t-14);
  letter-spacing: -.02em;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.14);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; }
.brand-copy strong {
  font-family: var(--font-display); font-size: var(--t-15); font-weight: 680;
  letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-copy span { font-size: var(--t-11); color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; }

.rail-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--s-3) var(--s-3) var(--s-4); }
.rail-scroll::-webkit-scrollbar { width: 8px; }
.rail-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; border: 2px solid var(--surface); }

.rail-label {
  font-size: var(--t-11); font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3); padding: var(--s-4) var(--s-2) var(--s-2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: 9px var(--s-3); border-radius: var(--r-md);
  font-size: var(--t-14); font-weight: 500; color: var(--text-2);
  text-align: left; text-decoration: none;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item .nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-count {
  font-family: var(--font-mono); font-size: var(--t-11); color: var(--text-3);
  background: var(--surface-3); padding: 1px 7px; border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item[aria-current="page"] {
  background: var(--brand-tint); color: var(--brand-fg); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--brand);
}
.nav-item[aria-current="page"] svg { opacity: 1; }
.nav-item[aria-current="page"] .nav-count { background: var(--brand); color: var(--brand-on); }

.rail-foot { border-top: 1px solid var(--line-soft); padding: var(--s-3); display: grid; gap: var(--s-2); }
.user-chip {
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2);
  border-radius: var(--r-md); width: 100%; text-align: left;
}
.user-chip:hover { background: var(--surface-3); }
.user-chip .who { min-width: 0; flex: 1; }
.user-chip strong { display: block; font-size: var(--t-13); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip span { display: block; font-size: var(--t-11); color: var(--text-3); }

/* Collapsed rail */
.rail-collapsed .rail .nav-text,
.rail-collapsed .rail .nav-count,
.rail-collapsed .rail .brand-copy,
.rail-collapsed .rail .rail-label,
.rail-collapsed .rail .user-chip .who { display: none; }
.rail-collapsed .rail .nav-item { justify-content: center; padding: 10px; }
.rail-collapsed .rail .rail-brand { justify-content: center; padding-inline: 0; }
.rail-collapsed .rail .rail-label { display: block; height: var(--s-4); padding: 0; }
.rail-collapsed .rail .user-chip { justify-content: center; }

/* ============================ 3. Top bar ================================= */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: var(--topbar-h); padding: var(--s-2) var(--s-5);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  font-size: var(--t-18); font-weight: 680; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .crumb { font-size: var(--t-12); color: var(--text-3); }
.topbar-spacer { flex: 1; }

.searchbox {
  display: flex; align-items: center; gap: var(--s-2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 0 var(--s-3); height: 36px;
  min-width: 190px; max-width: 340px; flex: 1 1 250px;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.searchbox:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.searchbox svg { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.searchbox input { border: 0; background: none; outline: 0; width: 100%; font-size: var(--t-13); }
.searchbox kbd {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-3);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px;
}

/* ============================ 4. Buttons ================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-4); border-radius: var(--r-md);
  font-size: var(--t-13); font-weight: 600; white-space: nowrap;
  border: 1px solid transparent; text-decoration: none;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand); color: var(--brand-on); box-shadow: var(--sh-1); }
.btn-primary:hover { background: var(--brand-deep); box-shadow: var(--sh-2); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-3); border-color: var(--text-3); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--t-12); }
.btn-lg { height: 44px; padding: 0 var(--s-6); font-size: var(--t-15); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--r-md); color: var(--text-2); border: 1px solid transparent;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.bordered { border-color: var(--line); background: var(--surface); }

.segmented {
  display: inline-flex; background: var(--surface-3); border-radius: var(--r-md);
  padding: 3px; gap: 2px; border: 1px solid var(--line-soft);
}
.segmented button {
  height: 28px; padding: 0 var(--s-3); border-radius: 6px;
  font-size: var(--t-12); font-weight: 600; color: var(--text-2);
  transition: all var(--fast) var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* ============================ 5. Layout blocks =========================== */
/* Every single-column grid declares its track explicitly: an implicit `auto`
   track sizes to max-content and lets wide children push the layout out. */
.page { padding: var(--s-6) var(--s-5) var(--s-16); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-5); align-content: start; }
@media (min-width: 1500px) { .page { padding-inline: var(--s-8); } }

.card {
  min-width: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { font-size: var(--t-15); font-weight: 650; letter-spacing: -.01em; }
.card-head .sub { font-size: var(--t-12); color: var(--text-3); }
.card-head .spacer { flex: 1; }
.card-body { padding: var(--s-5); }
.card-body.tight { padding: var(--s-3); }
.card-body.flush { padding: 0; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-5); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.split-main { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); }
@media (max-width: 1180px) { .split-main { grid-template-columns: minmax(0, 1fr); } }

.eyebrow {
  font-size: var(--t-11); font-weight: 650; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-3);
}

/* ============================ 6. Stat tiles ============================== */
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--s-4) var(--s-5) var(--s-5);
  display: grid; gap: var(--s-2); box-shadow: var(--sh-1);
  transition: box-shadow var(--mid) var(--ease), transform var(--mid) var(--ease);
}
.stat::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--tone, var(--brand)); opacity: .9;
}
.stat:hover { box-shadow: var(--sh-2); transform: translateY(-1px); }
.stat-top { display: flex; align-items: center; gap: var(--s-2); }
.stat-ico {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--tone-tint, var(--brand-tint)); color: var(--tone, var(--brand));
}
.stat-ico svg { width: 15px; height: 15px; }
.stat-label { font-size: var(--t-12); font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.stat-value {
  font-family: var(--font-display); font-size: var(--t-32); font-weight: 680;
  letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums;
}
.stat-value small { font-size: var(--t-16); font-weight: 600; color: var(--text-3); letter-spacing: 0; }
.stat-foot { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-12); color: var(--text-3); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 650; font-variant-numeric: tabular-nums; }
.delta svg { width: 12px; height: 12px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--text-3); }

/* ============================ 7. Badges & chips ========================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-pill);
  font-size: var(--t-11); font-weight: 650; letter-spacing: .01em; white-space: nowrap;
  background: var(--idle-tint); color: var(--idle); border: 1px solid var(--idle-line);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.badge.ok   { background: var(--ok-tint);   color: var(--ok);   border-color: var(--ok-line); }
.badge.warn { background: var(--warn-tint); color: var(--warn); border-color: var(--warn-line); }
.badge.bad  { background: var(--bad-tint);  color: var(--bad);  border-color: var(--bad-line); }
.badge.info { background: var(--info-tint); color: var(--info); border-color: var(--info-line); }
.badge.brand{ background: var(--brand-tint);color: var(--brand-fg); border-color: var(--brand-line); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 var(--s-3); border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface);
  font-size: var(--t-12); font-weight: 550; color: var(--text-2);
  transition: all var(--fast) var(--ease);
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand-line); color: var(--brand-fg); font-weight: 650; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--text-3)); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }

.dot-key { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-12); color: var(--text-2); }
.dot-key i { width: 9px; height: 9px; border-radius: 3px; background: var(--dot); display: block; }

/* ============================ 8. Avatars ================================= */
.avatar {
  flex: none; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--av, var(--surface-3)); color: #fff;
  font-size: var(--t-11); font-weight: 700; letter-spacing: .02em;
  font-family: var(--font-body);
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg { width: 40px; height: 40px; font-size: var(--t-13); }
.av-stack { display: inline-flex; }
.av-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.av-stack .avatar:first-child { margin-left: 0; }

/* ============================ 9. Tables ================================== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--t-13); }
table.data th {
  position: sticky; top: 0; z-index: 2;
  text-align: left; font-size: var(--t-11); font-weight: 650;
  letter-spacing: .07em; text-transform: uppercase; color: var(--text-3);
  padding: var(--s-3) var(--s-4); background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .sort-ind { opacity: .45; margin-left: 4px; font-size: 9px; }
table.data th[aria-sort] .sort-ind { opacity: 1; color: var(--brand); }
table.data td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tbody tr { transition: background var(--fast) var(--ease); cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:focus-visible { background: var(--brand-tint); outline: none; box-shadow: inset 0 0 0 2px var(--brand); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.static { cursor: default; }
table.data .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
table.data .code { font-family: var(--font-mono); font-size: var(--t-12); color: var(--text-3); }
.cell-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cell-main strong { font-weight: 600; font-size: var(--t-13); }
.cell-main span { font-size: var(--t-11); color: var(--text-3); }
.cell-people { display: flex; align-items: center; gap: var(--s-2); }

/* ============================ 10. Lists & feeds ========================== */
.rows { display: grid; grid-template-columns: minmax(0, 1fr); }
.row-item {
  display: flex; align-items: center; gap: var(--s-3); width: 100%;
  padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line-soft);
  text-align: left; transition: background var(--fast) var(--ease);
}
.row-item:last-child { border-bottom: 0; }
.row-item:hover { background: var(--surface-2); }
.row-item .grow { flex: 1; min-width: 0; }
.row-item strong { display: block; font-size: var(--t-13); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .meta { display: block; font-size: var(--t-11); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-rule { width: 3px; align-self: stretch; border-radius: 2px; background: var(--tone, var(--line-strong)); flex: none; }

.feed { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); padding: var(--s-5); }
.feed-item { display: grid; grid-template-columns: 26px minmax(0,1fr); gap: var(--s-3); position: relative; }
.feed-item::before {
  content: ""; position: absolute; left: 13px; top: 28px; bottom: -22px;
  width: 1px; background: var(--line);
}
.feed-item:last-child::before { display: none; }
.feed-ico {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--tone-tint, var(--surface-3)); color: var(--tone, var(--text-2));
  border: 1px solid var(--line-soft); z-index: 1;
}
.feed-ico svg { width: 13px; height: 13px; }
.feed-body p { font-size: var(--t-13); }
.feed-body p b { font-weight: 650; }
.feed-body time { font-size: var(--t-11); color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ============================ 11. Progress =============================== */
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--tone, var(--brand)); transition: width var(--slow) var(--ease-out); }
.meter.thin { height: 4px; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 150px) 1fr auto; gap: var(--s-3); align-items: center; font-size: var(--t-12); }
.bar-row .bar-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-val { font-family: var(--font-mono); font-size: var(--t-12); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Sparkline / mini column chart */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.spark i {
  flex: 1; min-width: 3px; border-radius: 3px 3px 1px 1px;
  background: var(--brand-line); transition: background var(--fast) var(--ease);
  position: relative;
}
.spark i.hi { background: var(--brand); }
.spark i:hover { background: var(--brand-deep); }
.spark-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-3); margin-top: 6px; font-family: var(--font-mono); }

/* Donut */
.donut { display: grid; place-items: center; position: relative; width: 132px; height: 132px; }
.donut svg { transform: rotate(-90deg); width: 132px; height: 132px; }
.donut-mid { position: absolute; text-align: center; }
.donut-mid strong { display: block; font-family: var(--font-display); font-size: var(--t-26); letter-spacing: -.03em; line-height: 1; }
.donut-mid span { font-size: var(--t-11); color: var(--text-3); }

/* ============================ 12. Empty & loading ======================== */
.empty {
  display: grid; justify-items: center; gap: var(--s-2); text-align: center;
  padding: var(--s-12) var(--s-5); color: var(--text-3);
}
.empty svg { width: 30px; height: 30px; opacity: .4; }
.empty strong { font-size: var(--t-14); color: var(--text-2); font-family: var(--font-body); font-weight: 600; }
.empty p { font-size: var(--t-12); max-width: 42ch; }

/* ============================ 13. Toast ================================== */
.toast-host {
  position: fixed; z-index: 90; bottom: var(--s-5); left: 50%; transform: translateX(-50%);
  display: grid; gap: var(--s-2); justify-items: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--n-90); color: var(--n-05);
  padding: 10px var(--s-4); border-radius: var(--r-pill);
  font-size: var(--t-13); font-weight: 500; box-shadow: var(--sh-3);
  animation: toast-in var(--mid) var(--ease-out) both;
  max-width: min(92vw, 520px);
}
:root[data-theme="dark"] .toast { background: var(--n-15); color: var(--n-90); }
.toast svg { width: 16px; height: 16px; flex: none; color: var(--ok); }
.toast.leaving { animation: toast-out var(--fast) var(--ease) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ============================ 14. Drawer ================================= */
.drawer {
  position: fixed; inset: 0 0 0 auto; z-index: 70;
  width: min(560px, 100vw); max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--sh-pop);
  display: flex; flex-direction: column;
  transform: translateX(100%); visibility: hidden;
  transition: transform var(--slow) var(--ease-out), visibility var(--slow);
}
.drawer.open { transform: none; visibility: visible; }
.drawer-scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(20,19,16,.42);
  opacity: 0; visibility: hidden; transition: opacity var(--mid) var(--ease), visibility var(--mid);
  backdrop-filter: blur(1.5px);
}
.drawer-scrim.open { opacity: 1; visibility: visible; }
.drawer-head {
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.drawer-head::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--tone, var(--brand)); }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.drawer-foot {
  display: flex; gap: var(--s-2); padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--line); background: var(--surface-2);
}
.drawer-sec { padding: var(--s-5); border-bottom: 1px solid var(--line-soft); display: grid; gap: var(--s-3); }
.drawer-sec:last-child { border-bottom: 0; }
.drawer-sec > h4 { font-size: var(--t-11); font-weight: 650; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); font-family: var(--font-body); }
.kv { display: grid; grid-template-columns: 124px minmax(0,1fr); gap: var(--s-2) var(--s-3); font-size: var(--t-13); }
.kv dt { color: var(--text-3); font-size: var(--t-12); }
.kv dd { font-weight: 550; }
.fact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--s-3); }
.fact {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: var(--s-3);
}
.fact span { display: block; font-size: var(--t-11); color: var(--text-3); }
.fact strong { font-family: var(--font-display); font-size: var(--t-18); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.drawer-hero { margin: 0; aspect-ratio: 16/9; max-height: 220px; overflow: hidden; background: var(--surface-3); }
.drawer-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb { width: 48px; height: 27px; object-fit: cover; border-radius: 4px; flex: none; background: var(--surface-3); }

/* Supplier cards */
.supplier {
  border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4);
  display: grid; gap: 6px; background: var(--surface-2); align-content: start; min-width: 0;
}
.supplier strong { font-size: var(--t-14); }
.person .card-body { min-width: 0; }

/* Drawer tabs */
.drawer-tabs { display: flex; gap: 2px; padding: 0 var(--s-5); border-bottom: 1px solid var(--line); background: var(--surface); overflow-x: auto; flex: none; }
.drawer-tab { padding: 10px 12px; font-size: var(--t-13); font-weight: 600; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.drawer-tab:hover { color: var(--text); }
.drawer-tab[aria-selected="true"] { color: var(--text); border-color: var(--brand); }
.drawer-tab .n { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); margin-left: 5px; }
.dept .row-item .meta { white-space: normal; }
.dept .line { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.dept .line .icon { flex: none; }

/* ============================ 15. Modal ================================== */
dialog.modal {
  border: 0; padding: 0; background: transparent;
  max-width: 100vw; max-height: 100vh;
  inset: 0; margin: auto;              /* keep it centred in the top layer */
  color: var(--text);
}
dialog.modal::backdrop { background: rgba(20,19,16,.5); backdrop-filter: blur(2px); }
dialog.modal[open] .modal-card { animation: modal-in var(--mid) var(--ease-out) both; }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.modal-card {
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-pop);
  width: min(620px, 94vw); max-height: 88vh; display: flex; flex-direction: column;
  border: 1px solid var(--line);
}
.modal-card.wide { width: min(880px, 95vw); }
.modal-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-5) var(--s-5) var(--s-4); border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { font-size: var(--t-18); }
.modal-head p { font-size: var(--t-12); color: var(--text-3); margin-top: 2px; }
.modal-body { padding: var(--s-5); overflow-y: auto; display: grid; gap: var(--s-4); }
.modal-foot { display: flex; gap: var(--s-2); justify-content: flex-end; align-items: center; padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.modal-foot .msg { margin-right: auto; font-size: var(--t-12); color: var(--text-3); }

/* ============================ 16. Forms ================================== */
.field { display: grid; gap: 5px; }
.field > label, .field-label { font-size: var(--t-12); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--t-11); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 8px var(--s-3); font-size: var(--t-13); outline: 0;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: var(--s-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 15px, calc(100% - 12px) 15px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-4); }
.check { display: flex; align-items: flex-start; gap: var(--s-3); font-size: var(--t-13); cursor: pointer; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--brand); flex: none; }

.signature-pad {
  border: 1px dashed var(--line-strong); border-radius: var(--r-md);
  background: var(--surface-2); position: relative; touch-action: none;
}
.signature-pad canvas { display: block; width: 100%; height: 150px; border-radius: var(--r-md); cursor: crosshair; }
.signature-pad .sig-line { position: absolute; left: 22px; right: 22px; bottom: 36px; border-bottom: 1px solid var(--line-strong); pointer-events: none; }
.signature-pad .sig-hint { position: absolute; left: 22px; bottom: 14px; font-size: var(--t-11); color: var(--text-3); pointer-events: none; }

/* ============================ 17. Calendar =============================== */
.cal-toolbar { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.cal-toolbar .period {
  font-family: var(--font-display); font-size: var(--t-21); font-weight: 680;
  letter-spacing: -.02em; min-width: 190px;
}
.cal {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
}
.cal .dow {
  font-size: var(--t-11); font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3); padding: var(--s-2) var(--s-3); text-align: left;
  background: var(--surface-2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.cal .dow.we { color: var(--text-3); opacity: .7; }
.day {
  min-height: 132px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; background: var(--surface);
  transition: background var(--fast) var(--ease); position: relative;
}
.day.out { background: var(--surface-2); }
.day.out .daynum { color: var(--text-3); opacity: .55; }
.day.we:not(.out) { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.day.drop { background: var(--brand-tint); box-shadow: inset 0 0 0 2px var(--brand); }
.day.sel { box-shadow: inset 0 0 0 2px var(--brand-line); }
.day-top { display: flex; align-items: center; gap: 6px; }
.daynum {
  font-family: var(--font-mono); font-size: var(--t-12); font-weight: 600;
  width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%;
  color: var(--text-2); transition: all var(--fast) var(--ease);
}
.daynum:hover { background: var(--surface-3); color: var(--text); }
.daynum.today { background: var(--brand); color: var(--brand-on); }
.day-more { font-size: var(--t-11); color: var(--text-3); padding-left: 3px; font-weight: 600; }
.day-more:hover { color: var(--brand); }

.ev {
  --tone: var(--brand);
  display: flex; align-items: center; gap: 5px; width: 100%;
  padding: 4px 7px; border-radius: 5px; text-align: left;
  background: var(--tone-tint); color: var(--tone-ink);
  border: 1px solid transparent; border-left: 3px solid var(--tone);
  font-size: var(--t-11); line-height: 1.3; cursor: grab;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), filter var(--fast) var(--ease);
}
.ev:hover { box-shadow: var(--sh-1); filter: brightness(.98); transform: translateX(1px); }
.ev:active { cursor: grabbing; }
.ev.dragging { opacity: .4; }
/* Days 2..n of a multi-day job: a slim band, not a repeated title. */
.ev.cont {
  height: 7px; padding: 0; border: 0; border-radius: 3px;
  background: var(--tone); opacity: .32;
}
.ev.cont:hover { opacity: .5; transform: none; }
.ev.cont.last { border-radius: 3px 8px 8px 3px; }
.ev { min-width: 0; max-width: 100%; }
.ev strong { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.ev .ev-time { font-family: var(--font-mono); font-size: 10px; opacity: .8; flex: none; }
.ev .ev-flag { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.dragging-on .day { transition: none; }
/* Photo chips: the calendar card for a project with a picture. */
.ev.has-photo { padding: 3px 7px 3px 3px; align-items: center; }
.ev-photo { width: 40px; height: 28px; object-fit: cover; border-radius: 3px; flex: none; background: var(--surface-3); }
.ev-body { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.ev-body strong { display: block; }
.ev-body small { font-size: 10px; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.has-photo .ev-time { align-self: flex-start; }
.day { min-height: 150px; }

/* Week/lane board */
.lanes { display: grid; grid-template-columns: 132px repeat(var(--cols, 5), minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.lane-head, .lane-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: var(--s-2) var(--s-3); }
.lane-head { background: var(--surface-2); font-size: var(--t-12); font-weight: 650; position: sticky; top: 0; z-index: 2; }
.lane-head small { display: block; font-size: var(--t-11); font-weight: 500; color: var(--text-3); }
.lane-side {
  background: var(--surface-2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: var(--s-3); display: flex; align-items: flex-start; gap: var(--s-2);
}
.lane-side .who { min-width: 0; }
.lane-side strong { display: block; font-size: var(--t-13); font-weight: 650; }
.lane-side span { font-size: var(--t-11); color: var(--text-3); }
.lane-cell { background: var(--surface); min-height: 96px; display: grid; gap: 4px; align-content: start; }
.lane-cell.drop { background: var(--brand-tint); box-shadow: inset 0 0 0 2px var(--brand); }
.lane-cell.we { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }

/* Gantt-ish project bars */
.gantt { display: grid; gap: 2px; }
.gantt-row { display: grid; grid-template-columns: 200px minmax(0,1fr); gap: var(--s-3); align-items: center; }
.gantt-track { position: relative; height: 30px; background: var(--surface-2); border-radius: var(--r-sm); overflow: hidden; }
.gantt-track .gline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.gantt-bar {
  position: absolute; top: 5px; bottom: 5px; border-radius: 4px;
  background: var(--tone, var(--brand)); color: #fff;
  font-size: 10px; font-weight: 650; display: flex; align-items: center; padding: 0 6px;
  white-space: nowrap; overflow: hidden; box-shadow: var(--sh-1);
}
.gantt-bar .pct { position: absolute; inset: 0 auto 0 0; background: rgba(255,255,255,.25); }
.gantt-head { display: grid; grid-template-columns: 200px minmax(0,1fr); gap: var(--s-3); font-size: var(--t-11); color: var(--text-3); }
.gantt-scale { position: relative; height: 15px; }
.gantt-scale span { position: absolute; top: 0; font-family: var(--font-mono); transform: translateX(1px); }
.gantt-row > .cell-main { min-width: 0; }
.gantt-row > .cell-main strong { font-size: var(--t-13); font-weight: 600; }

/* ============================ 18. Kanban ================================= */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: var(--s-4); overflow-x: auto; padding-bottom: var(--s-3); }
.board-col { display: flex; flex-direction: column; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-lg); min-height: 180px; }
.board-col.drop { box-shadow: inset 0 0 0 2px var(--brand); background: var(--brand-tint); }
.board-col-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-3) var(--s-2); }
.board-col-head strong { font-size: var(--t-12); font-weight: 650; letter-spacing: .02em; flex: 1; }
.board-col-head .n { font-family: var(--font-mono); font-size: var(--t-11); color: var(--text-3); }
.board-col-head i { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); }
.board-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); padding: 0 var(--s-2) var(--s-3); align-content: start; }
.kcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-3); display: grid; gap: 6px; text-align: left; cursor: grab;
  box-shadow: var(--sh-1); transition: box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.kcard:hover { box-shadow: var(--sh-2); transform: translateY(-1px); }
.kcard.dragging { opacity: .45; }
.kcard-photo { width: 100%; height: 72px; object-fit: cover; border-radius: 6px; margin-bottom: 2px; }
.kcard strong { font-size: var(--t-13); font-weight: 600; }
.kcard .kmeta { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); font-size: var(--t-11); color: var(--text-3); }

/* ============================ 19. Photos ================================= */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--s-3); }
.photo-tile {
  position: relative; aspect-ratio: 4/3; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line); background: var(--surface-2); display: block;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile figcaption {
  position: absolute; inset: auto 0 0 0; padding: 14px 7px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  color: #fff; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-tile .rm {
  position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(20,19,16,.6); color: #fff; display: grid; place-items: center;
  opacity: 0; transition: opacity var(--fast) var(--ease);
}
.photo-tile:hover .rm { opacity: 1; }
.photo-tile .rm svg { width: 12px; height: 12px; }
.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-md);
  padding: var(--s-6); display: grid; place-items: center; gap: var(--s-2);
  text-align: center; color: var(--text-3); font-size: var(--t-12);
  transition: all var(--fast) var(--ease); cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-tint); color: var(--brand-fg); }
.dropzone svg { width: 22px; height: 22px; }

/* ============================ 20. Command palette ======================== */
.cmdk { position: fixed; inset: 0; z-index: 95; display: none; }
.cmdk.open { display: block; }
.cmdk-scrim { position: absolute; inset: 0; background: rgba(20,19,16,.44); backdrop-filter: blur(3px); }
.cmdk-panel {
  position: relative; margin: 11vh auto 0; width: min(580px, 92vw);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--sh-pop); overflow: hidden;
  animation: modal-in var(--mid) var(--ease-out) both;
}
.cmdk-input { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-soft); }
.cmdk-input svg { width: 17px; height: 17px; color: var(--text-3); }
.cmdk-input input { flex: 1; border: 0; outline: 0; background: none; font-size: var(--t-15); }
.cmdk-list { max-height: 54vh; overflow-y: auto; padding: var(--s-2); }
.cmdk-item {
  display: flex; align-items: center; gap: var(--s-3); width: 100%;
  padding: var(--s-2) var(--s-3); border-radius: var(--r-md); text-align: left; font-size: var(--t-13);
}
.cmdk-item svg { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.cmdk-item .grow { flex: 1; min-width: 0; }
.cmdk-item small { display: block; font-size: var(--t-11); color: var(--text-3); }
.cmdk-item[aria-selected="true"] { background: var(--brand-tint); color: var(--brand-fg); }
.cmdk-item[aria-selected="true"] svg { color: var(--brand); }
.cmdk-group { font-size: var(--t-11); font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); padding: var(--s-3) var(--s-3) var(--s-1); }

/* ============================ 21. Demo banner ============================ */
.demo-strip {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: 7px var(--s-5); font-size: var(--t-12);
  background: var(--accent-tint); color: var(--warn);
  border-bottom: 1px solid var(--warn-line);
}
.demo-strip svg { width: 14px; height: 14px; flex: none; }
.demo-strip b { font-weight: 650; }
.demo-strip a, .demo-strip button { color: inherit; text-decoration: underline; font-weight: 600; text-underline-offset: 2px; }
.demo-strip .spacer { flex: 1; }

/* ============================ 22. Responsive ============================= */
.rail-toggle-mobile { display: none; }
.show-sm { display: none; }
/* Base rules for things the media queries below switch on. They must come
   first: same specificity, so source order decides. */
.cal-mobile { display: none; gap: var(--s-2); padding: var(--s-4); }
.rail-scrim { display: none; position: fixed; inset: 0; z-index: 38; background: rgba(20,19,16,.42); }
@media (max-width: 1000px) {
  .shell, .shell.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 84vw);
    transform: translateX(-102%); transition: transform var(--mid) var(--ease-out);
  }
  .rail.open { transform: none; box-shadow: var(--sh-pop); }
  .shell.rail-open .rail-scrim { display: block; }
  .rail-toggle-mobile { display: inline-grid; }
  .rail-collapsed .rail .nav-text, .rail-collapsed .rail .nav-count,
  .rail-collapsed .rail .brand-copy, .rail-collapsed .rail .rail-label,
  .rail-collapsed .rail .user-chip .who { display: revert; }
  .rail-collapsed .rail .nav-item { justify-content: flex-start; padding: 9px var(--s-3); }
  .rail-collapsed .rail .rail-brand { justify-content: flex-start; padding-inline: var(--s-4); }
  .page { padding: var(--s-4) var(--s-4) var(--s-12); }
  .topbar { padding-inline: var(--s-4); }
  .split-main { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 760px) {
  .cal { display: none; }
  .cal-mobile { display: grid; }
  .searchbox { min-width: 0; flex: 1 1 120px; }
  .searchbox kbd { display: none; }
  .show-sm { display: inline-grid; }
  .topbar h1 { font-size: var(--t-15); }
  .stat-value { font-size: var(--t-26); }
  .drawer { width: 100vw; }
  .hide-sm { display: none !important; }
  .gantt-row, .gantt-head { grid-template-columns: 116px minmax(0,1fr); }
  .gantt-scale span:nth-child(even) { display: none; }   /* every other week label at phone width */
  .lanes { grid-template-columns: 96px repeat(var(--cols, 5), minmax(78px, 1fr)); overflow-x: auto; }
}
.cal-mobile h3 { font-size: var(--t-14); display: flex; justify-content: space-between; align-items: baseline; }
.cal-mobile h3 span { font-size: var(--t-11); color: var(--text-3); font-family: var(--font-body); font-weight: 500; }
.cal-strip { display: flex; gap: 5px; overflow-x: auto; padding-bottom: var(--s-2); }
.cal-strip button {
  flex: none; width: 46px; padding: 6px 0; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); text-align: center;
}
.cal-strip button span { display: block; font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.cal-strip button strong { display: block; font-family: var(--font-mono); font-size: var(--t-14); }
.cal-strip button i { display: block; height: 3px; width: 16px; margin: 3px auto 0; border-radius: 2px; background: var(--dot, transparent); }
.cal-strip button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-on); }
.cal-strip button[aria-pressed="true"] span { color: rgba(255,255,255,.8); }

/* ============================ 23. Utilities ============================== */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-3); }
.stack-sm { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
.rowflex { display: flex; align-items: center; gap: var(--s-3); }
.rowflex.wrap { flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.muted { color: var(--text-3); }
.small { font-size: var(--t-12); }
.tiny { font-size: var(--t-11); }
.strong { font-weight: 650; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fade-in { animation: fade-in var(--mid) var(--ease-out) both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }
.stagger > * { animation: fade-in var(--mid) var(--ease-out) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 45ms; }
.stagger > *:nth-child(3) { animation-delay: 90ms; }
.stagger > *:nth-child(4) { animation-delay: 135ms; }
.stagger > *:nth-child(5) { animation-delay: 180ms; }
.stagger > *:nth-child(6) { animation-delay: 225ms; }
