:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f0f2f5; --line: #e2e5ea; --text: #16191d; --muted: #6b727d;
  --accent: #e8590c; --accent-ink: #fff; --ok: #2b8a3e; --warn: #e67700; --bad: #c92a2a; --info: #1c7ed6; --violet: #7048e8;
  --bubble-in: #ffffff; --bubble-bot: #fff1e6; --bubble-master: #e7f5ff;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114; --panel: #171a1f; --panel2: #1f232a; --line: #2a2f37; --text: #e8eaed; --muted: #8b939e;
    --accent: #ff7a2f; --ok: #51cf66; --warn: #fcc419; --bad: #ff6b6b; --info: #4dabf7; --violet: #9775fa;
    --bubble-in: #1f232a; --bubble-bot: #3a2516; --bubble-master: #13304a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.chk { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chk input { width: auto; }

/* вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.logo { color: var(--accent); font-size: 22px; }

/* шапка */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 15px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs button.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.live { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); flex: none; }
.live.on { background: var(--ok); }
.bot-off { border-color: var(--warn); background: var(--warn); color: #fff; font-weight: 600; }
.sound-off { border-color: var(--warn); color: var(--warn); font-weight: 600; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.pill { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; line-height: 18px; min-width: 18px; text-align: center; }
.menu { position: fixed; right: 16px; top: 54px; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); display: grid; padding: 4px; min-width: 200px; }
.menu button { border: 0; background: none; text-align: left; padding: 9px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--panel2); }

main { padding: 14px 16px 40px; }

/* доска */
.board-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.board-tools input[type=search] { max-width: 340px; }
.board-tools select { width: auto; }
#newOrder { margin-left: auto; }
.push-hint { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 12px; overflow-x: auto; align-items: start; padding-bottom: 8px; }
.col { background: var(--panel2); border-radius: 12px; padding: 8px; min-height: 120px; }
.col h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; gap: 8px; align-items: center; padding: 4px 6px 10px; }
.col h3 .n { margin-left: auto; font-weight: 600; }
.col h3::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); }
.col.hot { outline: 2px solid var(--accent); outline-offset: -2px; }
.card { background: var(--panel); border-radius: var(--r); padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; border-left: 3px solid var(--c, transparent); display: grid; gap: 4px; }
.card:hover { transform: translateY(-1px); }
.card .row { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.card .car { font-weight: 600; }
.card .sub { color: var(--muted); font-size: 12.5px; }
.card .last { color: var(--muted); font-size: 12.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.card.fresh { animation: fresh 1.2s ease 3; }
@keyframes fresh { 50% { box-shadow: 0 0 0 3px var(--accent); } }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11.5px; border-radius: 6px; padding: 1px 6px; background: var(--panel2); color: var(--muted); }
.tag.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.tag.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.info { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 20px 8px; font-size: 13px; }

.st-lead { --c: var(--muted); } .st-waiting_slot { --c: var(--accent); } .st-proposed { --c: var(--violet); } .st-confirmed { --c: var(--ok); }
.st-reschedule_offered { --c: var(--warn); } .st-in_work { --c: var(--info); } .st-done { --c: var(--ok); } .st-cancelled, .st-no_show { --c: var(--bad); }
.status { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; font-weight: 600; color: var(--c); }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }

