:root {
  /* palette: #0E0906 #F8F8F8 #D8493B #E9C204 #0276E4 — สไตล์ neo-brutalism */
  --color-primary: #0276E4;
  --color-primary-hover: #025FBA;
  --color-primary-strong: #0260B8;
  --color-primary-soft: #DCEBFC;
  --color-on-primary: #FFFFFF;
  --color-teal: #2B2724;          /* slot สีกลาง (แค่ดู) */
  --color-teal-soft: #ECEAE7;
  --color-teal-text: #46413B;
  --color-yellow: #E9C204;
  --color-yellow-soft: #FAF1C6;
  --color-yellow-text: #6E5C00;
  --color-destructive: #D8493B;
  --color-destructive-soft: #F9DEDB;
  --color-destructive-text: #A52A1C;
  --color-background: #F8F8F8;
  --color-surface: #FFFFFF;
  --color-foreground: #0E0906;
  --color-text-secondary: #5C5650;
  --color-muted: #EFEEEC;
  --color-border: #0E0906;
  --color-ring: #0276E4;
  --bw: 2px;                      /* ความหนาเส้นขอบ */
  --shadow: 4px 4px 0 var(--color-foreground);
  --shadow-sm: 3px 3px 0 var(--color-foreground);
  --radius: 12px;
  --nav-height: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-background);
  color: var(--color-foreground);
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
}

input {
  font-family: inherit;
  font-size: 1rem;
}

/* ปุ่มกดแล้ว "ยุบ" ลงไปแทนเงา — เอกลักษณ์ neo-brutalism */
.press {
  box-shadow: var(--shadow);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out, color 150ms ease-out;
}
.press:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--color-foreground);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  background: var(--color-background);
  z-index: 20;
}
.header .brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}
.header .brand small {
  display: block;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}
.employee-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-yellow);
  border: var(--bw) solid var(--color-border);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
  min-height: 44px;
  box-shadow: var(--shadow-sm);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out;
}
.employee-chip:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--color-foreground); }
.employee-chip svg { color: var(--color-foreground); }

/* ---------- Sections / cards ---------- */
.screen { padding: 4px 16px 24px; }
.section {
  background: var(--color-surface);
  border: var(--bw) solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.section-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 14px;
}
.section-label svg { flex-shrink: 0; }
.section-label .icon-tile {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: var(--bw) solid var(--color-border);
  background: var(--color-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.section-label .icon-tile.yellow { background: var(--color-yellow); color: var(--color-foreground); }
.section-label .icon-tile.red { background: var(--color-destructive); }
.section-label .opt {
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

/* ---------- Segmented big buttons ---------- */
.seg-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.seg-row.three { grid-template-columns: 1fr 1fr 1fr; }
.seg-btn {
  min-height: 58px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow-sm);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out, color 150ms ease-out;
}
.seg-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--color-foreground); }
.seg-btn.active {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 800;
}
.seg-btn.active.danger { background: var(--color-destructive); }
.seg-btn.active.neutral { background: var(--color-teal); color: #FFFFFF; }

/* ---------- Chips ---------- */
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.chip {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out, color 150ms ease-out;
}
.chip:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--color-foreground); }
.chip.active {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
}
.chip.warn.active {
  background: var(--color-yellow);
  color: var(--color-foreground);
}

.search-input, .text-input {
  width: 100%;
  min-height: 50px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  padding: 10px 14px;
  margin-bottom: 12px;
  color: var(--color-foreground);
  font-weight: 500;
}
.search-input:focus, .text-input:focus, .bill-input:focus {
  outline: none;
  box-shadow: var(--shadow-sm);
}
.search-input::placeholder, .text-input::placeholder { color: #9C968E; }

.helper { font-size: 0.85rem; color: var(--color-text-secondary); margin: 8px 0 0; }

/* ---------- Bill input ---------- */
.bill-input {
  width: 100%;
  min-height: 64px;
  font-size: 1.7rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-yellow-soft);
  color: var(--color-foreground);
}

