/* ==========================================================================
   Client CRM — light Claude-style UI
   Cream canvas · white cards · coral CTA · horizontal nav
   ========================================================================== */

:root {
  /* Slack-inspired tokens (DESIGN.md) */
  --primary: #4a154b;
  --primary-active: #611f69;
  --primary-soft: rgba(74, 21, 75, 0.10);
  --link: #1264a3;

  --canvas: #f4ede4;
  --surface-white: #ffffff;
  --surface-soft: #f9f0ff;
  --surface-card: #ffffff;
  --hairline: #e6e6e6;
  --hairline-soft: #eee8f0;

  --ink: #1d1d1d;
  --body-strong: #1d1d1d;
  --body: #1d1d1d;
  --muted: #696969;
  --muted-soft: #8b8b8b;
  --on-primary: #ffffff;

  --success: #007a5a;
  --warning: #d4a017;
  --error: #cc4117;

  --font-display: "Lato", "Helvetica Neue", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-ui: "Lato", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --xxs: 4px;
  --xs: 8px;
  --sm: 12px;
  --md: 16px;
  --lg: 24px;
  --xl: 32px;
  --xxl: 48px;
  --section: 64px;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 9999px;

  --nav-h: 64px;
  --shadow-soft: 0 1px 3px rgba(29, 29, 29, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--body);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
}

.nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    90deg,
    transparent,
    var(--primary) 35%,
    var(--primary) 65%,
    transparent
  );
  transform: translateX(-100%);
  transition: opacity 0.15s ease;
}

html.is-navigating .nav-progress {
  opacity: 1;
  animation: nav-progress-slide 0.9s ease-in-out infinite;
}

@keyframes nav-progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

html.is-navigating .main-content {
  opacity: 0.92;
  transition: opacity 0.12s ease;
}

/* ---- Typography --------------------------------------------------------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--ink);
  margin: 0;
}

h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.8px; }
h2 { font-size: 32px; line-height: 1.15; letter-spacing: -0.5px; }
h3 { font-size: 24px; line-height: 1.2; letter-spacing: -0.3px; }
h4 { font-size: 20px; line-height: 1.25; letter-spacing: -0.2px; }

p { margin: 0 0 var(--md); }

strong { font-weight: 500; color: var(--body-strong); }

a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }

.text-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
}

.text-link:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface-soft);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline);
}

/* ---- Site header & nav -------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--lg);
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: var(--md);
}

.wordmark {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}

.wordmark-accent { color: var(--primary); }

.desktop-nav {
  display: flex;
  align-items: center;
  gap: var(--xxs);
  flex: 1;
  min-width: 0;
}

.nav-item {
  padding: var(--xs) var(--sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--r-md);
  white-space: nowrap;
}

.nav-item:hover { color: var(--ink); }
.nav-item.active {
  background: var(--surface-white);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-left: auto;
  flex-shrink: 0;
}

.btn-nav {
  height: 36px;
  padding: 0 var(--md);
  font-size: 13px;
  white-space: nowrap;
}

.nav-toggle {
  display: none;
  background: var(--surface-white);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
}

.mobile-drawer {
  border-top: 1px solid var(--hairline-soft);
  background: var(--surface-white);
  padding: var(--md) var(--lg) var(--lg);
}

.mobile-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: var(--xxs);
  max-width: 1200px;
  margin: 0 auto;
}

.mobile-drawer-nav .nav-item {
  padding: var(--sm) var(--md);
  font-size: 16px;
}

.mobile-drawer-cta {
  margin-top: var(--md);
  width: 100%;
}

/* Bottom tab bar (mobile) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface-white);
  border-top: 1px solid var(--hairline);
  padding: var(--xs) var(--xxs) calc(var(--xs) + env(safe-area-inset-bottom));
  justify-content: space-around;
  box-shadow: 0 -2px 8px rgba(20, 20, 19, 0.06);
}

/* ---- Diagnostic panel (bottom-right) ------------------------------------ */

.diag-panel {
  position: fixed;
  right: var(--lg);
  bottom: var(--lg);
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sm);
  pointer-events: none;
}

.diag-panel > * { pointer-events: auto; }

