/* US Partnerly Internal: design system and layout.
   No inline styles anywhere (strict CSP); every visual state is a class here. */

/* ------------------------------------------------------------------ font */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/InterVariable.2bf3d951bf9d.woff2") format("woff2");
}

/* ------------------------------------------------------------------ tokens */
:root {
  /* neutrals */
  --gray-0: #ffffff;
  --gray-25: #fcfcfd;
  --gray-50: #f8f9fb;
  --gray-75: #f4f5f8;
  --gray-100: #eff1f5;
  --gray-150: #e8ebf0;
  --gray-200: #e2e5eb;
  --gray-300: #d0d5dd;
  --gray-400: #98a2b3;
  --gray-500: #667085;
  --gray-600: #475467;
  --gray-700: #344054;
  --gray-800: #1d2939;
  --gray-900: #101828;

  /* brand */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-soft-2: #e0e7ff;
  --accent-ink: #3730a3;
  --ring: rgba(79, 70, 229, .22);

  /* semantic: fg on soft bg, plus a solid for bars/dots */
  --success-bg: #ecfdf3; --success-fg: #067647; --success-line: #abefc6; --success-solid: #17b26a;
  --warning-bg: #fffaeb; --warning-fg: #93370d; --warning-line: #fedf89; --warning-solid: #f79009;
  --danger-bg:  #fef3f2; --danger-fg:  #b42318; --danger-line:  #fecdca; --danger-solid:  #f04438;
  --info-bg:    #eff8ff; --info-fg:    #175cd3; --info-line:    #b2ddff; --info-solid:    #2e90fa;
  --neutral-bg: #f2f4f7; --neutral-fg: #475467; --neutral-line: #e4e7ec; --neutral-solid: #98a2b3;
  --violet-bg:  #f4f3ff; --violet-fg:  #5925dc; --violet-line:  #d9d6fe; --violet-solid:  #7a5af8;

  /* surfaces & text */
  --canvas: var(--gray-75);
  --surface: var(--gray-0);
  --surface-sunken: var(--gray-50);
  --line: var(--gray-200);
  --line-soft: var(--gray-150);
  --line-strong: var(--gray-300);
  --text: var(--gray-900);
  --text-2: var(--gray-700);
  --muted: var(--gray-500);

  /* spacing */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* radius & shadow */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-card: 10px;
  --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .05);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 240px;
  --sticky-top: 0px;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; line-height: 1.35; }
p { margin: 0 0 var(--space-3); }
strong, .strong { font-weight: 600; }
small, .small { font-size: 12.5px; font-weight: 400; }
code {
  font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: var(--radius-xs);
  background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--line-soft); white-space: nowrap;
}
img { max-width: 100%; }
svg { flex-shrink: 0; }
.icon { width: 16px; height: 16px; vertical-align: -3px; }
::selection { background: var(--accent-soft-2); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }

