@font-face {
  font-family: Prompt;
  src: url("/fonts/Prompt-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Prompt;
  src: url("/fonts/Prompt-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: Prompt;
  src: url("/fonts/Prompt-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  --blue: #00629d;
  --blue-dark: #004e7c;
  --blue-soft: #e7f2f8;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --text: #1a2330;
  --muted: #5b6b7c;
  --line: #d7dee6;
  --danger: #b42318;
  --danger-soft: #fdecec;
  --ok: #0f7b4d;
  --ok-soft: #e7f6ee;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --radius: 14px;
  --tab-h: 56px;
  --top-h: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 8px 28px rgba(16, 36, 58, 0.12);
  font-family: Prompt, "IBM Plex Sans Thai", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--top-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: var(--blue); color: #fff;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.topbar .brand img { width: 32px; height: 32px; border-radius: 8px; background: #fff; }
.topbar .brand .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand .sub { font-size: 12px; font-weight: 400; opacity: 0.85; }
.topbar nav.desk { margin-left: auto; display: none; gap: 4px; }
.topbar nav.desk a {
  color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 10px; min-height: 44px;
  display: inline-flex; align-items: center; font-weight: 500;
}
.topbar nav.desk a.active, .topbar nav.desk a:hover { background: rgba(255,255,255,0.18); }
.topbar .user { margin-left: 8px; font-size: 13px; opacity: 0.9; display: none; }

.main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 20px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted);
  font-size: 11px; font-weight: 500; min-height: var(--tab-h);
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--blue); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search {
  flex: 1; min-width: 180px; height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px;
}
.select, .btn, .input, .textarea {
  height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px;
}
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; width: 100%; }
.input { width: 100%; }
.select { min-width: 120px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface); color: var(--text); font-weight: 500; min-width: 44px; text-decoration: none;
}
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16,36,58,0.04);
}
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-weight: 600; color: var(--muted); font-size: 13px; background: #f8fafc; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data tr:hover td { background: #f7fbfe; }
table.data tr { cursor: pointer; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--blue-soft); color: var(--blue-dark);
}
.badge.via { background: var(--warn-soft); color: var(--warn); }
.badge.direct { background: var(--blue-soft); color: var(--blue-dark); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.cards { display: grid; gap: 10px; }
.entity-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; gap: 12px; align-items: flex-start; text-decoration: none; color: inherit;
  min-height: 64px;
}
.entity-card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.entity-card p { margin: 0; font-size: 13px; color: var(--muted); }
.thumb {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--blue-soft); flex-shrink: 0;
}

.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--safe-t));
  background: linear-gradient(180deg, #00629d 0%, #0a4a75 100%);
}
.login-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 20px; padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.lead { margin: 0 0 20px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 759px) {
  .form-grid { grid-template-columns: 1fr; }
  .desk-only { display: none !important; }
  .topbar nav.desk, .topbar .user { display: none !important; }
}
@media (min-width: 760px) {
  .tabbar { display: none; }
  .main { padding-bottom: 32px; }
  .topbar nav.desk, .topbar .user { display: flex; }
  .mob-only { display: none !important; }
}

/* Bottom sheet / modal */
.backdrop {
  position: fixed; inset: 0; background: rgba(16, 36, 58, 0.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-height: min(92dvh, 920px);
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); box-shadow: var(--shadow);
}
.sheet-handle { width: 42px; height: 4px; border-radius: 4px; background: #c5ced6; margin: 8px auto 0; }
.sheet-head, .sheet-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
}
.sheet-head { border-bottom: 1px solid var(--line); justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { overflow: auto; padding: 16px; flex: 1; }
.sheet-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
@media (min-width: 760px) {
  .backdrop { align-items: center; padding: 24px; }
  .sheet { max-width: 760px; border-radius: 20px; }
  .sheet-handle { display: none; }
}

.images { display: flex; gap: 10px; flex-wrap: wrap; }
.img-tile {
  width: 112px; position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
}
.img-tile img { width: 112px; height: 112px; object-fit: cover; display: block; background: #eef3f7; }
.img-tile .img-actions {
  display: flex; justify-content: space-between; padding: 4px;
}
.img-tile button { height: 36px; min-width: 36px; padding: 0 6px; font-size: 13px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 48px;
}
.switch-row .meta { font-size: 13px; color: var(--muted); }
.toggle {
  appearance: none; width: 48px; height: 28px; border-radius: 999px; border: 0;
  background: #c5ced6; position: relative; flex-shrink: 0;
}
.toggle:checked { background: var(--blue); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: left 0.15s;
}
.toggle:checked::after { left: 23px; }

.match-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .match-grid { grid-template-columns: 1fr 1fr; } }
.match-col h2 { margin: 0 0 8px; font-size: 16px; }
.match-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.stat-pill { background: var(--blue-soft); color: var(--blue-dark); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 500; }

.audit-item { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.audit-item pre {
  margin: 8px 0 0; background: #f6f8fa; padding: 8px; border-radius: 8px;
  font-size: 12px; overflow: auto; max-height: 180px;
}

.toasts { position: fixed; top: calc(12px + var(--safe-t)); right: 12px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1a2330; color: #fff; padding: 10px 14px; border-radius: 12px;
  box-shadow: var(--shadow); min-width: 200px; max-width: 360px;
}
.toast.err { background: var(--danger); }

.install-bar {
  position: sticky; top: var(--top-h); z-index: 19;
  background: var(--blue-soft); color: var(--blue-dark);
  padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 14px;
}

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; justify-content: center; padding: 32px; }
.more-list a, .more-list button.linkish {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; background: var(--surface); border: 0; border-bottom: 1px solid var(--line);
  padding: 16px; min-height: 52px; text-decoration: none; color: inherit; font-weight: 500; border-radius: 0;
}
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; background: #fff; font-size: 13px;
}
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 14px; }

.strike { text-decoration: line-through; color: var(--muted); font-weight: 400; margin-left: 6px; }
.price-now { font-weight: 600; color: var(--ok); }
.price-callout {
  background: var(--ok-soft); border: 1px solid #b7e0c8; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px;
}
.price-callout.none { background: #f6f8fa; border-color: var(--line); }
.price-callout strong { display: block; font-size: 18px; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: grid; grid-template-columns: 16px 1fr auto; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line); align-items: start;
}
.timeline-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--line);
  margin-top: 6px; box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--line);
}
.timeline-item.current .timeline-dot { background: var(--ok); box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--ok); }
.timeline-item .when { font-size: 13px; color: var(--muted); }
.campaign-card { padding: 14px; display: block; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.campaign-card:last-child { border-bottom: 0; }
.campaign-card h3 { margin: 0 0 4px; font-size: 16px; }
.status-draft { background: #f0f2f5; color: #445; }
.status-active { background: var(--ok-soft); color: var(--ok); }
.status-ended { background: #eee; color: var(--muted); }
.status-upcoming { background: var(--warn-soft); color: var(--warn); }
.price-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
@media (max-width: 759px) {
  .price-form { grid-template-columns: 1fr 1fr; }
  .timeline-item { grid-template-columns: 16px 1fr; }
  .timeline-item .row-actions { grid-column: 2; }
}
#revealed-value { font-family: ui-monospace, monospace; letter-spacing: 0.02em; }
.audit-item .btn { margin-top: 8px; }