/* ---------- Save bar ---------- */
.save-btn {
  width: 100%;
  min-height: 62px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 1.2rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out, opacity 150ms ease-out;
  margin-top: 4px;
}
.save-btn:hover { background: var(--color-primary-hover); }
.save-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--color-foreground); }
.save-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: var(--shadow); transform: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 24px);
  transform: translateX(-50%) rotate(-1deg);
  background: var(--color-yellow);
  color: var(--color-foreground);
  border: var(--bw) solid var(--color-border);
  border-radius: 999px;
  padding: 12px 24px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
  animation: toast-in 200ms ease-out;
  box-shadow: var(--shadow);
}
.toast svg { color: var(--color-foreground); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) rotate(-1deg); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-1deg); }
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: var(--bw) solid var(--color-border);
  display: flex;
  z-index: 40;
}
.bottom-nav .inner {
  max-width: 560px;
  margin: 0 auto;
  flex: 1;
  display: grid;
  gap: 8px;
  padding: 8px 12px;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  border-radius: 10px;
  border: var(--bw) solid transparent;
  transition: color 150ms ease-out, background 150ms ease-out, border-color 150ms ease-out;
}
.nav-btn.active {
  color: var(--color-foreground);
  background: var(--color-yellow);
  border-color: var(--color-border);
}

/* ---------- Login / เลือกสาขา / รายชื่อพนักงาน ---------- */
.login {
  padding: 40px 20px;
  text-align: center;
}
.login h1 { font-size: 1.6rem; font-weight: 800; margin: 6px 0 4px; }
.login p { color: var(--color-text-secondary); margin: 0 0 26px; font-weight: 500; }
.login .logo {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  border: var(--bw) solid var(--color-border);
  background: var(--color-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.logo-img {
  display: block;
  width: 190px;
  max-width: 55vw;
  height: auto;
  margin: 0 auto 18px;
}
.branch-list {
  display: grid;
  gap: 16px;
  max-width: 360px;
  margin: 0 auto;
}
.branch-btn {
  min-height: 70px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  font-weight: 800;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out;
}
.branch-btn:hover { background: var(--color-primary-soft); }
.branch-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--color-foreground); }
.branch-btn svg { color: var(--color-primary); }
.admin-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 30px;
  color: var(--color-text-secondary);
  font-weight: 700;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  transition: background 150ms ease-out, color 150ms ease-out;
}
.admin-link:hover { background: var(--color-muted); color: var(--color-foreground); }

.employee-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: center;
}
.employee-btn {
  min-height: 80px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: var(--shadow);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out;
}
.employee-btn:hover { background: var(--color-primary-soft); }
.employee-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--color-foreground); }
.role-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-foreground);
  background: var(--color-primary-soft);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 1px 10px;
}
.sent-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-foreground);
  background: var(--color-yellow);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 1px 10px;
  transform: rotate(-2deg);
}
.login .hint { font-size: 0.8rem; color: var(--color-text-secondary); margin-top: 24px; }

/* ---------- PIN ---------- */
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}
.pin-dots .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: var(--bw) solid var(--color-border);
  background: var(--color-surface);
  transition: background 120ms ease-out;
}
.pin-dots .dot.filled { background: var(--color-primary); }
.pin-dots.error .dot { border-color: var(--color-destructive); }
.pin-dots.error .dot.filled { background: var(--color-destructive); }
.pin-error { color: var(--color-destructive-text); font-weight: 700; font-size: 0.9rem; }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 78px);
  gap: 16px;
  justify-content: center;
  margin-top: 20px;
}
.key {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--color-surface);
  border: var(--bw) solid var(--color-border);
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform 90ms ease-out, box-shadow 90ms ease-out, background 130ms ease-out;
}
.key:hover { background: var(--color-muted); }
.key:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--color-foreground); background: var(--color-yellow); }
.key.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-secondary);
  box-shadow: none;
}
.key.ghost:active { transform: none; }

