:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #efe8dc;
  --ink: #1d2520;
  --muted: #6d756f;
  --line: #ddd4c7;
  --green: #2f8f67;
  --amber: #b46f16;
  --red: #c64b43;
  --blue: #286c9d;
  --shadow: 0 18px 48px rgba(54, 45, 33, 0.14);
  --radius: 8px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: #d9d2c7;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(76, 121, 91, 0.18), transparent 27rem),
    linear-gradient(135deg, #e8dfd2, #cfd9d6);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  color: inherit;
  cursor: pointer;
}

a {
  color: inherit;
}

.phone-frame {
  width: min(100%, 480px);
  min-height: 100svh;
  margin: 0 auto;
  overflow-x: hidden;
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(29, 37, 32, 0.08), var(--shadow);
}

.app {
  min-height: 100svh;
}

.screen {
  min-height: 100svh;
  overflow-x: hidden;
  padding: 16px 16px calc(92px + env(safe-area-inset-bottom));
}

.screen--login {
  display: grid;
  align-content: center;
  min-height: 100svh;
  padding: 28px;
  background: #edf4ee;
}

.login-card {
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.auth-segment,
.auth-form {
  margin-top: 12px;
}

.brand {
  display: grid;
  gap: 6px;
  margin-bottom: 22px;
}

.brand__mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  color: #fffdf8;
  background: #365b48;
  font-weight: 800;
}

