:root {
  color-scheme: light;
  --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);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(42, 171, 238, 0.18), transparent 38%),
    linear-gradient(180deg, #edf3f8 0%, var(--tg-bg) 48%, #e8eef4 100%);
  color: var(--tg-text);
}

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

.app-frame {
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 30px;
  box-shadow: 0 24px 72px rgba(13, 37, 62, 0.12);
  overflow: hidden;
}

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

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

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

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

.app-badge,
.status-badge,
.section-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.app-badge {
  background: var(--tg-accent-soft);
  color: var(--tg-accent);
}

.status-badge {
  background: rgba(112, 132, 153, 0.12);
  color: var(--tg-muted);
}

.status-badge[data-mode="active"] {
  background: var(--tg-accent-soft);
  color: var(--tg-accent);
}

.status-badge[data-mode="success"] {
  background: rgba(49, 181, 69, 0.12);
  color: var(--tg-success);
}

.status-badge[data-mode="error"] {
  background: rgba(229, 76, 64, 0.12);
  color: #d44a3a;
}

.section-kicker {
  margin: 0 0 4px;
  padding: 0;
  min-height: auto;
  background: none;
  color: var(--tg-muted);
  font-size: 0.8rem;
}

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

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

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

.section-head h2 {
  margin: 0;
  letter-spacing: -0.03em;
  font-size: 1.28rem;
}

.merchant-name {
  max-width: 44%;
  text-align: right;
  color: var(--tg-muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.section-note {
  border-radius: 999px;
  background: var(--tg-surface-muted);
  color: var(--tg-muted);
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 600;
}

.scanner-actions {
  margin: 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

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

.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);
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--tg-line);
  color: var(--tg-text);
}

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

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

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

.empty-state {
  margin-top: 14px;
  padding: 28px 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #f8fbfe 0%, #f2f6fa 100%);
  color: var(--tg-muted);
  border: 1px dashed rgba(112, 132, 153, 0.22);
  text-align: center;
}

.empty-state__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: white;
  color: var(--tg-accent);
  font-size: 1.8rem;
  box-shadow: 0 10px 24px rgba(30, 76, 117, 0.08);
}

.empty-state__title {
  font-weight: 700;
  color: var(--tg-text);
  margin-bottom: 6px;
}

.empty-state__text {
  font-size: 0.95rem;
  line-height: 1.45;
}

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

.items-list.is-loading {
  gap: 12px;
}

.receipt-skeleton {
  height: 96px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.85) 50%, rgba(255, 255, 255, 0) 100%),
    linear-gradient(180deg, #edf3f8 0%, #e7eef5 100%);
  background-size: 220px 100%, 100% 100%;
  background-repeat: no-repeat;
  animation: skeleton-shimmer 1.2s linear infinite;
}

.receipt-item {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--tg-surface-muted);
  border: 1px solid rgba(24, 44, 63, 0.05);
  display: grid;
  gap: 10px;
  opacity: 0;
  transform: translateY(8px);
  animation: card-enter 220ms ease forwards;
}

.receipt-item__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

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

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

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

.quantity-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 12px;
  background: white;
  color: var(--tg-accent);
  border: 1px solid rgba(42, 171, 238, 0.18);
}

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

.summary-bar {
  position: sticky;
  bottom: 10px;
  margin: 0 12px 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(24, 44, 63, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: 0 16px 36px rgba(15, 35, 53, 0.12);
}

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

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

.summary-meta strong {
  font-size: clamp(1.5rem, 6vw, 2.15rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

.summary-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.confirm-button {
  min-width: 132px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--tg-accent);
  color: var(--tg-button-text);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

.confirm-button[disabled] {
  background: #d8e0e8;
  color: #8fa0b1;
  cursor: default;
  box-shadow: none;
}

@keyframes skeleton-shimmer {
  from {
    background-position: -220px 0, 0 0;
  }
  to {
    background-position: calc(100% + 220px) 0, 0 0;
  }
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: 100%;
    padding: 0;
  }

  .app-frame {
    min-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    border: 0;
  }

  .hero {
    padding: 18px 16px 8px;
  }

  .content-stack {
    padding: 8px 10px 116px;
  }

  .surface {
    padding: 16px;
  }

  .scanner-actions > * {
    flex: 1 1 calc(50% - 5px);
  }

  .section-head {
    align-items: flex-start;
  }

  .merchant-name {
    max-width: 50%;
  }

  .summary-bar {
    margin: 0 10px 10px;
  }

  .summary-bar {
    align-items: flex-end;
  }

  .summary-actions {
    width: 100%;
  }

  .confirm-button {
    width: 100%;
  }
}