.muted { color: var(--muted); }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: var(--mono); font-size: .95em; }
.num, time, td.num { font-variant-numeric: tabular-nums; }
.wide { width: 100%; }
.inline { display: inline; }
.break { word-break: break-word; }
.truncate { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.big { font-size: 20px; }
.danger { color: var(--danger-fg); }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-3); top: -48px; z-index: 100; padding: 8px 14px; border-radius: var(--radius);
  background: var(--gray-900); color: #fff; font-weight: 600;
}
.skip-link:focus { top: var(--space-3); color: #fff; text-decoration: none; }

/* ------------------------------------------------------------------ app shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.nav-toggle-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--gray-25); border-right: 1px solid var(--line); z-index: 30;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 14px 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); border-radius: var(--radius-sm); }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark { display: inline-flex; width: 28px; height: 28px; }
.brand-mark svg { width: 28px; height: 28px; }
.brand-word { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.brand-tag {
  font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--accent-ink); background: var(--accent-soft);
  border: 1px solid var(--accent-soft-2); padding: 1px 7px; border-radius: var(--radius-pill);
}
.nav-toggle-btn { display: none; }

.sidebar-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 4px 10px 12px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-label {
  margin: 18px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--gray-500);
}
.side-nav a, .side-link {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--gray-700); font: inherit; font-weight: 500; font-size: 13.5px; background: none; border: 0;
  cursor: pointer; text-align: left; transition: background-color .12s var(--ease), color .12s var(--ease);
}
.side-nav a .icon, .side-link .icon { color: var(--gray-500); width: 17px; height: 17px; transition: color .12s var(--ease); }
.side-nav a:hover, .side-link:hover { background: var(--gray-100); color: var(--text); text-decoration: none; }
.side-nav a:hover .icon, .side-link:hover .icon { color: var(--gray-700); }
.side-nav a.active, .side-link.active {
  background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-xs), inset 0 0 0 1px var(--line);
}
.side-nav a.active .icon, .side-link.active .icon { color: var(--accent); }
.side-nav .badge { margin-left: auto; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--danger-fg);
  color: #fff; font-size: 11.5px; font-weight: 600; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.side-foot form { margin: 0; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.me-role { flex-shrink: 0; font-size: 11px; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft); border-radius: var(--radius-pill); padding: 0 6px; line-height: 18px; }
.me-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { min-width: 0; padding: 28px 32px 56px; width: 100%; max-width: 1320px; }
.content.wide-page { max-width: none; }

/* ------------------------------------------------------------------ page header */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.page-header-text { min-width: 0; flex: 1 1 320px; }
.page-title { font-size: 22px; font-weight: 650; letter-spacing: -.02em; overflow-wrap: anywhere; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; max-width: 72ch; }
.page-sub .icon { margin-right: 4px; }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-bottom: var(--space-3); font-size: 13px; color: var(--muted); }
.breadcrumbs a { color: var(--muted); font-weight: 500; }
.breadcrumbs a:hover { color: var(--text); }
.breadcrumbs .icon { width: 14px; height: 14px; color: var(--gray-400); }
.breadcrumbs [aria-current] { color: var(--text-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm); padding: var(--space-5); margin: 0 0 var(--space-4); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin: -2px 0 var(--space-4); }
.card-head h2 { display: inline-flex; align-items: center; gap: 8px; }
.card-head h2 .icon { color: var(--gray-400); }
.card-head-note { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.count {
  display: inline-block; padding: 0 7px; border-radius: var(--radius-pill); background: var(--gray-100); color: var(--gray-600);
  font-size: 12px; font-weight: 500; line-height: 20px; font-variant-numeric: tabular-nums;
}
.split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.split > .card { margin: 0; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2);
  font: inherit; font-size: 13.5px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer;
  box-shadow: var(--shadow-xs); transition: background-color .12s var(--ease), border-color .12s var(--ease), color .12s var(--ease);
}
.btn .icon { width: 15px; height: 15px; color: currentColor; }
.btn:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--text); text-decoration: none; }
.btn:active { background: var(--gray-100); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.danger { background: var(--danger-fg); border-color: var(--danger-fg); color: #fff; }
.btn.danger:hover { background: #912018; border-color: #912018; color: #fff; }
.btn.danger-ghost { color: var(--danger-fg); }
.btn.danger-ghost:hover { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger-fg); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--gray-600); }
.btn.ghost:hover { background: var(--gray-100); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.xs { height: 26px; padding: 0 8px; font-size: 12.5px; border-radius: var(--radius-sm); gap: 4px; }
.btn.xs .icon { width: 13px; height: 13px; }
.btn.wide { width: 100%; height: 38px; margin-top: var(--space-2); }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger-fg); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--gray-400); cursor: pointer;
}
.icon-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger-fg); }

/* ------------------------------------------------------------------ chips & tags */
.chips { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip, .tag {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 0 8px; height: 22px;
  border-radius: var(--radius-sm); border: 1px solid var(--neutral-line); background: var(--neutral-bg); color: var(--neutral-fg);
  font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap; vertical-align: middle;
}
.chip .icon { width: 12px; height: 12px; }
.chip.xs { height: 20px; padding: 0 6px; font-size: 11.5px; }
.chip.dot::before, .tag::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--neutral-solid)); flex-shrink: 0;
}
.chip.success, .chip.status-active, .chip.store-live, .tag.s-approved { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-line); --dot: var(--success-solid); }
.chip.warning, .chip.status-paused, .chip.store-test_mode, .tag.s-applied { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); --dot: var(--warning-solid); }
.chip.danger, .tag.s-rejected { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-line); --dot: var(--danger-solid); }
.chip.info, .chip.status-onboarding, .chip.store-building { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); --dot: var(--info-solid); }
.chip.accent, .chip.status-lead { background: var(--violet-bg); color: var(--violet-fg); border-color: var(--violet-line); --dot: var(--violet-solid); }
.chip.neutral, .chip.status-closed, .chip.store-paused, .chip.store-closed, .tag.s-closed, .tag.s-not_started, .tag.s-none { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-line); --dot: var(--neutral-solid); }
.tag.s-closed { --dot: var(--gray-600); }
.chip.stage { background: var(--surface); color: var(--text-2); border-color: var(--line); }
.chip.stage::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--stage, var(--neutral-solid)); }
.tags { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 100%; }
.tags .tag { white-space: normal; height: auto; min-height: 22px; line-height: 1.35; padding-top: 1px; padding-bottom: 1px; }

