:root {
  --bg: #f5efe6;
  --surface: #fffaf3;
  --surface-2: #efe4d3;
  --ink: #1d1a17;
  --muted: #7a6f63;
  --line: #e2d5c1;
  --gold: #b08a4e;
  --gold-ink: #8a6a35;
  --dark: #1d1a17;
  --ok: #3f7d4e;
  --warn: #b5702a;
  --bad: #a83f3f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .06);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f; --surface: #1f1c17; --surface-2: #2a261f; --ink: #f1e9dc; --muted: #a99c8a;
    --line: #38322a; --gold: #c9a467; --gold-ink: #d9b679; --dark: #0c0b09;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 .5em; letter-spacing: .01em; }
h1 { font-size: 1.75rem; line-height: 1.15; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.gold { color: var(--gold-ink); }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--gold); }
.topnav { display: none; gap: 4px; margin-left: 12px; }
.topnav a { text-decoration: none; padding: 8px 12px; border-radius: 999px; color: var(--muted); font-size: .95rem; }
.topnav a.on { background: var(--dark); color: #f5e9d4; }
.topbar .who { margin-left: auto; font-size: .85rem; color: var(--muted); text-align: right; }
.topbar .who a { color: var(--muted); }

/* ---------- нижнее меню (телефон) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--dark);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; text-decoration: none; color: #b7a990; display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: .7rem; padding: 4px 0; min-height: 48px; justify-content: center;
}
.bottomnav a svg { width: 22px; height: 22px; }
.bottomnav a.on { color: #e9c98f; }
.bottomnav a.plus span.dot {
  width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: #1d1a17;
  display: grid; place-items: center; margin-top: -2px;
}
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
}

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } .layout-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; } }
.grid-4 { grid-template-columns: 1fr 1fr; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.right { margin-left: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--dark); color: #f3e3c4; border-color: var(--dark); }
.btn.gold { background: var(--gold); color: #1d1a17; border-color: var(--gold); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn:active { transform: translateY(1px); }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; accent-color: var(--gold); }
.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 1rem; min-height: 40px; }

.flash { background: var(--dark); color: #f3e3c4; padding: 12px 16px; border-radius: 12px; margin-bottom: 12px; }
.error { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad); padding: 12px 16px; border-radius: 12px; margin-bottom: 12px; border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); }
.note { background: var(--surface-2); padding: 12px 14px; border-radius: 12px; font-size: .92rem; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.scheduled { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--gold-ink); }
.badge.done, .badge.sent { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.no_show, .badge.failed { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.badge.cancelled, .badge.no_channel { background: var(--surface-2); color: var(--muted); }
.badge.dry_run { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; font-size: .9rem; background: var(--surface); white-space: nowrap; }
.chip.on { background: var(--dark); color: #f3e3c4; border-color: var(--dark); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- журнал ---------- */
.daybar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daybar h1 { margin: 0; font-size: 1.45rem; flex: 1; text-align: center; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.week a { text-decoration: none; text-align: center; padding: 6px 0; border-radius: 12px; font-size: .78rem; color: var(--muted); }
.week a b { display: block; font-size: 1.05rem; color: var(--ink); }
.week a.on { background: var(--dark); color: #b7a990; }
.week a.on b { color: #f3e3c4; }
.week a.today b { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 3px; }
.week a i { display: block; height: 6px; font-style: normal; }
.week a i::before { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); vertical-align: top; }
.week a i.none::before { display: none; }

.appt { display: flex; gap: 12px; text-decoration: none; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--gold)); }
.appt + .appt { margin-top: 8px; }
.appt .t { font-weight: 700; font-size: 1.05rem; min-width: 52px; }
.appt .t small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.appt .b { flex: 1; min-width: 0; }
.appt .b .n { font-weight: 600; }
.appt.cancelled, .appt.no_show { opacity: .55; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.fab { position: fixed; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 25; width: 56px; height: 56px; border-radius: 50%; background: var(--gold); color: #1d1a17; display: none; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.2); text-decoration: none; font-size: 28px; }

/* ---------- списки ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > a, .list > div { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; border-bottom: 1px solid var(--line); }
.list > :last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; color: var(--gold-ink); flex: none; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .9rem; }
dl.kv dd { margin: 0; font-weight: 500; }

/* ---------- карта клиента ---------- */
.loyalty-card {
  background: radial-gradient(120% 140% at 0% 0%, #2b2620 0%, #14120f 60%); color: #e9d3a8; border-radius: 14px;
  padding: 16px; aspect-ratio: 9 / 5; max-width: 380px; display: flex; flex-direction: column; justify-content: center;
}
.loyalty-card .title { font-family: var(--serif); text-align: center; font-size: 1.1rem; margin-bottom: 10px; letter-spacing: .08em; }
.stamps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; justify-items: center; }
.stamp { width: 100%; max-width: 46px; aspect-ratio: 1; border-radius: 50%; border: 1.5px solid #c9a467; display: grid; place-items: center; font-size: .78rem; }
.stamp.filled { background: #c9a467; color: #14120f; font-weight: 700; }
.stamp.next { box-shadow: 0 0 0 3px rgba(201, 164, 103, .35); }

/* ---------- аналитика ---------- */
.kpi { padding: 14px; }
.kpi .v { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.kpi .l { font-size: .8rem; color: var(--muted); }
.bars .bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: .9rem; padding: 4px 0; }
.bars .track { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--gold); border-radius: 6px; }
.chart-wrap { position: relative; height: 220px; }

table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 500; font-size: .82rem; }
.scroll-x { overflow-x: auto; }

/* ---------- поиск клиента ---------- */
.search-wrap { position: relative; }
.search-results { position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.search-results button { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; cursor: pointer; }
.search-results button:last-child { border-bottom: 0; }
.picked { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--gold); border-radius: 12px; background: color-mix(in srgb, var(--gold) 10%, var(--surface)); }

.offer { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.offer + .offer { margin-top: 8px; }
.offer:has(input:checked) { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--surface)); }
.offer .pct { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; color: var(--gold-ink); min-width: 56px; }
.total { font-family: var(--serif); font-size: 2rem; font-weight: 700; }

details.card summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.card summary::after { content: "＋"; color: var(--gold); }
details.card[open] summary::after { content: "－"; }
details.card[open] summary { margin-bottom: 12px; }
.section-title { margin: 24px 0 10px; }
.shiftbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; margin-bottom: 12px; background: var(--surface-2); border: 1px dashed var(--gold); font-size: .92rem; }
.shiftbar.on { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.shiftbar .grow { flex: 1; min-width: 0; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(63,125,78,.5); } 70% { box-shadow: 0 0 0 8px rgba(63,125,78,0); } 100% { box-shadow: 0 0 0 0 rgba(63,125,78,0); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.login-box { max-width: 380px; margin: 10vh auto 0; }
