/* Тема: цвета только через переменные. Авто = следуем браузеру; явный выбор ставит data-theme на <html>. */
:root {
  color-scheme: light;
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-2: #f3f1ea;
  --border: #e6e3d8;
  --text: #1c1b18;
  --muted: #6d6a60;
  --accent: #c4623f;
  --accent-ink: #ffffff;
  --accent-soft: #f7e6df;
  --danger: #b3382c;
  --ok: #2f7d4f;
  --shadow: 0 1px 2px rgba(28, 27, 24, .05), 0 6px 20px rgba(28, 27, 24, .05);
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171614;
  --surface: #211f1d;
  --surface-2: #2a2825;
  --border: #38352f;
  --text: #f0ede4;
  --muted: #a29e92;
  --accent: #dc7a58;
  --accent-ink: #1a0f0a;
  --accent-soft: #3a2a23;
  --danger: #ee7b6e;
  --ok: #6cc08a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #171614;
    --surface: #211f1d;
    --surface-2: #2a2825;
    --border: #38352f;
    --text: #f0ede4;
    --muted: #a29e92;
    --accent: #dc7a58;
    --accent-ink: #1a0f0a;
    --accent-soft: #3a2a23;
    --danger: #ee7b6e;
    --ok: #6cc08a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  transition: background .2s, color .2s;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); font-size: 13px; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1320px; margin: 0 auto; padding: 0 20px; }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #f2b36b));
  box-shadow: var(--shadow);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --- кнопки и переключатель темы --- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 550; font-size: 14px;
  padding: 9px 16px; border-radius: 999px; line-height: 1.2;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .seg button:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-size: 13px; font-weight: 550;
  padding: 6px 12px; border-radius: 999px; background: transparent; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- карточки, вкладки --- */
/* minmax(0, 1fr): ширину колонки задаёт страница, а не содержимое — широкая воронка прокручивается внутри карточки */
main { padding-top: 24px; padding-bottom: 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.card {
  min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  appearance: none; cursor: pointer; font: inherit; font-weight: 550; font-size: 14px;
  padding: 8px 16px; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--muted);
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

.problems { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.problems h2 { color: var(--danger); margin-bottom: 8px; font-size: 16px; }
.problems ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }

/* --- обзор --- */
.stats { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { padding: 18px 20px; }
.stat b { display: block; font-size: 30px; line-height: 1.1; font-weight: 650; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-top: 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* --- чипы --- */
.chip {
  --c: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 550; line-height: 1.6;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.chip.plain::before { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); }

/* --- воронка (канбан) --- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.col {
  --c: var(--muted);
  scroll-snap-align: start; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--c);
}
.col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.col-head h3 { overflow-wrap: anywhere; }
.count { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; }
.deal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px; display: grid; gap: 8px;
}
.deal-title { font-weight: 600; overflow-wrap: anywhere; }
.deal-sum { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 6px; border: 1px dashed var(--border); border-radius: var(--r-sm); }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* --- нижняя панель действий --- */
.actions { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); flex-wrap: wrap; }
.actions-btns { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .card { padding: 16px; border-radius: var(--r-md); }
  .board { grid-auto-columns: 82%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