/* stage accent colours (pipeline columns, stage chips) */
.stage-llc_applied { --stage: #8098f9; }
.stage-llc_created { --stage: #2e90fa; }
.stage-flex_applied { --stage: #f79009; }
.stage-flex_approved { --stage: #7a5af8; }
.stage-processing_approved { --stage: #15b79e; }
.stage-active { --stage: #17b26a; }
.stage-none { --stage: #98a2b3; }

/* ------------------------------------------------------------------ avatars */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 32px; height: 32px;
  border-radius: var(--radius); font-size: 12px; font-weight: 600; letter-spacing: .02em;
  background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .06);
}
.avatar.xs { width: 20px; height: 20px; font-size: 9.5px; border-radius: 5px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; border-radius: 50%; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; border-radius: 12px; }
.tone-0 { background: #eef2ff; color: #3730a3; }
.tone-1 { background: #ecfdf3; color: #05603a; }
.tone-2 { background: #fff6ed; color: #93370d; }
.tone-3 { background: #eff8ff; color: #1849a9; }
.tone-4 { background: #fdf2fa; color: #9e165f; }
.tone-5 { background: #f0fdf9; color: #125d56; }

.entity { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); }
.entity:hover { text-decoration: none; color: var(--text); }
a.entity:hover .entity-name { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.entity-text { display: flex; flex-direction: column; min-width: 0; }
.entity-name { font-weight: 600; overflow-wrap: anywhere; }
.entity-sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.strong-link { font-weight: 500; }

/* ------------------------------------------------------------------ meters */
meter.meter {
  -webkit-appearance: none; -moz-appearance: none; appearance: none; display: inline-block; width: 64px; height: 6px;
  border: 0; border-radius: var(--radius-pill); background: var(--gray-150); overflow: hidden; vertical-align: middle;
}
meter.meter::-webkit-meter-inner-element { display: block; }
meter.meter::-webkit-meter-bar { height: 6px; border: 0; border-radius: var(--radius-pill); background: var(--gray-150); }
meter.meter::-webkit-meter-optimum-value,
meter.meter::-webkit-meter-suboptimum-value,
meter.meter::-webkit-meter-even-less-good-value { border-radius: var(--radius-pill); background: var(--accent); transition: none; }
meter.meter.complete::-webkit-meter-optimum-value { background: var(--success-solid); }
meter.meter.low::-webkit-meter-optimum-value { background: var(--warning-solid); }
meter.meter::-moz-meter-bar { border-radius: var(--radius-pill); background: var(--accent); }
meter.meter.complete::-moz-meter-bar { background: var(--success-solid); }
meter.meter.low::-moz-meter-bar { background: var(--warning-solid); }
meter.meter.block { display: block; width: 100%; height: 8px; margin: 0 0 var(--space-4); }
meter.meter.block::-webkit-meter-bar { height: 8px; }
.docs-meter { display: inline-flex; align-items: center; gap: 8px; }
.docs-meter strong { font-size: 13px; }

/* ------------------------------------------------------------------ stats */
.stats { list-style: none; margin: 0 0 var(--space-5); padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--space-3); }
.stat {
  display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 14px; border-radius: var(--radius-card);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); color: var(--text);
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.stat:hover { text-decoration: none; color: var(--text); border-color: var(--gray-300); box-shadow: var(--shadow-md); }
.stat-label { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat.stat-danger .stat-value { color: var(--danger-fg); }
.stat.stat-warning .stat-value { color: var(--warning-fg); }
.stat.stat-danger { box-shadow: var(--shadow-sm), inset 3px 0 0 var(--danger-solid); }
.stat.stat-warning { box-shadow: var(--shadow-sm), inset 3px 0 0 var(--warning-solid); }

/* ------------------------------------------------------------------ forms */
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); max-width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-xs);
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
input:where(:not([type=checkbox]):not([type=radio]):not([type=file])), select { height: 36px; padding: 0 10px; }
textarea { width: 100%; padding: 8px 10px; line-height: 1.5; resize: vertical; min-height: 64px; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 16px;
}
input::placeholder, textarea::placeholder { color: var(--gray-500); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--gray-400); }
input:focus, select:focus, textarea:focus { outline: 2px solid transparent; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
input[readonly] { background: var(--surface-sunken); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); box-shadow: none; cursor: pointer; }
input[type=checkbox]:focus-visible, input[type=radio]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=file] { padding: 4px; height: auto; font-size: 13px; color: var(--gray-600); width: 100%; }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 500; font-size: 13px; margin-right: 10px; padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--gray-50); color: var(--text-2); cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--gray-100); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); min-width: 0; }
.field > label, .field > legend { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea { width: 100%; }
.field .req { color: var(--danger-fg); }
.field.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 10px; align-self: end; min-height: 36px; margin-bottom: var(--space-4); }
.field.check > label { font-weight: 500; cursor: pointer; }
.field .help { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.field .help ul { margin: 4px 0 0; padding-left: 18px; }
.field .error { color: var(--danger-fg); font-size: 12.5px; font-weight: 500; display: flex; gap: 4px; }
.field .error::before { content: "!"; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 15px; height: 15px; margin-top: 1px; border-radius: 50%; background: var(--danger-fg); color: #fff; font-size: 10px; font-weight: 700; }
.has-error > label { color: var(--danger-fg); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger-solid); }
.has-error input:focus, .has-error select:focus, .has-error textarea:focus { box-shadow: 0 0 0 3px rgba(240, 68, 56, .2); }
fieldset { margin: 0; min-width: 0; }
fieldset.checks { border: 0; padding: 0; }
fieldset.checks > legend { padding: 0; margin-bottom: 6px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13.5px; cursor: pointer; }

.form-stack { display: flex; flex-direction: column; gap: 0; }
.form-narrow { max-width: 760px; }
.form-card { padding: var(--space-5) var(--space-5) var(--space-1); }
.card-legend { float: left; width: 100%; padding: 0 0 var(--space-4); margin: 0 0 var(--space-4); border-bottom: 1px solid var(--line-soft); font-size: 15px; font-weight: 600; }
.card-legend + * { clear: both; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-5); }
.form-grid.one { grid-template-columns: minmax(0, 1fr); max-width: 420px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions {
  display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-4) var(--space-5);
  margin-top: var(--space-1); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-sm);
}
.form-actions.sticky-actions { position: sticky; bottom: var(--space-4); z-index: 5; box-shadow: var(--shadow-md); }
.form-actions.plain { padding: 0; margin-top: var(--space-5); background: none; border: 0; box-shadow: none; }

/* ------------------------------------------------------------------ filter bar */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-4); padding: var(--space-3);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-sm);
}
.filter-bar select { flex: 0 1 auto; min-width: 0; height: 34px; font-size: 13.5px; }
.search-field { position: relative; flex: 1 1 280px; min-width: 200px; display: flex; }
.search-field .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.search-field input { width: 100%; height: 34px; padding-left: 34px; }
.filter-actions { display: flex; gap: var(--space-2); margin-left: auto; }

