/* Beture LINE Mini App — design tokens and components.
 *
 * Ported from the Claude Design canvas "Beture LINE Mini App.dc.html". The
 * prototype carried every rule as an inline style; here the same values live as
 * tokens and classes so a colour or radius changes in one place.
 *
 * The prototype also drew a presentation rail and a phone bezel around the app.
 * Inside LINE the Mini App IS the viewport, so that chrome is dev-only and lives
 * behind ?frame=1 (see .dev-* rules at the bottom).
 */

:root {
  --brand: #e01d25;
  --line: #06c755;
  --bg: #0e0e0e;
  --bg-deep: #0a0a0b;
  --surface: #161618;
  --surface-2: #151517;
  --surface-3: #141416;
  --border: #232327;
  --border-2: #2a2a2e;
  --fg: #ffffff;
  --muted: #9aa0a6;
  --dim: #8a9099;
  --faint: #6b7178;
  --warn: #f59e0b;
  --ok: #22c55e;
  --info: #3b82f6;
  --sheet: rgba(14, 14, 14, 0.96);
  --font: "Prompt", "Noto Sans Thai", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  overscroll-behavior-y: none;
}

button, input, select { font-family: var(--font); }

.form-field {
  display: block;
  margin-top: 11px;
}

.form-field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

.form-field input {
  width: 100%;
  box-sizing: border-box;
  min-height: 42px;
  padding: 0 12px;
  color: #fff;
  background: #0b0d12;
  border: 1px solid var(--line-2, #252a33);
  border-radius: 10px;
  outline: none;
}

.form-field input:focus {
  border-color: var(--line);
}
button { cursor: pointer; }
a { color: inherit; }

/* ---------- app shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.appbar {
  flex: 0 0 54px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid #1a1a1d;
  z-index: 40;
}
.appbar__btn {
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: #1d1d20; color: var(--fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.appbar__btn--close { color: var(--muted); font-size: 17px; }
.appbar__title {
  flex: 1; text-align: center;
  font-weight: 600; font-size: 16px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.screen { padding: 18px 16px 28px; animation: betFade 0.22s ease both; }
.screen--flush { padding: 0 0 28px; }

@keyframes betFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes betSpin { to { transform: rotate(360deg); } }
@keyframes betPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes betPop { 0% { transform: scale(0.85); } 55% { transform: scale(1.07); } 100% { transform: scale(1); } }

/* ---------- typography ---------- */
.h1 { font-size: 22px; font-weight: 800; line-height: 1.2; }
.h2 { font-size: 16px; font-weight: 700; }
.label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--faint); margin: 22px 0 10px;
}
.label:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); font-size: 12px; }
.mono { font-family: var(--mono); }
.note { font-size: 11.5px; color: var(--faint); line-height: 1.55; text-align: center; }

/* ---------- cards / rows ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  width: 100%; height: 50px;
  border: none; border-radius: 13px;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: 15.5px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  box-shadow: 0 10px 26px -8px rgba(224, 29, 37, 0.7);
}
.btn:disabled { opacity: 0.55; box-shadow: none; }
.btn--ghost {
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); box-shadow: none;
}
.btn--line { background: var(--line); color: #06210f; box-shadow: none; }
.btn--danger-ghost { background: transparent; color: var(--brand); border: 1px solid rgba(224,29,37,.4); box-shadow: none; }
.btn--sm { height: 40px; font-size: 13.5px; border-radius: 11px; }

.chip {
  flex: 0 0 auto;
  padding: 8px 15px; border-radius: 20px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--muted);
}
.chip[aria-pressed="true"] { border-color: transparent; background: var(--brand); color: #fff; }

.badge {
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 5px;
}
.badge--hot { background: #ff6b0022; color: #ff6b00; }
.badge--new { background: #3b82f622; color: #3b82f6; }
.badge--sale { background: #e01d2522; color: #e01d25; }
.badge--ok { background: #22c55e22; color: #22c55e; }
.badge--warn { background: #f59e0b22; color: #f59e0b; }
.badge--dim { background: #75757522; color: #9aa0a6; }

/* ---------- sticky footer over the scroll ---------- */
.sheet {
  flex: 0 0 auto;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--sheet);
  backdrop-filter: blur(12px);
  border-top: 1px solid #1c1c20;
}