.diag-panel-toggle {
  width: 48px;
  height: 48px;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: var(--surface-white);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.diag-panel-toggle:hover {
  box-shadow: 0 4px 14px rgba(20, 20, 19, 0.12);
  transform: translateY(-1px);
}

.diag-panel.is-open .diag-panel-toggle {
  background: var(--primary-soft);
  border-color: rgba(92, 107, 192, 0.35);
  color: var(--primary);
}

.diag-panel-body {
  width: min(320px, calc(100vw - 2 * var(--lg)));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: var(--surface-white);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(20, 20, 19, 0.14);
  padding: var(--md);
  transform-origin: bottom right;
  animation: diag-panel-in 0.22s ease;
}

.diag-panel-body[hidden] { display: none !important; }

@keyframes diag-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.diag-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sm);
  margin-bottom: var(--md);
}

.diag-panel-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.diag-panel-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--r-md);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.diag-panel-section { margin-bottom: var(--md); }

.diag-panel-label {
  margin: 0 0 var(--xs);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.diag-status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--xs);
}

.diag-panel-nav {
  display: flex;
  flex-direction: column;
  gap: var(--xs);
  margin-bottom: var(--md);
}

.diag-panel-link {
  display: flex;
  align-items: flex-start;
  gap: var(--sm);
  padding: var(--sm) var(--md);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--ink);
  background: var(--canvas);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.diag-panel-link:hover {
  border-color: var(--hairline);
  background: var(--surface-white);
}

.diag-panel-link.active {
  border-color: rgba(92, 107, 192, 0.35);
  background: var(--primary-soft);
}

.diag-panel-link-icon {
  flex-shrink: 0;
  width: 24px;
  text-align: center;
  font-size: 16px;
  line-height: 1.4;
  opacity: 0.85;
}

.diag-panel-link-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.diag-panel-link-desc {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.diag-panel-meta {
  margin: 0;
  padding-top: var(--sm);
  border-top: 1px solid var(--hairline-soft);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--xs);
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  min-width: 56px;
}

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-icon { font-size: 18px; line-height: 1; }

/* Hero empty state */
.hero-empty {
  text-align: center;
  padding: var(--xxl) var(--lg);
  background: var(--surface-white);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-soft);
}

.hero-empty h2 {
  font-size: 32px;
  margin-bottom: var(--md);
}

.hero-actions {
  display: flex;
  gap: var(--md);
  justify-content: center;
  flex-wrap: wrap;
  margin: var(--xl) 0;
}

.btn-lg {
  height: 48px;
  padding: 0 var(--xl);
  font-size: 15px;
}

.hero-steps {
  text-align: left;
  max-width: 360px;
  margin: var(--xl) auto 0;
  padding-left: var(--lg);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.hero-steps strong { color: var(--ink); }

/* ---- Page layout -------------------------------------------------------- */

.main-content { min-height: calc(100vh - var(--nav-h)); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--xl) var(--lg) var(--section);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--lg);
  margin-bottom: var(--xl);
  flex-wrap: wrap;
}

.subtitle {
  font-size: 16px;
  color: var(--muted);
  margin: var(--xs) 0 0;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--xs);
}

.status-pill {
  font-size: 12px;
  font-weight: 500;
  padding: var(--xxs) var(--sm);
  background: var(--surface-white);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  color: var(--muted);
}

.status-pill.ok { color: #3d7a4d; border-color: rgba(93, 184, 114, 0.35); background: rgba(93, 184, 114, 0.08); }
.status-pill.warn { color: #8a5a20; border-color: rgba(212, 160, 23, 0.35); background: rgba(212, 160, 23, 0.08); }
.status-pill.muted { color: var(--muted-soft); }

/* ---- Workflow ----------------------------------------------------------- */

.workflow {
  display: flex;
  gap: var(--md);
  list-style: none;
  margin: 0 0 var(--xl);
  padding: 0;
  flex-wrap: wrap;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: var(--sm);
  padding: var(--sm) var(--md);
  background: var(--surface-white);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  font-size: 14px;
  color: var(--muted);
}

.workflow-step.done { border-color: rgba(93, 184, 114, 0.4); }
.workflow-step.done .workflow-num { background: var(--success); color: white; }
.workflow-step.current { border-color: var(--primary); color: var(--ink); box-shadow: 0 0 0 3px var(--primary-soft); }
.workflow-step.current .workflow-num { background: var(--primary); color: white; }

.workflow-num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-pill);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 600;
}

/* ---- Empty state & quick actions ---------------------------------------- */

.empty-state {
  /* legacy alias */
}

.hero-empty { margin-bottom: var(--xl); }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--md);
  margin-bottom: var(--xl);
}

.action-card {
  display: flex;
  flex-direction: column;
  gap: var(--xxs);
  padding: var(--lg);
  background: var(--surface-white);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-soft);
}

.action-card:hover { border-color: var(--primary); }