/* карточка заказа */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(1000px, 100%); background: var(--bg); z-index: 31; display: grid; grid-template-rows: auto 1fr; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
.d-head { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.d-head h2 { font-size: 17px; }
.d-head .close { margin-left: auto; font-size: 18px; }
.d-body { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.d-body.solo { grid-template-columns: minmax(0, 640px); justify-content: center; }
.d-body.solo .d-left { border-right: 0; }
.d-left { overflow-y: auto; padding: 14px 16px; display: grid; gap: 14px; align-content: start; border-right: 1px solid var(--line); }
.d-chat { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; background: var(--panel2); }
.box { background: var(--panel); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.box h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fields label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.fields .wide { grid-column: 1 / -1; }
.phone-link { font-size: 18px; font-weight: 700; color: var(--text); text-decoration: none; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days .wd { font-size: 11px; color: var(--muted); text-align: center; }
.day { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 5px 2px; text-align: center; cursor: pointer; display: grid; gap: 1px; font-size: 13px; }
.day small { font-size: 10.5px; color: var(--muted); }
.day.full small { color: var(--bad); font-weight: 600; }
.day.off { opacity: .45; }
.day.pick { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); font-weight: 700; }
.day.today { box-shadow: inset 0 -2px 0 var(--info); }
.day.blank { visibility: hidden; }
.day.past { opacity: .3; cursor: default; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.month-nav .btn { min-width: 36px; font-size: 18px; line-height: 1; }
.pick-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pick-row input[type=time] { width: 110px; }
.preview { white-space: pre-line; background: var(--bubble-master); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.events { display: grid; gap: 4px; font-size: 12.5px; }
.events div { display: flex; gap: 8px; }
.events time { color: var(--muted); white-space: nowrap; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.switch { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 99px; background: var(--line); position: relative; transition: .2s; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 16px; }
.msgs { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 7px 11px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--bubble-bot); }
.msg.master { background: var(--bubble-master); }
.msg .meta { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; text-align: right; }
.msg-day { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--panel); border-radius: 99px; padding: 1px 10px; margin: 6px 0; }
.composer { display: flex; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { min-height: 40px; max-height: 140px; height: 40px; }

/* календарь */
.cal-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.cal-head h2 { font-size: 17px; min-width: 220px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal .wd { font-size: 12px; color: var(--muted); text-align: center; }
.cal-day { background: var(--panel); border-radius: 10px; min-height: 110px; padding: 6px; display: grid; gap: 4px; align-content: start; box-shadow: var(--shadow); }
.cal-day.off { opacity: .55; }
.cal-day.today { outline: 2px solid var(--info); }
.cal-day .dh { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; }
.cal-day .dh small { color: var(--muted); font-weight: 400; }
.cal-day.full .dh small { color: var(--bad); font-weight: 600; }
.cal-o { font-size: 12px; padding: 3px 6px; border-radius: 6px; background: var(--panel2); cursor: pointer; border-left: 3px solid var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* тест-чат */
.test-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 14px; height: calc(100vh - 110px); }
.test-list { display: grid; gap: 8px; align-content: start; overflow-y: auto; }
.test-item { background: var(--panel); border-radius: 10px; padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.test-item.on { outline: 2px solid var(--accent); }
.test-chat { background: var(--panel2); border-radius: 12px; display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: hidden; }
.test-chat .msg.in { align-self: flex-end; background: var(--bubble-master); }
.test-chat .msg.out { align-self: flex-start; background: var(--bubble-in); }

/* настройки */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; align-items: start; }
.set-grid label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.set-grid label.chk { display: flex; color: var(--text); }
.set-grid textarea.big { min-height: 220px; font-size: 13px; }
#botSet textarea { font-size: 13px; line-height: 1.5; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.users { display: grid; gap: 6px; }
.users .u { display: flex; gap: 8px; align-items: center; justify-content: space-between; background: var(--panel2); border-radius: 8px; padding: 6px 10px; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; background: var(--panel2); padding: 6px 8px; border-radius: 6px; }
.savebar { position: sticky; bottom: 0; padding: 10px 0; display: flex; gap: 10px; align-items: center; background: linear-gradient(transparent, var(--bg) 30%); }

/* уведомления */
.toasts { position: fixed; left: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; width: min(360px, calc(100% - 32px)); }
.toast { background: var(--panel); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); cursor: pointer; white-space: pre-line; font-size: 13px; animation: slide .25s ease; }
.toast b { display: block; margin-bottom: 2px; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .tabs { order: 3; width: 100%; }
  #userBtn { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  main { padding: 12px 16px 40px; }
  .board { grid-auto-columns: 86%; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .d-body { grid-template-columns: 1fr; overflow-y: auto; }
  .d-left { border-right: 0; overflow: visible; }
  .d-chat { min-height: 75vh; }
  .cal { grid-template-columns: 1fr; }
  .cal .wd { display: none; }
  .cal-day { min-height: 0; }
  .cal-day.blank { display: none; }
  .test-wrap { grid-template-columns: 1fr; height: auto; }
  .test-chat { height: 75vh; }
  .set-grid { grid-template-columns: 1fr; }
}

/* цены */
.stats { display: flex; gap: 8px 20px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.stats b { color: var(--text); }
.tag.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.items { display: grid; gap: 6px; }
.item-row { display: grid; grid-template-columns: 1fr 96px auto; gap: 6px; align-items: center; }
.price { text-align: right; font-variant-numeric: tabular-nums; }
.item-total { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.item-total label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); width: 110px; }
.item-total b { font-size: 16px; }

.completed-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.completed-entry { min-width: 0; }
.completed-entry .card { margin-bottom: 4px; }
.completed-date { color: var(--muted); font-size: 12px; padding: 0 8px 8px; }
.completed-pages { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 20px; }
.completed-pages button:disabled { opacity: .4; cursor: default; }
