:root {
  /* ARR brand: logo blue #2E3192 on white */
  --bg: #f3f6fc;
  --surface: #ffffff;
  --surface-2: #eef2fa;
  --text: #151a45;
  --muted: #5d6488;
  --border: #dce3f1;
  --accent: #2e3192;
  --accent-ink: #ffffff;
  --accent-soft: #e7e9f8;
  --brand-bright: #1f63d8;
  --gold: #f4b400;
  --ok: #1e7a4c;
  --ok-soft: #e0f3e9;
  --warn: #8a6100;
  --warn-soft: #fdf2d3;
  --bad: #c4262e;
  --bad-soft: #fde6e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(30 40 110 / 0.05), 0 6px 20px rgb(30 40 110 / 0.07);
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", "Sukhumvit Set", "Thonburi", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 64px; }
.wrap.narrow { max-width: 560px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar { flex-wrap: wrap; }
.topbar .brand { font-weight: 700; font-size: 1.05rem; min-width: 0; flex: 1 1 180px; }
.topbar .row { flex-wrap: nowrap; flex-shrink: 0; gap: 4px; }
.topbar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 0.82rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"], input[type="radio"] { width: auto; margin: 0; }
textarea { min-height: 80px; resize: vertical; }

button, .btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px;
  padding: 9px 16px; cursor: pointer; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.ghost, .btn.ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
button.danger { background: var(--bad-soft); color: var(--bad); }
button.ok { background: var(--ok-soft); color: var(--ok); }
button.block, .btn.block { width: 100%; }
button.sm, .btn.sm { padding: 5px 10px; font-size: 0.85rem; }

.badge {
  display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--accent-soft); color: var(--accent); }
.badge.completed { background: var(--ok-soft); color: var(--ok); }
.badge.rejected, .badge.cancelled { background: var(--bad-soft); color: var(--bad); }
.badge.new, .badge.increase { background: var(--ok-soft); color: var(--ok); }
.badge.decrease { background: var(--bad-soft); color: var(--bad); }

.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 0.9rem; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--surface-2); color: var(--muted); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.success { background: var(--ok-soft); color: var(--ok); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.8rem; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button {
  background: transparent; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent;
  padding: 10px 14px; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; font-size: 0.75rem; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog.wide { width: min(820px, calc(100vw - 32px)); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 0.9rem;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* Brand header */
.topbar { border-bottom: 3px solid var(--accent); }
.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-lockup img { height: 34px; width: auto; display: block; }
.brand-lockup .divider { width: 1px; align-self: stretch; background: var(--border); }
.brand-lockup .name { font-weight: 700; color: var(--accent); line-height: 1.2; }
.brand-lockup .name small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }

/* Customer page */
.points-hero {
  position: relative; overflow: hidden; isolation: isolate;
  background: linear-gradient(135deg, var(--accent) 0%, var(--brand-bright) 100%);
  color: #fff; border-radius: 20px; padding: 22px; margin-bottom: 16px;
  box-shadow: 0 10px 28px rgb(46 49 146 / 0.28);
}
/* Concentric rings echoing the ARR logo mark */
.points-hero::after {
  content: ""; position: absolute; z-index: -1; right: -36px; top: -30px; width: 220px; height: 209px;
  background: url("/img/logo-mark-white.png") center / contain no-repeat;
  opacity: 0.12;
}
.points-hero .label { opacity: 0.9; font-size: 0.9rem; }
.points-hero .big { font-size: 3.2rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.points-hero .big small { font-size: 1rem; font-weight: 600; opacity: 0.9; margin-left: 6px; }
.points-hero .points-note { font-size: 0.75rem; opacity: 0.8; margin-top: 4px; }
.points-hero .meta {
  display: flex; gap: 18px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; font-size: 0.82rem;
  border-top: 1px solid rgb(255 255 255 / 0.22);
}
.points-hero .meta b { display: block; font-size: 1rem; }
/* The baht value gets its own full-width line; earned / used sit side by side below it. */
.points-hero .meta > :first-child { flex-basis: 100%; }
.points-hero .meta > :first-child b { font-size: 1.25rem; }

.shop-bar { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-bottom: 12px; }
.shop-bar select { flex: 1; min-width: 0; font-weight: 600; color: var(--accent); }

.rate-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface); color: var(--accent);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 14px; font-weight: 700; font-size: 0.9rem;
}
.rate-chip small { font-weight: 400; color: var(--muted); }

.section-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.section-title h2 { margin: 0; color: var(--accent); }
.section-title::before { content: ""; width: 5px; height: 22px; border-radius: 3px; background: var(--brand-bright); }

.reward {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.reward .pic {
  aspect-ratio: 4 / 3; background: #fff; display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border); overflow: hidden;
}
/* Reward images are designed at 4:3 (e.g. 1200 x 900 px) and fill the frame exactly. */
.reward .pic img { width: 100%; height: 100%; object-fit: contain; }
.reward .pic.empty { background: var(--accent-soft); }
.reward .pic.empty img { width: 56px; height: auto; opacity: 0.5; }
.reward .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.reward h3 { margin: 0; font-size: 1rem; }
.reward .cost {
  align-self: flex-start; font-weight: 800; color: #fff; background: var(--accent);
  border-radius: 8px; padding: 2px 10px; font-size: 0.95rem;
}
.reward .desc { color: var(--muted); font-size: 0.86rem; flex: 1; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand-bright); }

.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }

.terms { white-space: pre-line; font-size: 0.88rem; color: var(--muted); margin: 0; }
details.card > summary { cursor: pointer; font-weight: 700; color: var(--accent); }
details.card[open] > summary { margin-bottom: 10px; }

.poster-link { display: block; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); }
.poster-link img { display: block; width: 100%; height: auto; }

/* Login */
.login-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #e8eefb 0%, var(--bg) 340px);
}
.login-box { max-width: 420px; margin: 0 auto; padding-top: 5vh; }
.login-logo { display: block; width: min(240px, 70%); margin: 0 auto 6px; }
.login-tagline { text-align: center; color: var(--accent); font-weight: 700; margin-bottom: 18px; }
.login-tagline small { display: block; font-weight: 400; color: var(--muted); }

dialog .stats { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
@media (max-width: 600px) {
  dialog { padding: 16px; }
  dialog .card { padding: 14px; }
}

/* Name suggestions on the sign-up form */
.combo-box { position: relative; }
.combo-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 280px; overflow-y: auto;
}
.combo-hint { margin: 4px 0 0; }
.combo-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.combo-list li small { display: block; color: var(--muted); font-size: 0.78rem; }
.combo-list li.active, .combo-list li[role="option"]:hover { background: var(--accent-soft); }
.combo-list li.combo-empty { cursor: default; color: var(--muted); font-size: 0.85rem; }

.staff-link { text-align: center; margin: 18px 0 0; font-size: 0.85rem; }
.staff-link a { color: var(--muted); text-decoration: none; }
.staff-link a:hover { color: var(--accent); text-decoration: underline; }

/* Sales staff: read-only customer list */
.role-sales #add-customer-btn { display: none; }
.role-sales #customer-table tr.clickable { cursor: default; }
.role-sales #customer-table tr.clickable:hover td { background: none; }