.action-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.action-desc { font-size: 13px; color: var(--muted); }

/* ---- Cards -------------------------------------------------------------- */

.card {
  background: var(--surface-white);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-lg);
  padding: var(--xl);
  margin-bottom: var(--lg);
  box-shadow: var(--shadow-soft);
}

.card-area:empty { display: none; }

.muted-card { background: var(--surface-soft); box-shadow: none; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--lg);
  flex-wrap: wrap;
  gap: var(--md);
}

.toolbar-card { padding: var(--lg) var(--xl); }

.meta-tags { display: flex; flex-wrap: wrap; gap: var(--md); }

.tag { font-size: 13px; font-weight: 500; color: var(--muted); }
.tag.ok { color: var(--success); }

.callout-light {
  padding: var(--lg);
  background: var(--primary-soft);
  border-radius: var(--r-lg);
  margin-bottom: var(--lg);
  border: 1px solid rgba(204, 120, 92, 0.2);
}

/* ---- KPI ---------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--md);
  margin-bottom: var(--xl);
}

.kpi-card {
  background: var(--surface-white);
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-lg);
  padding: var(--lg);
  box-shadow: var(--shadow-soft);
}

.kpi-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi-value {
  font-family: var(--font-display);
  font-size: 32px;
  letter-spacing: -0.5px;
  color: var(--ink);
  line-height: 1.1;
}

.kpi-value.sm { font-size: 22px; }
.kpi-growth { font-size: 13px; font-weight: 500; }
.kpi-growth.up { color: var(--success); }
.kpi-growth.down { color: var(--error); }

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--lg);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--lg);
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--xxs);
  margin-bottom: var(--lg);
}

.config-dl { margin: 0; }
.config-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 2fr;
  gap: var(--sm) var(--md);
  padding: var(--sm) 0;
  border-bottom: 1px solid var(--hairline-soft);
}
.config-row:last-child { border-bottom: none; }
.config-row dt {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.config-row dd { margin: 0; font-size: 14px; }

/* ---- Filters ------------------------------------------------------------ */

.filter-tabs { display: flex; gap: var(--xxs); margin-bottom: var(--md); }

.filter-tab {
  padding: var(--xs) var(--md);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--r-md);
}

.filter-tab.active {
  background: var(--surface-soft);
  color: var(--ink);
}

.group-filter-cloud {
  margin-bottom: var(--md);
  padding: var(--md);
  border-radius: var(--r-lg);
  background:
    radial-gradient(ellipse at 0% 0%, hsla(var(--chip-hue, 220), 55%, 62%, 0.08), transparent 55%),
    radial-gradient(ellipse at 100% 100%, hsla(280, 45%, 58%, 0.06), transparent 50%),
    var(--surface-soft);
  border: 1px solid var(--hairline-soft);
}

.group-cloud-head {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-bottom: var(--sm);
  flex-wrap: wrap;
}

.group-cloud-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink);
}

.group-cloud-hint {
  font-size: 12px;
  color: var(--muted);
}

.group-cloud-clear {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
}

.group-cloud-clear:hover { text-decoration: underline; }

.group-cloud-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-chip {
  --chip-hue: 220;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  color: hsl(var(--chip-hue), 35%, 28%);
  background: hsla(var(--chip-hue), 48%, 52%, 0.12);
  border: 1px solid hsla(var(--chip-hue), 40%, 45%, 0.22);
  box-shadow: 0 1px 2px hsla(var(--chip-hue), 30%, 20%, 0.06);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.group-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px hsla(var(--chip-hue), 35%, 30%, 0.14);
  background: hsla(var(--chip-hue), 50%, 50%, 0.18);
}

.group-chip.is-active {
  color: #fff;
  background: linear-gradient(
    135deg,
    hsl(var(--chip-hue), 52%, 48%) 0%,
    hsl(calc(var(--chip-hue) + 24), 48%, 42%) 100%
  );
  border-color: transparent;
  box-shadow: 0 4px 14px hsla(var(--chip-hue), 45%, 35%, 0.35);
}

.group-chip-all {
  --chip-hue: 210;
  color: var(--muted);
  background: var(--surface);
  border-color: var(--hairline-soft);
}

.group-chip-all.is-active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.group-chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.55);
  color: inherit;
}

.group-chip.is-active .group-chip-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.group-chip-all .group-chip-count {
  background: var(--surface-soft);
}

.filter-form, .period-form, .campaign-form, .comm-rule-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--md);
  align-items: flex-end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: var(--xxs);
  min-width: 160px;
}