.brand h1,
.topbar h1,
.view-title {
  margin: 0;
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand p,
.topbar p,
.muted {
  margin: 0;
  color: var(--muted);
}

.topbar {
  position: sticky;
  z-index: 12;
  top: 0;
  margin: -16px -16px 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(221, 212, 199, 0.7);
  background: rgba(247, 243, 234, 0.92);
  backdrop-filter: blur(18px);
}

.topbar__row,
.row,
.split,
.card-row,
.actions {
  display: flex;
  align-items: center;
}

.topbar__row,
.split {
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.row,
.card-row,
.actions {
  gap: 8px;
}

.actions {
  flex-wrap: wrap;
}

.actions--wide > .btn {
  flex: 1 1 130px;
}

.range-presets > .btn {
  flex: 1 1 86px;
}

.searchbar,
.segment,
.tabs,
.field,
.stack,
.grid,
.list,
.form-grid {
  display: grid;
  gap: 10px;
}

.searchbar {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.segment,
.tabs {
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  overflow-x: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segment button,
.tabs button {
  min-height: 38px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.segment .is-active,
.tabs .is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 5px 14px rgba(54, 45, 33, 0.1);
}

.segment--presets {
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  overflow-x: visible;
}

.segment--presets button {
  white-space: normal;
}

.card,
.empty,
.error,
.stat,
.template-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card {
  padding: 12px;
  min-width: 0;
}

.card--button {
  display: block;
  width: 100%;
  text-align: left;
}

/* .stack задаёт display:grid раньше в файле — при равной специфичности
   .card--button.display:block перебивает его и съедает gap между строками. */
.card--button.stack {
  display: grid;
}

.request-open {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.request-card {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.request-card--new {
  border-color: rgba(47, 143, 103, 0.28);
  box-shadow: inset 3px 0 0 rgba(47, 143, 103, 0.24);
}

.request-card--lost {
  border-color: rgba(198, 75, 67, 0.24);
  box-shadow: inset 3px 0 0 rgba(198, 75, 67, 0.18);
}

.request-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.request-name {
  display: block;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.28;
}

.request-line {
  align-items: baseline;
}

/* Строка назначенного тура в компактной карточке — своя строка на всю ширину,
   чтобы длинные ФИО и названия туров не выдавливали друг друга. */
.request-card__tour {
  display: block;
  min-width: 0;
  margin-top: -6px;
  text-align: left;
}

.request-amount {
  display: grid;
  justify-items: end;
  font-size: 14px;
  white-space: nowrap;
}

.request-rest {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.request-rest--paid {
  color: var(--green);
}

.meta.request-received {
  display: block;
  font-size: 12px;
}

.request-details {
  display: grid;
  gap: 10px;
}

.request-details summary {
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.status-select {
  width: auto;
  min-width: 118px;
  min-height: 34px;
  padding: 0 26px 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-select.badge--blue,
.status-select.badge--amber,
.status-select.badge--red {
  border-color: transparent;
}

.date-filter {
  display: flex;
  gap: 8px;
  align-items: center;
}

.date-filter__field {
  flex: 1;
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
  text-align: left;
  font-weight: 800;
}

.range-picker {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.range-picker__head,
.range-weekdays,
.range-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.range-picker__head {
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  text-align: center;
}

.range-picker__head strong {
  text-transform: capitalize;
}

.range-weekdays span {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  font-weight: 800;
}

.range-day {
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.range-day--blank {
  min-height: 36px;
}

.range-day.is-today {
  outline: 1px solid rgba(40, 108, 157, 0.4);
}

.range-day.is-in-range {
  background: #edf4ee;
}

.range-day.is-selected {
  color: #fffdf8;
  background: #365b48;
}

.card:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(40, 108, 157, 0.52);
  outline-offset: 2px;
}

.tour-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
}

.date-tile {
  display: grid;
  place-items: center;
  align-self: start;
  min-height: 58px;
  border-radius: var(--radius);
  color: #fffdf8;
  background: #365b48;
  line-height: 1;
}

.date-tile strong {
  font-size: 20px;
}

.date-tile span {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.card h2,
.card h3,
.modal h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.18;
}

.card p {
  margin: 0;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.booking-desired-dates {
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: #365b48;
  background: #dfece4;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge-row {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}

.badge--amber {
  color: #744404;
  background: #f3dfb8;
}

.badge--red {
  color: #8b2722;
  background: #f7d7d4;
}

.badge--blue {
  color: #174c70;
  background: #d8e8f3;
}

.progress {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8e0d4;
}

.progress span {
  display: block;
  width: var(--value);
  max-width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--bar, var(--green));
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats--four {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  padding: 12px;
  min-width: 0;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: max(0px, calc((100vw - 480px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 480px) / 2));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(221, 212, 199, 0.9);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  display: grid;
  gap: 3px;
  place-items: center;
  min-height: 54px;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
}

.bottom-nav .is-active {
  color: var(--ink);
  background: var(--surface-2);
}

.nav-icon {
  font-size: 18px;
  line-height: 1;
}

.fab {
  position: fixed;
  z-index: 18;
  right: max(18px, calc((100vw - 480px) / 2 + 18px));
  bottom: calc(84px + env(safe-area-inset-bottom));
  min-width: 112px;
  padding: 0 16px;
  border-radius: 999px;
  color: #fffdf8;
  background: #365b48;
  box-shadow: 0 16px 30px rgba(54, 91, 72, 0.28);
  font-weight: 800;
}

.fab--secondary {
  right: auto;
  left: max(18px, calc((100vw - 480px) / 2 + 18px));
  min-width: 0;
  color: #365b48;
  background: #fffdf8;
  border: 1px solid rgba(54, 91, 72, 0.35);
  box-shadow: 0 16px 30px rgba(54, 91, 72, 0.16);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.btn--primary {
  color: #fffdf8;
  border-color: #365b48;
  background: #365b48;
}

.btn--danger {
  color: #fffdf8;
  border-color: var(--red);
  background: var(--red);
}

.btn--ghost {
  background: transparent;
}

.btn--block {
  width: 100%;
}

.icon-btn {
  width: 44px;
  padding: 0;
}

.btn--compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.btn--contact {
  min-height: 32px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.icon-btn.btn--compact {
  width: 34px;
}

.contact-row {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

/* Панель действий заявки: связь с клиентом и системные кнопки — раздельными строками. */
.action-bar {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.action-bar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.action-bar__label {
  flex: none;
}

.phone-field {
  display: grid;
  gap: 6px;
}

.phone-field__actions {
  justify-content: flex-start;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.participant-row {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.participant-row__meta {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  min-width: 0;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.file-input {
  display: none;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-section-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.template-choice {
  display: grid;
  gap: 7px;
}

.template-slug {
  display: inline-block;
}

.form-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  align-items: end;
  padding: 18px max(12px, calc((100vw - 480px) / 2 + 12px));
  background: rgba(29, 37, 32, 0.34);
}

.modal[hidden] {
  display: none;
}

.modal__panel {
  max-height: min(86svh, 760px);
  overflow: auto;
  /* Дойдя до края формы, прокрутка не должна передаваться экрану под ней. */
  overscroll-behavior: contain;
  padding: 14px;
  border-radius: 12px 12px 8px 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
  will-change: transform;
}

/* Полоска-«грип» вверху формы — подсказка, что можно потянуть вниз, чтобы закрыть. */
.modal__grip {
  position: sticky;
  top: -14px;
  z-index: 3;
  width: 40px;
  height: 4px;
  margin: -8px auto 4px;
  border-radius: 999px;
  background: var(--line);
  cursor: grab;
}

/* Пока открыта модалка или ваучер, фон не прокручивается. */
html.modal-open,
html.modal-open body,
html.voucher-open,
html.voucher-open body {
  overflow: hidden;
}

/* Кнопки формы прилипают к низу модалки — не нужно листать до конца */
.form-actions {
  position: sticky;
  z-index: 2;
  bottom: -14px;
  display: flex;
  gap: 8px;
  margin: 2px -14px -14px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: rgba(247, 243, 234, 0.96);
  backdrop-filter: blur(14px);
}

.form-actions .btn {
  flex: 1;
}

.request-tour {
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

p.request-tour {
  margin: 0;
}

.request-tour--link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(54, 91, 72, 0.45);
  text-underline-offset: 3px;
}

.request-tour--link:active {
  opacity: 0.65;
}

.request-wish {
  font-weight: 600;
}

.overlap-list {
  display: grid;
}

.overlap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 4px 0;
  border: 0;
  border-bottom: 1px dashed var(--line);
  background: none;
  text-align: left;
  font-size: 12px;
  color: inherit;
  cursor: pointer;
}

.overlap-row:last-child {
  border-bottom: 0;
}

.overlap-row__main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.overlap-row .badge {
  flex: none;
}

.form-payments {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(54, 91, 72, 0.05);
}

/* Ваучер: полноэкранный слой поверх приложения; при печати остаётся только он. */
.voucher-layer {
  position: fixed;
  inset: 0;
  /* Выше модалки (40), ниже тоста (60), чтобы уведомления оставались видны. */
  z-index: 55;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.voucher {
  max-width: 680px;
  margin: 0 auto;
  color: #1f2a24;
  font-size: 14px;
  line-height: 1.45;
}

.voucher-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.voucher-actions .btn {
  flex: 1;
}

.voucher-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 12px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 2px solid #365b48;
}

.voucher-head h1 {
  margin: 0;
  font-size: 19px;
  color: #365b48;
}

.voucher-org {
  text-align: right;
  font-size: 12px;
  color: #5c6660;
}

.voucher-meta {
  margin: 0 0 14px;
  font-size: 12px;
  color: #5c6660;
}

.voucher section {
  margin-bottom: 14px;
}

.voucher h2 {
  margin: 0 0 6px;
  padding-bottom: 3px;
  border-bottom: 1px solid #e2ded2;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #365b48;
}

.voucher p {
  margin: 0;
}

.voucher-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
}

.voucher-row span {
  color: #5c6660;
}

.voucher-row b {
  text-align: right;
}

.voucher-note {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid #e2ded2;
  font-size: 12px;
  color: #5c6660;
}

@media print {
  body.voucher-open > *:not(.voucher-layer) {
    display: none !important;
  }

  body.voucher-open .voucher-actions {
    display: none;
  }

  body.voucher-open .voucher-layer {
    position: static;
    padding: 0;
    overflow: visible;
  }
}

.modal__head {
  position: sticky;
  z-index: 2;
  top: -14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -6px -14px 12px;
  padding: 8px 14px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 234, 0.96);
  backdrop-filter: blur(14px);
  cursor: grab;
}

.modal__head h2 {
  /* Заголовок захватывается для свайпа — не выделяем текст при протягивании. */
  user-select: none;
}

.template-preview {
  min-height: 190px;
  padding: 12px;
  white-space: pre-wrap;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.task-card {
  display: grid;
  gap: 10px;
}

.finance-row {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.template-vars {
  display: grid;
  gap: 6px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.chip-list code {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #365b48;
  background: #edf4ee;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.save-status {
  margin: 0;
}

.split > *,
.topbar__row > *,
.row > *,
.card-row > *,
.actions > *,
.tour-card > *,
.request-head > *,
.participant-row__meta > *,
.bottom-nav button {
  min-width: 0;
}

.card,
.card p,
.card strong,
.card h2,
.card h3,
.meta,
.badge,
.request-details,
.request-details summary,
.bottom-nav button,
.topbar h1,
.topbar p {
  overflow-wrap: anywhere;
}

.warning {
  padding: 10px 12px;
  border: 1px solid #f0cc85;
  border-radius: var(--radius);
  color: #744404;
  background: #fff2d5;
  font-size: 13px;
}

.empty,
.error {
  padding: 20px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 60;
  right: max(16px, calc((100vw - 480px) / 2 + 16px));
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: max(16px, calc((100vw - 480px) / 2 + 16px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fffdf8;
  background: #1d2520;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-open {
  opacity: 1;
  transform: translateY(0);
}

.noscript {
  padding: 20px;
}

@media (min-width: 700px) {
  .phone-frame {
    min-height: calc(100svh - 32px);
    margin-top: 16px;
    margin-bottom: 16px;
    border-radius: 18px;
    overflow: hidden;
  }

  .bottom-nav {
    left: calc((100vw - 480px) / 2);
    right: calc((100vw - 480px) / 2);
  }
}

@media (max-width: 420px) {
  .screen {
    padding-right: 12px;
    padding-left: 12px;
  }

  .form-grid--two,
  .participant-row__meta,
  .request-head {
    grid-template-columns: 1fr;
  }

  .status-select {
    width: 100%;
  }

  .tour-card {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
  }

  .split {
    flex-wrap: wrap;
  }

  .stats--three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats--three .stat:last-child {
    grid-column: 1 / -1;
  }

  .bottom-nav {
    padding-right: 8px;
    padding-left: 8px;
  }
}

html.in-telegram {
  background: var(--bg);
}

html.in-telegram body {
  background: var(--bg);
}

html.in-telegram .phone-frame {
  width: 100%;
  min-height: 100svh;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

html.in-telegram .bottom-nav {
  left: 0;
  right: 0;
}
