/* Colours follow the admin's Telegram theme (light or dark). */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #6f7680);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --ok: #1f9d55;
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17191c; --bg2: #0f1113; --text: #eceef1; --hint: #8b929b; --line: #2a2e33;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
.card, .hist, .who, .note, .lines li span { min-width: 0; overflow-wrap: anywhere; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, "Noto Sans Khmer", "Khmer OS", sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.totals { display: flex; gap: 12px; align-items: center; padding: 10px 16px 6px; }
.total { display: flex; flex-direction: column; min-width: 0; }
.total .label { font-size: 12px; color: var(--hint); }
.total strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.icon-btn {
  margin-left: auto; border: 0; background: var(--bg2); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; font-size: 20px; cursor: pointer;
}
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); }
.tab {
  position: relative; border: 0; background: none; color: var(--hint); cursor: pointer;
  padding: 6px 2px 8px; font-size: 18px; border-bottom: 3px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 11px; line-height: 1.2; }
.tab.active { color: var(--btn); border-bottom-color: var(--btn); }
.badge {
  position: absolute; top: 3px; right: calc(50% - 26px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px;
}
.badge:empty { display: none; }

/* ---------- content ---------- */
main { padding: 12px 12px 40px; max-width: 720px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--bg); border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 6%); transition: opacity .25s, transform .25s;
}
.card.leaving { opacity: 0; transform: translateX(40px); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head h3 { margin: 0; font-size: 16px; }
.muted { color: var(--hint); font-size: 13px; }
.who a { color: var(--link); text-decoration: none; }
.grab { font-weight: 600; letter-spacing: .3px; }
.note { background: var(--bg2); border-radius: 10px; padding: 6px 10px; margin-top: 8px; font-size: 14px; }

.photos { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 8px; margin: 10px 0; }
.photos.single { grid-template-columns: minmax(0, 1fr); }
.photo {
  position: relative; background: var(--bg2); border-radius: 10px; overflow: hidden; min-width: 0;
  min-height: 140px; cursor: zoom-in; display: flex; align-items: center; justify-content: center;
}
.photo img { width: 100%; height: 100%; max-height: 360px; object-fit: contain; display: block; }
.photo .tag {
  position: absolute; left: 6px; top: 6px; background: rgb(0 0 0 / 60%); color: #fff;
  border-radius: 6px; padding: 1px 6px; font-size: 11px;
}
.photo.big { min-height: 220px; }
.photo.big img { max-height: 420px; }

.row { display: flex; gap: 8px; align-items: stretch; margin-top: 8px; }
.row > input { flex: 1; min-width: 0; }
.row.full { width: 100%; }
.nowrap { white-space: nowrap; }
input, select {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus { border-color: var(--btn); }
.preview { font-size: 13px; color: var(--ok); min-height: 18px; margin-top: 4px; }
.error { color: var(--danger); font-size: 13px; margin-top: 6px; white-space: pre-line; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--btn); color: var(--btn-text); white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.wide { width: 100%; margin-top: 10px; padding: 13px; }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 999px; padding: 6px 12px; cursor: pointer;
}

.pay-total { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lines { margin: 8px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.lines li {
  display: flex; justify-content: space-between; gap: 8px; padding: 7px 0;
  border-bottom: 1px solid var(--line); font-size: 14px; font-variant-numeric: tabular-nums;
}
.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }

.empty { text-align: center; color: var(--hint); padding: 50px 16px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search input { flex: 1; min-width: 0; }
.search select { max-width: 40%; }
.hist { background: var(--bg); border-radius: 12px; margin-bottom: 8px; padding: 10px 12px; cursor: pointer; }
.hist .top-line { display: flex; justify-content: space-between; gap: 8px; }
.hist .detail { margin-top: 8px; cursor: default; }
.status { font-size: 12px; white-space: nowrap; }

/* ---------- overlays ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 92%);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  background: #222; color: #fff; border-radius: 12px; padding: 12px 14px; font-size: 14px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 25%); white-space: pre-line;
}
.toast.bad { background: var(--danger); }
.blocked {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); color: var(--text);
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px;
  white-space: pre-line;
}
[hidden] { display: none !important; }
.row > .btn.ok { flex: 1; }
.row > input { font-size: 17px; }

/* payment photo attached on the Pay tab */
.proof { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.proof[hidden] { display: none; }
.proof img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; background: var(--bg2); cursor: zoom-in; }
.proof-side { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
