:root {
  --bg: #faf6f0;
  --panel: #ffffff;
  --ink: #2c2622;
  --muted: #8a7f76;
  --line: #ece3d8;
  --accent: #9b2c3a;
  --accent-soft: #f4e3e0;
  --ok: #2f7d5b;
  --ok-soft: #e2f1ea;
  --warn: #b5772a;
  --warn-soft: #f7ecd9;
  --bad: #a33;
  --bad-soft: #f6e0e0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: inherit; text-decoration: none; }

/* ---- Топбар ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand-mark { font-size: 16px; }
.tabs { display: flex; gap: 6px; }
.tab {
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--accent); color: #fff; }
.logout { margin-left: auto; color: var(--muted); font-size: 14px; }
.logout:hover { color: var(--accent); }

.content { padding: 24px 28px; }

/* ---- Вход ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(80, 50, 40, 0.08);
}
.login-brand { font-family: Georgia, serif; font-size: 24px; font-weight: 600; }
.login-sub { color: var(--muted); margin: 6px 0 24px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.05); }
.error { color: var(--bad); font-size: 14px; margin: 10px 0 0; }

/* ---- Переписки ---- */
.split {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
.pane-title { font-size: 15px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 0 0 12px; }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.list-pane, .chat-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.dialog-list { list-style: none; margin: 0; padding: 0; }
.dialog-item { display: block; padding: 12px 14px; border-radius: 12px; margin-bottom: 4px; }
.dialog-item:hover { background: var(--bg); }
.dialog-item.active { background: var(--accent-soft); }
.dialog-head { display: flex; justify-content: space-between; gap: 10px; }
.dialog-name { font-weight: 600; }
.dialog-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dialog-preview { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-pane { min-height: 60vh; display: flex; flex-direction: column; }
.chat-header { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.chat-title { font-weight: 700; font-size: 17px; }
.chat-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chat-thread { display: flex; flex-direction: column; gap: 8px; }
.bubble-row { display: flex; }
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 70%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble-row.in .bubble { background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble-row.out .bubble { background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble-time { color: var(--muted); font-size: 11px; margin-top: 4px; text-align: right; }
.chat-placeholder, .empty { color: var(--muted); padding: 24px; text-align: center; }

/* Форма ответа человеку */
.reply-form { display: flex; gap: 8px; margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.reply-form textarea {
  flex: 1;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
}
.reply-form textarea:focus { outline: none; border-color: var(--accent); }
.reply-form button {
  align-self: flex-end;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.reply-form button:hover { filter: brightness(1.05); }

/* Уведомления */
.flash { padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }

/* ---- Лиды ---- */
.subtabs { display: flex; gap: 8px; margin-bottom: 18px; }
.subtab {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 500;
}
.subtab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.leads-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.leads-table th, .leads-table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.leads-table th { background: var(--bg); color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: 0.4px; }
.leads-table tr:last-child td { border-bottom: none; }
.leads-table a { color: var(--accent); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-paid { background: var(--ok-soft); color: var(--ok); }
.badge-prezapis { background: var(--accent-soft); color: var(--accent); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-started { background: var(--bg); color: var(--muted); }
.badge-rejected { background: var(--bad-soft); color: var(--bad); }

/* ---- Расписание (недельный календарь) ---- */
.schedule-wrap { display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint-inline { color: var(--muted); font-size: 12px; margin-left: 6px; }

.btn-secondary, .btn-danger {
  display: inline-block; padding: 9px 16px; border: none; border-radius: 10px;
  background: var(--ink); color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary {
  display: inline-block; padding: 9px 16px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-danger { background: var(--bad); }
.btn-secondary:hover, .btn-danger:hover, .btn-primary:hover { filter: brightness(1.08); }
.badge-level { background: #eef5ff; color: #3d5a8a; margin-left: 4px; }

.lesson-dialog {
  border: none; border-radius: 16px; padding: 0; max-width: 480px; width: calc(100% - 32px);
  box-shadow: 0 20px 50px rgba(40, 20, 20, 0.18);
}
.lesson-dialog::backdrop { background: rgba(30, 15, 15, 0.35); }
.lesson-dialog-form {
  display: flex; flex-direction: column; gap: 10px; padding: 20px 22px 18px;
}
.lesson-dialog-form label {
  display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px;
}
.lesson-dialog-form input, .lesson-dialog-form select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit;
}
.repeat-toggle { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; }
.repeat-toggle legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.radio-line { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); margin: 4px 0; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }

.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cal-nav { display: flex; gap: 8px; }
.cal-title { font-weight: 600; font-size: 16px; }
.cal-msk { color: var(--muted); font-size: 13px; }

.cal-layout { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }

/* сетка календаря */
.cal { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.cal-gutter { width: 54px; flex: none; border-right: 1px solid var(--line); }
.cal-corner { height: 44px; border-bottom: 1px solid var(--line); }
.cal-hour { font-size: 11px; color: var(--muted); text-align: right; padding: 2px 6px 0 0; box-sizing: border-box; }
.cal-main { flex: 1; min-width: 0; }
.cal-head-row { display: grid; grid-template-columns: repeat(7, 1fr); height: 44px; border-bottom: 1px solid var(--line); }
.cal-head { display: flex; flex-direction: column; align-items: center; justify-content: center; border-left: 1px solid var(--line); font-size: 12px; }
.cal-head:first-child { border-left: none; }
.cal-head-wd { color: var(--muted); text-transform: uppercase; font-size: 11px; }
.cal-head-date { font-weight: 600; }
.cal-head.today .cal-head-date { color: var(--accent); }

.cal-body { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-col { border-left: 1px solid var(--line); }
.cal-col:first-child { border-left: none; }
.cal-col.today { background: #fbf3ef; }
.cal-slot { border-bottom: 1px solid var(--line); }

.cal-event {
  position: absolute; width: calc(100% / 7 - 6px);
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 8px; padding: 4px 6px; overflow: hidden; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 1px; line-height: 1.2;
  min-height: 44px;
}
.cal-event:hover { filter: brightness(0.98); box-shadow: 0 4px 12px rgba(120,40,50,0.12); }
.cal-event.sel { outline: 2px solid var(--accent); }
.ev-time { font-size: 11px; color: var(--accent); font-weight: 600; }
.ev-title { font-size: 12px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.ev-badge { position: absolute; top: 4px; right: 6px; font-size: 10px; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 5px; }

/* аватарки записанных на занятие */
.avatar-legend { font-size: 12px; color: var(--muted); }
.ev-avatars { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; padding-top: 3px; max-height: 40px; overflow: hidden; }
.ev-avatar {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 700; line-height: 1; border: 1.5px solid transparent;
}
.ev-avatar.is-pending {
  opacity: 0.42;
  background: hsl(var(--av-hue, 12), 28%, 90%);
  color: hsl(var(--av-hue, 12), 22%, 58%);
  border-color: hsl(var(--av-hue, 12), 18%, 82%);
}
.ev-avatar.is-confirmed {
  opacity: 1;
  background: hsl(var(--av-hue, 12), 52%, 58%);
  color: #fff;
  border-color: hsl(var(--av-hue, 12), 52%, 44%);
  box-shadow: 0 1px 3px rgba(80, 30, 30, 0.18);
}

.side-enrolled { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.enrolled-avatars { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.enrolled-person { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.enrolled-person.is-pending { opacity: 0.55; }
.enrolled-person.is-confirmed { opacity: 1; }

.enrolled-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; border: 2px solid transparent;
}
.enrolled-person.is-pending .enrolled-avatar {
  background: hsl(var(--av-hue, 12), 28%, 90%);
  color: hsl(var(--av-hue, 12), 22%, 58%);
  border-color: hsl(var(--av-hue, 12), 18%, 82%);
}
.enrolled-person.is-confirmed .enrolled-avatar {
  background: hsl(var(--av-hue, 12), 52%, 58%);
  color: #fff;
  border-color: hsl(var(--av-hue, 12), 52%, 44%);
}
.enrolled-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cal-event.ev-cancelled { background: var(--bad-soft); border-color: var(--bad); opacity: 0.75; }
.cal-event.ev-cancelled .ev-title { text-decoration: line-through; color: var(--muted); }
.cal-event.ev-cancelled .ev-time { color: var(--bad); }

/* боковая панель */
.cal-side .card { position: sticky; top: 84px; }
.side-when { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.side-form { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.side-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.side-form input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; font-family: inherit;
}
.side-form input:focus { outline: none; border-color: var(--accent); }
.side-attend { margin-top: 8px; }

/* формы настроек / разового занятия */
.rule-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 12px; }
.rule-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.rule-form input, .rule-form select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-family: inherit;
}
.rule-form input:focus, .rule-form select:focus { outline: none; border-color: var(--accent); }
.rule-form button {
  padding: 9px 16px; border: none; border-radius: 10px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}

.mini-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.mini-table th, .mini-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 12px; }
.mini-table th { color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; }

.badge-planned { background: var(--ok-soft); color: var(--ok); }
.badge-cancelled { background: var(--bad-soft); color: var(--bad); }
.badge-language_interest { background: #e8eef8; color: #3d5a8a; }

/* ---- База (CRM) ---- */
.base-wrap { display: flex; flex-direction: column; gap: 18px; }
.filter-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 8px; }
.filter-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.filter-form input, .filter-form select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-family: inherit; min-width: 140px;
}
.filter-form button {
  padding: 9px 16px; border: none; border-radius: 10px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer;
}
.broadcast-form textarea {
  width: 100%; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-family: inherit; font-size: 14px; box-sizing: border-box;
}
.broadcast-form button {
  padding: 10px 18px; border: none; border-radius: 10px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer; margin-bottom: 16px;
}
.base-table { margin-top: 8px; }
.base-table th:first-child, .base-table td:first-child { width: 36px; text-align: center; }
.chat-link { color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; }

.feedback-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.feedback-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.feedback-head { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.feedback-time { margin-left: auto; font-size: 12px; }
.feedback-text { margin: 0; white-space: pre-wrap; font-size: 14px; }

/* ---- Бухгалтерия ---- */
.accounting-wrap { display: flex; flex-direction: column; gap: 18px; }
.acc-period { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.acc-period label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.acc-period select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px;
}
.acc-kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.acc-kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.acc-kpi-value { font-size: 22px; font-weight: 700; }
.acc-kpi-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.acc-expense { color: var(--bad); }
.acc-profit-pos { color: var(--ok); }
.acc-profit-neg { color: var(--bad); }
.acc-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; margin-top: 12px; overflow-x: auto; }
.acc-bar-group { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 36px; }
.acc-bars { display: flex; gap: 3px; align-items: flex-end; height: 130px; width: 100%; justify-content: center; }
.acc-bar { width: 10px; border-radius: 4px 4px 0 0; min-height: 2px; }
.acc-bar-in { background: #5a9a6e; }
.acc-bar-out { background: #c96a6a; }
.acc-bar-label { font-size: 10px; color: var(--muted); margin-top: 4px; }
.acc-two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; align-items: start; }
.acc-table-wrap { overflow-x: auto; margin-top: 8px; }
.acc-inline-form { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.acc-input-sm { width: 72px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.acc-form-sep { font-size: 12px; color: var(--muted); }
.btn-xs { padding: 4px 8px !important; font-size: 12px !important; }
.acc-actions { white-space: nowrap; }
.acc-cat-breakdown { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.acc-cat-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.acc-categories { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.acc-cat-list { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; }
.acc-cat-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.acc-cat-add { display: flex; gap: 6px; margin-top: 8px; }
.acc-cat-add input { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .cal-layout { grid-template-columns: 1fr; }
  .cal-side .card { position: static; }
  .acc-two-col { grid-template-columns: 1fr; }
}
