:root {
  color-scheme: light dark;
  --tg-bg: #eef2f5;
  --tg-surface: #ffffff;
  --tg-surface-muted: #f5f7fa;
  --tg-text: #17212b;
  --tg-muted: #708499;
  --tg-line: rgba(15, 35, 53, 0.08);
  --tg-accent: #2aabee;
  --tg-accent-pressed: #2297d4;
  --tg-accent-soft: rgba(42, 171, 238, 0.12);
  --tg-button-text: #ffffff;
  --tg-success: #31b545;
  --tg-shadow: 0 12px 32px rgba(16, 38, 59, 0.10);
  --app-bg:
    radial-gradient(circle at top, rgba(42, 171, 238, 0.18), transparent 38%),
    linear-gradient(180deg, #edf3f8 0%, var(--tg-bg) 48%, #e8eef4 100%);
  --app-frame-bg: rgba(255, 255, 255, 0.48);
  --app-frame-border: rgba(255, 255, 255, 0.8);
  --app-frame-shadow: 0 24px 72px rgba(13, 37, 62, 0.12);
  --receipt-item-border: rgba(24, 44, 63, 0.05);
  --quantity-bg: #ffffff;
  --quantity-border: rgba(42, 171, 238, 0.18);
  --summary-bg: rgba(255, 255, 255, 0.96);
  --summary-border: rgba(24, 44, 63, 0.08);
  --summary-shadow: 0 10px 28px rgba(15, 35, 53, 0.16);
  --disabled-bg: #eef2f5;
  --disabled-text: #9aabbb;
  --sheet-backdrop: rgba(23, 33, 43, 0.34);
  --sheet-shadow: 0 -18px 42px rgba(15, 35, 53, 0.18);
  --handle-bg: rgba(112, 132, 153, 0.28);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tg-bg: #17212b;
    --tg-surface: #1f2a36;
    --tg-surface-muted: #263241;
    --tg-text: #f5f7fa;
    --tg-muted: #9aa8b5;
    --tg-line: rgba(255, 255, 255, 0.08);
    --tg-accent: #5288c1;
    --tg-accent-pressed: #4577ac;
    --tg-accent-soft: rgba(82, 136, 193, 0.18);
    --tg-button-text: #ffffff;
    --tg-shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
    --app-bg:
      radial-gradient(circle at top, rgba(82, 136, 193, 0.24), transparent 38%),
      linear-gradient(180deg, #111922 0%, var(--tg-bg) 50%, #0f1720 100%);
    --app-frame-bg: rgba(31, 42, 54, 0.72);
    --app-frame-border: rgba(255, 255, 255, 0.07);
    --app-frame-shadow: 0 24px 72px rgba(0, 0, 0, 0.34);
    --receipt-item-border: rgba(255, 255, 255, 0.05);
    --quantity-bg: #1a2430;
    --quantity-border: rgba(82, 136, 193, 0.28);
    --summary-bg: rgba(31, 42, 54, 0.94);
    --summary-border: rgba(255, 255, 255, 0.08);
    --summary-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
    --disabled-bg: #263241;
    --disabled-text: #6f7d8a;
    --sheet-backdrop: rgba(0, 0, 0, 0.52);
    --sheet-shadow: 0 -18px 42px rgba(0, 0, 0, 0.34);
    --handle-bg: rgba(154, 168, 181, 0.30);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--app-bg);
  color: var(--tg-text);
}

.page-shell {
  width: min(720px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 14px 0 148px;
}

.app-frame {
  overflow: hidden;
  border: 1px solid var(--app-frame-border);
  border-radius: 30px;
  background: var(--app-frame-bg);
  box-shadow: var(--app-frame-shadow);
}

.hero {
  padding: 20px 20px 8px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 2.8rem);
  letter-spacing: 0;
}

.hero-copy {
  max-width: 36ch;
  margin: 10px 0 0;
  color: var(--tg-muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.content-stack {
  display: grid;
  gap: 12px;
  padding: 8px 12px 24px;
}

.surface {
  padding: 18px;
  border: 1px solid var(--tg-line);
  border-radius: var(--radius-xl);
  background: var(--tg-surface);
  box-shadow: var(--tg-shadow);
}

.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

button,
.upload-button {
  border: 0;
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease, border-color 140ms ease;
}

button:active {
  transform: translateY(1px) scale(0.995);
}

button:disabled {
  cursor: default;
  opacity: 0.6;
}

.primary-button {
  background: var(--tg-accent);
  color: var(--tg-button-text);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

.primary-button:hover {
  background: var(--tg-accent-pressed);
}

.secondary-button {
  border: 1px solid transparent;
  background: var(--tg-surface-muted);
  color: var(--tg-text);
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.full-button {
  width: 100%;
}

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

#scanner-video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  margin-top: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  background: #0b1116;
}

.captcha-wrap {
  min-height: 92px;
  margin: 16px 0 12px;
}

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

.receipt-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--receipt-item-border);
  border-radius: var(--radius-lg);
  background: var(--tg-surface-muted);
}

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

.receipt-item__name {
  font-weight: 700;
  line-height: 1.35;
}

.receipt-item__meta {
  margin-top: 4px;
  color: var(--tg-muted);
  font-size: 0.88rem;
}

.receipt-item__top strong {
  min-width: max-content;
  max-width: 118px;
  text-align: right;
  white-space: nowrap;
  font-size: clamp(0.92rem, 3.4vw, 1rem);
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.item-quantity {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.quantity-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--quantity-border);
  border-radius: 12px;
  background: var(--quantity-bg);
  color: var(--tg-accent);
}

.quantity-value {
  min-width: 42px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.split-link {
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--tg-accent);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
}

.split-link:active {
  transform: none;
}

.split-link:hover {
  color: var(--tg-accent);
}

.summary-bar {
  position: fixed;
  left: 50%;
  bottom: 10px;
  z-index: 20;
  display: flex;
  width: min(720px, calc(100vw - 20px));
  margin: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--summary-border);
  border-radius: 16px;
  background: var(--summary-bg);
  backdrop-filter: blur(20px);
  box-shadow: var(--summary-shadow);
}

.summary-meta {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.summary-label {
  color: var(--tg-muted);
  font-size: 0.88rem;
}

.summary-meta strong {
  font-size: clamp(1.36rem, 5.3vw, 1.95rem);
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.summary-actions {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 6px;
}

.secondary-action-button {
  min-width: 88px;
  padding: 11px 12px;
  border-radius: 14px;
  background: var(--tg-accent);
  color: var(--tg-button-text);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
  font-size: 0.9rem;
}

.split-dialog {
  position: fixed;
  inset: 0;
  z-index: 45;
}

.split-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 0;
  background: var(--sheet-backdrop);
}

.split-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(720px, 100vw);
  padding: 10px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  border-radius: 22px 22px 0 0;
  background: var(--tg-surface);
  box-shadow: var(--sheet-shadow);
}

.split-panel::before {
  display: block;
  width: 42px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--handle-bg);
  content: "";
}

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

.split-head h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.split-head p {
  margin: 4px 0 0;
  color: var(--tg-muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.close-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 12px;
  background: var(--tg-surface-muted);
  color: var(--tg-muted);
}

.split-counter {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
}

.counter-button {
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid var(--tg-line);
  border-radius: 18px;
  background: var(--tg-surface-muted);
  color: var(--tg-accent);
  font-size: 1.35rem;
}

.counter-button[disabled] {
  color: var(--disabled-text);
  cursor: default;
}

.split-counter strong {
  display: grid;
  min-height: 68px;
  place-items: center;
  border: 1px solid var(--tg-line);
  border-radius: 20px;
  background: var(--tg-surface-muted);
  font-size: 2rem;
  line-height: 1;
}

.split-preview {
  margin: 12px 2px 0;
  color: var(--tg-muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

@media (max-width: 420px) {
  .page-shell {
    width: min(720px, calc(100vw - 20px));
  }

  .scanner-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
