:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --line: #dfe3e8;
  --text: #1f2933;
  --muted: #667085;
  --accent: #176b87;
  --accent-weak: #e7f3f6;
  --ok: #2f7d32;
  --warn: #9a6a00;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.copy-code-button {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
}

.copy-code-button code {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.copy-code-button:hover code,
.copy-code-button:focus-visible code {
  background: var(--accent-weak);
}

.copy-status {
  margin-left: 6px;
  color: var(--ok);
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 56px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
}

.nav a.nav-alert {
  font-weight: 700;
}

.nav a.active,
.nav a:hover {
  color: var(--accent);
  background: var(--accent-weak);
  text-decoration: none;
}

.logout {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 22px 60px;
}

.section,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.section.narrow {
  max-width: 820px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0 0 8px;
  line-height: 1.2;
}

h1 {
  font-size: 24px;
}

h2 {
  margin-top: 24px;
  font-size: 18px;
}

.muted {
  color: var(--muted);
}

.alert {
  padding: 10px 12px;
  border: 1px solid #f5c2c0;
  border-radius: 6px;
  color: var(--danger);
  background: #fff4f2;
}

.telegram-refresh-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #9ccbd6;
  border-radius: 6px;
  color: var(--text);
  background: #eef8fb;
}

.telegram-refresh-notice[hidden] {
  display: none;
}

.telegram-refresh-notice p {
  margin: 0;
}

.telegram-profile {
  display: grid;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.telegram-profile-label {
  color: var(--muted);
  font-size: 12px;
}

.telegram-profile-changed {
  padding-left: 8px;
  border-left: 2px solid #9ccbd6;
}

.actions,
.search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.open-date-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.week-picker-label {
  position: relative;
}

.week-picker {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.week-picker input[readonly] {
  cursor: pointer;
}

.week-picker input[readonly]:disabled {
  cursor: not-allowed;
}

.week-picker-clear {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.week-calendar {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100vw - 64px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(16, 24, 40, 0.18);
}

.week-calendar-head {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.week-calendar-head strong {
  text-align: center;
}

.week-calendar-nav {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 18px;
}

.week-calendar-weekdays,
.week-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.week-calendar-weekdays span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.week-calendar-day {
  min-height: 34px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.week-calendar-day.is-outside-month {
  color: #98a2b3;
}

.week-calendar-day.is-today {
  border-color: #9ccbd6;
}

.week-calendar-day.is-week-hover {
  background: var(--accent-weak);
}

.week-calendar-day.is-week-selected {
  border-color: var(--accent);
  background: #d8edf3;
  color: var(--accent);
  font-weight: 700;
}

.public-waitlist-page {
  max-width: 760px;
  margin: 0 auto;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.button.secondary,
button.secondary {
  background: #fff;
  color: var(--accent);
}

.button.compact-button {
  min-height: 28px;
  padding: 4px 10px;
  line-height: 1;
  white-space: nowrap;
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input.date-input {
  width: 18ch;
  min-width: 18ch;
}

textarea {
  resize: vertical;
}

.field-label {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  width: max-content;
  max-width: 100%;
  white-space: nowrap;
}

.required-mark {
  color: var(--danger);
  font-weight: 700;
}

.tour-select-filter {
  margin-bottom: 6px;
}

.record-count {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.record-count span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfd;
}

.record-count strong {
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fbfcfd;
  font-size: 12px;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.right {
  text-align: right;
}

.row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.link-button {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.link-button:hover,
.link-button:focus-visible {
  background: transparent;
  text-decoration-style: solid;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  min-height: 22px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
}

.chat-status-ok {
  background: #edf7ed;
  color: var(--ok);
}

.chat-status-error {
  background: #fff4f2;
  color: var(--danger);
}

.chat-status-pending {
  background: #eef2f6;
  color: var(--muted);
}

.status-active {
  background: #e8f5e9;
  color: var(--ok);
}

.status-inactive {
  background: #fff4f2;
  color: var(--danger);
}

.status-pending {
  background: #fff8e6;
  color: var(--warn);
}

.event-level-error {
  background: #fff4f2;
  color: var(--danger);
}

.event-level-warning {
  background: #fff8e6;
  color: var(--warn);
}

.event-level-info {
  background: #eef2f6;
  color: #344054;
}

.events-table td {
  max-width: 360px;
}

.raw-data {
  max-width: 520px;
  max-height: 260px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.ok {
  color: var(--ok);
  font-weight: 700;
}

.warn {
  color: var(--warn);
  font-weight: 700;
}

.error-text {
  color: var(--danger);
  font-weight: 700;
}

.modal-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.24);
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-head h2 {
  margin-top: 0;
}

.chat-check-row {
  display: grid;
  grid-template-columns: minmax(18ch, 24ch) max-content;
  align-items: end;
  gap: 10px;
}

.small-note {
  margin: 0 0 10px;
  font-size: 12px;
}

.chat-check-status {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.number-stepper {
  display: grid;
  grid-template-columns: 34px minmax(7ch, 10ch) 34px;
  align-items: center;
  gap: 6px;
}

.number-stepper input {
  text-align: center;
  appearance: textfield;
}

.number-stepper input::-webkit-outer-spin-button,
.number-stepper input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.number-stepper button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.booking-transfer-seat-block {
  display: grid;
  gap: 10px;
}

.booking-transfer-seat-row {
  display: grid;
  grid-template-columns: minmax(18ch, 28ch) minmax(0, 1fr);
  gap: 14px;
  align-items: end;
}

.booking-transfer-calculation,
.booking-transfer-balance-warning {
  margin: 0;
}

.booking-transfer-calculation {
  color: var(--muted);
}

.booking-transfer-balance-warning {
  color: var(--warn);
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metrics a {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
}

.metrics strong {
  font-size: 28px;
}

.metrics span {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-grid.booking-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-grid div {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.summary-grid strong {
  font-size: 22px;
}

.summary-grid span,
.key-value span {
  color: var(--muted);
}

.tour-income-summary {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 12px;
  margin: 10px 0 24px;
}

.tour-income-summary span {
  color: var(--muted);
}

.tour-income-summary strong {
  font-size: 18px;
}

.key-value {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.key-value div {
  display: grid;
  gap: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.compact {
  margin-top: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.panel {
  margin: 16px 0 22px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.compact-head {
  margin-bottom: 10px;
}

.promocode-panel h2 {
  margin-top: 0;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.inline-form {
  display: grid;
  gap: 6px;
  min-width: 240px;
  margin: 8px 0;
}

.promocode-summary {
  display: grid;
  gap: 4px;
  min-width: 140px;
}

.promocode-summary .muted {
  max-width: 28ch;
  overflow-wrap: anywhere;
}

.promocode-actions {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.compact-action-form {
  margin: 0;
}

.actions-cell {
  min-width: 280px;
}

.confirmation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.confirmation-actions form {
  margin: 0;
}

.refund-queue-actions {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 170px;
}

.refund-queue-actions button {
  width: 100%;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check input {
  width: auto;
  min-height: 0;
}

.login-panel {
  max-width: 460px;
  margin: 8vh auto 0;
}

.dev-login {
  margin-top: 18px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .logout {
    width: 100%;
    justify-content: space-between;
  }

  .section-head,
  .metrics,
  .summary-grid,
  .key-value,
  .form-grid,
  .form-grid.compact,
  .chat-check-row,
  .booking-transfer-seat-row {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 240px;
  }
}
