/* Тёмная тема — база. Светлая переопределяет те же токены ниже. */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --bg-soft: #111319;
  --surface: #15171f;
  --surface-2: #1b1e28;
  --line: #262a36;
  --line-soft: #1e2129;
  --text: #e8eaf0;
  --muted: #8b90a0;
  --faint: #5d6270;
  --accent: #7c5cff;
  --good: #2fbf7a;
  --warn: #e8b13a;
  --bad: #e8545b;
  --page-glow: radial-gradient(1100px 620px at 78% -12%, #1a1630 0%, transparent 62%);
  --sidebar-bg: rgba(12, 13, 18, .7);
  --hover: rgba(255, 255, 255, .015);
  --scrim: rgba(6, 7, 10, .7);
  --shadow: 0 18px 48px rgba(0, 0, 0, .45);
  --page-pad: 34px;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-soft: #fbfcfd;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --line: #d8dde6;
  --line-soft: #e6eaf0;
  --text: #171a21;
  --muted: #5b6273;
  --faint: #8a91a1;
  --accent: #5b3ce0;
  --good: #12925a;
  --warn: #a8760c;
  --bad: #cf3840;
  --page-glow: radial-gradient(1100px 620px at 78% -12%, #e9e4ff 0%, transparent 62%);
  --sidebar-bg: rgba(255, 255, 255, .78);
  --hover: rgba(18, 22, 32, .025);
  --scrim: rgba(28, 32, 44, .42);
  --shadow: 0 16px 40px rgba(20, 26, 40, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page-glow), var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: rgba(124, 92, 255, .35); }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.auth-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.auth-mark {
  width: 64px; height: 64px; margin-bottom: 16px; object-fit: contain; display: block;
}

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line-soft); padding: 22px 16px; background: var(--sidebar-bg);
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; object-fit: contain; flex: none;
}
.nav-icon { width: 19px; flex: none; text-align: center; font-size: 13px; opacity: .85; }
.nav-emoji { width: 19px; flex: none; text-align: center; font-size: 14px; line-height: 1; }
.nav-logo { width: 19px; height: 19px; object-fit: contain; border-radius: 5px; flex: none; margin: 0 -2px 0 -3px; }
.brand b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.brand span { display: block; font-size: 11px; color: var(--faint); }
.nav-label { padding: 14px 10px 6px; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--muted); text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%;
  text-align: left; font-size: 13.5px; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { box-shadow: inset 0 0 0 1px var(--line-soft); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.nav-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line-soft); }

.main { padding: 26px var(--page-pad) 80px; max-width: 1280px; }
/*
 * Элементы сетки и флекса по умолчанию не уже своего содержимого, поэтому широкая
 * таблица или лента фильтров растягивала бы всю страницу — на телефоне Chrome
 * из-за этого отзумливает вёрстку. Разрешаем им сжиматься и скроллиться внутри себя.
 */
.shell, .main, .card, .grid > *, .table-wrap, .chips, .board, .board-col, .post, .wish, .kpi { min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 25px; letter-spacing: -.025em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- элементы ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 13px; border-radius: 10px; cursor: pointer; font-size: 13px;
  transition: border-color .15s, background .15s, transform .05s;
}
.btn:hover { border-color: var(--line); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:hover { background: #8d71ff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(232, 84, 91, .3); }
.btn.danger:hover { background: rgba(232, 84, 91, .1); }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .16); }
textarea.input { resize: vertical; min-height: 72px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }

.kpi .label { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.kpi .value { font-size: 27px; font-weight: 650; letter-spacing: -.03em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--faint); }

.bar { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar.good > i { background: var(--good); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px;
  font-size: 11.5px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line-soft);
}
.pill.good { color: var(--good); border-color: rgba(47, 191, 122, .28); background: rgba(47, 191, 122, .1); }
.pill.warn { color: var(--warn); border-color: rgba(232, 177, 58, .28); background: rgba(232, 177, 58, .1); }
.pill.bad { color: var(--bad); border-color: rgba(232, 84, 91, .28); background: rgba(232, 84, 91, .1); }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--faint); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- таблица ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th {
  text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
  font-weight: 500; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
tr.group-row td { background: var(--bg-soft); font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
tr.total-row td { background: var(--bg-soft); font-weight: 600; }
.cell-input {
  width: 78px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 8px; text-align: right; font-variant-numeric: tabular-nums; outline: none;
}
.cell-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .16); }
.cell-input.wide { width: 100%; text-align: left; }
.cell-input.ok { border-color: rgba(47, 191, 122, .5); }

