:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --line: #e3e6e1;
  --text: #1e2421;
  --muted: #6b736e;
  --faint: #9aa19c;
  --accent: #356e6a;
  --accent-soft: #e3efed;
  --accent-text: #24524f;
  --warn: #9a6412;
  --warn-soft: #fbf1df;
  --danger: #a33a3a;
  --danger-soft: #f8e6e5;
  --ok: #2f6f3e;
  --ok-soft: #e4f1e6;
  --violet: #5a4a9c;
  --violet-soft: #ecebf8;
  --note: #fff6d6;
  --note-text: #6d5614;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917; --surface: #1d2220; --surface-2: #222826; --line: #2e3532; --text: #e6ebe8;
    --muted: #9aa49f; --faint: #6f7974; --accent: #6fb3ad; --accent-soft: #23403d; --accent-text: #a9dcd6;
    --warn: #e2b264; --warn-soft: #3a2f1c; --danger: #ee8d8d; --danger-soft: #3d2423; --ok: #8fd09d;
    --ok-soft: #213727; --violet: #b4a9ee; --violet-soft: #2c2843; --note: #3a3420; --note-text: #f0dc9c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; white-space: nowrap; transition: background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.err { color: var(--danger); font-size: 13px; margin: 6px 0; }

.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2);
  color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.violet { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.count { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; min-width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }

/* ---------- вход ---------- */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.logo i { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-style: normal; font-weight: 700; }
.auth-card h1 { font-size: 18px; margin: 18px 0 4px; font-weight: 600; }
.auth-card p { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 210px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: 14px 10px; gap: 4px; }
.side .logo { padding: 4px 8px 16px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text);
  text-decoration: none; cursor: pointer; }
.nav:hover { background: var(--surface-2); }
.nav.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot .who { font-weight: 500; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 20px 24px; overflow: auto; height: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 600; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.bottom-nav { display: none; }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 14px; font-size: 13px; display: flex;
  gap: 10px; align-items: center; }

/* ---------- чаты ---------- */
.chats { display: grid; grid-template-columns: 300px minmax(0, 1fr) 290px; height: 100%; min-height: 0; }
.chat-list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column;
  min-height: 0; }
.chat-list .tools { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 3px 10px; border-radius: 99px;
  font-size: 12px; cursor: pointer; }
.chip.on { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.items { overflow: auto; flex: 1; }
.item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column;
  gap: 3px; }
.item:hover { background: var(--surface-2); }
.item.on { background: var(--accent-soft); }
.item .top { display: flex; gap: 6px; align-items: center; }
.item .name { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { font-size: 11px; color: var(--faint); }
.item .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.item .meta { display: flex; gap: 6px; align-items: center; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); line-height: 1.5; }

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex;
  align-items: center; gap: 10px; min-height: 54px; }
.thread-head .title { font-weight: 600; }
.msgs { flex: 1; overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  border-radius: 99px; padding: 2px 10px; margin: 8px 0 4px; }
.bubble { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); align-self: flex-start; line-height: 1.4; word-wrap: break-word; position: relative; }
.bubble.out { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.bubble.note { align-self: flex-end; background: var(--note); color: var(--note-text); border-color: transparent; }
.bubble.failed { border: 1px solid var(--danger); }
.bubble .who { font-size: 11px; font-weight: 600; color: var(--accent-text); margin-bottom: 2px; }
.bubble.note .who { color: var(--note-text); }
.bubble .text { white-space: pre-wrap; }
.bubble .foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px;
  color: var(--faint); margin-top: 2px; }
.bubble .foot button { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0; font-size: 11px; }
.bubble .foot button:hover { color: var(--accent); }
.bubble img.media { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; margin: 2px 0 4px; cursor: zoom-in; }
.bubble video.media { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; margin: 2px 0 4px; }
.bubble audio { max-width: 260px; display: block; margin: 2px 0 4px; }
.bubble .file { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px;
  background: var(--surface-2); margin: 2px 0 4px; text-decoration: none; color: var(--text); }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; font-size: 12px; color: var(--muted);
  background: rgba(0,0,0,.03); border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble .error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.deleted .text { text-decoration: line-through; opacity: .6; }

.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 10px; }
.composer .reply-bar, .composer .file-bar { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted);
  padding: 2px 4px 8px; }
.composer textarea { resize: none; min-height: 40px; max-height: 160px; border-radius: 10px; }
.composer.note-mode textarea { background: var(--note); }
.composer .opts { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); padding: 6px 2px 0; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; }

.info { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; padding: 14px; }
.info h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; text-transform: none; }
.info h3:first-child { margin-top: 0; }
.lesson-mini { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; margin-bottom: 6px; font-size: 13px; }
.lesson-mini .row { justify-content: space-between; }

/* ---------- занятия ---------- */
.week { display: grid; gap: 12px; }
.daycol h2 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.daycol h2 .faint { font-weight: 400; }
.lesson { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.lesson.trial { border-left-color: var(--violet); }
.lesson.st-done { border-left-color: var(--ok); }
.lesson.st-cancelled, .lesson.st-noshow { border-left-color: var(--danger); opacity: .8; }
.lesson.st-moved { border-left-color: var(--warn); opacity: .8; }
.lesson .when { font-weight: 600; min-width: 92px; }
.lesson .what { flex: 1; min-width: 180px; }
.lesson .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- таблицы и отчёты ---------- */
table.t { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; }
table.t th, table.t td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.t th { color: var(--muted); font-weight: 500; background: var(--surface-2); }
table.t tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.fstep { display: grid; grid-template-columns: 170px 1fr 90px; gap: 12px; align-items: center; }
.fbar { height: 28px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.fbar > div { height: 100%; background: var(--accent); border-radius: 6px; min-width: 2px; display: flex;
  align-items: center; padding-left: 8px; color: #fff; font-size: 12px; font-weight: 600; }
.fstep .pct { font-size: 12px; color: var(--muted); text-align: right; }
.reasons div.r { display: grid; grid-template-columns: 1fr 40px; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line);
  font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.section-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

/* ---------- окна ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 18, .45); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 440px; padding: 20px;
  box-shadow: var(--shadow); max-height: 92vh; overflow: auto; }
.modal h2 { margin: 0 0 14px; font-size: 17px; font-weight: 600; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.copybox { display: flex; gap: 6px; }
.copybox input { font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; z-index: 60; font-size: 13px; max-width: 90vw; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center;
  z-index: 70; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

/* ---------- адаптив ---------- */
@media (max-width: 1180px) {
  .chats { grid-template-columns: 280px minmax(0, 1fr); }
  .info { display: none; }
  .chats.show-info .info { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw);
    z-index: 40; box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { display: none; }
  .bottom-nav { display: flex; background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav .nav { flex: 1; flex-direction: column; gap: 2px; font-size: 11px; padding: 7px 2px; border-radius: 0; position: relative; }
  .bottom-nav .nav .count { position: absolute; top: 3px; left: 55%; }
  .chats { grid-template-columns: 1fr; }
  .chats.open .chat-list { display: none; }
  .chats:not(.open) .thread { display: none; }
  .page { padding: 14px; }
  .bubble { max-width: 88%; }
  .grid2 { grid-template-columns: 1fr; }
  .fstep { grid-template-columns: 110px 1fr 60px; }
  .shell.in-thread .bottom-nav { display: none; }
}
::placeholder { color: var(--faint); opacity: 1; }
