* { box-sizing: border-box; }

:root {
  --navy: #1b2838;
  --navy-2: #22334a;
  --teal: #16a085;
  --teal-dark: #128a72;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e8ebee;
  --text: #1b2838;
  --text-muted: #93a2b4;
  --danger: #e74c3c;
  --warning: #f39c12;
}

body {
  font-family: 'Public Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* --- каркас: сайдбар + контент ------------------------------------------------------------------ */

.app-shell {
  display: flex;
  min-height: 100vh;
}

#sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 22px;
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
}

.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--teal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

#sidebar button {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  color: #93a2b4;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  font-family: inherit;
}

#sidebar button svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

#sidebar button:hover {
  color: #ffffff;
}

#sidebar button.active {
  background: var(--teal);
  color: #ffffff;
  border-radius: 8px;
  margin: 0 12px;
  padding: 10px 14px;
  width: calc(100% - 24px);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#topbar {
  height: 58px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

#topbar-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
}

main {
  padding: 24px 28px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

section h2 {
  margin-top: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  margin: 12px 0;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  background: #f7f8fa;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 32, .04);
  padding: 16px;
  margin-bottom: 16px;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 32, .04);
  padding: 14px 16px;
  text-align: left;
}

.stat-tile .value {
  font-size: 24px;
  font-weight: 700;
}

.stat-tile .label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-top: 4px;
}

a.stat-tile {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow 0.15s, transform 0.15s;
}

a.stat-tile.clickable:hover {
  box-shadow: 0 0 0 2px var(--teal) inset;
  transform: translateY(-1px);
}

.warn-tile {
  background: #fdf3e3;
  border-color: #f5d99b;
}

.npd-banner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  margin-bottom: 16px;
  font-size: 13px;
}

.npd-banner.warn {
  background: #fdf3e3;
  border-color: #f5d99b;
  color: #7a5200;
}

form.inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 12px 0;
}

form.filters {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

form.filters label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text);
}

input, select, textarea {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

textarea {
  width: 100%;
  min-height: 70px;
}

button.action {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}

button.action:hover {
  background: var(--teal-dark);
}

button.secondary {
  background: #eef1f3;
  color: #333;
}

button.secondary.active {
  background: var(--teal);
  color: #fff;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  background: #eef1f3;
}

.pill.ok { background: #dcf3ec; color: #0e7057; }
.pill.bad { background: #fbe4e2; color: #a5311f; }
.pill[title] { cursor: help; }

.checkbox-list label.dim {
  color: #999;
}

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 0;
}

.msg {
  font-size: 13px;
  margin-top: 4px;
}

.msg.error { color: #cc3333; }
.msg.ok { color: #228833; }

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

/* --- аккордеоны (справочники/чаты) ------------------------------------------------------------- */

details.card {
  padding: 0;
}

details.card > summary {
  padding: 16px;
}

/* Обёртка тела аккордеона: даёт padding через box-sizing, а не margin рядом с width:100% —
   иначе table{width:100%} + margin по бокам вместе вылезают за границы карточки. */
.details-body {
  box-sizing: border-box;
  width: 100%;
  padding: 0 16px 16px;
  overflow-x: auto;
}

.details-body table {
  min-width: 100%;
}

.section-title {
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  list-style: none;
}

.section-title::-webkit-details-marker {
  display: none;
}

.section-title::before {
  content: "▸ ";
  color: var(--teal);
}

details[open] > .section-title::before {
  content: "▾ ";
}

tr.dim {
  color: #999;
}

tr.dim .pill {
  opacity: 0.6;
}

/* --- дерево чатов -------------------------------------------------------------------------------- */

.tree-node {
  margin: 6px 0;
}

.tree-node > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 6px 0;
}

.tree-node > summary::-webkit-details-marker {
  display: none;
}

.tree-node > summary::before {
  content: "▾ ";
  color: var(--teal);
}

.tree-node:not([open]) > summary::before {
  content: "▸ ";
}

.tree-node-nested {
  margin-left: 20px;
  border-left: 2px solid #eee;
  padding-left: 10px;
}

/* --- воронка --------------------------------------------------------------------------------------- */

.funnel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.funnel-step .funnel-label {
  font-size: 13px;
  margin-bottom: 4px;
}

.funnel-track {
  background: #eef0f5;
  border-radius: 6px;
  height: 18px;
  overflow: hidden;
}

.funnel-bar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s;
}

.funnel-bar.step-total { background: #94a3b8; }
.funnel-bar.step-filtered { background: var(--warning); }
.funnel-bar.step-llm { background: #5bc0de; }
.funnel-bar.step-lead { background: var(--teal); }

/* --- кнопки действий у строителя --------------------------------------------------------------- */

.builder-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
}

button.btn-extend {
  background: #eef0f5;
  color: #333;
}

button.btn-pause {
  background: #fff3cd;
  color: #7a5b00;
}

button.btn-resume {
  background: #dcf3ec;
  color: #0e7057;
}

/* --- ручная отправка лида ------------------------------------------------------------------------ */

tr.manual-send-row td {
  background: #f7f8fc;
  border-bottom: 2px solid #e0e3ec;
}

.manual-send-panel {
  padding: 8px 4px;
}

.manual-send-panel .checkbox-list {
  flex-direction: column;
  gap: 6px;
}

/* --- дашборд: таблицы с итогом, drill-down, графики ------------------------------------------------ */

tr.total-row {
  font-weight: 700;
  background: #f7f8fa;
}

tr.total-row td {
  border-bottom: 2px solid var(--border);
}

.pct-muted {
  color: var(--text-muted);
  font-size: 12px;
}

tr.builder-row {
  cursor: pointer;
}

tr.builder-row:hover {
  background: #f7f8fa;
}

tr.builder-row .drill-toggle {
  color: var(--teal);
  font-size: 11px;
  margin-left: 6px;
}

tr.builder-drilldown td {
  background: #f7f8fc;
  padding: 10px 16px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.granularity-toggle {
  display: flex;
  gap: 4px;
}

.granularity-toggle button {
  padding: 5px 10px;
  font-size: 12px;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
}

.payments-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 20px;
  align-items: center;
}

.payments-sum-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.payments-sum-box .value {
  font-size: 28px;
  font-weight: 700;
}

.payments-sum-box .label {
  font-size: 12px;
  color: var(--text-muted);
}