/* ---------- обложка направления ---------- */
.hero {
  position: relative; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line-soft); margin-bottom: 18px; background: #0c0e13;
  min-height: 150px; display: flex; align-items: flex-end;
}
.hero-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center 14%; opacity: .5;
}
.hero::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, rgba(10, 11, 15, .95) 0%, rgba(10, 11, 15, .78) 38%, rgba(10, 11, 15, .42) 100%);
}
.hero-body { position: relative; z-index: 1; padding: 20px 22px; display: flex; align-items: center; gap: 16px; width: 100%; }
.hero-logo {
  height: 74px; width: auto; max-width: 230px; object-fit: contain; flex: none;
  filter: drop-shadow(0 8px 22px rgba(0, 0, 0, .7));
}
.hero h1 { margin: 0; font-size: 26px; letter-spacing: -.025em; color: #f4f5f8; }
.hero .sub { color: rgba(244, 245, 248, .62); font-size: 13px; margin-top: 4px; }
.card-logo { width: 24px; height: 24px; object-fit: contain; border-radius: 6px; flex: none; }

/* ---------- карта желаний ---------- */
.wish-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); }
.wish {
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 8px; cursor: pointer;
  transition: border-color .15s, transform .12s; position: relative; overflow: hidden;
}
.wish:hover { border-color: var(--line); transform: translateY(-2px); }
.wish.done { opacity: .58; }
.wish.done .wish-title { text-decoration: line-through; }
.wish-cover { height: 108px; margin: -14px -14px 2px; background: var(--surface-2) center/cover no-repeat; }
.wish-title { font-size: 14px; font-weight: 550; letter-spacing: -.01em; }
.wish-price { font-size: 18px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.wish-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.cat-head { display: flex; align-items: baseline; gap: 12px; margin: 26px 0 12px; }
.cat-head h2 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
.chip.active { background: var(--surface-2); color: var(--text); border-color: var(--line); }

/* ---------- модалка ---------- */
.modal-back {
  position: fixed; inset: 0; background: var(--scrim); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 22px; z-index: 50;
}
.modal {
  width: min(540px, 100%); max-height: 88vh; overflow-y: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 18px; font-size: 18px; letter-spacing: -.02em; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }
.alert.error { background: rgba(232, 84, 91, .12); color: #ff9aa0; border: 1px solid rgba(232, 84, 91, .25); }
.alert.info { background: rgba(124, 92, 255, .1); color: #c3b4ff; border: 1px solid rgba(124, 92, 255, .25); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 11px;
  box-shadow: var(--shadow); z-index: 90; font-size: 13px; animation: rise .22s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

}

/* ---------- контент-доска ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(212px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.board-col { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 10px; }
.board-head b { font-size: 12.5px; font-weight: 600; letter-spacing: -.01em; }
.board-head .count { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.board-col > .cards { display: grid; gap: 9px; }
.post {
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: 11px; padding: 11px;
  display: grid; gap: 7px; cursor: pointer; transition: border-color .15s, transform .12s;
}
.post:hover { border-color: var(--line); transform: translateY(-1px); }
.post-title { font-size: 13px; line-height: 1.35; font-weight: 550; }
.post-meta { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dots { display: flex; gap: 3px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.owner {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-2); border: 1px solid var(--line-soft); font-size: 10px; font-weight: 600; color: var(--muted);
}
.move { display: flex; gap: 2px; }
.move button {
  border: 1px solid var(--line-soft); background: var(--bg-soft); color: var(--muted); cursor: pointer;
  width: 22px; height: 22px; border-radius: 7px; font-size: 11px; line-height: 1; padding: 0;
}
.move button:hover:not([disabled]) { color: var(--text); border-color: var(--line); }
.move button[disabled] { opacity: .3; cursor: default; }
.channel-mark { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.nav-sub { display: grid; gap: 2px; margin: 2px 0 6px 12px; padding-left: 10px; border-left: 1px solid var(--line-soft); }
.nav-sub .nav-item { padding: 6px 9px; font-size: 12.5px; }

/* ---------- контент списком ---------- */
.list-input {
  width: 100%; background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 5px 7px; outline: none; font-size: 13px; transition: border-color .12s, background .12s;
}
.list-input:hover { border-color: var(--line-soft); }
.list-input:focus { border-color: var(--accent); background: var(--bg-soft); box-shadow: 0 0 0 3px rgba(124, 92, 255, .14); }
.list-input.ok { border-color: rgba(47, 191, 122, .5); }
select.list-input { appearance: none; cursor: pointer; }
input[type="date"].list-input { font-variant-numeric: tabular-nums; }
input[type="date"].list-input::-webkit-calendar-picker-indicator { opacity: .4; cursor: pointer; }
input[type="date"].list-input:hover::-webkit-calendar-picker-indicator { opacity: .75; }
.list-table td { padding: 5px 8px; }
.list-table th { padding: 11px 8px; }
.list-table .list-input { font-size: 12.5px; }
.plat-toggle { display: flex; gap: 4px; }
.plat-toggle button {
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  cursor: pointer; padding: 0; transition: opacity .12s, transform .12s;
}
.plat-toggle button[aria-pressed="false"] { opacity: .22; }
.plat-toggle button:hover { transform: scale(1.15); }
.view-switch { display: flex; gap: 2px; background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 10px; padding: 2px; }
.view-switch button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 5px 11px; border-radius: 8px; font-size: 12.5px;
}
.view-switch button.active { background: var(--surface-2); color: var(--text); }
.dict-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.dict-row .count { font-size: 11.5px; color: var(--faint); white-space: nowrap; }

/* ---------- мобильная шапка и выезжающее меню ---------- */
.topbar { display: none; }
.scrim { display: none; }

.burger {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-content: center; gap: 4px; cursor: pointer; padding: 0;
}
.burger span { display: block; width: 16px; height: 1.5px; background: var(--text); border-radius: 2px; }
.topbar-mark { width: 26px; height: 26px; object-fit: contain; }

/* ---------- широкий десктоп ---------- */
@media (min-width: 1700px) {
  .main { max-width: 1520px; }
}

/* ---------- ноутбуки поуже ---------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 208px 1fr; }
  :root, :root[data-theme] { --page-pad: 22px; }
  .main { padding: 24px var(--page-pad) 70px; }
  .hero-logo { height: 62px; max-width: 180px; }
  .hero h1 { font-size: 22px; }
}

/* ---------- планшеты и телефоны: меню уезжает в шторку ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }

  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--sidebar-bg); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line-soft);
  }
  .topbar b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(280px, 86vw); height: 100dvh; z-index: 50;
    transform: translateX(-102%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
    border-right: 1px solid var(--line); box-shadow: none;
    padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom));
    background: var(--surface);
  }
  .nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  /* Затемнение существует только при открытой шторке: иначе оно перехватывало бы касания. */
  .scrim { display: none; position: fixed; inset: 0; z-index: 40; background: var(--scrim); }
  .nav-open .scrim { display: block; }

  :root, :root[data-theme] { --page-pad: 16px; }
  .main { padding: 18px var(--page-pad) calc(64px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 21px; }
  .hero { min-height: 118px; }
  .hero-body { padding: 16px; gap: 12px; }
  .hero-logo { height: 46px; max-width: 132px; }
  .hero h1 { font-size: 19px; }
  .hero .sub, .page-head .sub { font-size: 12.5px; }
  .kpi .value { font-size: 23px; }
  .card { padding: 15px; }

  /* Полосы фильтров и вкладок прокручиваются вбок, не переносясь в три этажа. */
  .chips {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-inline: calc(var(--page-pad) * -1); padding-inline: var(--page-pad); scroll-snap-type: x proximity;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { scroll-snap-align: start; }

  .board {
    grid-auto-columns: minmax(258px, 82vw); scroll-snap-type: x proximity;
    margin-inline: calc(var(--page-pad) * -1); padding-inline: var(--page-pad);
  }
  .board-col { scroll-snap-align: start; }

  /* iOS зумит страницу, если шрифт поля меньше 16px */
  .input, .cell-input, .list-input, .list-table .list-input, select.input, textarea.input { font-size: 16px; }
  .cell-input { width: 88px; }

  .head-actions { gap: 6px; }
  .btn { padding: 9px 13px; }
  .btn.sm { padding: 7px 10px; }
  .view-switch button { padding: 7px 12px; }

  .modal { width: 100%; max-height: 92dvh; border-radius: 16px; padding: 18px; }
  .modal-back { padding: 12px; align-items: flex-end; }
  .row { flex-direction: column; gap: 0; }

  /* Первая колонка таблиц остаётся на месте при боковой прокрутке. */
  .list-table th:first-child, .list-table td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--surface);
  }
  .list-table thead th:first-child { background: var(--surface); }
  tr.group-row td, tr.total-row td { background: var(--bg-soft); }
}

