:root {
  --bg: #ffffff; --side: #f7f6f2; --panel: #ffffff; --text: #1f2421; --muted: #5f6561; --line: #e7e5df;
  --hover: #efede7; --accent: #10846b; --accent-soft: #e2f3ee; --accent-ink: #0d6e59; --accent-text: #ffffff;
  --red: #b3372e; --red-soft: #fbe3e1; --orange: #8a5300; --orange-soft: #fdf1dc; --blue: #2a5bb0; --blue-soft: #e4edfb;
  --p1: #d1453b; --p2: #e88a1a; --p3: #3a76d8; --p4: #9aa09c;
  --shadow: 0 10px 30px rgba(20, 30, 25, .16), 0 2px 6px rgba(20, 30, 25, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d1c; --side: #222524; --panel: #262928; --text: #e9ebe9; --muted: #a3a9a6; --line: #353938;
    --hover: #2e3231; --accent: #2fb08f; --accent-soft: #1f3a33; --accent-ink: #5fd1b2; --accent-text: #08130f;
    --red: #f08a80; --red-soft: #3d2422; --orange: #e9b062; --orange-soft: #3a2f1c; --blue: #8fb4f0; --blue-soft: #1f2c40;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; min-height: 36px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 14px; border-radius: 8px; background: var(--hover); font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn.pr { background: var(--accent); color: var(--accent-text); }
.btn.gh { background: transparent; border: 1px solid var(--line); }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.on { background: var(--accent-soft); color: var(--accent-ink); }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.mut { color: var(--muted); }
.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--hover); white-space: nowrap; }
.h-up, .h-ok, .h-back { background: var(--accent-soft); color: var(--accent-ink); }
.h-warn { background: var(--orange-soft); color: var(--orange); }
.h-down { background: var(--red-soft); color: var(--red); }
.h-sleep, .h-none { background: var(--hover); color: var(--muted); }
.red { color: var(--red); font-weight: 600; }
.green { color: var(--accent-ink); font-weight: 600; }
.orange { color: var(--orange); font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* раскладка */
#app { display: flex; min-height: 100vh; }
#side { width: 248px; flex: none; background: var(--side); border-right: 1px solid var(--line); padding: 12px 10px 16px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#main { flex: 1; min-width: 0; padding: 24px 32px 80px; display: flex; flex-direction: column; gap: 16px; }
.me { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-weight: 600; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.nav-head { padding: 14px 10px 4px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; min-height: 36px; }
.nav:hover { background: var(--hover); }
.nav.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.side-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.topbar { display: none; }

/* карточки-цифры */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpi .lbl { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.kpi .val { font-size: 22px; font-weight: 700; margin: 4px 0; }
.bar { height: 8px; border-radius: 99px; background: var(--hover); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* задачи */
.task { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.task:last-child { border-bottom: 0; }
.check { width: 20px; height: 20px; border-radius: 50%; border: 1.6px solid var(--p4); flex: none; margin-top: 1px; }
.check.p1 { border-color: var(--p1); background: color-mix(in srgb, var(--p1) 12%, transparent); }
.check.p2 { border-color: var(--p2); background: color-mix(in srgb, var(--p2) 12%, transparent); }
.check.p3 { border-color: var(--p3); background: color-mix(in srgb, var(--p3) 12%, transparent); }
.check.done { background: var(--p4); border-color: var(--p4); }
.task .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; margin-top: 3px; color: var(--muted); }
.due-over { color: var(--red); font-weight: 600; }
.due-today { color: var(--accent-ink); font-weight: 600; }
.due-later { color: #7a4fd0; }
.task.is-done .ttl { text-decoration: line-through; color: var(--muted); }
.group-head { display: flex; align-items: center; gap: 8px; padding: 14px 0 6px; border-bottom: 1px solid var(--line); font-weight: 700; }

/* таблица клиентов */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--side); white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: color-mix(in srgb, var(--hover) 60%, transparent); }
td.num, th.num { text-align: right; }

/* карточка клиента */
.cols { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.col-l { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.col-r { flex: 2 1 480px; min-width: 0; }
.kv { display: flex; gap: 8px; font-size: 13px; padding: 3px 0; }
.kv > span:first-child { color: var(--muted); width: 110px; flex: none; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.feed-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.feed-item .chip { width: 92px; justify-content: center; flex: none; }
.k-Звонок, .k-Макс, .k-Telegram, .k-Письмо { background: var(--blue-soft); color: var(--blue); }
.k-Визит { background: #efe8fb; color: #5b3aa8; }
.k-КП, .k-Образцы { background: var(--orange-soft); color: var(--orange); }
.k-Задача { background: var(--accent-soft); color: var(--accent-ink); }
.contact { padding: 10px 0; border-top: 1px solid var(--line); }
.sales-bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin-top: 8px; }
.sales-bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.sales-bars div.cur { background: var(--p2); }

/* окна */
.overlay { position: fixed; inset: 0; background: rgba(20, 25, 22, .35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal .lbl { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; }
.modal input, .modal select, .modal textarea { width: 100%; }
.pills .btn { white-space: normal; line-height: 1.2; text-align: center; }
.pills { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* вход */
.login { margin: auto; width: min(420px, 100%); padding: 32px 20px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { width: 200px; height: 200px; margin: 0 auto; border-radius: 8px; background: #fff; }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  #side { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  #side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 30; }
  #main { padding: 16px 16px 80px; }
  .grid2 { grid-template-columns: 1fr; }
}
