/* Мобильная вёрстка первична: ссылку открывают с телефона во встроенном
   браузере Telegram. */
:root {
  --bg: #fbfaf8;
  --card: #ffffff;
  --ink: #1a1a19;
  --muted: #6b6a66;
  --line: #e3e0da;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #a2392b;
  --bad-bg: #fdf3f1;
  --ok-bg: #eef6f1;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #1e2024;
    --ink: #e9e7e3;
    --muted: #9a978f;
    --line: #32353b;
    --accent: #6fbf90;
    --accent-ink: #12251a;
    --danger: #e08476;
    --bad-bg: #2c2020;
    --ok-bg: #1d2a22;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; }
.wrap.narrow { max-width: 520px; }

h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 20px 0 6px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.dim { opacity: 0.5; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}

.flash { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--bad-bg); color: var(--danger); }
.empty { color: var(--muted); padding: 14px 0; }
.err { color: var(--danger); font-size: 13px; margin-top: 4px; }
.hint { display: block; color: var(--muted); font-size: 12px; }
.badge { background: var(--ok-bg); color: var(--accent); border-radius: 20px; padding: 3px 10px; font-size: 13px; white-space: nowrap; }

label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }

button {
  font: inherit; font-weight: 500; cursor: pointer;
  padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  min-height: 44px; /* палец, а не курсор */
}
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { color: var(--danger); }
form { margin: 0; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.row .grow { flex: 1 1 240px; }
.row input { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.full { display: block; }

table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.bad td { background: var(--bad-bg); }

.days { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.day { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.day label { margin-bottom: 8px; }
.day input[type=time] { margin-bottom: 6px; }

/* --- страница гостя --- */
.guest-head { margin-bottom: 18px; }
.guest-head .meta { color: var(--muted); font-size: 14px; }
.owner-profile { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.owner-profile p { margin: 0; }
.avatar {
  display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center;
  border-radius: 50%; object-fit: cover; background: var(--line); color: var(--muted);
  border: 1px solid var(--line);
}
.avatar-guest { width: 64px; height: 64px; }
.avatar-admin { width: 72px; height: 72px; font-size: 28px; font-weight: 600; }
.avatar-placeholder { text-transform: uppercase; }
.profile-editor { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.profile-editor label { flex: 1 1 auto; min-width: 0; margin: 0; }
body.cropper-open { overflow: hidden; }
.cropper-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0, 0, 0, 0.68);
}
.cropper-card {
  width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 18px; border-radius: 14px; background: var(--card); color: var(--ink);
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.35);
}
.crop-frame {
  position: relative; width: min(320px, 78vw); aspect-ratio: 1;
  margin: 12px auto; overflow: hidden; background: #111; touch-action: none;
}
.crop-frame canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.crop-frame canvas:active { cursor: grabbing; }
.crop-frame::after {
  content: ""; position: absolute; inset: 1px; pointer-events: none;
  border: 2px solid rgba(255, 255, 255, 0.95); border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.52);
}
.crop-zoom { margin: 12px 0; }
.crop-actions { justify-content: flex-end; }
.tzrow { margin-bottom: 18px; }
.dayhead { font-size: 15px; margin: 20px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
button.slot { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
button.slot:hover { border-color: var(--accent); color: var(--accent); }
.chosen { font-size: 17px; }
dl { margin: 0; font-size: 14px; }
dt { color: var(--muted); font-size: 13px; margin-top: 10px; }
dd { margin: 2px 0 0; }

/* ссылка, выглядящая как кнопка */
a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px; border-radius: 8px;
  border: 1px solid transparent; background: var(--accent);
  color: var(--accent-ink); text-decoration: none; font-weight: 500;
}
a.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }

ul.links { list-style: none; padding: 0; margin: 0 0 14px; }
ul.links li { padding: 6px 0; border-bottom: 1px solid var(--line); }
ul.links li:last-child { border-bottom: none; }
ul.links a { font-weight: 500; margin-right: 8px; white-space: nowrap; }

/* --- недельная сетка --- */
.weekbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.weekbar .btn { min-height: 38px; padding: 6px 14px; }
.weekrange { flex: 1 1 auto; }
.weekrange span { display: block; }
.weekbar select { width: auto; margin: 0; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legenditem { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.key.free { background: var(--ok-bg); border: 1.5px solid var(--accent); }
.key.busy { background: var(--line); border: 1px solid var(--muted); }
.key.booking { background: var(--accent); }

.week {
  display: grid;
  grid-template-columns: 46px repeat(7, minmax(84px, 1fr));
  gap: 0;
  margin: 14px 0 18px;
  overflow-x: auto;       /* на телефоне неделя прокручивается вбок */
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
/* колонка часов остаётся на месте при горизонтальной прокрутке недели */
.hours {
  position: sticky; left: 0; z-index: 5;
  height: 620px; margin-top: 30px;
  border-right: 1px solid var(--line); background: var(--card);
}
.hours::before {
  content: ""; position: absolute; left: 0; right: 0; top: -30px; height: 30px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.hourmark {
  position: absolute; right: 6px; z-index: 1; transform: translateY(-50%);
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.daycol { border-right: 1px solid var(--line); }
.daycol:last-child { border-right: none; }
.daycol.today { background: var(--ok-bg); }
.dayname {
  height: 30px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500; border-bottom: 1px solid var(--line);
}
.daycol.today .dayname { color: var(--accent); }
.track { position: relative; height: 620px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); opacity: 0.5; }

.ev {
  position: absolute; left: 2px; right: 2px;
  border-radius: 4px; padding: 1px 4px; overflow: hidden;
  font-size: 10px; line-height: 1.25;
}
.ev b { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.ev span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.free { background: var(--ok-bg); border: 1px solid var(--accent); color: var(--accent); }
.ev.busy { background: var(--line); color: var(--ink); opacity: 0.85; z-index: 2; }
.ev.booking { background: var(--accent); color: var(--accent-ink); z-index: 3; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); white-space: nowrap;
}

/* --- выбор длительности и навигация по дням --- */
.field { margin-bottom: 16px; }
.fieldname { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: 20px; min-height: 40px;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.daystrip {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px;
  margin-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.daychip {
  flex: 0 0 auto; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; min-height: 46px; line-height: 1.2;
}
.daychip b { display: block; font-size: 12px; font-weight: 600; }
.daychip span { display: block; font-size: 11px; color: var(--muted); }
.daychip:hover { border-color: var(--accent); }

/* --- переключатель вида и месячная сетка --- */
.viewtoggle { display: flex; gap: 0; margin-bottom: 16px; }
.viewtoggle button {
  flex: 1 1 50%; background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 0; min-height: 40px;
  font-size: 14px;
}
.viewtoggle button:first-child { border-radius: 8px 0 0 8px; }
.viewtoggle button:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.viewtoggle button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.calhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.calhead strong { font-size: 16px; }
.calhead button { min-height: 38px; padding: 6px 16px; }
.calhead button:disabled { opacity: 0.35; cursor: default; }

.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 18px; }
.calname { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.calday {
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; min-height: 46px; padding: 4px 2px; line-height: 1.1;
}
.calday b { display: block; font-size: 14px; font-weight: 500; }
.calday span { display: block; font-size: 10px; color: var(--accent); min-height: 12px; }
.calday:not(.off):not(.on) { border-color: var(--accent); background: var(--ok-bg); }
.calday.off { opacity: 0.35; background: transparent; }
.calday.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.calday.on span { color: var(--accent-ink); }

/* --- недельная сетка на странице гостя --- */
.guestweek {
  grid-template-columns: 46px repeat(var(--visible-days, 7), minmax(84px, 1fr));
  margin: 0 0 10px;
}
.guestweek .hours, .guestweek .track { height: 520px; }
.guestweek .dayname { font-size: 11px; }
/* Свободное время — область, а не россыпь кнопок. Пока гость не указал место,
   ему незачем видеть все возможные начала встречи: их десятки, и каждое из них
   ничего не значит само по себе. */
.freezone {
  position: absolute; left: 2px; right: 2px;
  border-radius: 6px; overflow: hidden; cursor: pointer;
  background: var(--ok-bg);
  border: 1px dashed var(--accent);
}
.freezone:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.zonelabel {
  position: absolute; left: 5px; right: 5px; top: 2px; pointer-events: none;
  font-size: 10px; line-height: 1.2; color: var(--accent);
  font-variant-numeric: tabular-nums; opacity: 0.8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.freezone.on .zonelabel { opacity: 0.35; }
/* Призрак будущей встречи: показывает не точку, а кусок времени, который она
   займёт, и ездит за курсором, прилипая к разрешённым началам. */
.slotghost {
  position: absolute; left: 0; right: 0; min-height: 18px;
  display: none; align-items: center; gap: 4px;
  padding: 1px 5px; border-radius: 5px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; line-height: 1.2; pointer-events: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
  transition: top 90ms ease-out, height 90ms ease-out;
}
.freezone.on .slotghost { display: flex; }
.slotghost b { font-weight: 600; font-variant-numeric: tabular-nums; }
.slotghost span { opacity: 0.75; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .slotghost { transition: none; } }

.mobile-continue {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -5px 18px rgba(0, 0, 0, 0.14);
}
.mobile-choice { flex: 1 1 auto; min-width: 0; line-height: 1.25; }
.mobile-choice span { display: block; color: var(--muted); font-size: 11px; }
.mobile-choice strong {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.mobile-continue button { flex: 0 0 auto; }

/* --- страница гостя: узкая на телефоне, просторная на десктопе --- */
.wrap.guest { max-width: 560px; }
@media (min-width: 900px) {
  .wrap.guest { max-width: 1060px; padding-top: 32px; }
  .wrap.guest .guest-head { max-width: 720px; }
  .wrap.guest h1 { font-size: 32px; }
  .guestweek { grid-template-columns: 58px repeat(var(--visible-days, 7), minmax(120px, 1fr)); }
  .guestweek .hours, .guestweek .track { height: 660px; }
  .guestweek .dayname { height: 36px; font-size: 13px; }
  .guestweek .hours { margin-top: 36px; }
  .guestweek .hours::before { top: -36px; height: 36px; }
  .zonelabel, .slotghost { font-size: 12px; }
  .slotghost { min-height: 22px; }
  .calgrid { gap: 6px; max-width: 720px; }
  .calday { min-height: 62px; }
  .calday b { font-size: 16px; }
  .calname { font-size: 13px; }
  .calhead, #daytimes, #listview, .viewtoggle, .field { max-width: 720px; }
  .slots { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); max-width: 720px; }
}

/* форма записи остаётся узкой в любом случае — это короткая анкета */
.formcard { max-width: 520px; }
.backlink {
  background: none; border: none; padding: 0 0 10px; min-height: 0;
  color: var(--accent); font-size: 14px; font-weight: 500;
}
.backlink:hover { text-decoration: underline; }
.formcard button[type=submit] { width: 100%; }

details.howto { margin: 10px 0 14px; font-size: 14px; }
details.howto summary { cursor: pointer; color: var(--accent); }
details.howto ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); }
details.howto li { margin-bottom: 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
       background: var(--bg); padding: 1px 5px; border-radius: 4px; }