/* ---------- телефоны ---------- */
@media (max-width: 560px) {
  :root, :root[data-theme] { --page-pad: 12px; }
  .main { padding: 14px var(--page-pad) calc(56px + env(safe-area-inset-bottom)); }
  .page-head { gap: 12px; margin-bottom: 16px; }
  .page-head h1 { font-size: 19px; }
  .head-actions { width: 100%; }
  .head-actions > input.input { flex: 1 1 100%; min-width: 0; }
  .head-actions > select.input { flex: 0 1 auto; }
  .move button { width: 30px; height: 30px; font-size: 13px; }
  .grid { gap: 10px; }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .wish-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .wish { padding: 11px; }
  .wish-price { font-size: 16px; }
  .kpi .value { font-size: 21px; }
  .hero-body { flex-direction: column; align-items: flex-start; gap: 10px; }
  .hero-logo { height: 38px; }
  .board { grid-auto-columns: minmax(232px, 88vw); }
  .modal { padding: 16px; border-radius: 16px 16px 0 0; }
  .modal-back { padding: 0; }
  .modal-foot .btn { flex: 1; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}

/* ---------- очень узкие экраны ---------- */
@media (max-width: 380px) {
  .wish-grid { grid-template-columns: 1fr; }
  .view-switch button { padding: 7px 9px; font-size: 12px; }
}

/* ---------- печать ---------- */
@media print {
  .sidebar, .topbar, .scrim, .head-actions, .move, .btn { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card, .table-wrap { break-inside: avoid; }
}

/* ---------- контент: дашборд, воронка, ферма ---------- */
.content-dash { padding: 16px 18px; margin-bottom: 18px; }
.dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; margin-bottom: 16px; }
.dash-kpi { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 12px; padding: 11px 13px; }
.dash-kpi .k-val { font-size: 23px; font-weight: 650; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.dash-kpi .k-lab { font-size: 11px; color: var(--muted); margin-top: 3px; }
.dash-kpi.bad .k-val { color: var(--bad); }
.dash-kpi.good .k-val { color: var(--good); }
.dash-split { display: grid; grid-template-columns: 1.25fr 1fr; gap: 22px; }
.dash-side { display: grid; gap: 16px; align-content: start; }
.dash-h { font-size: 12px; color: var(--muted); margin: 0 0 9px; letter-spacing: .01em; }

.funnel { display: grid; gap: 6px; }
.funnel-row {
  display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 11px;
  background: transparent; border: 0; padding: 5px 7px; border-radius: 10px; cursor: pointer; text-align: left; color: inherit;
}
.funnel-row:hover { background: var(--hover); }
.funnel-row.active { background: var(--surface-2); }
.funnel-name { display: flex; align-items: center; gap: 8px; font-size: 12.5px; white-space: nowrap; overflow: hidden; }
.funnel-name .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.funnel-name em { font-style: normal; color: var(--faint); font-size: 11px; margin-left: 2px; overflow: hidden; text-overflow: ellipsis; }
.funnel-track { height: 11px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.funnel-track > i { display: block; height: 100%; border-radius: 99px; min-width: 2px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.funnel-val { font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 48px; text-align: right; }
.funnel-val small { color: var(--faint); margin-left: 6px; font-size: 11px; }

.farm { display: grid; gap: 7px; }
.farm-person {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 11px;
  padding: 8px 11px; cursor: pointer; text-align: left; color: inherit; transition: border-color .12s;
}
.farm-person:hover { border-color: var(--line); }
.farm-person.active { border-color: var(--accent); background: var(--surface-2); }
.farm-person .owner { width: 30px; height: 30px; font-size: 11.5px; }
.farm-person .fp-body { display: grid; min-width: 0; }
.farm-person .fp-body b { font-size: 13px; font-weight: 600; }
.farm-person .fp-title { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.farm-person .fp-count { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 7px; }
.farm-person .fp-late { font-size: 10.5px; font-weight: 500; color: var(--bad); }

.rubs { display: grid; gap: 7px; }
.rub-row { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: center; }
.rub-row .r-name { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rub-row .r-val { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rub-bar { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.rub-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s cubic-bezier(.2,.8,.2,1); }

/* воронка-степпер в строке списка и этап на доске */
.funnel-steps { display: flex; gap: 3px; }
.funnel-steps button {
  width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; padding: 0; transition: transform .12s, background .12s, border-color .12s;
}
.funnel-steps button.on { background: var(--c); border-color: var(--c); }
.funnel-steps button.cur { box-shadow: 0 0 0 2px rgba(124, 92, 255, .22); transform: scale(1.1); }
.funnel-steps button:hover { transform: scale(1.2); }
.funnel-cur { font-size: 11px; margin-top: 5px; white-space: nowrap; font-weight: 550; }
.list-table .lead-date { font-weight: 550; }
.stage-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.board-role { font-size: 11px; color: var(--faint); padding: 0 4px 8px; margin-top: -4px; }

@media (max-width: 760px) {
  .dash-split { grid-template-columns: 1fr; gap: 18px; }
  .funnel-row { grid-template-columns: 118px 1fr auto; }
}

/* ---------- попап-разбивка (drill-down) ---------- */
.rub-row { cursor: pointer; background: transparent; border: 0; padding: 3px 4px; border-radius: 8px; width: 100%; text-align: left; color: inherit; }
.rub-row:hover { background: var(--hover); }
.drill-list { display: grid; gap: 2px; max-height: 58dvh; overflow-y: auto; margin: -4px -4px 0; padding: 4px; }
.drill-row {
  display: grid; grid-template-columns: 96px 128px 1fr auto; align-items: center; gap: 12px;
  width: 100%; text-align: left; color: inherit; cursor: pointer;
  background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 10px; padding: 9px 12px;
  transition: border-color .12s, background .12s;
}
.drill-row:hover { border-color: var(--line); background: var(--surface-2); }
.drill-row.late { border-color: rgba(232, 84, 91, .4); }
.drill-row .d-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.drill-row .d-stage { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.drill-row .d-stage i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.drill-row .d-title { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.owner.sm { width: 24px; height: 24px; font-size: 10px; }

@media (max-width: 560px) {
  .drill-row { grid-template-columns: 1fr auto; gap: 4px 10px; }
  .drill-row .d-date { grid-row: 2; }
  .drill-row .d-stage { grid-row: 2; justify-self: end; }
  .drill-row .d-title { grid-column: 1 / -1; order: -1; }
}

/* ---------- календарь: месячная сетка (как Google Calendar) ---------- */
.calgrid-wrap { display: grid; gap: 12px; }
.cg-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cg-title { font-size: 17px; font-weight: 650; text-transform: capitalize; letter-spacing: -.02em; }
.cg-nav { display: flex; gap: 6px; }
.calgrid { border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.cg-head { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--bg-soft); border-bottom: 1px solid var(--line-soft); }
.cg-dow { padding: 8px 10px; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.cg-body { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(106px, auto); }
.cg-cell { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 5px 5px 7px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cg-cell:nth-child(7n) { border-right: 0; }
.cg-cell.muted { background: var(--bg-soft); }
.cg-cell.muted .cg-num { color: var(--faint); }
.cg-cell.today { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.cg-dayrow { display: flex; align-items: center; justify-content: space-between; }
.cg-num { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 23px; height: 22px; display: inline-grid; place-content: center; }
.cg-cell.today .cg-num { background: var(--accent); color: #fff; border-radius: 7px; }
.cg-add { opacity: 0; width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; padding: 0; font-size: 14px; line-height: 1; transition: opacity .12s; }
.cg-cell:hover .cg-add, .cg-add:focus-visible { opacity: 1; }
.cg-add:hover { border-color: var(--accent); color: var(--text); }
.cg-events { display: grid; gap: 3px; align-content: start; }
.cg-event {
  display: block; width: 100%; text-align: left; cursor: pointer; color: inherit;
  background: color-mix(in srgb, var(--c) 15%, transparent); border: 0; border-left: 3px solid var(--c);
  border-radius: 5px; padding: 3px 7px;
}
.cg-event:hover { background: color-mix(in srgb, var(--c) 26%, transparent); }
.cg-event.late { outline: 1px solid var(--bad); outline-offset: -1px; }
.cg-event span { display: block; font-size: 11.5px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-more { font-size: 11px; color: var(--muted); background: transparent; border: 0; cursor: pointer; text-align: left; padding: 1px 7px; }
.cg-more:hover { color: var(--text); }
.cg-nodate { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); padding: 11px 13px; }
.cg-nodate-h { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.cg-nodate-items { display: flex; flex-wrap: wrap; gap: 6px; }
.cg-nodate-items .cg-event { width: auto; max-width: 260px; }

@media (max-width: 720px) {
  .calgrid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cg-head, .cg-body { min-width: 660px; }
}

/* ---------- доска: drag-and-drop как Trello ---------- */
.post { touch-action: pan-y; }
.board-col { display: flex; flex-direction: column; }
.board-col > .cards { flex: 1; }
.board-col.drop { outline: 2px dashed var(--accent); outline-offset: -3px; background: color-mix(in srgb, var(--accent) 8%, var(--bg-soft)); }
.post.dragging { opacity: .32; }
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none; margin: 0;
  box-shadow: var(--shadow); transform: rotate(2.5deg); opacity: .96; cursor: grabbing;
}
body.board-dragging { cursor: grabbing; user-select: none; }
.col-empty { font-size: 12px; padding: 14px 8px; text-align: center; border: 1px dashed var(--line-soft); border-radius: 9px; margin-top: 4px; }
.col-add {
  margin-top: 8px; width: 100%; border: 1px dashed var(--line); background: transparent; color: var(--muted);
  cursor: pointer; padding: 7px; border-radius: 9px; font-size: 12.5px; transition: border-color .12s, color .12s;
}
.col-add:hover { border-color: var(--accent); color: var(--text); }

/* календарь: ячейка кликабельна (важно на мобильном) */
.cg-cell { cursor: pointer; }
.cg-event, .cg-add, .cg-more { cursor: pointer; }

/* ---------- задачи по людям ---------- */
.tasks { display: grid; gap: 16px; }
.task-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.task-col { background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 11px; display: flex; flex-direction: column; }
.task-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 2px 2px 10px; }
.task-head .owner { width: 32px; height: 32px; font-size: 12px; }
.task-head .th-body { display: grid; min-width: 0; }
.task-head .th-body b { font-size: 13.5px; }
.task-head .th-body span { font-size: 11px; color: var(--faint); }
.task-head .th-count { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted); }
.task-head .th-count.bad { color: var(--bad); }
.task-list { display: grid; gap: 7px; }
.task-card {
  display: grid; gap: 4px; text-align: left; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-soft); border-left: 3px solid var(--c);
  border-radius: 10px; padding: 9px 11px; transition: border-color .12s, transform .12s;
}
.task-card:hover { border-color: var(--line); transform: translateY(-1px); }
.task-card.late { border-left-color: var(--bad); }
.task-card .t-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.task-card .t-stage { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.task-card .t-stage i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.task-card .t-due { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.task-card .t-due.bad { color: var(--bad); font-weight: 600; }
.task-card .t-title { font-size: 13px; font-weight: 550; line-height: 1.3; }
.task-card .t-meta { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.task-assign { border-color: rgba(232, 177, 58, .4); }
.ta-head { font-size: 13px; font-weight: 600; margin-bottom: 11px; }
.ta-list { display: grid; gap: 7px; }
.ta-row { display: grid; grid-template-columns: 120px 1fr auto auto; align-items: center; gap: 12px; padding: 7px 2px; border-top: 1px solid var(--line-soft); }
.ta-row.late .ta-due { color: var(--bad); font-weight: 600; }
.ta-stage { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.ta-stage i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.ta-title { text-align: left; background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 13px; font-weight: 550; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ta-title:hover { text-decoration: underline; }
.ta-due { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ta-pick { display: flex; gap: 5px; }

@media (max-width: 560px) {
  .ta-row { grid-template-columns: 1fr auto; row-gap: 6px; }
  .ta-stage { grid-row: 2; }
  .ta-due { grid-row: 2; justify-self: end; }
  .ta-title { grid-column: 1 / -1; }
  .ta-pick { grid-column: 1 / -1; }
}

/* ---------- управление пользователями ---------- */
.user-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.user-row:last-child { border-bottom: 0; }
.user-row .owner { width: 36px; height: 36px; font-size: 12.5px; }
.user-row .ur-body { min-width: 0; }
.user-row .ur-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-row .ur-login { font-size: 12px; margin: 1px 0 6px; }
.user-row .ur-access { display: flex; flex-wrap: wrap; gap: 5px; }
.user-row .ur-access .pill { font-size: 10.5px; padding: 2px 8px; }
@media (max-width: 560px) {
  .user-row { grid-template-columns: auto 1fr; }
  .user-row [data-edit] { grid-column: 2; justify-self: start; margin-top: 4px; }
}
