:root {
  --bg: var(--tg-theme-bg-color, #08111f);
  --surface: var(--tg-theme-secondary-bg-color, #111f34);
  --surface-2: #1a2d48;
  --line: #2a4468;
  --text: var(--tg-theme-text-color, #f3f7fc);
  --muted: var(--tg-theme-hint-color, #9cafc6);
  --accent: var(--tg-theme-button-color, #8ebcf0);
  --accent-text: var(--tg-theme-button-text-color, #102039);
  --success: #87d8bc;
  --shadow: 0 18px 48px rgba(1, 7, 16, .32);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  background: radial-gradient(circle at 8% 0%, rgba(95, 153, 220, .16), transparent 36%), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  line-height: 1.45;
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(30px, env(safe-area-inset-bottom));
}
.app-header { display: flex; align-items: center; gap: 13px; padding: 8px 2px 18px; }
.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, #9fc8f5, #78a9df);
  color: #102039;
  font-size: 23px;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(88, 145, 208, .26);
}
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0; font-size: clamp(18px, 4.5vw, 24px); letter-spacing: -.5px; }
.brand-copy p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.section-block {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.tab {
  padding: 11px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab:disabled { opacity: .65; cursor: wait; }
.view { display: none; }
.view.active { display: block; }
.section-block { margin-top: 16px; padding: 18px; }
.section-title, .section-title > div { display: flex; align-items: center; gap: 9px; }
.section-title { justify-content: space-between; margin-bottom: 15px; }
.section-title h2 { margin: 0; font-size: 17px; }
.section-meta { color: var(--muted); font-size: 12px; }
.step {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 900;
}

.product-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.product-card {
  min-width: 0;
  min-height: 92px;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s ease, transform .12s ease, background .15s ease;
}
.product-card:active { transform: scale(.985); }
.product-card.selected { border-color: var(--accent); background: #203958; box-shadow: inset 0 0 0 1px var(--accent); }
.product-card strong { display: block; min-height: 41px; font-size: 14px; word-break: keep-all; }
.product-card span { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }

.selected-product { margin-bottom: 15px; padding: 13px; border-radius: 12px; background: var(--surface-2); }
.selected-product strong { font-size: 13px; }
label { display: block; margin: 2px 0 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: #0c1829;
  color: var(--text);
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(142, 188, 240, .12); }
.input-help { display: flex; justify-content: space-between; gap: 10px; margin: 7px 2px 14px; color: var(--muted); font-size: 11px; }
.primary-button, .secondary-button, .text-button { border: 0; border-radius: 12px; font-weight: 800; }
.primary-button { width: 100%; padding: 13px 16px; background: var(--accent); color: var(--accent-text); }
.secondary-button { padding: 13px 16px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.text-button { padding: 7px 9px; background: transparent; color: var(--accent); }
.primary-button:disabled { opacity: .55; cursor: wait; }

.orders-heading { display: flex; align-items: center; justify-content: space-between; margin: 20px 3px 12px; }
.orders-heading h2 { margin: 0; font-size: 18px; }
.order-list { display: grid; gap: 11px; }
.order-card { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.order-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.order-top strong { min-width: 0; font-size: 14px; word-break: keep-all; }
.status-badge { flex: 0 0 auto; padding: 5px 8px; border-radius: 999px; background: rgba(142, 188, 240, .14); color: var(--accent); font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-badge.done { background: rgba(135, 216, 188, .14); color: var(--success); }
.order-card p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.transaction { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--line); }
.transaction strong { display: block; margin-bottom: 5px; font-size: 12px; }
.transaction code { display: block; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.empty-card { padding: 36px 18px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }
.error-card { color: #ffdce2; border-color: #71404b; background: #3b222b; }
.loading-card { display: grid; place-items: center; }
.small-spinner { width: 28px; height: 28px; border: 3px solid rgba(142, 188, 240, .2); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }

.modal-layer, .loading-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 8, 17, .76);
  backdrop-filter: blur(8px);
}
.modal-card { width: min(100%, 430px); max-height: calc(100vh - 40px); overflow: auto; padding: 22px; border: 1px solid #385a84; border-radius: 21px; background: #12223a; box-shadow: 0 24px 70px rgba(0, 0, 0, .48); }
.modal-icon { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 14px; border-radius: 13px; background: rgba(135, 216, 188, .14); color: var(--success); font-size: 20px; font-weight: 900; }
.modal-card h2 { margin: 0 0 15px; font-size: 19px; }
.modal-content { padding: 14px; border-radius: 13px; background: #0d192b; color: var(--muted); font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }
.modal-content strong { color: var(--text); }
.modal-actions { display: grid; grid-template-columns: .75fr 1.25fr; gap: 9px; margin-top: 16px; }
.modal-actions .primary-button { padding: 13px; }

.loading-layer { z-index: 80; color: var(--muted); }
.loading-layer p { margin: 15px 0 0; font-size: 13px; }
.spinner { width: 38px; height: 38px; border: 3px solid rgba(142, 188, 240, .2); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 90; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 36px); transform: translateX(-50%); padding: 12px 15px; border: 1px solid #396088; border-radius: 12px; background: #172b47; color: var(--text); font-size: 12px; font-weight: 700; box-shadow: var(--shadow); }
.toast.error { border-color: #71404b; background: #3b222b; color: #ffdce2; }
.hidden { display: none !important; }
.session-recovery {
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  display: grid;
  place-items: center;
  padding: 20px;
}
.session-card {
  width: min(100%, 390px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.session-card h1 { margin: 0 0 18px; text-align: center; font-size: 20px; }
.session-card p { margin: -7px 0 18px; color: var(--muted); text-align: center; font-size: 13px; }

@media (min-width: 720px) {
  .app-shell { padding-left: 28px; padding-right: 28px; }
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 390px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .section-block { padding: 14px; }
  .product-card { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