.filter-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.result-count { font-size: 14px; color: var(--muted); margin: var(--sm) 0 0; }

.status-chips { display: flex; flex-wrap: wrap; gap: var(--sm); }

.chip, .tag-chip {
  font-size: 13px;
  padding: var(--xxs) var(--sm);
  background: var(--surface-soft);
  border-radius: var(--r-pill);
  color: var(--body);
}

/* ---- Forms -------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--lg);
}

.file-drop {
  display: flex;
  flex-direction: column;
  gap: var(--xs);
  padding: var(--xl);
  background: var(--canvas);
  border: 2px dashed var(--hairline);
  border-radius: var(--r-lg);
  cursor: pointer;
  text-align: center;
}

.file-drop:hover { border-color: var(--primary); background: var(--primary-soft); }

.file-drop-title { font-size: 15px; font-weight: 500; color: var(--ink); }
.file-drop-hint { font-size: 13px; color: var(--muted); }

.file-drop input[type="file"] {
  margin-top: var(--sm);
  border: none;
  background: transparent;
  width: 100%;
}

input, select, textarea {
  color: var(--ink);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 14px;
  min-height: 40px;
  font-family: var(--font-ui);
  font-size: 15px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.campaign-form label, .comm-rule-form label {
  display: flex;
  flex-direction: column;
  gap: var(--xs);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.segment-form {
  display: flex;
  align-items: center;
  gap: var(--lg);
  flex-wrap: wrap;
}

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 20px;
  border: none;
  border-radius: var(--r-md);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.btn:active { background: var(--primary-active); }

.btn.secondary {
  background: var(--surface-white);
  color: var(--ink);
  border: 1px solid var(--hairline);
}

.btn.small { height: 32px; padding: 0 14px; font-size: 13px; }

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface-white);
  cursor: pointer;
  color: var(--muted);
}

.result-actions {
  display: flex;
  gap: var(--md);
  margin-bottom: var(--lg);
  flex-wrap: wrap;
}

/* ---- Tables ------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-lg);
}

table { width: 100%; border-collapse: collapse; font-size: 15px; }

th, td {
  padding: var(--sm) var(--md);
  border-bottom: 1px solid var(--hairline-soft);
  text-align: left;
}

th {
  background: var(--canvas);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(250, 249, 245, 0.6); }

td.ai-added { background: rgba(93, 184, 114, 0.06); }

.ai-cell-stack {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}
.ai-cell-new {
  display: inline-block;
  padding: 2px 6px;
  border: 2px solid var(--success);
  border-radius: var(--r-sm);
  line-height: 1.3;
}
.ai-cell-old {
  display: inline-block;
  padding: 2px 6px;
  border: 2px solid #c45c5c;
  border-radius: var(--r-sm);
  font-size: 0.82em;
  color: #8b3a3a;
  line-height: 1.3;
}
.ai-cell-old::before {
  content: "было: ";
  font-size: 0.9em;
  opacity: 0.75;
}
.ai-cell-unknown {
  display: inline-block;
  padding: 2px 6px;
  border: 2px solid #c45c5c;
  border-radius: var(--r-sm);
  background: rgba(196, 92, 92, 0.08);
  color: #8b3a3a;
  font-size: 0.85em;
  line-height: 1.3;
  text-transform: lowercase;
}

.ai-cell-running {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid rgba(212, 160, 23, 0.55);
  border-radius: var(--r-sm);
  background: rgba(212, 160, 23, 0.18);
  color: #8a6500;
  font-size: 0.85em;
  font-weight: 500;
  line-height: 1.3;
  text-transform: lowercase;
}

.ai-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.group-chip-ms {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 0.82em;
  line-height: 1.3;
  /* МойСклад — фиолетовый (Slack primary) */
  border: 1px solid #611f69;
  background: rgba(74, 21, 75, 0.10);
  color: #4a154b;
  font-weight: 600;
}
.ai-tag-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 0.82em;
  line-height: 1.3;
  cursor: help;
  border: 1px solid var(--border, var(--hairline));
  background: var(--surface-soft);
}
/* AI-группы/теги — зелёные, явно другой цвет от МС */
.ai-tag-chip.ai-tag-ai {
  border: 2px solid #007a5a !important;
  background: #e6f6f0 !important;
  color: #065f46 !important;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(0, 122, 90, 0.25);
}
.ai-tag-chip.ai-tag-pending {
  border: 2px dashed #007a5a;
  background: #f0faf6;
  color: #065f46;
  font-weight: 600;
  font-size: 0.78em;
}
.groups-tags-legend {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  font-size: 0.78em;
  color: var(--muted);
  margin-left: 8px;
}
.groups-tags-legend .leg-ms::before,
.groups-tags-legend .leg-ai::before {
  content: "";
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: -1px;
}
.groups-tags-legend .leg-ms::before {
  background: #4a154b;
  border: 1px solid #611f69;
}
.groups-tags-legend .leg-ai::before {
  background: #007a5a;
  border: 1px solid #007a5a;
}
.campaign-hero-title {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  color: var(--primary, #4a154b);
}
.campaign-hero-copy {
  margin-bottom: var(--md, 1rem);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.brand-logo {
  display: block;
  border-radius: 8px;
}
.brand-logo-wide {
  height: 40px;
  width: auto;
  max-width: min(220px, 42vw);
  object-fit: contain;
  border-radius: 0;
  background: transparent;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.footer-logo {
  display: block;
  border-radius: 5px;
}
.crm-exclusion-hint {
  margin: 8px 0 0;
  font-size: 12px;
}
.nav-logout {
  margin-left: 12px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}
.nav-logout:hover { color: var(--primary); }
.login-card { max-width: 420px; margin: 24px auto; }
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  text-align: center;
}
.login-logo {
  display: block;
  height: 56px;
  width: auto;
  max-width: min(260px, 70vw);
  object-fit: contain;
}
.login-tagline {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  font: inherit;
}
.campaign-recipients {
  list-style: none;
  padding: 0;
  margin: 8px 0 12px;
}
.campaign-recipients li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline-soft);
}
.chip-sent { background: rgba(0, 122, 90, 0.12); color: #0a5c45; }
.chip-demo { background: rgba(18, 100, 163, 0.12); color: #1264a3; }
.chip-failed { background: rgba(204, 65, 23, 0.12); color: #cc4117; }
.filter-form-base select {
  min-width: 140px;
}

.clients-table-wide {
  font-size: 13px;
  width: max-content;
  min-width: 100%;
}
.clients-table-wide th,
.clients-table-wide td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.clients-table-wide td.tags-cell {
  white-space: normal;
  max-width: 320px;
  overflow: visible;
  text-overflow: unset;
}
.clients-table-wide th {
  max-width: none;
  overflow: visible;
  white-space: nowrap;
  vertical-align: middle;
  padding: 0;
}
.clients-table-wide th .th-label {
  display: inline;
  white-space: nowrap;
  word-break: normal;
  font-weight: 600;
}
.clients-table-wide .tags-cell { max-width: 220px; white-space: normal; }
.clients-table-wide .tg-conv-cell { max-width: 220px; white-space: normal; }
.clients-table-wide .name-cell { max-width: 260px; overflow: visible; }
.clients-table-wide th.col-hidden,
.clients-table-wide td.col-hidden { display: none; }

.ai-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #3d7a4d;
  background: rgba(93, 184, 114, 0.12);
  border-radius: var(--r-pill);
  padding: 2px 8px;
}

.ai-ref {
  font-size: 10px;
  color: var(--primary);
  cursor: help;
  margin-left: var(--xxs);
}

.reasoning { white-space: normal; max-width: 280px; color: var(--muted); font-size: 14px; }
.tags-cell { white-space: normal; max-width: 180px; }
.orders-expand-row td {
  padding: 0;
  border: none;
}

.clients-table-wide .orders-expand-row td {
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.clients-table-wide .actions-col,
.clients-table-wide .actions-cell {
  max-width: none;
  min-width: 6.5rem;
  overflow: visible;
  text-overflow: clip;
}

.orders-expand-row.is-open td {
  padding: 0;
}
.orders-nested { padding: var(--md); background: var(--canvas); }
.orders-compact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}
.orders-compact-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline-soft);
  font-size: 13px;
  line-height: 1.4;
}
.orders-compact-item:last-child { border-bottom: none; }
.orders-compact-main {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: baseline;
}
.oc-num {
  font-weight: 600;
  color: var(--ink);
  min-width: 52px;
}
.oc-date { color: var(--muted); min-width: 72px; }
.oc-amount { font-weight: 600; color: var(--primary); }
.oc-status {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  background: var(--hairline-soft);
}
.oc-channel {
  font-size: 12px;
  color: var(--muted);
}
.oc-positions, .oc-comment {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.orders-compact-empty, .orders-compact-more {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.orders-nested-empty { padding: var(--md); color: var(--muted); font-size: 13px; }
.positions-cell, .positions-summary { font-size: 13px; line-height: 1.45; max-width: 280px; }

/* ---- Modals ------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--lg);
  background: rgba(20, 20, 19, 0.35);
  backdrop-filter: blur(4px);
}

.modal-overlay[hidden] { display: none !important; }

.upload-modal[hidden] { display: none !important; }
.modal-overlay[hidden] { display: none !important; }
.upload-modal:not([hidden]) {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface-white);
  border-radius: var(--r-xl);
  padding: var(--xl);
  box-shadow: 0 8px 32px rgba(20, 20, 19, 0.12);
}

.client-card-modal {
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.orders-modal-overlay {
  z-index: 260;
}

.orders-modal-loading-overlay {
  z-index: 255;
}

.orders-modal {
  max-width: 720px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.orders-modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.orders-modal-loading {
  margin: 0 0 var(--sm);
  text-align: center;
  padding: var(--md) 0 0;
}

.orders-modal-progress {
  margin-top: var(--md);
  padding-top: var(--md);
  border-top: 1px solid var(--hairline-soft);
}

.orders-modal-progress .progress-label {
  margin-bottom: var(--sm);
  text-align: center;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn-text + .btn-text {
  margin-left: var(--sm);
}

.modal-close {
  position: absolute;
  top: var(--md);
  right: var(--md);
  width: 32px;
  height: 32px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface-white);
  cursor: pointer;
  color: var(--muted);
}

.progress-track {
  height: 4px;
  background: var(--hairline);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-bottom: var(--md);
}

.progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; }
.progress-track.indeterminate .progress-fill {
  width: 40%;
  animation: indeterminate 1.1s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.progress-label { font-size: 14px; color: var(--muted); margin: 0; }
.progress-label.error { color: var(--error); }

/* ---- Footer ------------------------------------------------------------- */

.footer {
  border-top: 1px solid var(--hairline-soft);
  padding: var(--lg);
  margin-top: var(--xxl);
  background: var(--canvas);
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sm);
  font-size: 13px;
  color: var(--muted-soft);
}

.footer-brand { font-weight: 500; color: var(--muted); }

/* ---- Misc --------------------------------------------------------------- */

.env-list { list-style: none; padding: 0; margin: 0; }
.env-list li { padding: var(--sm) 0; border-bottom: 1px solid var(--hairline-soft); }
.alert.error {
  padding: var(--lg);
  background: rgba(198, 69, 69, 0.06);
  border: 1px solid rgba(198, 69, 69, 0.2);
  border-radius: var(--r-md);
  color: var(--error);
}

.messenger-status-block .ok { color: var(--success); }
.messenger-status-block .warn { color: var(--warning); }

.moysklad-block { display: flex; flex-direction: column; gap: var(--md); }
.moysklad-popup { padding: var(--sm) var(--md); border-radius: var(--r-md); font-size: 0.9rem; }
.moysklad-popup.ok { color: var(--success); background: rgba(93, 184, 114, 0.08); border: 1px solid rgba(93, 184, 114, 0.25); }
.moysklad-popup.warn { color: var(--warning); background: rgba(198, 140, 45, 0.08); border: 1px solid rgba(198, 140, 45, 0.25); }
.moysklad-popup.muted { color: var(--muted); background: var(--surface-soft); }
.moysklad-block .sync-msg.ok { color: var(--success); }
.moysklad-block .sync-msg.warn { color: var(--warning); }
.moysklad-stats { margin: 0; }
.moysklad-total { font-weight: 500; }
.moysklad-stats strong { color: var(--text); }
.cache-badge {
  display: inline-block;
  margin-left: var(--xs);
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
  border-radius: var(--r-sm);
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: var(--xs);
}
.pagination-card { padding: var(--md); }
.pagination-card .pagination { margin-top: 0; }
.pagination-btn,
.pagination-num,
.pagination-current {
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  line-height: 1;
}
.pagination-num { min-width: 2.25rem; }
.pagination-current {
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid rgba(92, 107, 192, 0.25);
  border-radius: var(--r-sm);
}
.pagination-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: default;
}
.pagination-ellipsis {
  color: var(--muted);
  padding: 0 4px;
  user-select: none;
}
.pagination-info {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: var(--sm);
}

