:root {
  --paper: #f8f3ea;
  --paper-strong: #fffaf2;
  --ink: #1f2a24;
  --muted: #6f786f;
  --line: rgba(31, 42, 36, 0.08);
  --emerald: #1b7f63;
  --emerald-soft: #d9f0e7;
  --coral: #d9684d;
  --sand: #e5d5b8;
  --gold: #f1b24a;
  --shadow: 0 22px 44px rgba(52, 59, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(217, 240, 231, 0.95), transparent 32%),
    radial-gradient(circle at top right, rgba(241, 178, 74, 0.18), transparent 24%),
    linear-gradient(180deg, #f4efe5 0%, #f8f3ea 55%, #f2ece0 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(31, 42, 36, 0.02) 1px, transparent 1px);
  background-size: 100% 28px;
  opacity: 0.45;
}

body.busy {
  cursor: progress;
}

.page-shell {
  width: min(1240px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--emerald);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

h1 {
  font-size: clamp(32px, 4vw, 54px);
  line-height: 0.98;
  max-width: 10ch;
}

.hero-text {
  max-width: 58ch;
  margin: 12px 0 0;
  line-height: 1.5;
  color: var(--muted);
}

.telegram-badge {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #2b6cb0, #1b7f63);
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-shell {
  display: grid;
  gap: 16px;
}

.card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 250, 242, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  border: 1px solid var(--line);
}

.topbar,
.welcome-stage,
.participants,
.settlement,
.confirm-stage,
.scenario-stage,
.payments-stage,
.results-stage {
  padding: 16px 18px;
}

.confirm-items-preview,
.welcome-steps,
.scenario-grid,
.ocr-editor-grid,
.ocr-add-card {
  display: grid;
  gap: 12px;
}

.confirm-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
  line-height: 1.45;
}

.welcome-steps {
  margin: 0;
  padding-left: 20px;
  line-height: 1.55;
}

.welcome-footnote {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.scenario-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  text-align: left;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.scenario-card strong {
  font-size: 16px;
}

.scenario-card span {
  color: var(--muted);
  line-height: 1.4;
}

.ocr-editor-panel {
  display: grid;
  gap: 16px;
}

.ocr-editor-grid {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.field-block {
  display: grid;
  gap: 8px;
}

.text-input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font: inherit;
}

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

.ocr-add-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(27, 127, 99, 0.06);
}

.topbar {
  display: grid;
  gap: 12px;
}

.flow-guide {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 20px;
  background: rgba(27, 127, 99, 0.08);
  border: 1px solid rgba(27, 127, 99, 0.14);
}

.flow-summary {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
}

.swipe-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(31, 42, 36, 0.06);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.swipe-arrows {
  display: inline-flex;
  gap: 4px;
  color: var(--emerald);
  animation: swipePulse 1.3s ease-in-out infinite;
}

.topbar-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(27, 127, 99, 0.09);
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
}

.stat-label,
.muted {
  color: var(--muted);
}

.progress-strip {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(31, 42, 36, 0.08);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--emerald) 0%, #3ba889 100%);
  transition: width 220ms ease;
}

@keyframes swipePulse {
  0%,
  100% {
    transform: translateX(0);
    opacity: 0.7;
  }
  50% {
    transform: translateX(3px);
    opacity: 1;
  }
}

.flow-notice {
  padding: 8px 10px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.3;
  border: 1px solid transparent;
}

#telegram-meta {
  display: none !important;
}

.flow-notice.neutral {
  color: var(--ink);
  background: rgba(31, 42, 36, 0.06);
}

.flow-notice.warning {
  color: #8a5a12;
  background: rgba(241, 178, 74, 0.16);
  border-color: rgba(241, 178, 74, 0.28);
}

.flow-notice.success {
  color: #0f5b45;
  background: rgba(27, 127, 99, 0.12);
  border-color: rgba(27, 127, 99, 0.22);
}

.participant-list,
.settlement-list,
.payments-list,
.results-people,
.results-transfer-list {
  display: grid;
  gap: 10px;
}

.section-summary {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.45;
}

.participant-card,
.settlement-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--paper-strong);
  border: 1px solid var(--line);
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
}

.participant-name {
  font-weight: 700;
}

.participant-share {
  font-size: 18px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.sheet-handle {
  display: none;
}

.items-pane,
.editor-pane {
  min-height: 620px;
  padding: 18px 20px 20px;
}

.items-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.items-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.section-head-sticky {
  position: sticky;
  top: 0;
  z-index: 3;
  padding-bottom: 12px;
  background: linear-gradient(180deg, rgba(255, 250, 242, 0.95), rgba(255, 250, 242, 0.8) 70%, transparent);
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-button,
.segment,
.button {
  border: 0;
  cursor: pointer;
  transition:
    transform 140ms ease,
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.chip-button {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(31, 42, 36, 0.06);
  color: var(--ink);
}

.chip-button.active {
  background: var(--ink);
  color: #fff;
}

.collapse-toggle {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(31, 42, 36, 0.04);
  color: var(--ink);
  font-weight: 700;
}

.mobile-only {
  display: none;
}

.button {
  padding: 12px 16px;
  border-radius: 16px;
  font-weight: 700;
}

.button:hover,
.chip-button:hover,
.segment:hover {
  transform: translateY(-1px);
}

.button:disabled,
.chip-button:disabled,
.segment:disabled,
.participant-chip:disabled,
.weight-slider:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
  box-shadow: none;
}

.button.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--emerald), #2f9a7b);
}

