/* หน้านับเงิน + หน้าประวัติ */
:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #6b7684;
  --line: #dde2e8;
  --head: #13202f;
  --gold: #e8b931;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --danger: #c2410c;
  --ok: #15803d;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: 'Sarabun', 'Prompt', system-ui, sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- header ---------- */
.cm-header {
  background: var(--head);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.cm-header-inner {
  max-width: 640px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.cm-title { font-size: 1.35rem; font-weight: 700; letter-spacing: .3px; }
.cm-title b { color: var(--gold); }
.cm-title small { color: #8a96a6; font-size: .75rem; font-weight: 400; margin-left: 4px; }
.cm-clock { margin-left: auto; text-align: right; line-height: 1.2; }
.cm-clock .date { color: #c9d2dd; font-size: .85rem; }
.cm-clock .time { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--gold); }
.cm-link {
  color: #fff; text-decoration: none; font-size: .9rem;
  border: 1px solid #3a4a5e; border-radius: 8px; padding: 6px 10px; white-space: nowrap;
}
.cm-link:hover { background: #22344a; }

/* ---------- layout ---------- */
.cm-main { max-width: 640px; margin: 0 auto; padding: 14px 16px 120px; }
.cm-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06); padding: 14px;
  margin-bottom: 12px;
}
.cm-field { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 10px; }
.cm-field + .cm-field { margin-top: 10px; }
.cm-field label { color: var(--muted); font-size: .95rem; }
.cm-input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: 1.05rem; background: #fbfcfd;
}
.cm-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }

/* ---------- denomination rows ---------- */
.cm-list { padding: 4px 0; }
.cm-list-head, .cm-row {
  display: grid; grid-template-columns: 96px 1fr 110px; align-items: center; gap: 10px;
  padding: 0 14px;
}
.cm-list-head { color: var(--muted); font-size: .8rem; padding-top: 6px; padding-bottom: 6px; }
.cm-list-head span:last-child, .cm-amount { text-align: right; }
.cm-row { padding-top: 7px; padding-bottom: 7px; border-top: 1px solid var(--line); }
.cm-row.has-value { background: #f5f9ff; }

.cm-chip {
  display: flex; flex-direction: column; justify-content: center;
  height: 44px; border-radius: 8px; padding: 0 10px; color: #fff; line-height: 1.05;
}
.cm-chip b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.cm-chip small { font-size: .7rem; opacity: .85; }
.cm-chip.coin { border-radius: 22px; }
/* สีตามธนบัตร/เหรียญไทย */
.d1000 { background: #7a6650; }
.d500  { background: #7b4fa0; }
.d100  { background: #c53a3a; }
.d50   { background: #2f6fb8; }
.d20   { background: #2e8b57; }
.d10   { background: linear-gradient(135deg, #c9a43a 0 45%, #a9b0b8 45%); color: #1b2430; }
.d5, .d1 { background: #b8bfc7; color: #1b2430; }
.d2    { background: #d4ac3c; color: #1b2430; }

.cm-stepper { display: grid; grid-template-columns: 40px 1fr 40px; height: 44px; }
.cm-stepper button {
  border: 1px solid var(--line); background: #f3f5f8; font-size: 1.3rem; line-height: 1;
}
.cm-stepper button:first-child { border-radius: 8px 0 0 8px; }
.cm-stepper button:last-child { border-radius: 0 8px 8px 0; }
.cm-stepper button:active { background: #e3e8ee; }
.cm-qty {
  width: 100%; min-width: 0; border: 1px solid var(--line); border-left: 0; border-right: 0;
  text-align: center; font-size: 1.2rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cm-qty:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.cm-qty::placeholder { color: #c3cad3; font-weight: 400; }
.cm-amount { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cm-amount.zero { color: #c3cad3; font-weight: 400; }

/* ---------- bottom bar ---------- */
.cm-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, .08);
}
.cm-bar-inner {
  max-width: 640px; margin: 0 auto; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
}
.cm-total { flex: 1; min-width: 0; line-height: 1.15; }
.cm-total small { color: var(--muted); font-size: .8rem; display: block; }
.cm-total b { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.cm-btn {
  border: none; border-radius: 10px; padding: 12px 18px; font-size: 1.05rem; font-weight: 600;
  white-space: nowrap;
}
.cm-btn-primary { background: var(--accent); color: var(--accent-ink); }
.cm-btn-primary:disabled { background: #93a3c4; cursor: wait; }
.cm-btn-ghost { background: #f3f5f8; color: var(--ink); border: 1px solid var(--line); }
.cm-btn-ghost.confirm { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- toast ---------- */
.cm-toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px);
  background: var(--head); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: .95rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 20;
  max-width: calc(100% - 32px); text-align: center;
}
.cm-toast.show { opacity: 1; transform: translate(-50%, 0); }
.cm-toast.error { background: var(--danger); }
.cm-toast.ok { background: var(--ok); }

/* ---------- history ---------- */
.cm-main.wide { max-width: 980px; padding-bottom: 40px; }
.cm-header-inner.wide { max-width: 980px; }
.cm-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.cm-filters label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.cm-filters .grow { flex: 1; min-width: 160px; }
.cm-filters .cm-input { padding: 8px 10px; font-size: 1rem; }
.cm-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.cm-quick button { border: 1px solid var(--line); background: #f3f5f8; border-radius: 20px; padding: 4px 12px; font-size: .85rem; }
.cm-summary { display: flex; gap: 12px; flex-wrap: wrap; }
.cm-summary div { flex: 1; min-width: 140px; }
.cm-summary small { color: var(--muted); display: block; font-size: .8rem; }
.cm-summary b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

.cm-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cm-table th { text-align: left; color: var(--muted); font-weight: 400; font-size: .85rem; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.cm-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cm-table .r { text-align: right; }
.cm-table tr.cm-hrow { cursor: pointer; }
.cm-table tr.cm-hrow:hover td { background: #f7f9fc; }
.cm-table .detail td { background: #f7f9fc; color: var(--muted); font-size: .9rem; }
.cm-detail-items { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.cm-reprint { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: .85rem; }
.cm-empty { text-align: center; color: var(--muted); padding: 30px 10px; }

@media (max-width: 640px) {
  .cm-table thead { display: none; }
  .cm-table, .cm-table tbody, .cm-table tr, .cm-table td { display: block; width: 100%; }
  .cm-table tr.cm-hrow { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .cm-table tr.cm-hrow td { border: 0; padding: 2px 10px; }
  .cm-table td.no { color: var(--muted); font-size: .85rem; }
  .cm-table td.when { grid-column: 1; }
  .cm-table td.total { grid-column: 2; grid-row: 1 / span 2; font-size: 1.15rem; font-weight: 600; align-self: center; }
  .cm-table td.unit { grid-column: 1; }
  .cm-table td.act { grid-column: 2; text-align: right; }
}

@media (max-width: 420px) {
  .cm-list-head, .cm-row { grid-template-columns: 78px 1fr 92px; gap: 8px; padding-left: 10px; padding-right: 10px; }
  .cm-chip b { font-size: 1.05rem; }
  .cm-stepper { grid-template-columns: 34px 1fr 34px; }
  .cm-amount { font-size: 1rem; }
  .cm-total b { font-size: 1.4rem; }
  .cm-btn { padding: 12px 14px; }
  .cm-title small { display: none; }
}

/* ---------- ใส่รหัสดูประวัติ ---------- */
.cm-pin { max-width: 340px; margin: 40px auto 0; display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 24px 20px; }
.cm-pin-icon { font-size: 2rem; }
.cm-pin label { color: var(--muted); }
.cm-pin .cm-input { text-align: center; font-size: 1.8rem; letter-spacing: .5em; padding: 10px; }
.cm-pin-error { color: var(--danger); font-size: .95rem; }
.cm-lock-form { margin-left: auto; }
.cm-lock-form .cm-link { background: none; }