/* ---- Tag rules drawer --------------------------------------------------- */

.rules-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 240;
  background: rgba(20, 20, 19, 0.35);
}
.rules-drawer-overlay[hidden],
.rules-drawer[hidden] { display: none !important; }

.rules-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 250;
  width: min(420px, 100vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--surface-white);
  border-left: 1px solid var(--hairline);
  box-shadow: -8px 0 24px rgba(20, 20, 19, 0.12);
  padding: var(--lg);
}

.rules-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--md);
  margin-bottom: var(--md);
}
.rules-drawer-header h3 { margin: 0; font-size: 1.15rem; }

.tag-rules-form { display: flex; flex-direction: column; gap: var(--md); }
.tag-rule-card {
  border: 1px solid var(--hairline-soft);
  border-radius: var(--r-md);
  padding: var(--md);
  margin: 0;
}
.tag-rule-enable {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-bottom: var(--sm);
  font-size: 0.95rem;
}
.tag-rule-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: var(--sm);
  font-size: 0.85rem;
}
.tag-rule-field textarea,
.tag-rule-field input[type="text"],
.tag-rule-field input[type="number"] {
  width: 100%;
  padding: var(--xs) var(--sm);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  font: inherit;
}
.tag-rule-card.tag-rule-custom { border-color: rgba(92, 107, 192, 0.35); }
.tag-rule-card.tag-rule-new {
  border-style: dashed;
  background: var(--surface-soft);
}
.tag-rule-card legend { font-size: 0.95rem; margin-bottom: var(--sm); }
.tag-rule-tag-input,
.tag-rule-title-input {
  padding: 2px 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  font: inherit;
  max-width: 8rem;
}
.tag-rule-title-input { max-width: 10rem; }
.tag-rule-delete {
  display: flex;
  align-items: center;
  gap: var(--xs);
  margin-top: var(--sm);
  font-size: 0.82rem;
  color: var(--warning);
}
.tag-rule-field select {
  width: 100%;
  padding: var(--xs) var(--sm);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  font: inherit;
}
.tag-rule-type { margin: var(--xs) 0 0; font-size: 0.8rem; }
.rules-drawer-actions {
  display: flex;
  gap: var(--sm);
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  background: var(--surface-white);
  padding-top: var(--md);
}