/* ------------------------------------------------------------------ tables */
.table-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-sm);
  overflow-x: auto; margin-bottom: var(--space-4);
}
.table-card.sticky-head { overflow: clip; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th, .data-table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.data-table th {
  font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface-sunken); white-space: nowrap;
  padding-top: 9px; padding-bottom: 9px; border-bottom-color: var(--line);
}
.data-table th.right, .data-table td.right { text-align: right; }
.sticky-head .data-table th { position: sticky; top: var(--sticky-top); z-index: 2; }
.data-table th:first-child { border-top-left-radius: var(--radius-card); }
.data-table th:last-child { border-top-right-radius: var(--radius-card); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background-color .1s var(--ease); }
.data-table tbody tr:hover td { background: var(--gray-50); }
.data-table tr.warn td { background: var(--warning-bg); }
.data-table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger-solid); }
.data-table tr.done td { color: var(--muted); }
.data-table tr.done .task-title { text-decoration: line-through; text-decoration-color: var(--gray-300); }
.data-table td.empty, .empty-row td { text-align: center; padding: 40px 16px; }
.empty-row td { background: var(--surface) !important; }
.empty-row .empty-title, .empty-row .muted { display: block; }
.cell-actions { white-space: nowrap; }
.cell-actions > * + * { margin-left: 4px; }
.cell-note { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.cell-note .icon { width: 13px; height: 13px; }
.mini { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--muted); }
.mini > span { white-space: nowrap; }
.mini .yes { color: var(--success-fg); } .mini .no { color: var(--danger-fg); }

.client-table th, .client-table td { padding-left: 12px; padding-right: 12px; }
.client-table th:first-child, .client-table td:first-child { padding-left: 16px; }
.client-table th:last-child, .client-table td:last-child { padding-right: 16px; }
.client-table td { padding-top: 12px; padding-bottom: 12px; }
.client-table td.right { font-size: 13px; }
.client-table .cell-tracking { min-width: 150px; max-width: 230px; }
.client-table .cell-client { min-width: 180px; }
.client-table .cell-client .chip { margin: 6px 0 0 42px; }
.client-table .cell-status .chips { gap: 4px; }
.client-table .cell-docs { min-width: 130px; max-width: 170px; }
.client-table .cell-stores { min-width: 96px; max-width: 150px; }
.client-table .cell-stores .truncate { max-width: 140px; }
.client-table .col-contact { max-width: 220px; }

.pager { display: flex; gap: var(--space-3); align-items: center; justify-content: center; margin: var(--space-5) 0; }

/* ------------------------------------------------------------------ segmented control */
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; margin-bottom: var(--space-4); border-radius: var(--radius);
  background: var(--gray-150); border: 1px solid var(--line);
}
.segmented a { padding: 5px 12px; border-radius: var(--radius-sm); color: var(--gray-600); font-weight: 500; font-size: 13px; }
.segmented a:hover { color: var(--text); text-decoration: none; background: rgba(255, 255, 255, .6); }
.segmented a.current { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* due-date chips */
.due {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid var(--neutral-line); background: var(--neutral-bg); color: var(--neutral-fg);
}
.due .icon { width: 12px; height: 12px; }
.due-overdue { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-line); }
.due-today { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); }
.due-done { background: transparent; color: var(--muted); }