/* ---------- Log list ---------- */
.log-entry {
  background: var(--color-surface);
  border: var(--bw) solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.log-entry .row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 6px;
}
.log-entry .time {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.log-entry .meta { font-size: 0.85rem; color: var(--color-text-secondary); font-weight: 500; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  border: 1.5px solid var(--color-border);
  padding: 3px 12px;
  font-size: 0.8rem;
  font-weight: 800;
}
.badge.buy { background: var(--color-primary); color: var(--color-on-primary); }
.badge.nobuy { background: var(--color-destructive); color: #fff; }
.badge.look { background: var(--color-surface); color: var(--color-foreground); }
.log-entry .products { font-size: 0.92rem; margin-top: 4px; }
.log-entry .notfound { font-size: 0.88rem; color: var(--color-yellow-text); font-weight: 600; margin-top: 2px; }
.log-entry .del {
  color: var(--color-text-secondary);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1.5px solid transparent;
  transition: background 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}
.log-entry .del:hover { background: var(--color-destructive-soft); color: var(--color-destructive); border-color: var(--color-border); }
.log-entry .del.edit:hover { background: var(--color-primary-soft); color: var(--color-primary-strong); border-color: var(--color-border); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-secondary);
}
.empty-state svg { color: #C9C5C0; margin-bottom: 8px; }

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.submit-status {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  padding: 14px 16px;
  font-weight: 700;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.submit-status.done { background: var(--color-yellow-soft); color: var(--color-foreground); }
.submit-status.editing { background: var(--color-primary-soft); color: var(--color-foreground); }
.submit-status .cancel-edit {
  margin-left: auto;
  font-weight: 800;
  color: inherit;
  text-decoration: underline;
  min-height: 44px;
  padding: 0 8px;
  flex-shrink: 0;
}

/* ---------- Report ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--color-surface);
  border: var(--bw) solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-card .val {
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat-card .lbl { font-size: 0.82rem; color: var(--color-text-secondary); font-weight: 600; }
.stat-card .sub { font-size: 0.78rem; color: var(--color-text-secondary); margin-top: 2px; }
.stat-card.hero { grid-column: span 2; background: var(--color-primary); color: var(--color-on-primary); }
.stat-card.hero .val { font-size: 2rem; }
.stat-card.hero .lbl, .stat-card.hero .sub { color: #CFE4FB; }

.rank-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1.5px dashed #D5D2CE;
  font-size: 0.95rem;
  gap: 8px;
}
.rank-row:last-child { border-bottom: none; }
.rank-row .n {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--color-muted);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 2px 12px;
  white-space: nowrap;
}
.rank-row.warn .n { background: var(--color-yellow); color: var(--color-foreground); }
.rank-row .n.ok { background: var(--color-primary); color: #fff; font-size: 0.82rem; }
.rank-row .n.pending { background: var(--color-destructive-soft); color: var(--color-destructive-text); font-size: 0.82rem; }

table.emp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.emp-table th {
  text-align: left;
  font-size: 0.78rem;
  color: var(--color-foreground);
  font-weight: 800;
  padding: 6px 4px;
  border-bottom: var(--bw) solid var(--color-border);
}
.emp-table td {
  padding: 10px 4px;
  border-bottom: 1.5px dashed #D5D2CE;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.emp-table tr:last-child td { border-bottom: none; }
.emp-table .num { text-align: right; }
.emp-table th.num { text-align: right; }

.action-row { display: grid; gap: 14px; margin-top: 4px; }
.outline-btn {
  width: 100%;
  min-height: 54px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  color: var(--color-foreground);
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out;
}
.outline-btn:hover { background: var(--color-yellow-soft); }
.outline-btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--color-foreground); }

/* ---------- จัดการสาขา/พนักงาน (Admin) ---------- */
.manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1.5px dashed #D5D2CE;
}
.manage-row:last-of-type { border-bottom: none; }
.manage-row .info { flex: 1; min-width: 0; }
.manage-row .info .name { font-weight: 700; }
.manage-row .info .sub { font-size: 0.8rem; color: var(--color-text-secondary); }
.icon-btn {
  color: var(--color-text-secondary);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1.5px solid transparent;
  flex-shrink: 0;
  transition: background 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}
.icon-btn:hover { background: var(--color-destructive-soft); color: var(--color-destructive); border-color: var(--color-border); }
.form-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.form-row .text-input, .form-row .search-input { margin-bottom: 0; flex: 1; }
.form-row .pin-input { flex: 0 0 110px; text-align: center; font-variant-numeric: tabular-nums; }
.add-btn {
  min-height: 50px;
  border-radius: var(--radius);
  border: var(--bw) solid var(--color-border);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 800;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: transform 100ms ease-out, box-shadow 100ms ease-out, background 150ms ease-out, opacity 150ms ease-out;
  flex-shrink: 0;
}
.add-btn:hover { background: var(--color-primary-hover); }
.add-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--color-foreground); }
.add-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }
.sub-label {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin: 16px 0 4px;
}
.sub-label:first-of-type { margin-top: 0; }

/* ---------- Modal ---------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(14, 9, 6, 0.55);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--color-surface);
  border: var(--bw) solid var(--color-border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: modal-in 220ms ease-out;
}
@keyframes modal-in {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal h3 { margin: 0 0 4px; font-weight: 800; }
.modal .to { font-size: 0.85rem; color: var(--color-text-secondary); margin-bottom: 14px; }
.modal pre {
  background: var(--color-background);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.82rem;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.7;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