/* ---------- tab bar ---------- */
.tabbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #0c0c0d; border-top: 1px solid #1c1c20;
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  border: none; background: transparent;
  padding: 9px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; color: var(--faint);
  position: relative;
}
.tabbar button[aria-current="page"] { color: var(--brand); }
.tabbar .dot {
  position: absolute; top: 5px; right: calc(50% - 20px);
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 9px; background: var(--brand); color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- home ---------- */
.hero {
  background: linear-gradient(160deg, #1c1c20 0%, #121214 60%, var(--bg) 100%);
  border-bottom: 1px solid #1c1c20;
  padding: 18px 16px 20px;
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #232327; display: flex; align-items: center; justify-content: center;
  font-size: 21px; flex: 0 0 auto; object-fit: cover;
}
.pill {
  font-size: 10.5px; font-weight: 600; color: var(--line);
  background: rgba(6, 199, 85, 0.12); border-radius: 20px; padding: 4px 9px;
  white-space: nowrap;
}
.hero__headline { margin: 16px 0 0; font-size: 20px; font-weight: 800; line-height: 1.3; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.quick button {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 13px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  position: relative; color: var(--brand);
}
.quick span { font-size: 11px; font-weight: 600; color: #e7e7ea; }
.quick .dot {
  position: absolute; top: 8px; right: 12px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px;
  background: var(--brand); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.cats button {
  text-align: left;
  background: linear-gradient(135deg, #1b1b1f, #121214);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; display: flex; align-items: center; gap: 12px; color: var(--fg);
}
.cats .thumb {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  background: repeating-conic-gradient(#070707 0deg 12deg, #2a2a2a 12deg 24deg);
  box-shadow: inset 0 0 0 4px #121212, inset 0 0 0 5px var(--brand);
}

/* ---------- search / stock ---------- */
.searchbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); padding: 14px 16px 10px;
  border-bottom: 1px solid #1a1a1d;
}
.searchbar__field {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 13px; padding: 11px 13px;
}
.searchbar__field input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: var(--fg); font-size: 14px;
}
.chiprow { display: flex; gap: 7px; overflow-x: auto; margin-top: 10px; padding-bottom: 2px; }
.chiprow::-webkit-scrollbar { display: none; }

.product {
  display: flex; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 12px;
}
/* Tyre placeholder: a tread ring, not a starburst square. Beture's master data
   carries no product images (data/import/01_products.csv has no image column),
   so every card would otherwise be an empty box — this at least reads as a
   tyre. Replace with real photography when the client supplies it. */
.product__thumb {
  width: 72px; height: 72px; border-radius: 50%; flex: 0 0 auto;
  background: repeating-conic-gradient(#0a0a0a 0deg 9deg, #262629 9deg 18deg);
  box-shadow: inset 0 0 0 3px #303034, inset 0 0 0 16px #131315,
              inset 0 0 0 17px rgba(224, 29, 37, 0.45), inset 0 0 0 26px #1a1a1d;
  border: none; padding: 0;
}
.product__brand { font-size: 11px; font-weight: 700; color: var(--brand); }
.product__name {
  border: none; background: transparent; padding: 0; text-align: left;
  font-weight: 700; font-size: 14.5px; color: var(--fg); line-height: 1.25;
  display: block; width: 100%;
}
.product__spec { font-size: 12px; color: var(--muted); margin-top: 2px; font-family: var(--mono); }
.product__price { font-weight: 800; font-size: 16px; }
.product__add {
  border: none; background: var(--brand); color: #fff;
  width: 38px; height: 38px; border-radius: 11px;
  font-size: 22px; font-weight: 300; line-height: 1;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}

.stockline { display: flex; align-items: center; gap: 9px; font-size: 12.5px; padding: 7px 0; }
.stockline + .stockline { border-top: 1px solid #1c1c20; }
.stockline .led { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- quantity stepper ---------- */
.stepper {
  display: flex; align-items: center; gap: 2px;
  background: #0f0f11; border: 1px solid var(--border); border-radius: 11px; padding: 3px;
}
.stepper button {
  width: 34px; height: 34px; border: none; border-radius: 9px;
  background: #1d1d20; color: var(--fg); font-size: 18px; line-height: 1;
}
.stepper span { min-width: 40px; text-align: center; font-weight: 700; font-size: 15px; }

/* ---------- totals ---------- */
.totals { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.totals__row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.totals__row span:first-child { color: var(--muted); }
.totals__rule { height: 1px; background: var(--border); margin: 9px 0; }
.totals__grand { display: flex; justify-content: space-between; align-items: baseline; }
.totals__grand b { font-size: 20px; font-weight: 800; }

/* ---------- selectable option cards ---------- */
.opt {
  display: flex; align-items: center; gap: 13px;
  width: 100%; text-align: left;
  padding: 15px 14px; border-radius: 14px;
  background: var(--surface-2); border: 1.5px solid var(--border); color: var(--fg);
}
.opt[aria-pressed="true"] { background: rgba(224, 29, 37, 0.08); border-color: var(--brand); }
.opt__radio {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid #3a3a40; display: flex; align-items: center; justify-content: center;
}
.opt[aria-pressed="true"] .opt__radio { border-color: var(--brand); }
.opt[aria-pressed="true"] .opt__radio::after {
  content: ""; width: 11px; height: 11px; border-radius: 50%; background: var(--brand);
}
.opt__label { font-weight: 600; font-size: 14px; }
.opt__sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.opt__amount { text-align: right; font-weight: 700; font-size: 14.5px; }

.months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.months button {
  padding: 10px 4px; border-radius: 12px;
  background: var(--surface-2); border: 1.5px solid var(--border); color: var(--fg);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.months button[aria-pressed="true"] { background: rgba(224, 29, 37, 0.1); border-color: var(--brand); }
.months .n { font-size: 17px; font-weight: 800; }
.months .u { font-size: 10px; color: var(--dim); }
.months .p { font-size: 10px; color: var(--muted); margin-top: 3px; }

/* ---------- timeline ---------- */
.track { display: flex; gap: 13px; }
.track__rail { display: flex; flex-direction: column; align-items: center; }
.track__dot {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; background: #26262b;
}
.track__dot--done { background: var(--line); }
.track__dot--current { background: var(--brand); animation: betPulse 1.4s infinite; }
.track__line { width: 2px; flex: 1; min-height: 30px; background: #26262b; }
.track__line--done { background: var(--line); }
.track__body { padding-bottom: 18px; }
.track__body .t { font-weight: 600; font-size: 13.5px; }
.track__body .s { font-size: 11.5px; color: var(--dim); margin-top: 2px; }

/* ---------- success ---------- */
.success__mark {
  width: 92px; height: 92px; border-radius: 50%; margin: 6px auto 16px;
  background: rgba(6, 199, 85, 0.12); border: 1.5px solid rgba(6, 199, 85, 0.4);
  display: flex; align-items: center; justify-content: center;
  animation: betPop 0.45s ease both;
}

/* ---------- misc ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--dim); }
.empty__icon { font-size: 40px; margin-bottom: 12px; }

.toast {
  position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: #26262b; color: #fff; font-size: 12.5px;
  padding: 10px 16px; border-radius: 22px; white-space: nowrap;
  z-index: 90; animation: betFade 0.2s ease both;
  max-width: 88%; overflow: hidden; text-overflow: ellipsis;
}

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  border-radius: 13px; padding: 12px 13px; font-size: 12px; line-height: 1.5;
}
.banner--warn { background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.3); color: #f6d28a; }
.banner--info { background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3); color: #a9c7f7; }
.banner--err { background: rgba(224, 29, 37, 0.1); border: 1px solid rgba(224, 29, 37, 0.35); color: #f7a9ad; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.28); border-top-color: #fff;
  animation: betSpin 0.7s linear infinite;
}

.skeleton {
  background: linear-gradient(90deg, #161618, #1d1d21, #161618);
  background-size: 200% 100%; animation: betPulse 1.2s ease-in-out infinite;
  border-radius: 12px;
}

.linkbox {
  display: flex; align-items: center; gap: 9px;
  background: #0f0f11; border: 1px solid var(--border);
  border-radius: 11px; padding: 11px 12px;
}
.linkbox code {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 11.5px; color: #cfd3d8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- dev-only prototype frame (?frame=1) ---------- */
body.dev-frame {
  background: radial-gradient(1200px 600px at 78% -8%, rgba(224, 29, 37, 0.14), transparent 60%), var(--bg-deep);
  padding: 32px 20px;
  display: flex; justify-content: center; align-items: flex-start; gap: 36px;
}
body.dev-frame #app {
  width: 390px; height: 800px; max-width: none;
  border-radius: 44px; border: 10px solid #1b1b1e;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.9);
  flex: 0 0 auto;
}
.dev-rail { display: none; }
body.dev-frame .dev-rail {
  display: flex; flex-direction: column; gap: 20px;
  width: 320px; position: sticky; top: 32px;
}
.dev-rail__card {
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px;
}
.dev-rail__seg { display: flex; gap: 4px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 14px; padding: 5px; }
.dev-rail__seg button {
  flex: 1; border: none; border-radius: 10px; padding: 10px 6px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 13px;
}
.dev-rail__seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.dev-rail__step {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  font-size: 13px; padding: 8px 9px; border-radius: 9px;
  border: none; background: transparent; color: var(--muted);
}
.dev-rail__step[aria-current="step"] { background: rgba(224, 29, 37, 0.12); color: #fff; }
.dev-rail__num {
  width: 22px; height: 22px; flex: 0 0 auto; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; background: #26262b; color: #7d7d82;
}
.dev-rail__step[aria-current="step"] .dev-rail__num { background: var(--brand); color: #fff; }

@media (max-width: 900px) { body.dev-frame { padding: 0; } body.dev-frame .dev-rail { display: none; } body.dev-frame #app { width: 100%; height: 100dvh; border: none; border-radius: 0; } }
