:root {
  /* Theme = warm APRICOT base (headers, badges, borders, accents) with
     CHILLI-PEPPER buttons (--btn). Softer winning green (--win). */
  --red: #c66a3a;           /* apricot / terracotta accent (kept the name so the rest of the CSS is untouched) */
  --red-dark: #a4522a;
  --red-light: #e08a55;
  --pink-border: #ecc3a3;   /* light apricot for the entry columns */
  --pink-bg: #fcefe3;
  --pink-bg-alt: #f8e2d0;
  --btn: #c0392b;           /* chilli pepper — buttons */
  --btn-dark: #9c2b20;
  --btn-light: #d65445;
  --win: #4a7a52;           /* muted green for winnings (was bright) */
  --win-bg: #eef4ec;
  --blue-check: #2d7bff;
  --gray-pill-a: #cfcfd4;
  --gray-pill-b: #9a9aa2;
  --ink: #a4522a;
  --white: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

/* ============ TOP NAV ============ */
.topnav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  background: #1c1c1c;
  padding: 0 8px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-brand {
  display: flex;
  align-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  padding: 0 14px 0 6px;
}
.topnav .nav-link,
.nav-menu button {
  background: transparent;
  border: none;
  color: #eee;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.topnav .nav-link:hover,
.nav-menu button:hover { background: #333; color: #fff; }
.topnav .nav-link.active { background: var(--red); color: #fff; }
.nav-group { position: relative; }
.nav-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #2a2a2a;
  min-width: 180px;
  flex-direction: column;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
}
.nav-group:hover .nav-menu { display: flex; }
.nav-menu button { text-align: left; padding: 11px 16px; }
.nav-user {
  margin-left: auto;
  background: #333; border: none; color: #ffd84d;
  font-size: 13px; font-weight: 700; padding: 0 16px; cursor: pointer;
}
.nav-user:hover { background: #444; }

/* ============ VIEWS ============ */
.view { display: none; }
.view.active { display: block; }
.page-pad { max-width: 1100px; margin: 0 auto; padding: 18px 20px 40px; }
.page-h { color: var(--red); font-size: 24px; margin: 6px 0 10px; }
.page-h3 { color: var(--red); font-size: 18px; margin: 22px 0 8px; }
.muted { color: #777; font-size: 14px; margin: 4px 0 14px; }
.placeholder {
  border: 2px dashed var(--pink-border);
  border-radius: 10px;
  padding: 30px;
  text-align: center;
  color: #999;
  font-size: 16px;
  background: #fff8fb;
}
.role-list { line-height: 2; font-size: 15px; }
.role-list b { color: var(--red); }

/* dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.dash-card { border: 1px solid var(--pink-border); border-radius: 10px; padding: 14px; text-align: center; background: #fff; }
.dash-val { font-size: 26px; font-weight: 800; color: var(--red); }
.dash-lbl { color: #777; font-size: 13px; margin-top: 4px; }
.dash-title { text-align: center; }
.dash-links { display: flex; flex-wrap: wrap; gap: 12px; }
.dash-links button { height: 42px; padding: 0 20px; }

/* Grand Total table (dashboard) — auto-fit, single-line headers */
.gt-table { width: auto; border-collapse: collapse; font-size: 14px; }
.gt-table th, .gt-table td { white-space: nowrap; }
.gt-table th { background: #f2f2f2; color: #333; border: 1px solid #cfcfcf; padding: 6px 12px; text-align: right; font-weight: 700; }
.gt-table th.l { text-align: left; }
.gt-table td { border: 1px solid #e0e0e0; padding: 6px 12px; text-align: right; }
.gt-table td.l { text-align: left; font-weight: 600; }
.gt-table tr.gt td { border-top: 2px solid #333; font-weight: 800; background: #fafafa; font-size: 15px; }

/* financial values: positive = blue, negative = red, zero = gray (everywhere) */
.pos { color: #1a4ea8; }
.neg { color: #c0272d; }
.zero { color: #888; }
.gt-table .neg, .gt-table .pos { font-weight: 700; }

/* permission group checkboxes */
.perm-checks { display: flex; flex-wrap: wrap; gap: 16px; padding: 8px 0; align-items: flex-start; }
.perm-cat { border: 1px solid #e3c9d6; border-radius: 8px; padding: 10px 12px; min-width: 180px; }
.perm-item { display: flex; align-items: center; gap: 6px; font-weight: 600; color: #444; padding: 2px 0; }
.perm-item input { width: 17px; height: 17px; }
.perm-cat-head { border-bottom: 1px solid #eee; padding-bottom: 6px; margin-bottom: 4px; }
.perm-cat-head small { color: #999; font-weight: 400; }
.perm-sub { padding-left: 16px; font-weight: 400; }

/* login gate — nothing shows until a user logs in */
body.locked .topnav,
body.locked main.views { display: none !important; }
.modal.gate { background: linear-gradient(135deg, var(--red-light) 0%, var(--red) 55%, var(--red-dark) 100%); }
.modal.gate .modal-box { width: 340px; }
.modal.gate .modal-box h3::before { content: "🎯 BramSamnang 2 & 3 — "; }

/* login modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px 24px; width: 320px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0 0 14px; color: var(--red); }
.modal-box .ff { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.login-error { color: #c0272d; font-size: 13px; min-height: 18px; font-weight: 700; }

/* dealer search field in entry header */
.hc-dealer input { width: 190px; height: 34px; border: 1px solid #fff; border-radius: 4px; padding: 0 8px; font-size: 14px; }

/* header draw/product selects */
.hc-field { display: flex; flex-direction: column; gap: 3px; color: #fff; font-weight: 700; font-size: 12px; }
.hc-field select { height: 34px; border: 1px solid #fff; border-radius: 4px; padding: 0 6px; font-size: 13px; }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; align-items: end; }
.ff { display: flex; flex-direction: column; gap: 5px; }
.ff > span { color: var(--red); font-weight: 700; font-size: 13px; }
.ff input, .ff select {
  height: 40px; border: 2px solid var(--red); border-radius: 8px; padding: 0 10px; font-size: 15px;
}
.ff--actions { flex-direction: row; gap: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 14px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid #e3c9d6; border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.data th, table.data td { border: 1px solid #ecd7e2; padding: 6px 9px; text-align: right; }
table.data th { background: var(--red); color: #fff; font-weight: 700; position: sticky; top: 0; }
table.data td.l, table.data th.l { text-align: left; }
table.data tr:nth-child(even) td { background: #faf3f7; }
table.data tr.group td { background: #fbe0ee; color: var(--red); font-weight: 800; text-align: left; }
table.data tr.total td { background: #f0f0f0; font-weight: 800; }
table.data .rm { color: #c33; cursor: pointer; font-weight: 800; }
/* Enter Result series grid */
.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 16px; }
.sr { display: flex; align-items: center; gap: 10px; }
.sr-lbl {
  flex: 0 0 auto; width: 38px; height: 48px; display: flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff; font-weight: 800; font-size: 20px; border-radius: 8px;
}
.sr-in {
  width: 140px; height: 48px; border: 2px solid var(--red); border-radius: 8px;
  font-size: 24px; letter-spacing: 4px; text-align: center; padding: 0 8px;
}
.sr-d { color: #2a7a3a; font-weight: 700; font-size: 13px; }
.rs-bar { display: flex; align-items: center; gap: 14px; margin: 8px 0 6px; }
.rs-stage { font-weight: 800; color: var(--red); }
.rs-stage.confirm { color: #d98200; }

.report-summary { margin-top: 14px; font-size: 14px; line-height: 1.9; }
.report-summary b { color: var(--red); }

/* dealer-report footer summary — bottom LEFT, matches the paper format */
.sumtab { margin: 20px auto 0 0; border-collapse: collapse; min-width: 360px; font-size: 15px; }
.sumtab td { padding: 6px 14px; text-align: right; }
.sumtab td.l { text-align: left; font-weight: 700; color: #333; }
.sumtab tr.sub td { border-top: 2px solid #bbb; font-weight: 800; }
.sumtab tr.grand td { border-top: 2px solid #999; font-weight: 800; font-size: 18px; }
/* win = company ahead (blue មេស៊ី) · loss = company behind (red មេខាต) */
.sumtab tr.win td { color: #1a4ea8; }
.sumtab tr.loss td { color: #c0272d; }

.report-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dash-tools { display: flex; align-items: center; gap: 10px; }
.dash-tools input { height: 36px; border: 2px solid var(--red); border-radius: 6px; padding: 0 8px; font-size: 14px; }
#debtCalc td { padding: 7px 14px; }
#debtCalc input { width: 150px; height: 32px; border: 1px solid var(--red); border-radius: 4px; padding: 0 8px; text-align: right; font-size: 14px; }
#debtCalc .btn-submit { height: 38px; }
.btn-mini { border: 1px solid var(--red); background: #fff; color: var(--red); border-radius: 5px; padding: 3px 9px; font-weight: 700; cursor: pointer; }
.pagelink { color: #1a4ea8; font-weight: 700; cursor: pointer; text-decoration: underline; }
.pagelink:hover { color: var(--red); }

/* Dealer report — styled to match the paper slip */
.dr-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dr-table .dr-bannerrow td { background: #2a5ca8; color: #fff; font-weight: 800; font-size: 15px; padding: 9px 12px; }
.dr-table .dr-bannerrow td:last-child { text-align: right; }
.dr-table thead tr:nth-child(2) th { background: #8a8a8a; color: #fff; font-weight: 700; padding: 6px 12px; text-align: right; }
.dr-table td { border: 1px solid #ead7e2; padding: 6px 12px; text-align: right; color: #333; }
.dr-table .dr-group td { background: #fbe2ef; color: #c0272d; text-align: left; font-weight: 800; }
.dr-table .dr-total td { background: #efefef; font-weight: 800; text-align: right; }
.dr-table .riel { color: #1a4ea8; font-weight: 700; }
.dr-table .pagelink { color: #1a4ea8; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, "Khmer OS", system-ui, sans-serif;
  background: #fff;
  color: #222;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
}

/* ============ HEADER ============ */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--red-light) 0%, var(--red) 55%, var(--red-dark) 100%);
  border-top: 5px solid #1c1c1c;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.logo {
  flex: 0 0 auto;
  display: inline-flex;
  background: #fff;
  border-radius: 50%;
  padding: 2px;
  box-shadow: var(--shadow);
}

.title {
  margin: 0;
  color: #fff;
  font-size: clamp(20px, 3vw, 34px);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: stretch;
  gap: 14px;
}

.page-no {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.page-no input {
  width: 120px;
  height: 34px;
  border: 1px solid #fff;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 15px;
}

.dealer-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-dealer {
  background: #fff;
  color: var(--red);
  border: 1px solid #fff;
  border-radius: 4px;
  padding: 6px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-dealer:hover { background: #fff4f4; }

.dealer-select {
  height: 28px;
  border: 1px solid #fff;
  border-radius: 4px;
  padding: 0 6px;
  font-size: 13px;
  background: #fff;
}

/* ============ CONTROL ROWS ============ */
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 6px 8px;
  background: linear-gradient(180deg, var(--red-light) 0%, var(--red) 100%);
}
.ctrl-row + .ctrl-row { padding-top: 4px; }

.check-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 0;
  min-width: 0;
  padding: 2px 6px;
}
.check-group--wide { flex: 1.2 1 0; }

/* checkbox */
.cbx {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid #b9b9bf;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  position: relative;
}
.cbx:checked {
  background: var(--blue-check);
  border-color: var(--blue-check);
}
.cbx:checked::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 5px;
  width: 8px;
  height: 16px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

/* circular A-E badges */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #fff;
  color: var(--red);
  border: 2px solid var(--red);
  font-weight: 800;
  font-size: 20px;
  box-shadow: var(--shadow);
}

/* pill buttons */
.pill {
  flex: 1 1 auto;
  border: none;
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.35), var(--shadow);
}
.pill--red {
  background: radial-gradient(120% 120% at 50% 25%, var(--red-light), var(--red) 60%, var(--red-dark));
}
.pill--red:active { filter: brightness(0.92); }
.pill--gray {
  background: linear-gradient(180deg, var(--gray-pill-a), var(--gray-pill-b));
  color: #6b1417;
  text-shadow: none;
}
.pill.is-active {
  outline: 3px solid #ffe14d;
  outline-offset: 1px;
}

/* ============ ENTRY ROW ============ */
.entry-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 10px 14px 14px;
  background: #fff;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* `.field` display:flex would otherwise override the [hidden] attribute */
.field[hidden] { display: none; }
.field-label {
  color: var(--red);
  font-weight: 700;
  font-size: 15px;
  padding-left: 4px;
}
.field input {
  width: 165px;
  height: 44px;
  border: 2px solid var(--red);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 20px;
  color: #333;
}
.field input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(212, 32, 39, 0.2);
}

.btn-submit {
  height: 44px;
  padding: 0 28px;
  background: var(--btn);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-submit:hover { background: var(--btn-light); }
.btn-submit:active { background: var(--btn-dark); }

.btn-outline {
  height: 44px;
  padding: 0 22px;
  background: #fff;
  color: var(--btn);
  border: 2px solid var(--btn);
  border-radius: 6px;
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
}
.btn-outline:hover { background: #fff4f4; }

/* Selection 1 + wildcard W key */
.sel1-wrap {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.sel1-wrap input { width: 130px; }
.r-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 2px solid var(--red);
  border-radius: 8px;
  background: #fff;
  color: var(--red);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
}
.r-btn:hover { background: var(--red); color: #fff; }
.r-btn:active { background: var(--red-dark); color: #fff; }

/* Box Type dropdown */
.field--box select {
  height: 44px;
  border: 2px solid var(--red);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--red);
  background: #fff;
}

/* parity (All / Odd / Even) */
.parity {
  display: inline-flex;
  border: 2px solid var(--red);
  border-radius: 8px;
  overflow: hidden;
  height: 44px;
}
.parity-btn {
  border: none;
  background: #fff;
  color: var(--btn);
  font-size: 15px;
  font-weight: 400;
  padding: 0 14px;
  cursor: pointer;
}
.parity-btn + .parity-btn { border-left: 2px solid var(--red); }
.parity-btn.is-active { background: var(--btn); color: #fff; }
.parity { border-color: var(--btn); }
.parity-btn + .parity-btn { border-left-color: var(--btn); }

/* live preview bar */
.preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 14px 8px;
  padding: 8px 12px;
  border: 1px dashed var(--pink-border);
  border-radius: 8px;
  background: #fff8fb;
}
.preview-label {
  flex: 0 0 auto;
  color: var(--red);
  font-weight: 800;
  font-size: 14px;
}
.preview-body {
  font-size: 14px;
  color: #444;
  word-break: break-word;
}
.preview-body.is-error { color: #b00; font-weight: 700; }

.shortcuts {
  margin: 0 14px 10px;
  font-size: 12px;
  color: #777;
}
.shortcuts b { color: var(--red); }

.dbstatus {
  margin: 0 14px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #2a7a3a;
}
.dbstatus.is-error { color: #b00; }

/* ============ COLUMNS ============ */
.sheet {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 1fr);
  gap: 0;
  padding: 0 8px 24px;
  overflow-x: auto;          /* columns 7,8,9… scroll horizontally */
}

.column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0 4px;
}

.col-title {
  color: var(--red);
  font-weight: 700;
  font-size: 17px;
  margin: 8px 0 6px 2px;
}
.column.is-active .col-title::after {
  content: " ◀ active";
  font-size: 12px;
  font-weight: 800;
  color: #2d7bff;
}
.column.is-active .col-list {
  box-shadow: 0 0 0 2px #2d7bff inset;
}

.col-total {
  border: 2px solid var(--pink-border);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  font-size: 15px;
  color: var(--red);
  font-weight: 700;
  line-height: 1.9;
  margin-bottom: 8px;
}
.col-total span { color: #c4202a; }

.col-list {
  border: 2px solid var(--pink-border);
  border-radius: 8px;
  background: var(--pink-bg);
  padding: 6px 0;
  max-height: 62vh;
  overflow-y: auto;
}

.col-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 6px;
  font-size: 13px;
  color: #6b3a55;
  border-bottom: 1px solid transparent;
}
.col-row:nth-child(even) { background: var(--pink-bg-alt); }

.col-row .idx {
  flex: 0 0 22px;
  color: #8a4a6e;
  font-weight: 600;
}
.col-row .entry {
  flex: 1 1 auto;
  min-height: 18px;
  color: #222;
  word-break: break-word;
  line-height: 1.3;
}
.col-row .entry .lbl { color: var(--blue-check); font-weight: 800; }
.col-row .entry .tot { color: var(--red); font-weight: 700; }
.col-row .del {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  line-height: 1;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #c44;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  visibility: hidden;
}
.col-row.has-entry .del { visibility: visible; }
.col-row .del:hover { background: var(--red); color: #fff; }
.col-row .edit {
  flex: 0 0 auto;
  width: 20px; height: 20px; line-height: 1;
  border: none; border-radius: 4px; background: transparent;
  color: #2d7bff; font-size: 13px; font-weight: 800; cursor: pointer;
  visibility: hidden;
}
.col-row.has-entry .edit { visibility: visible; }
.col-row .edit:hover { background: var(--blue-check); color: #fff; }

.edit-banner {
  margin: 0 14px 10px;
  padding: 8px 12px;
  border: 2px solid var(--blue-check);
  border-radius: 8px;
  background: #eef4ff;
  color: #1a4ea8;
  font-weight: 800;
  font-size: 13px;
}

/* ============ RESPONSIVE ============ */
/* .sheet always uses auto-flow columns + horizontal scroll, all sizes */
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; }
  .entry-row { flex-wrap: wrap; }
  .field input { width: 120px; }
  .badge { width: 40px; height: 40px; font-size: 17px; }
  .cbx { width: 28px; height: 28px; }
  .cbx:checked::after { left: 9px; top: 4px; width: 6px; height: 13px; }
  .pill { font-size: 15px; padding: 8px 10px; }
}
@media (max-width: 520px) {
  .title { font-size: 20px; }
}

/* ===== Entry Form: compact, tidy density for PC browser / PWA ===== */
#view-entry .app { max-width: 1500px; }
#view-entry .topbar { padding: 7px 16px; border-top-width: 4px; }
#view-entry .title { font-size: 22px; white-space: nowrap; }
#view-entry .header-controls { gap: 12px; }
#view-entry .badge { width: 36px; height: 36px; font-size: 16px; }
#view-entry .cbx { width: 26px; height: 26px; }
#view-entry .cbx:checked::after { left: 8px; top: 3px; width: 6px; height: 13px; border-width: 0 3px 3px 0; }
#view-entry .ctrl-row { padding: 5px 8px; }
#view-entry .check-group { gap: 8px; padding: 2px 5px; }
#view-entry .pill { font-size: 15px; padding: 7px 12px; border-radius: 18px; }
#view-entry .entry-row { padding: 8px 14px 10px; gap: 12px; }
#view-entry .field-label { font-size: 13px; }
#view-entry .field input { height: 38px; font-size: 17px; }
#view-entry .sel1-wrap input { width: 120px; }
#view-entry .r-btn { width: 38px; height: 38px; font-size: 17px; }
#view-entry .parity, #view-entry .parity-btn { height: 38px; }
#view-entry .field--box select { height: 38px; font-size: 16px; }
#view-entry .btn-submit, #view-entry .btn-outline { height: 38px; font-size: 16px; padding: 0 18px; }
#view-entry .col-title { font-size: 15px; }
#view-entry .col-total { line-height: 1.7; font-size: 14px; padding: 6px 9px; }
/* Fit the entry form in ONE screen. Layout (top → bottom):
     [controls]  — series row, fixed height
     [input bar] — Selection/Amount + buttons, directly UNDER the series row, fixed
     [columns]   — FILL the remaining space, scroll INTERNALLY (~12 rows shown)
     [footer]    — Preview / Keys / save-status, pinned at the very bottom
   The page itself never scrolls (no jump when you pick a dealer or press Enter). */
#view-entry { height: calc(100vh - 48px); overflow: hidden; }
#view-entry .app { height: 100%; display: flex; flex-direction: column; min-height: 0; }
/* fixed rows keep their natural height and never shrink */
#view-entry .ctrl-row--top,
#view-entry .entry-row,
#view-entry .info-row,
#view-entry .edit-banner { flex: 0 0 auto; }
/* columns take all the space that's left and scroll inside */
#view-entry .sheet { flex: 1 1 auto; min-height: 0; padding-bottom: 4px; }
#view-entry .column { min-height: 0; }
#view-entry .col-list { flex: 1 1 auto; min-height: 0; max-height: none; }
#view-entry .col-title { margin: 4px 0 4px 2px; }
/* thin rules frame the column area: one under the input row, one above the footer */
#view-entry .entry-row { border-bottom: 1px solid var(--pink-border); padding-bottom: 8px; }
#view-entry .info-row { margin: 4px 14px 6px; border-top: 1px solid var(--pink-border); padding-top: 6px; }
/* pack the series A–E buttons to the left */
#view-entry .ctrl-row--series { justify-content: flex-start; }
#view-entry .ctrl-row--series .check-group { flex: 0 0 auto; }
#view-entry .ctrl-row--series .check-group--wide { margin-left: 10px; }

/* ===== Mode pills (compact, left) + entry inputs (fill remaining space) ===== */
.ctrl-row--modes { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.modes-left { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.mini-mode { display: inline-flex; align-items: center; gap: 5px; margin: 0; cursor: pointer; }
.cbx--mini { width: 22px; height: 22px; }
.cbx--mini:checked::after { left: 7px; top: 3px; width: 5px; height: 11px; border-width: 0 2px 2px 0; }
.pill--mini { flex: 0 0 auto; font-size: 13px; padding: 6px 14px; border-radius: 14px; line-height: 1; }
.inputs-right { display: flex; align-items: flex-end; gap: 10px; flex: 1 1 auto; flex-wrap: wrap; }
.inputs-right .hc-field { color: #fff; font-weight: 700; font-size: 11px; gap: 2px; }
.inputs-right .hc-field input,
.inputs-right .hc-field select { height: 30px; font-size: 13px; border: 1px solid #fff; border-radius: 4px; padding: 0 7px; }
.inputs-right .hc-dealer input { width: 170px; }
.inputs-right #pageNo { width: 80px; }
.inputs-right #entryDate { width: 140px; }

/* Keys legend now sits inline to the right of the Save Ticket / sheet buttons */
.entry-row .shortcuts { margin: 0 0 2px auto; align-self: flex-end; max-width: 360px; font-size: 11px; line-height: 1.35; }

/* Preview + winning remark live BELOW the form, side by side */
.below-form { display: flex; gap: 12px; align-items: stretch; margin: 0 14px 8px; flex-wrap: wrap; }
.below-form .preview { flex: 1 1 320px; margin: 0; }
.win-remark { flex: 1 1 320px; border: 1px solid #efc14d; border-radius: 8px; background: #fffbe8; padding: 8px 12px; font-size: 13px; color: #6b5300; line-height: 1.6; }
.win-remark[hidden] { display: none; }
.win-remark .wr-title { font-weight: 800; color: #c0272d; margin-right: 6px; }
.win-remark .wr-num { font-weight: 800; color: #1a4ea8; }
.win-remark .wr-amt { font-weight: 800; color: #c0272d; }

/* winning ticket rows in the sheet get a GREEN "win N" remark */
.col-row .entry .win-tag { color: var(--win); font-weight: 800; margin-left: 4px; }
.col-row.is-win { background: var(--win-bg) !important; }
.col-row.is-win .entry { color: var(--win); }

/* red won-amount in the dealer report Win 2D / Win 3D columns */
.dr-table .riel-win { color: #c0272d; font-weight: 700; }

/* ===== Entry: single top row (series + condition + inputs) ===== */
.ctrl-row--top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; row-gap: 8px; }
.top-series { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.top-series .check-group { flex: 0 0 auto; gap: 5px; padding: 2px 3px; }
.top-modes { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.top-inputs { display: flex; align-items: flex-end; gap: 9px; flex: 1 1 auto; flex-wrap: wrap; }
.top-inputs .hc-field { color: #fff; font-weight: 700; font-size: 11px; gap: 2px; }
.top-inputs .hc-field input, .top-inputs .hc-field select { height: 30px; font-size: 13px; border: 1px solid #fff; border-radius: 4px; padding: 0 7px; }
.top-inputs .hc-dealer input { width: 150px; }
.top-inputs #pageNo { width: 70px; }
.top-inputs #entryDate { width: 138px; }
/* compact series badges/checkboxes so the whole row fits */
#view-entry .ctrl-row--top .badge { width: 30px; height: 30px; font-size: 15px; }
#view-entry .ctrl-row--top .cbx { width: 22px; height: 22px; }
#view-entry .ctrl-row--top .cbx:checked::after { left: 7px; top: 3px; width: 5px; height: 11px; border-width: 0 2px 2px 0; }
#view-entry .ctrl-row--top .pill--gray { font-size: 13px; padding: 5px 12px; }

/* ===== Entry: action buttons live in the fields row (smaller, one line) ===== */
.btn-act { height: 36px; font-size: 13px; padding: 0 14px; white-space: nowrap; font-weight: 400; }
#view-entry .entry-row { flex-wrap: nowrap; overflow-x: auto; align-items: flex-end; }
#view-entry .entry-row .btn-act { align-self: flex-end; margin-bottom: 1px; }

/* Preview + Keys + saved-status on one info line */
.info-row { display: flex; align-items: center; gap: 14px; margin: 8px 14px; flex-wrap: wrap; }
.info-row .preview { flex: 1 1 260px; margin: 0; }
.info-row .shortcuts { flex: 2 1 320px; margin: 0; font-size: 11px; line-height: 1.35; color: #777; }
.info-row .shortcuts b { color: var(--red); }
.info-row .dbstatus { margin: 0; flex: 0 0 auto; }

/* per-column winning: green "Win 2D / Win 3D" next to each total line */
.col-total .ct-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.col-total .ct-win { color: var(--win); font-weight: 800; }
.col-total .ct-win b { color: var(--win); }

/* ===== Page popup rendered like the entry-form sheet ===== */
.pe-sheet { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; }
.pe-col { flex: 0 0 200px; display: flex; flex-direction: column; }
.pe-col-title { color: var(--red); font-weight: 700; font-size: 14px; margin: 2px 0 4px; }
.pe-col-total { border: 2px solid var(--pink-border); border-radius: 8px; background: #fff; padding: 5px 8px; font-size: 13px; color: var(--red); font-weight: 700; line-height: 1.6; margin-bottom: 6px; }
.pe-col-total .pe-cwin { color: var(--win); }
.pe-col-list { border: 2px solid var(--pink-border); border-radius: 8px; background: var(--pink-bg); padding: 4px; }
.pe-row { display: flex; align-items: center; gap: 5px; padding: 3px 4px; font-size: 12px; border-bottom: 1px solid #efe2ea; }
.pe-row.is-win { background: var(--win-bg); }
.pe-row .pe-txt { flex: 1 1 auto; color: #333; }
.pe-row .pe-txt .lbl { color: var(--blue-check); font-weight: 800; }
.pe-row .pe-amt { width: 64px; height: 26px; border: 1px solid var(--red); border-radius: 4px; padding: 0 4px; text-align: right; font-size: 12px; }
.pe-row .pe-del { width: 16px; height: 16px; }
.pe-row .pe-wintag { color: var(--win); font-weight: 800; font-size: 11px; }
/* result entry / verify form inside the page popup */
.pe-result { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 10px; background: #fff8ef; border: 1px solid var(--pink-border); border-radius: 8px; }
.pe-reslbl { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--ink); }
.pe-res { width: 62px; height: 28px; border: 1px solid var(--btn); border-radius: 4px; text-align: center; font-size: 14px; letter-spacing: 1px; }
.pe-hint { color: #999; font-size: 11px; }

/* wide modal for the page editor */
.modal-wide { width: min(680px, 94vw); }
#peBody table.data td input.pe-amt { width: 90px; height: 30px; border: 1px solid var(--red); border-radius: 4px; padding: 0 6px; text-align: right; font-size: 14px; }
#peBody .pe-win { color: var(--win); font-weight: 800; }

/* dealer-report footer: ស៊ីសង (winnings paid out) shown in red */
.sumtab tr.dr-sisang td { color: #c0272d; }

/* wide Agent Detail report — compact, horizontal scroll, sticky header */
.ag-table { font-size: 11px; }
.ag-table th, .ag-table td { white-space: nowrap; padding: 4px 7px; }
.ag-table tbody tr.total td { background: #eef6f4; font-weight: 800; border-top: 2px solid var(--red); }
.ag-table tbody tr:nth-child(even) td { background: #f3faf8; }