/* ------------------------------------------------------------------ messages & notices */
.messages { list-style: none; padding: 0; margin: 0 0 var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.msg {
  display: flex; align-items: flex-start; gap: 10px; margin: 0 0 var(--space-3); padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--info-line); background: var(--info-bg); color: var(--info-fg); font-size: 13.5px; font-weight: 500;
}
.messages .msg { margin: 0; }
.msg .icon { margin-top: 2px; }
.msg.success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-line); }
.msg.error { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-line); }
.msg.warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); }
.notice {
  display: flex; align-items: flex-start; gap: 8px; padding: 9px 12px; margin: 0 0 var(--space-3); border-radius: var(--radius);
  background: var(--warning-bg); color: var(--warning-fg); border: 1px solid var(--warning-line); font-size: 13px;
}
.notice .icon { margin-top: 1px; }
.notice a { color: inherit; text-decoration: underline; font-weight: 600; }
.notice.subtle { background: var(--surface); color: var(--muted); border-color: var(--line); }

/* ------------------------------------------------------------------ empty states */
.empty-state { text-align: center; padding: var(--space-12) var(--space-6); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty-state .btn { margin-top: var(--space-3); }
.empty-state p { margin: 0; }
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin: 0 auto var(--space-3);
  border-radius: var(--radius); background: var(--gray-100); color: var(--gray-500); border: 1px solid var(--line);
}
.empty-icon .icon { width: 20px; height: 20px; }
.empty-title { font-weight: 600; color: var(--text); font-size: 14px; }
.empty-inline { color: var(--muted); font-size: 13px; padding: var(--space-3); margin: 0; text-align: center; background: var(--surface-sunken); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ------------------------------------------------------------------ client detail */
.record-head { padding: var(--space-5) var(--space-6); }
.record-head-main { display: flex; align-items: flex-start; gap: var(--space-4); flex-wrap: wrap; }
.record-head-text { flex: 1 1 280px; min-width: 0; }
.record-head-text .page-sub { margin: 2px 0 10px; }
.quick-stats {
  display: grid; grid-template-columns: repeat(5, minmax(0, auto)); justify-content: start; gap: var(--space-3) var(--space-8);
  margin: var(--space-5) 0 0; padding: var(--space-4) 0 0; border-top: 1px solid var(--line-soft);
}
.quick-stats dt { font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.quick-stats dd { margin: 0; font-weight: 600; font-size: 15px; display: flex; align-items: center; min-height: 22px; }
.quick-stats .tag { font-weight: 500; }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-4); align-items: start; }
.detail-main, .detail-rail { min-width: 0; }

dl { margin: 0; }
dd { margin: 0; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: minmax(130px, 34%) minmax(0, 1fr); column-gap: 0; font-size: 13.5px; }
.kv > dt { padding-right: var(--space-4) !important; }
.kv > dt, .kv > dd { padding: 9px 0; border-top: 1px solid var(--line-soft); }
.kv > dt:first-child, .kv > dt:first-child + dd { border-top: 0; padding-top: 0; }
.kv > dt { color: var(--muted); }
.kv > dd { color: var(--text); }
.kv.compact { font-size: 12.5px; }
.kv.compact > dt, .kv.compact > dd { padding: 6px 0; }
.record-meta { padding: var(--space-4) var(--space-5); background: var(--surface-sunken); box-shadow: none; }

.rows { list-style: none; margin: 0; padding: 0; }
.row-item { padding: var(--space-3) 0; border-top: 1px solid var(--line-soft); }
.row-item:first-child { border-top: 0; padding-top: 0; }
.row-item:last-child { padding-bottom: 0; }
.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.row-title { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.row-actions { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.mini-kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px var(--space-4); margin-top: 10px; font-size: 13px; }
.mini-kv dt { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.mini-kv .span-2 { grid-column: span 2; }
.mini-kv .span-all { grid-column: 1 / -1; }

.docsum { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.docsum li {
  padding: 2px 9px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 500;
  background: var(--danger-bg); color: var(--danger-fg); border: 1px solid var(--danger-line);
}
.docsum li.ok { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-line); }
.docsum li small { opacity: .85; font-size: 12px; }
.upload-form { padding: var(--space-4); margin-bottom: var(--space-4); border-radius: var(--radius); background: var(--surface-sunken); border: 1px solid var(--line-soft); }
.upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
.upload-grid .field { margin: 0; }
.upload-actions { display: flex; justify-content: flex-end; margin-top: var(--space-3); }
.doc-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: start; gap: 8px var(--space-3); }
.doc-row .row-actions { grid-column: 2; }
.doc-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.doc-main .cell-note { display: block; overflow-wrap: anywhere; }
.file-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--accent); flex-shrink: 0;
}

.note-form textarea { margin-bottom: var(--space-2); }
.note-form-actions { display: flex; justify-content: flex-end; }
.notes { list-style: none; padding: 0; margin: var(--space-4) 0 0; }
.notes > li { display: flex; gap: var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--line-soft); }
.notes > li.empty-inline { display: block; border: 1px dashed var(--line); padding: var(--space-3); }
.note-body { flex: 1; min-width: 0; font-size: 13.5px; }
.note-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; font-size: 13px; }
.note-meta .muted { font-size: 12px; }
.note-delete { margin-left: auto; }

