:root {
  --bg: #f6f7f5; --card: #ffffff; --ink: #1d2421; --muted: #6b7570; --line: #e4e8e5;
  --accent: #2f8f78; --accent-ink: #ffffff; --accent-soft: #e3f2ed;
  --wait: #3b82c4; --wait-soft: #e3eef8; --came: #2f8f78; --came-soft: #def1e9;
  --confirmed: #7a5cc2; --confirmed-soft: #ece6f8; --noshow: #c2553f; --noshow-soft: #f8e5e0; --cancel: #9aa39e; --cancel-soft: #eef0ef;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Каркас: боковое меню на широком экране, нижняя панель на телефоне */
.app { display: flex; height: 100vh; height: 100dvh; }
.nav { width: 220px; background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.nav .brand { font-weight: 700; font-size: 18px; padding: 4px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 10px; border-radius: 10px; cursor: pointer; text-align: left; color: var(--muted); font-weight: 500; }
.nav button svg { width: 22px; height: 22px; flex: none; }
.nav button.on { background: var(--accent-soft); color: var(--accent); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; overflow-y: auto; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; min-height: 60px; }
.topbar .grow { flex: 1; min-width: 0; }
.page { padding: 16px; max-width: 980px; width: 100%; }
.page.wide { max-width: none; padding: 0; }
@media (max-width: 760px) {
  .nav { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: auto; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; justify-content: space-around; }
  .nav .brand { display: none; }
  .nav button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; align-items: center; }
  .nav button.on { background: none; }
  .main { padding-bottom: 72px; }
}

/* Элементы */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--noshow-soft); color: var(--noshow); }
.btn.ghost { background: none; color: var(--ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--ink); flex: none; }
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 22px; height: 22px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: #fafbfa; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #cfd6d2; border-radius: 99px; transition: .2s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 100; font-size: 14px; max-width: calc(100% - 32px); }

/* Модальное окно: снизу на телефоне, по центру на компьютере */
.sheet-bg { position: fixed; inset: 0; background: rgba(20,25,22,.4); z-index: 50; display: flex; align-items: center; justify-content: center; }
.sheet { background: var(--card); border-radius: 18px; width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; flex: 1; }
.sheet-body { padding: 16px 18px; overflow-y: auto; }
.sheet-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; }
@media (max-width: 760px) { .sheet-bg { align-items: flex-end; } .sheet { border-radius: 18px 18px 0 0; max-height: 94vh; } }

/* Журнал */
.week { display: flex; gap: 4px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.week button { flex: 1; border: 0; background: none; border-radius: 12px; padding: 6px 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.week button b { font-size: 17px; }
.week button span { font-size: 12px; color: var(--muted); }
.week button.weekend span { color: var(--noshow); }
.week button.on { background: var(--accent); color: #fff; }
.week button.on span { color: #dff3ec; }
.week button.today:not(.on) b { color: var(--accent); }
.grid-wrap { overflow: auto; flex: 1; background: var(--card); }
.grid { display: grid; position: relative; min-width: 100%; }
.grid .corner { position: sticky; top: 0; left: 0; z-index: 4; background: var(--card); border-bottom: 1px solid var(--line); }
.grid .col-head { position: sticky; top: 0; z-index: 3; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 6px; text-align: center; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid .times { position: sticky; left: 0; z-index: 2; background: var(--card); }
.grid .time { font-size: 12px; color: var(--muted); text-align: right; padding-right: 8px; transform: translateY(-8px); }
.grid .col { position: relative; border-left: 1px solid var(--line); }
.grid .slot { border-top: 1px solid #f1f3f2; cursor: pointer; }
.grid .slot.hour { border-top-color: var(--line); }
.grid .slot.off { background: repeating-linear-gradient(135deg, #f6f7f6 0 6px, #fbfbfb 6px 12px); }
.grid .slot:hover { background: var(--accent-soft); }
.appt { position: absolute; left: 3px; right: 3px; border-radius: 10px; padding: 5px 8px; font-size: 13px; overflow: hidden; cursor: pointer; border-left: 4px solid; line-height: 1.3; }
.appt b { display: block; font-size: 12px; }
.appt.wait { background: var(--wait-soft); border-color: var(--wait); }
.appt.came { background: var(--came-soft); border-color: var(--came); }
.appt.confirmed { background: var(--confirmed-soft); border-color: var(--confirmed); }
.appt.brk { background: repeating-linear-gradient(135deg, #eceeed 0 6px, #f5f6f5 6px 12px); border-color: var(--cancel); color: var(--muted); }
.appt.noshow { background: var(--noshow-soft); border-color: var(--noshow); }
.appt.cancelled { background: var(--cancel-soft); border-color: var(--cancel); color: var(--muted); text-decoration: line-through; }
.appt .online { font-size: 11px; color: var(--accent); font-weight: 600; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--noshow); z-index: 1; pointer-events: none; }
.fab { position: fixed; right: 18px; bottom: 90px; width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: #fff; border: 0; box-shadow: 0 6px 20px rgba(47,143,120,.4); display: grid; place-items: center; cursor: pointer; z-index: 15; }
.fab svg { width: 26px; height: 26px; }
@media (min-width: 761px) { .fab { bottom: 24px; } }

/* Календарь месяца */
.month h3 { margin: 14px 0 8px; font-size: 16px; }
.month .dow, .month .days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 4px; }
.month .dow span { font-size: 12px; color: var(--muted); }
.month .days button { aspect-ratio: 1; border: 0; background: none; border-radius: 50%; cursor: pointer; position: relative; font-weight: 500; }
.month .days button.has { font-weight: 700; }
.month .days button.on { background: var(--accent); color: #fff; }
.month .days .bar { position: absolute; left: 25%; right: 25%; bottom: 4px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.month .days .bar i { display: block; height: 100%; background: var(--accent); }

/* График работы */
.sched { overflow-x: auto; }
.sched table { border-collapse: separate; border-spacing: 4px; }
.sched th { font-weight: 500; font-size: 13px; color: var(--muted); min-width: 66px; }
.sched th.weekend { color: var(--noshow); }
.sched td.name { font-weight: 600; font-size: 14px; position: sticky; left: 0; background: var(--bg); padding-right: 6px; min-width: 90px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched td.cell { background: var(--card); border-radius: 10px; height: 54px; font-size: 12px; text-align: center; cursor: pointer; border: 2px solid transparent; line-height: 1.25; }
.sched td.cell.work { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sched td.cell.sel { border-color: var(--ink); }

/* Аналитика */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .l { font-size: 13px; color: var(--muted); }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }

/* Вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 24px; }

/* Перенос записи */
.appt { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.appt.lifted { opacity: .45; }
.appt.ghost { border-style: dashed; border-width: 2px 2px 2px 4px; box-shadow: 0 8px 24px rgba(0,0,0,.15); z-index: 5; opacity: .95; }
body.dragging { overflow: hidden; }
.drag-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); z-index: 40; box-shadow: 0 -6px 20px rgba(0,0,0,.08); }
