:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6676;
  --line: #dfe3ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #1b7f3b;
  --warn-bg: #fff4d6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e8ebf1;
    --muted: #9aa3b2;
    --line: #2d3442;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --danger: #ff6b6b;
    --ok: #4cc77a;
    --warn-bg: #3a3118;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", "Leelawadee UI", "Noto Sans Thai", system-ui, sans-serif;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--danger); margin: 0; }

/* --- buttons and fields -------------------------------------------------- */
button, input, select {
  font: inherit;
  color: inherit;
}

button {
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: default; }

input, select {
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }

/* --- login --------------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(380px, 100%); display: grid; gap: 14px; padding: 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }

/* --- layout -------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
#tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { border-color: transparent; background: transparent; }
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.badge {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px;
  border-radius: 11px; background: var(--danger); color: #fff; font-size: 12px; text-align: center;
}
.badge.zero { background: var(--muted); }

.content { max-width: 1040px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { flex: 1; }

.toast { margin: 0 0 12px; padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); }
.toast.bad { color: var(--danger); }

/* --- pending slips ------------------------------------------------------- */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card {
  display: grid; gap: 10px; min-width: 0; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.card .who { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.card .amount { font-size: 22px; font-weight: 700; }
.slip-thumb {
  width: 100%; height: 220px; object-fit: contain; cursor: zoom-in;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.card label input { width: 100%; min-width: 0; }
.card .buttons { display: flex; gap: 8px; }
.card .buttons button { flex: 1; }
.empty { color: var(--muted); padding: 24px 0; }

/* --- tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { display: flex; gap: 6px; }
.status-approved { color: var(--ok); font-weight: 600; }
.status-rejected { color: var(--danger); font-weight: 600; }

/* --- dialogs ------------------------------------------------------------- */
dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog form { display: grid; gap: 12px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }
#info { width: min(720px, calc(100vw - 32px)); }
.info-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
#info-body img { width: 100%; max-height: 75vh; object-fit: contain; }

/* --- games tab ----------------------------------------------------------------------- */
.upload-card { margin-bottom: 14px; display: grid; gap: 10px; }
.upload-card .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
code { padding: 1px 5px; border-radius: 5px; background: var(--bg); }