.task-form { display: flex; flex-direction: column; gap: var(--space-2); padding-bottom: var(--space-4); margin-bottom: var(--space-2); border-bottom: 1px solid var(--line-soft); }
.task-form input:not([type=hidden]), .task-form select { width: 100%; height: 34px; font-size: 13.5px; }
.task-form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2); }
.task-form .btn { align-self: flex-start; }
.task-list { list-style: none; margin: 0; padding: 0; }
.task-list > li { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.task-list > li:first-child { border-top: 0; }
.task-list > li.empty-inline { display: block; border: 1px dashed var(--line); padding: var(--space-3); margin-top: var(--space-2); }
.task-list > li.done .task-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--gray-300); }
.task-check { margin: 0; }
.check-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin-top: 1px; border-radius: 6px;
  border: 1.5px solid var(--gray-300); background: var(--surface); color: transparent; cursor: pointer; padding: 0;
}
.check-btn .icon { width: 13px; height: 13px; stroke-width: 2.6; }
.check-btn:hover { border-color: var(--accent); color: var(--accent); }
.check-btn.checked { background: var(--accent); border-color: var(--accent); color: #fff; }
.task-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; }
.task-del { margin: -3px -4px 0 0; }

.checklist { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: flex; flex-direction: column; gap: 2px; }
.checklist li {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 6px 8px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--danger-fg);
}
.checklist li.ok { color: var(--success-fg); }
.checklist li:nth-child(odd) { background: var(--surface-sunken); }
.checklist li small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.checklist li.missing small { color: var(--danger-fg); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; flex-direction: column; padding: 0 0 var(--space-3) 20px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 14px; bottom: -2px; width: 1px; background: var(--line); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::before { display: none; }
.timeline-dot { position: absolute; left: 0; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline-text { font-weight: 500; }
.timeline-meta { font-size: 12px; color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; }

/* ------------------------------------------------------------------ pipeline */
.pipeline {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(244px, 1fr); gap: var(--space-3); align-items: start;
  overflow-x: auto; padding-bottom: var(--space-3); scroll-snap-type: x proximity; overscroll-behavior-x: contain;
}
.pipeline:focus-visible { outline-offset: 4px; }
.stage-col {
  scroll-snap-align: start; min-width: 0; padding: 0 var(--space-2) var(--space-2); border-radius: var(--radius-card);
  background: var(--gray-100); border: 1px solid var(--line); border-top: 3px solid var(--stage, var(--neutral-solid));
}
.stage-col-head { display: flex; align-items: center; gap: 8px; padding: 10px 4px; font-size: 13px; font-weight: 600; }
.stage-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--stage, var(--neutral-solid)); }
.stage-name { flex: 1; }
.count-pill {
  display: inline-block; min-width: 24px; padding: 0 7px; border-radius: var(--radius-pill); background: var(--surface);
  border: 1px solid var(--line); color: var(--gray-600); font-size: 12px; font-weight: 600; line-height: 20px; text-align: center;
}
.stage-cards { display: flex; flex-direction: column; gap: var(--space-2); }
.stage-card {
  display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-xs); transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
.stage-card:hover { border-color: var(--gray-300); box-shadow: var(--shadow-md); }
.stage-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.stage-card .entity { gap: 8px; align-items: flex-start; }
.stage-card .entity .avatar { margin-top: 1px; }
.stage-card-meta { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--gray-600); }
.stage-card-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.stage-card-meta .icon { width: 13px; height: 13px; color: var(--gray-400); }
.docs-meter.small { font-size: 12.5px; }
.docs-meter.small meter.meter { flex: 1; width: auto; max-width: 120px; }
.docs-meter .yes { color: var(--success-fg); font-weight: 500; }
.docs-meter .no { color: var(--gray-600); }
.stage-card .tags { gap: 3px; }
.stage-empty { margin: 0; padding: var(--space-4) var(--space-2); text-align: center; font-size: 12.5px; color: var(--gray-600); border: 1px dashed var(--gray-300); border-radius: var(--radius); }

/* ------------------------------------------------------------------ auth, dialogs, errors */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-6) var(--space-4); background: var(--canvas); }
.auth-inner { width: 100%; max-width: 400px; }
.auth-card { width: 100%; max-width: 400px; margin: 0 auto; padding: var(--space-8) var(--space-8) var(--space-6); box-shadow: var(--shadow-md); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: var(--space-6); }
.auth-title { font-size: 20px; font-weight: 650; margin-bottom: 4px; letter-spacing: -.02em; }
.auth-card > .muted { margin-bottom: var(--space-5); }
.auth-foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: var(--space-4); }
.center-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.error-card { text-align: left; }
.error-code { font-size: 13px; font-weight: 600; color: var(--accent); margin: 0 0 4px; letter-spacing: .04em; }
.error-card .btn { margin-top: var(--space-2); }
.dialog-card { max-width: 520px; padding: var(--space-6); }
.center-wrap .dialog-card { width: 100%; }
.dialog-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%;
  margin-bottom: var(--space-4); background: var(--neutral-bg); color: var(--neutral-fg);
}
.dialog-icon .icon { width: 20px; height: 20px; }
.dialog-icon.danger { background: var(--danger-bg); color: var(--danger-fg); box-shadow: 0 0 0 6px #fffbfa; }
.dialog-icon.warning { background: var(--warning-bg); color: var(--warning-fg); }
.dialog-icon.success { background: var(--success-bg); color: var(--success-fg); }
.dialog-title { font-size: 18px; font-weight: 650; margin-bottom: var(--space-2); }
.dialog-card p { color: var(--text-2); }
.dialog-card .field { margin-top: var(--space-4); }
.secret-value { font-size: 22px; font-weight: 600; letter-spacing: .06em; padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--surface-sunken); border: 1px solid var(--line); display: inline-block; }
.copy-field { font-size: 13px; }

