:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #24302b;
  --muted: #7b8a83;
  --line: #e2e0d8;
  --accent: #3f7d64;
  --accent-soft: #e8f1ec;
  --danger: #b3453a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36, 48, 43, .06), 0 6px 20px rgba(36, 48, 43, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a19;
    --panel: #1f2422;
    --ink: #e7ece9;
    --muted: #93a19a;
    --line: #2e3634;
    --accent: #79b79a;
    --accent-soft: #23302a;
    --danger: #d98a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .9em; }
.error { color: var(--danger); margin-top: 8px; min-height: 1.2em; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

/* ---------- вход ---------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--panel); padding: 32px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 20px; }

/* ---------- каркас ---------- */
#app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 600; font-size: 17px; padding: 0 10px 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink); text-decoration: none; display: flex;
  justify-content: space-between; align-items: center;
}
.sidebar nav a:hover { background: var(--accent-soft); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0 10px; }
.bot-state { font-size: 13px; margin-bottom: 10px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.on { background: #4caf7d; } .dot.off { background: #c0554a; }

main { padding: 26px 30px; max-width: 1200px; }
h2 { margin: 0 0 18px; font-size: 22px; }
h3 { margin: 22px 0 10px; font-size: 16px; }

/* ---------- элементы ---------- */
button {
  background: var(--accent); color: #fff; border: 0; padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
}
button:hover { filter: brightness(1.07); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.link { background: none; color: var(--muted); padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink);
  font: inherit; font-size: 14px;
}
textarea { resize: vertical; }
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label input, label textarea, label select { margin-top: 5px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }
.form-grid .wide, .form-grid h3, .form-grid .row, .form-grid p { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.row > .panel { flex: 1 1 320px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card b { display: block; font-size: 26px; font-weight: 600; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 16px;
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.item .grow { flex: 1; min-width: 0; }
.badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  padding: 1px 7px; font-size: 12px;
}

/* ---------- чаты ---------- */
.chat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: calc(100vh - 100px); }
.chat-list { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.chat-list > div { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.dialog {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer;
}
.dialog:hover { border-color: var(--accent); }
.dialog.active { background: var(--accent-soft); border-color: var(--accent); }
.dialog .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.dialog .snippet {
  color: var(--muted); font-size: 12.5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.chat-pane {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden;
}
.chat-header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 74%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.in { background: var(--accent-soft); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.out { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg .time { display: block; font-size: 11px; opacity: .65; margin-top: 3px; }
.compose { border-top: 1px solid var(--line); padding: 12px 16px; }
.compose-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- календарь ---------- */
.calendar { display: flex; flex-direction: column; gap: 14px; }
.day { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.day h4 { margin: 0 0 10px; font-size: 15px; }
.slots { display: flex; flex-wrap: wrap; gap: 8px; }
.slot {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px;
  font-size: 13px; display: flex; flex-direction: column; gap: 3px; min-width: 130px;
}
.slot.free { border-style: dashed; }
.slot.booked { background: var(--accent-soft); border-color: var(--accent); }
.slot.closed { opacity: .5; }
.slot .who { font-weight: 600; }
.slot .acts { display: flex; gap: 6px; margin-top: 4px; }
.slot .acts button { padding: 3px 8px; font-size: 12px; }
.weekdays { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.weekdays label {
  margin: 0; display: flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.weekdays input { width: auto; margin: 0; }

/* ---------- тост ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 20px;
  border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  main { padding: 18px; }
}

/* ---------- мини-календарь ---------- */
.cal-top { display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 16px; align-items: start; }
.mini-panel { padding: 16px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.mini-head button { padding: 4px 12px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mini-wd { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.mini-day {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 7px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; font-size: 13px; line-height: 1;
}
.mini-day:hover { border-color: var(--accent); }
.mini-day .marks { display: flex; gap: 3px; margin-top: 3px; height: 11px; font-size: 10px; }
.mini-day .marks b { color: var(--accent); font-weight: 700; }
.mini-day .marks i { color: var(--muted); font-style: normal; }
.mini-day.has-booked { background: var(--accent-soft); }
.mini-day.today .n { text-decoration: underline; font-weight: 700; }
.mini-day.picked { background: var(--accent); color: #fff; }
.mini-day.picked .marks b, .mini-day.picked .marks i { color: #fff; }
.mini-total { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }

/* ---------- пометки и диалоги ---------- */
.tag { font-size: 11px; padding: 1px 6px; border-radius: 20px; vertical-align: middle; }
.tag.first { background: var(--accent-soft); color: var(--accent); }
.tag.repeat { background: var(--accent); color: #fff; }
.slot .note {
  font-size: 12px; color: var(--muted); border-left: 2px solid var(--line);
  padding-left: 6px; margin-top: 2px; max-width: 220px;
}
.slot { max-width: 260px; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px;
  background: var(--panel); color: var(--ink); max-width: 460px; width: 92vw;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
label.inline { display: flex; align-items: center; gap: 8px; }
label.inline input { width: auto; margin: 0; }

@media (max-width: 860px) {
  .cal-top { grid-template-columns: 1fr; }
}

/* ---------- легенда мини-календаря ---------- */
.mini-legend {
  display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted);
  align-items: center;
}
.mini-legend b { font-size: 11px; padding: 1px 5px; border-radius: 4px; margin-right: 4px; }
.lg-booked { background: var(--accent); color: #fff; }
.lg-free { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 400; }
/* Записи — залитой плашкой, свободные — контуром: различимо не только цветом */
.mini-day .marks b {
  background: var(--accent); color: #fff; border-radius: 4px; padding: 0 4px; font-weight: 700;
}
.mini-day .marks i {
  border: 1px solid var(--line); border-radius: 4px; padding: 0 3px;
  color: var(--muted); font-style: normal;
}
.mini-day.picked .marks b { background: #fff; color: var(--accent); }
.mini-day.picked .marks i { border-color: rgba(255,255,255,.6); color: #fff; }

/* ---------- вкладка «Записи» ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button.active { background: var(--accent); color: #fff; border-color: transparent; }
.appt-day { margin-bottom: 18px; }
.appt-day-head {
  font-weight: 600; font-size: 14px; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.appt {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 8px;
  display: flex; gap: 14px; align-items: flex-start;
}
.appt-time {
  font-size: 17px; font-weight: 600; min-width: 58px;
  color: var(--accent); padding-top: 1px;
}
.appt-name { font-weight: 600; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.appt-note {
  font-size: 13px; color: var(--muted); margin-top: 5px;
  border-left: 2px solid var(--line); padding-left: 8px;
}
.appt-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.appt-acts button { padding: 4px 10px; font-size: 12.5px; }

@media (max-width: 720px) {
  .appt { flex-wrap: wrap; }
  .appt-acts { width: 100%; justify-content: flex-start; }
}

/* ---------- цветовые темы ---------- */
:root[data-theme="ocean"]    { --accent: #2f6f9f; --accent-soft: #e6eff6; }
:root[data-theme="sand"]     { --accent: #b4693f; --accent-soft: #f7ece5; }
:root[data-theme="lavender"] { --accent: #6c5aa8; --accent-soft: #eeeaf7; }
:root[data-theme="graphite"] { --accent: #4a5560; --accent-soft: #eaeef1; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="ocean"]    { --accent: #6fb0da; --accent-soft: #1d2b36; }
  :root[data-theme="sand"]     { --accent: #dd9b74; --accent-soft: #332520; }
  :root[data-theme="lavender"] { --accent: #a394de; --accent-soft: #262133; }
  :root[data-theme="graphite"] { --accent: #9aa7b4; --accent-soft: #232a30; }
}

.themes { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.theme-chip {
  background: transparent; color: var(--ink); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 7px; padding: 7px 12px; font-size: 13px;
}
.theme-chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.theme-chip .swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }

/* ---------- вложения и быстрые ответы ---------- */
.quick-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.quick-bar .quick { padding: 4px 10px; font-size: 12.5px; }
.msg-media {
  display: block; max-width: 260px; max-height: 260px; width: auto;
  border-radius: 8px; margin-bottom: 6px; cursor: pointer;
}
.msg-file {
  display: inline-block; margin-bottom: 4px; text-decoration: none;
  color: inherit; border-bottom: 1px dashed currentColor;
}
.msg.out .msg-file { color: #fff; }

/* ---------- диаграмма загрузки ---------- */
/* Серый «свободно» проверен валидатором палитры: отделяется от акцента любой
   темы (ΔE 19.8+ и при дальтонизме), но сам к фону контрастнее 3:1 не тянет —
   поэтому у сегмента есть обводка, а числа продублированы в подсказке и таблице. */
:root { --chart-free: #a9b2ae; --chart-free-stroke: #8b958f; }
@media (prefers-color-scheme: dark) {
  :root { --chart-free: #5c6864; --chart-free-stroke: #77837e; }
}

.chart-panel { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .hit { cursor: crosshair; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.lg-swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.lg-swatch.booked { background: var(--accent); }
.lg-swatch.free { background: var(--chart-free); border: 1px solid var(--chart-free-stroke); }

.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--ink); color: var(--bg); font-size: 12px; line-height: 1.35;
  padding: 6px 9px; border-radius: 7px; white-space: nowrap;
}

.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.mini-table th, .mini-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.mini-table th { color: var(--muted); font-weight: 500; }
.mini-table tr.sum td { font-weight: 600; border-bottom: 0; }

/* ---------- история клиента ---------- */
#history-dialog { max-width: 520px; }
#history-body { max-height: 60vh; overflow-y: auto; }
.hist-row { padding: 9px 0; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.hist-row.off { opacity: .55; }
.hist-note {
  font-size: 13px; color: var(--muted); margin-top: 4px;
  border-left: 2px solid var(--line); padding-left: 8px;
}
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chat-header button { padding: 4px 10px; font-size: 12.5px; }

/* ---------- сотрудники ---------- */
.who { font-size: 12.5px; margin-bottom: 8px; line-height: 1.3; }
.who .role { display: block; color: var(--muted); font-size: 11.5px; }
.item.off { opacity: .55; }
.item select { width: auto; min-width: 130px; padding: 5px 8px; font-size: 13px; }
.item button { padding: 5px 10px; font-size: 12.5px; }
.role-row { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; flex-wrap: wrap; }
.role-row b { min-width: 120px; }

/* ---------- специалисты ---------- */
.spec-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.spec-line { font-size: 12px; color: var(--muted); display: flex; align-items: center; }
.slot .spec-line { margin-top: 2px; }

/* ---------- журнал ---------- */
.audit-row { align-items: flex-start; }
.audit-time { font-size: 12px; color: var(--muted); min-width: 96px; padding-top: 2px; }