.tags-col-head { white-space: nowrap; }
.tag-rules-btn {
  display: inline-block;
  margin-left: var(--xs);
  font-size: 0.75rem;
  color: var(--primary);
  vertical-align: middle;
}

.client-drawer {
  width: min(480px, 100vw);
}

.drawer-loading {
  padding: var(--lg) 0;
}

.client-name-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--primary);
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(92, 107, 192, 0.35);
  text-underline-offset: 2px;
}
.client-name-link:hover {
  text-decoration-color: var(--primary);
}

.moysklad-push-area { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sm); }
.moysklad-push-area.inline-push { margin: 0; }
.moysklad-push-area .hint { flex-basis: 100%; margin: 0; }
.push-errors { margin: 0; padding-left: 1.2rem; color: var(--warning); font-size: 0.9rem; }

.campaign-list { list-style: none; padding: 0; margin: 0; }
.campaign-item { padding: var(--lg) 0; border-bottom: 1px solid var(--hairline-soft); }

.comm-rule-header { display: flex; justify-content: space-between; align-items: center; }
.rule-divider { border: none; border-top: 1px solid var(--hairline-soft); margin: var(--lg) 0; }

.client-meta, .tags-row, .kpi-inline { display: flex; flex-wrap: wrap; gap: var(--sm); margin-bottom: var(--lg); }
.client-section { margin-bottom: var(--lg); padding-top: var(--md); border-top: 1px solid var(--hairline-soft); }
.ai-block h4 { margin-bottom: var(--sm); }
.ai-client-summary,
.ai-summary,
.ai-recommendation {
  margin: 0 0 var(--sm);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.ai-client-summary {
  padding: var(--md);
  background: var(--canvas);
  border-radius: var(--r-md);
  border-left: 3px solid var(--primary);
}
.ai-block-recommendation .ai-recommendation {
  padding: var(--md);
  background: rgba(93, 184, 114, 0.08);
  border-radius: var(--r-md);
  border-left: 3px solid var(--success, #5db872);
  white-space: pre-line;
}
.client-orders-list:not([hidden]) { margin-top: var(--sm); }
.client-orders-expand-btn.is-open { opacity: 0.85; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: flex; gap: var(--sm); color: var(--muted); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--hairline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sm);
  margin-top: var(--md);
}

.toolbar-actions .toolbar-action-btn {
  position: relative;
  gap: 6px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease, border-color 0.14s ease;
}

.toolbar-actions .toolbar-action-btn:active:not(.htmx-request):not(.is-busy) {
  transform: scale(0.97);
}

.toolbar-actions .toolbar-action-btn.htmx-request,
.toolbar-actions .toolbar-action-btn.is-busy {
  pointer-events: none;
  opacity: 0.78;
  border-color: rgba(92, 107, 192, 0.45);
  box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.16);
  animation: toolbar-btn-pulse 1.1s ease-in-out infinite;
}