/* ------------------------------------------------------------------ document preview */
.preview.pdf { display: block; width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-sm); }
.preview.img { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--space-4); text-align: center; box-shadow: var(--shadow-sm); }
.preview.img img { max-width: 100%; max-height: 78vh; border-radius: var(--radius-sm); }
details summary { cursor: pointer; color: var(--accent); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1440px) {
  .client-table .col-contact { display: none; }
}
@media (max-width: 1240px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .detail-rail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-4); }
  .detail-rail > .card:first-child { grid-row: span 2; }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .quick-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --sticky-top: 57px; }
  .app { display: block; }
  .sidebar { position: sticky; top: 0; height: auto; border-right: 0; border-bottom: 1px solid var(--line); background: rgba(252, 252, 253, .96); }
  .sidebar-head { padding: 12px 12px 12px 16px; min-height: 56px; }
  .nav-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: var(--radius);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); cursor: pointer; box-shadow: var(--shadow-xs);
  }
  .nav-toggle-btn .icon { width: 20px; height: 20px; vertical-align: 0; }
  .nav-toggle-btn .when-open { display: none; }
  .nav-toggle-input:checked ~ .sidebar .nav-toggle-btn .when-open { display: inline-flex; }
  .nav-toggle-input:checked ~ .sidebar .nav-toggle-btn .when-closed { display: none; }
  .nav-toggle-input:focus-visible ~ .sidebar .nav-toggle-btn { outline: 2px solid var(--accent); outline-offset: 2px; }
  .sidebar-body { display: none; max-height: calc(100vh - 57px); padding: 4px 12px 16px; border-top: 1px solid var(--line); }
  .nav-toggle-input:checked ~ .sidebar .sidebar-body { display: flex; }
  .side-nav a, .side-link { padding: 10px 10px; font-size: 14.5px; }
  .content { padding: 20px 16px 48px; }
  .detail-rail { grid-template-columns: minmax(0, 1fr); }
  .detail-rail > .card:first-child { grid-row: auto; }
}

@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 20px; }
  .filter-bar select { flex: 1 1 calc(50% - var(--space-2)); }
  .filter-actions { margin-left: 0; width: 100%; }
  .filter-actions .btn { flex: 1; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .upload-grid { grid-template-columns: minmax(0, 1fr); }
  .mini-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
  .page-title { font-size: 20px; }
  .form-actions.sticky-actions { bottom: var(--space-2); }

  /* tables become stacked cards */
  .table-card.sticky-head, .table-card { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .client-table thead, .stack-mobile thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
  .client-table, .client-table tbody, .client-table tr, .client-table td,
  .stack-mobile, .stack-mobile tbody, .stack-mobile tr, .stack-mobile td { display: block; width: 100%; }
  .client-table tr, .stack-mobile tr {
    margin-bottom: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-sm);
  }
  .data-table tbody tr:hover td { background: transparent; }
  .data-table td { border: 0; padding: 6px 0; }
  .data-table td[data-label] { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 0 var(--space-3); align-items: start; justify-items: start; text-align: left; max-width: none; min-width: 0; }
  .data-table td[data-label]::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 6; font-size: 12px; font-weight: 500; color: var(--muted); padding-top: 2px; }
  .data-table td[data-label] > * { grid-column: 2; margin-top: 0; max-width: 100%; }
  .data-table td[data-label] > * + * { margin-top: 4px; }
  .client-table td { max-width: none !important; min-width: 0 !important; }
  .client-table th, .client-table td, .client-table td:first-child, .client-table td:last-child { padding-left: 0; padding-right: 0; }
  .data-table td.right { text-align: left; }
  .data-table td:first-child { padding-top: 2px; }
  .data-table td.cell-actions:not(:empty) { padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line-soft); }
  .data-table tr.overdue { border-left: 3px solid var(--danger-solid); }
  .data-table tr.overdue td:first-child { box-shadow: none; }
  .data-table tr.warn { background: var(--warning-bg); }
  .data-table tr.warn td { background: transparent; }
  .client-table .cell-client { padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line-soft); }
  .client-table .col-contact { display: grid; }
  .client-table .col-contact .cell-note { margin-top: 0; }
  .client-table .cell-stores .truncate { max-width: 100%; }
  .client-table .mini { white-space: normal; }
  .empty-row { padding: 0 !important; }
}