.button.ghost {
  color: var(--ink);
  background: rgba(31, 42, 36, 0.05);
}

.button.soft {
  color: var(--ink);
  background: rgba(217, 240, 231, 0.78);
}

.button.warn {
  background: rgba(217, 104, 77, 0.15);
  color: #8b3c29;
}

.item-card {
  padding: 14px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--paper-strong);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.item-card:hover {
  transform: translateY(-2px);
}

.item-card.selected {
  border-color: rgba(27, 127, 99, 0.35);
  box-shadow: 0 14px 28px rgba(27, 127, 99, 0.1);
}

.item-card.pending {
  border-left: 6px solid var(--gold);
}

.item-card.assigned {
  border-left: 6px solid var(--emerald);
}

.item-card.service {
  border-left: 6px solid var(--coral);
}

.item-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 8px;
}

.item-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(31, 42, 36, 0.07);
}

.item-main {
  display: grid;
  gap: 4px;
  flex: 1;
}

.item-name {
  font-size: 17px;
  font-weight: 700;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.item-price {
  white-space: nowrap;
  font-size: 18px;
  font-weight: 700;
}

.assignment-chips,
.editor-participants {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assignment-chip,
.participant-chip {
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(31, 42, 36, 0.04);
  font-size: 12px;
}

.participant-chip {
  cursor: pointer;
}

.participant-chip.active {
  color: #fff;
  border-color: transparent;
}

.status-badge {
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-badge.neutral {
  background: rgba(31, 42, 36, 0.08);
}

.status-badge.assigned {
  background: rgba(27, 127, 99, 0.15);
  color: #0f5b45;
}

.status-badge.pending {
  background: rgba(241, 178, 74, 0.22);
  color: #8a5a12;
}

.status-badge.service {
  background: rgba(217, 104, 77, 0.15);
  color: #8b3c29;
}

.editor-empty {
  display: grid;
  place-items: center;
  min-height: 520px;
  padding: 24px;
  text-align: center;
  line-height: 1.6;
  color: var(--muted);
  border: 1px dashed rgba(31, 42, 36, 0.16);
  border-radius: 22px;
}

.editor-body.hidden,
.weights-panel.hidden {
  display: none;
}

.editor-body {
  display: grid;
  gap: 18px;
}

.editor-summary,
.weights-head,
.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-index,
.editor-item-name {
  margin: 0;
}

.editor-index {
  font-weight: 700;
}

.editor-item-name {
  font-size: 28px;
  line-height: 1.05;
  font-family: Georgia, "Times New Roman", serif;
}

.price-badge {
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(241, 178, 74, 0.22);
  font-weight: 700;
}

.editor-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.editor-selection-summary {
  margin: -2px 0 0;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(27, 127, 99, 0.10);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.3;
  font-weight: 600;
}

.editor-actions {
  display: grid;
  gap: 10px;
}

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

.subsection-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}

.segmented {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(31, 42, 36, 0.06);
}

.segment {
  padding: 9px 12px;
  border-radius: 999px;
  background: transparent;
}

.segment.active {
  color: #fff;
  background: var(--ink);
}

.weight-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.weight-label {
  display: grid;
  gap: 6px;
}

.weight-slider {
  width: min(220px, 42vw);
  accent-color: var(--emerald);
}

.weight-value {
  min-width: 46px;
  text-align: right;
  font-weight: 700;
}

.settlement-row {
  grid-template-columns: auto 1fr auto auto;
}

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

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

.payment-row,
.results-transfer-row {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--paper-strong);
  border: 1px solid var(--line);
}

.payment-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.payment-person,
.payment-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.payment-controls {
  justify-content: flex-end;
}

.payment-input {
  width: 112px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.results-total-pill {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(27, 127, 99, 0.08);
  border: 1px solid rgba(27, 127, 99, 0.14);
}

.results-transfer-row {
  grid-template-columns: 1fr auto;
}

.results-empty {
  min-height: 0;
  padding: 18px;
}

.nav-row {
  margin-top: 6px;
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .hero {
    flex-direction: column;
    align-items: start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .items-pane,
  .editor-pane {
    min-height: auto;
  }

  .editor-pane {
    position: sticky;
    bottom: 12px;
    z-index: 4;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 12px, 100%);
    padding-top: 12px;
  }

  body::before {
    opacity: 0.2;
  }

  .topbar,
  .participants,
  .confirm-stage,
  .scenario-stage,
  .items-pane,
  .editor-pane,
  .settlement,
  .payments-stage,
  .results-stage {
    padding: 12px;
    border-radius: 22px;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .topbar {
    order: 1;
  }

  .workspace {
    order: 2;
    gap: 0;
  }

  .participants {
    order: 3;
  }

  .settlement {
    order: 4;
  }

  .hero {
    gap: 10px;
    margin-bottom: 12px;
  }

  .hero-actions .button:first-child {
    display: none;
  }

  .hero-copy {
    display: none;
  }

  .flow-guide {
    gap: 4px;
    padding: 8px 10px;
  }

  .topbar {
    gap: 8px;
  }

  #receipt-title {
    font-size: 20px;
    line-height: 1.05;
  }

  #receipt-meta,
  #telegram-meta {
    font-size: 12px;
    line-height: 1.3;
  }

  #flow-summary-title {
    font-size: 17px;
    line-height: 1.05;
  }

  .flow-summary {
    font-size: 13px;
    line-height: 1.3;
  }

  .swipe-hint {
    width: 100%;
    justify-content: center;
    font-size: 12px;
    padding: 6px 8px;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .scenario-grid,
  .ocr-editor-grid,
  .ocr-inline-actions,
  .ocr-add-grid {
    grid-template-columns: 1fr;
  }

  .section-head,
  .weights-head,
  .nav-row,
  .topbar-stats {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions {
    width: 100%;
  }

  .hero-actions .button {
    flex: 1 1 0;
  }

  .section-head-side {
    align-items: stretch;
  }

  .collapse-toggle {
    width: 100%;
  }

  .mobile-only {
    display: block;
  }

  .weight-row,
  .participant-card,
  .settlement-row,
  .payment-row {
    grid-template-columns: 1fr;
  }

  .item-topline {
    gap: 10px;
  }

  .item-price {
    font-size: 16px;
  }

  .item-card {
    padding: 12px 14px;
  }

  .item-name {
    font-size: 16px;
  }

  .items-pane {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .participants.is-collapsed #participants-body,
  .settlement.is-collapsed #settlement-body {
    display: none;
  }

  .participants.is-collapsed,
  .settlement.is-collapsed {
    padding-bottom: 14px;
  }

  .participants.is-collapsed .section-head,
  .settlement.is-collapsed .section-head {
    margin-bottom: 8px;
  }

  .participants.is-collapsed .section-summary,
  .settlement.is-collapsed .section-summary {
    display: block;
  }

  .weight-slider {
    width: 100%;
  }

  .editor-pane {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 0;
    z-index: 12;
    min-height: 0;
    max-height: min(76vh, 720px);
    padding: 10px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -18px 34px rgba(52, 59, 51, 0.18);
    overflow-y: auto;
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
    transition:
      transform 180ms ease,
      opacity 180ms ease;
  }

  body.editor-open .editor-pane {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  body.editor-open .items-pane {
    padding-bottom: min(72vh, 640px);
  }

  .sheet-handle {
    display: block;
    width: 44px;
    height: 5px;
    margin: 0 auto 10px;
    border-radius: 999px;
    background: rgba(31, 42, 36, 0.18);
  }

  .editor-empty {
    display: none;
  }

  .editor-body {
    gap: 14px;
  }

  .editor-item-name {
    font-size: 24px;
  }

  .editor-help {
    font-size: 13px;
  }

  .editor-participants {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
  }

  .participant-chip {
    width: 100%;
    min-height: 42px;
    padding: 10px 8px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
  }

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

  .payments-shortcuts,
  .results-totals {
    grid-template-columns: 1fr;
  }

  .payment-controls {
    justify-content: stretch;
  }

  .payment-input {
    width: 100%;
  }

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

  .topbar-stats .stat-pill:last-child {
    display: none;
  }

  .stat-pill {
    padding: 7px 9px;
    gap: 6px;
  }

  .stat-value {
    font-size: 15px;
  }

  .stat-label {
    font-size: 11px;
  }

  .progress-strip {
    height: 6px;
  }

  .flow-notice {
    padding: 7px 9px;
    font-size: 12px;
    line-height: 1.25;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 6;
  }

  .nav-row {
    position: sticky;
    bottom: calc(-8px - env(safe-area-inset-bottom, 0px));
    z-index: 2;
    margin: 0 -14px calc(-18px - env(safe-area-inset-bottom, 0px));
    padding: 12px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(255, 250, 242, 0), rgba(255, 250, 242, 0.96) 24%, rgba(255, 250, 242, 1) 100%);
    display: grid;
    grid-template-columns: 1fr 1fr 1.25fr;
  }

  .nav-row .button {
    width: 100%;
  }

  .nav-row .button.primary {
    width: 100%;
  }

  body.tg-compact .hero {
    display: none;
  }
}