.toolbar-actions .toolbar-action-btn.htmx-request::after,
.toolbar-actions .toolbar-action-btn.is-busy::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid var(--hairline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.toolbar-actions .toolbar-action-btn.htmx-request .btn-action-icon,
.toolbar-actions .toolbar-action-btn.is-busy .btn-action-icon {
  display: inline-block;
  animation: spin 0.85s linear infinite;
}

@keyframes toolbar-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.12); }
  50% { box-shadow: 0 0 0 3px rgba(92, 107, 192, 0.24); }
}

.btn-action-icon {
  line-height: 1;
}

.source-block {
  margin-bottom: var(--lg);
  padding-bottom: var(--lg);
  border-bottom: 1px solid var(--hairline-soft);
}

.source-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.progress-bar {
  height: 6px;
  background: var(--hairline-soft);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin: var(--sm) 0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.mini-badge {
  display: inline-block;
  margin-left: var(--xs);
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: var(--r-sm);
}

.orders-nested-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.message-item {
  padding: var(--sm) 0;
  border-bottom: 1px solid var(--hairline-soft);
  font-size: 13px;
}

.message-item .msg-channel {
  display: inline-block;
  min-width: 72px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
}

/* Не дублировать overflow/max-width на th — иначе снова пропадают названия колонок. */
.clients-table-wide th.col-hidden,
.clients-table-wide td.col-hidden { display: none; }
.name-with-orders {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}
.name-with-orders .client-name-link {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.name-with-orders .orders-modal-btn { flex-shrink: 0; }
.clients-columns-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.columns-picker { position: relative; }
.columns-picker-toggle { cursor: pointer; list-style: none; }
.columns-picker-toggle::-webkit-details-marker { display: none; }
.columns-picker-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 220px;
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  background: var(--surface, #fff);
  border: 1px solid var(--hairline-soft, #e5e5e5);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.columns-picker-hint { margin: 0 0 8px; font-size: 12px; }
.columns-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 13px;
  cursor: pointer;
}

.sortable-th { padding: 0; }
.col-drag-handle {
  display: inline-flex;
  align-items: center;
  margin-right: 2px;
  padding: 6px 2px 6px 6px;
  color: var(--muted-soft);
  font-size: 11px;
  line-height: 1;
  cursor: grab;
  user-select: none;
  touch-action: none;
  vertical-align: middle;
}
.col-drag-handle:hover { color: var(--muted); }
.col-drag-handle:active { cursor: grabbing; }
th.col-dragging { opacity: 0.55; }
th.col-drag-over { box-shadow: inset 3px 0 0 var(--primary); }
.sortable-th-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: none;
  padding: 6px 10px;
  color: var(--ink, #1d1c1d);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.sortable-th-link .th-label {
  display: inline;
  overflow: visible;
  white-space: nowrap;
  word-break: normal;
  line-height: 1.2;
}
.sortable-th-link:hover { color: var(--primary); }
.sortable-th-link.is-active { color: var(--ink, #1d1c1d); }
.sort-indicator {
  font-size: 10px;
  color: var(--primary);
  line-height: 1;
}
.sort-indicator-idle {
  color: var(--muted-soft);
  opacity: 0.7;
}
.clients-table-wide .tags-col-head .sortable-th-link { padding-right: 4px; }
.tg-conv-badge {
  display: inline-block;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--accent);
}
.clients-table-wide .muted-cell { color: var(--muted); font-size: 12px; }
.tag-chip.ai-chip { background: var(--primary-soft); color: var(--primary); }

.mobile-status-strip {
  padding: var(--sm) 0 var(--md);
  flex-wrap: wrap;
}

/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 900px) {
  .desktop-nav { display: none; }
  .nav-toggle { display: block; margin-left: auto; }
  .bottom-nav { display: flex; }
  .main-content { padding-bottom: 72px; }
  .diag-panel {
    right: var(--md);
    bottom: calc(72px + var(--sm));
  }
  .split-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  h1 { font-size: 28px; }
  .container { padding: var(--lg) var(--md) var(--xxl); }
  .workflow { flex-direction: column; }
  .workflow-text { font-size: 13px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