@media (max-width: 560px) {
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv > dt { padding-bottom: 0; }
  .kv > dd { border-top: 0; padding-top: 2px; }
  .kv > dt:first-child + dd { padding-top: 2px; }
  .mini-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-kv .span-2 { grid-column: 1 / -1; }
  .card { padding: var(--space-4); }
  .record-head { padding: var(--space-4); }
  .record-head-main .page-actions { width: 100%; }
  .record-head-main .page-actions .btn { flex: 1; }
  .avatar.lg { width: 44px; height: 44px; font-size: 16px; }
  .auth-card { padding: var(--space-6) var(--space-5); }
  .page-header .page-actions { width: 100%; }
  .page-header .page-actions .btn { flex: 1; }
  .form-actions { padding: var(--space-3); }
  .form-actions .btn { flex: 1; }
  .row-actions { width: 100%; }
  .task-form-row { grid-template-columns: minmax(0, 1fr); }
  .pipeline { grid-auto-columns: minmax(80%, 1fr); margin: 0 -16px; padding: 0 16px var(--space-3); scroll-padding: 0 16px; }
  .segmented { display: flex; }
  .segmented a { flex: 1; text-align: center; padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .chip, .tag, .due, .btn, .card, .stat { border: 1px solid CanvasText; }
  meter.meter { border: 1px solid CanvasText; }
}

@media print {
  .sidebar, .page-actions, .filter-bar, .row-actions, .task-form, .upload-form, .note-form { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  .card, .table-card { box-shadow: none; }
}

/* ------------------------------------------------------------------ alignment tweaks */
.stack-mobile td { vertical-align: middle; }
.cell-actions form.inline, .cell-actions > a { display: inline-flex; vertical-align: middle; }
.check-row { align-items: flex-start; }
.check-row input[type=checkbox] { margin-top: 2px; }
.data-table { font-size: 13.5px; }
.error-card .auth-title { font-size: 17px; line-height: 1.4; margin-bottom: 6px; }
input[type=checkbox], input[type=radio] { flex-shrink: 0; }
.segmented a { display: inline-flex; align-items: center; justify-content: center; }

/* ------------------------------------------------------------------ brand leads, website leads, application links */
.badge.accent { background: var(--accent); }
.client-table .cell-client .cell-client-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 0 42px; }
.client-table .cell-client .cell-client-chips .chip { margin: 0; }
.chip.lead-new { background: var(--violet-bg); color: var(--violet-fg); border-color: var(--violet-line); --dot: var(--violet-solid); }
.chip.lead-contacted { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); --dot: var(--info-solid); }
.chip.lead-qualified { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); --dot: var(--warning-solid); }
.chip.lead-won { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-line); --dot: var(--success-solid); }
.chip.lead-lost { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-line); --dot: var(--neutral-solid); }
.seg-count { margin-left: 6px; padding: 0 6px; border-radius: var(--radius-pill); background: rgba(16, 24, 40, .06); font-size: 11.5px; line-height: 18px; color: var(--gray-600); }
.segmented a.current .seg-count { background: var(--accent-soft); color: var(--accent-ink); }
.card-text { font-size: 13px; margin-bottom: var(--space-3); }
.app-link-kv { margin-bottom: var(--space-3); }
.app-link-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.help-note { margin: var(--space-3) 0 0; font-size: 12.5px; color: var(--muted); }
.field-label { display: block; margin: var(--space-4) 0 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.copy-hint { margin: 6px 0 0; }
.card-form-actions { display: flex; justify-content: flex-end; padding: var(--space-1) 0 var(--space-4); }
.lead-table .entity-sub { overflow-wrap: anywhere; }
@media (max-width: 768px) {
  .client-table .cell-client .cell-client-chips { margin-left: 42px; }
}

/* ------------------------------------------------------------------ archive */
.chip.archived { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-300); }
.archived-banner {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); padding: 12px 16px;
  border-radius: var(--radius-card); background: var(--gray-100); border: 1px solid var(--gray-300); color: var(--gray-700); font-size: 13.5px;
}
.archived-banner p { margin: 0; flex: 1 1 260px; }
.archived-banner form { margin: 0; }
.archived-banner-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--radius); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

/* ------------------------------------------------------------------ client tags */
.list-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.list-toolbar .segmented { margin-bottom: 0; }
.tag-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-bar-label { display: inline-flex; align-items: center; gap: 5px; color: var(--gray-600); font-size: 13px; font-weight: 500; margin-right: 2px; }
.tag-bar-label .icon { width: 14px; height: 14px; }
.chip.label-tag { background: #f0f9ff; color: #026aa2; border-color: #b9e6fe; text-decoration: none; }
.chip.label-tag:hover { background: #e0f2fe; text-decoration: none; }
.chip.label-tag .num { opacity: .75; margin-left: 2px; }
.chip.label-tag .icon { width: 12px; height: 12px; }
.chip.label-tag.current { background: #026aa2; color: #fff; border-color: #026aa2; }
.chip.label-tag.current .num { opacity: .9; }
.tags-form { display: flex; gap: var(--space-2); align-items: center; }
.tags-form input { flex: 1; min-width: 0; }
