:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-secondary-bg-color, #f4f7f5);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17201d);
  --muted: var(--tg-theme-hint-color, #66736e);
  --accent: var(--tg-theme-button-color, #087f75);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 24%, transparent);
  --warning: #b86b00;
  --danger: #bd3a3a;
  --success: #18794e;
  --shadow: 0 8px 24px rgb(22 42 34 / 10%);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.header-copy { min-width: 0; }
.header-copy-button { min-width: 0; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.header-copy-button::after { content: "Сменить группу"; display: block; margin-top: 2px; color: var(--accent); font-size: 11px; }
.group-name { margin: 0; overflow: hidden; font-size: 17px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.session-line { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content { width: min(100%, 760px); margin: 0 auto; padding: 16px 12px 40px; }
.section-header { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.section-header h1 { margin: 0; font-size: 20px; }
.section-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.items { display: grid; gap: 8px; }
.item-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgb(20 35 29 / 4%);
}
.item-card.not-found { opacity: .68; }
.item-photo {
  width: 100%;
  max-height: 280px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: var(--bg);
  object-fit: contain;
}
.item-photo-button { display: block; width: 100%; padding: 0; border: 0; border-radius: 6px; background: transparent; cursor: zoom-in; }
.item-photo-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.contact-link { color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }
.item-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.item-title { margin: 0; min-width: 0; font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.item-meta, .item-comment, .participants, .owner-line { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.item-comment { padding-left: 9px; border-left: 3px solid #e7a62b; color: var(--text); }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.item-actions .action-not-found { margin-left: auto; }

.badge { flex: 0 0 auto; padding: 3px 7px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-size: 11px; font-weight: 700; }
.badge.warning { color: var(--warning); background: color-mix(in srgb, #e7a62b 16%, transparent); }
.badge.success { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }

.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 650;
}
.button.primary { background: var(--accent); color: var(--accent-text); }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.danger { border-color: color-mix(in srgb, var(--danger) 30%, transparent); background: transparent; color: var(--danger); }
.button.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }

.empty, .loading, .error-panel { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty-state { display: grid; justify-items: center; gap: 12px; padding: 36px 16px; text-align: center; }
.empty-state p { max-width: 420px; margin: 0; color: var(--muted); line-height: 1.5; }
.profile-form, .feedback-form { display: grid; gap: 12px; margin-bottom: 24px; }
.feedback-form h2 { margin: 8px 0 0; font-size: 18px; }
.error-panel { border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: var(--surface); border-radius: 8px; color: var(--text); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.purchase-toolbar { display: grid; grid-template-columns: repeat(5, max-content); align-items: start; }
.purchase-toolbar #finish-purchase { grid-column: 1 / -1; justify-self: start; }
.summary-band.two-cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.list-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.receipt-notice { margin-bottom: 14px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.45; }
.receipt-lines { display: grid; gap: 0; border-top: 1px solid var(--line); }
.receipt-line { display: grid; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.receipt-line-title { display: flex; justify-content: space-between; gap: 12px; }
.receipt-line-title span { color: var(--muted); font-size: 12px; }
.check-row { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check-row input { width: 20px; min-height: 20px; }
.receipt-actions { position: sticky; bottom: 0; justify-content: flex-end; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.summary-band { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin-bottom: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--line); }
.summary-cell { min-width: 0; padding: 10px; background: var(--surface); }
.summary-cell span { display: block; color: var(--muted); font-size: 11px; }
.summary-cell label { display: block; color: var(--muted); font-size: 11px; }
.summary-cell strong { display: block; margin-top: 4px; overflow-wrap: anywhere; font-size: 14px; }
.summary-cell input { width: 100%; min-height: 32px; margin-top: 3px; padding: 5px 7px; font-size: 14px; }

.section-header.compact { margin: 0; }
.section-header.compact h2 { margin: 0; font-size: 17px; }
.payments { display: grid; gap: 8px; margin-top: 18px; }
.payment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.payment-row div { min-width: 0; }
.payment-row span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.payment-details { display: grid; gap: 5px; margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.payment-details span { color: var(--muted); font-size: 13px; }
.member-list { display: grid; border-top: 1px solid var(--line); }
.member-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 10px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.member-row:disabled { cursor: default; opacity: .72; }

.participant-fieldset { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.participant-fieldset legend { margin-bottom: 3px; color: var(--text); font-size: 14px; font-weight: 700; }
.participant-fieldset > p { margin: 0; color: var(--muted); font-size: 12px; font-weight: 400; }
.participant-options { display: grid; gap: 7px; }
.participant-option {
  display: flex;
  grid-template-columns: none;
  min-height: 46px;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.participant-option.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg)); }
.participant-option input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; pointer-events: none; }
.checkbox-mark { display: grid; flex: 0 0 26px; width: 26px; height: 26px; place-items: center; border: 2px solid var(--muted); border-radius: 6px; background: var(--surface); }
.participant-option input:checked + .checkbox-mark { border-color: var(--accent); background: var(--accent); }
.participant-option input:checked + .checkbox-mark::after { content: "✓"; color: white; font-size: 18px; font-weight: 800; line-height: 1; }
.participant-option input:focus-visible + .checkbox-mark { outline: 2px solid var(--accent); outline-offset: 2px; }
.participant-name { min-width: 0; overflow-wrap: anywhere; }
.participant-option .badge { margin-left: auto; }
.compact-dialog { max-width: 390px; }
.photo-dialog-panel { position: relative; width: min(100%, 720px); padding: 8px; background: var(--bg); }
.photo-dialog-panel img { width: 100%; max-height: calc(100dvh - 40px); border-radius: 6px; object-fit: contain; }
.photo-dialog-close { position: absolute; z-index: 1; top: 14px; right: 14px; background: var(--surface); box-shadow: var(--shadow); }
.dialog-copy { margin: 0; color: var(--muted); }
.scope-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-divider { display: grid; gap: 3px; padding-top: 12px; border-top: 1px solid var(--line); }
.form-divider span { color: var(--muted); font-size: 12px; font-weight: 400; }
.template-help { margin: -4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.template-help code { color: var(--text); }
.copy-value { user-select: text; -webkit-user-select: text; }
.help-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.help-section h2 { margin: 0 0 10px; font-size: 17px; }
.help-steps { display: grid; gap: 8px; margin: 0; padding-left: 22px; color: var(--text); font-size: 14px; line-height: 1.4; }

.dialog { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; width: 100%; height: 100%; padding: 12px; overflow-y: auto; border: 0; background: rgb(10 20 16 / 62%); color: var(--text); }
.dialog[hidden] { display: none; }
.dialog form, .dialog-panel { display: grid; width: min(100%, 520px); max-height: calc(100dvh - 24px); gap: 14px; padding: 16px; overflow-y: auto; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.modal-open { overflow: hidden; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }
.dialog-header h2 { margin: 0; font-size: 18px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 650; }
input, textarea, select { width: 100%; min-height: 42px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); opacity: 1; outline: none; pointer-events: auto; -webkit-text-fill-color: var(--text); caret-color: var(--accent); }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }
.photo-picker input { padding: 6px; }
.photo-picker input::file-selector-button {
  min-height: 30px;
  margin-right: 8px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.photo-preview { display: grid; gap: 8px; justify-items: start; }
.photo-preview[hidden] { display: none; }
.photo-preview img {
  width: 100%;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  object-fit: contain;
}
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, .55fr); gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.group-picker { display: grid; gap: 8px; }
.group-picker .button { width: 100%; justify-content: flex-start; text-align: left; }
.group-actions { display: grid; grid-template-columns: 1fr 1fr; }
.invite-panel { display: grid; gap: 7px; padding: 11px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.invite-panel[hidden] { display: none; }
.invite-panel > span { color: var(--muted); font-size: 12px; }
.invite-row { display: flex; gap: 8px; align-items: center; }
.invite-row code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: var(--text); font-size: 16px; font-weight: 700; }
.tabs.is-disabled { opacity: .45; pointer-events: none; }

.admin-sections { display: grid; gap: 22px; }
.admin-section { display: grid; gap: 8px; }
.admin-section-header { display: flex; justify-content: space-between; gap: 12px; align-items: end; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.admin-section-header h2 { margin: 0; font-size: 17px; }
.admin-section-header span { color: var(--muted); font-size: 12px; }
.admin-list { display: grid; }
.admin-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.admin-row-main { min-width: 0; }
.admin-row-main strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.admin-row-main span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.admin-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.admin-subscription { display: flex; gap: 6px; margin-top: 7px; }
.admin-subscription select { min-height: 34px; padding: 5px 8px; font-size: 12px; }
.admin-danger-zone { padding-top: 14px; border-top: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }

.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 20; max-width: calc(100% - 24px); padding: 10px 14px; border-radius: 8px; background: #17201d; color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 680px) {
  .content { padding: 22px 20px 50px; }
  .items.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 679px) {
  .purchase-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .purchase-toolbar .button { width: 100%; }
  .list-controls { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .payment-row { grid-template-columns: minmax(0, 1fr) auto; }
  .admin-row { grid-template-columns: 1fr; }
  .admin-actions { justify-content: flex-start; }
  .payment-row .button { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
