:root {
  /* ธีม CUTE TOWN: ชมพูหวาน ม่วงพลัม */
  --bg: #fff3f9;
  --surface: #ffffff;
  --ink: #3b1d36;
  --muted: #8c6a85;
  --line: #f5d7e7;
  --brand: #c42b83;
  --brand-2: #a8206f;
  --bar: linear-gradient(120deg, #4b1a55 0%, #8f2a86 55%, #d63a96 100%);
  --soft: #fde1ef;
  --soft-2: #fbe8f2;
  --soft-3: #fff0f7;
  --in: #0f8a5f;
  --in-soft: #e3f5ed;
  --out: #c2560f;
  --out-soft: #fdeee2;
  --danger: #c0352b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(196, 43, 131, .06), 0 8px 24px rgba(196, 43, 131, .09);
  --font-head: "Mali", "IBM Plex Sans Thai", "Sarabun", system-ui, sans-serif;
  --font: "IBM Plex Sans Thai", "Sarabun", "Leelawadee UI", "Noto Sans Thai", "Waree", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background-color: var(--bg); background-image: radial-gradient(#f9cfe3 1.3px, transparent 1.4px); background-size: 24px 24px; color: var(--ink); font: 15px/1.6 var(--font); }
a { color: var(--brand); }
h1, h2 { margin: 0 0 14px; line-height: 1.3; font-family: var(--font-head); }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
em { font-style: normal; color: var(--muted); font-size: 13px; }

/* ---------- top bar ---------- */
.topbar { background: var(--bar); color: #fff; box-shadow: 0 4px 16px rgba(196, 43, 131, .25); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 66px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; line-height: 1.2; font-family: var(--font-head); }
.brand small { display: block; font-weight: 400; font-size: 12px; opacity: .7; }
.brand-mark { width: 50px; height: 50px; flex: none; display: grid; place-items: center; }
.brand-mark img { width: 50px; height: 50px; display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); }
.login-logo { display: block; width: 150px; height: 150px; margin: -6px auto 4px; filter: drop-shadow(0 6px 10px rgba(196, 43, 131, .25)); }
.nav { display: flex; gap: 4px; }
.nav a { color: rgba(255,255,255,.8); text-decoration: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; }
.nav a.on, .nav a:hover { background: rgba(255,255,255,.16); color: #fff; }

main.wrap { padding-top: 22px; padding-bottom: 12px; }
.foot { color: var(--muted); font-size: 12px; padding-bottom: 28px; text-align: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* ---------- hero / clock ---------- */
.hero { display: grid; grid-template-columns: 1fr 1.15fr; gap: 18px; margin-bottom: 18px; }
.hero .card { margin: 0; }
.clock-card {
  border-radius: var(--radius); padding: 28px 24px; color: #fff;
  background: radial-gradient(circle at 85% 12%, rgba(255,255,255,.28) 0 6px, transparent 7px), radial-gradient(circle at 12% 88%, rgba(255,255,255,.22) 0 9px, transparent 10px), linear-gradient(150deg, #ff7ab8 0%, #c42b83 55%, #7b2a96 100%);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; box-shadow: var(--shadow);
}
.clock-card::after { content: ""; position: absolute; right: -18px; bottom: -22px; width: 150px; height: 150px; background: url(logo-sm.png) center / contain no-repeat; opacity: .35; pointer-events: none; }
.clock-label { font-size: 13px; opacity: .9; letter-spacing: .02em; }
.clock { font-size: clamp(44px, 9vw, 68px); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .01em; line-height: 1.1; margin: 6px 0; }
.clock-date { font-size: 16px; opacity: .9; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus { outline: 3px solid rgba(224, 72, 154, .25); border-color: var(--brand); }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; font-weight: 500; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 3px 0 #8e1d5f; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: var(--soft-2); color: var(--brand-2); }
.btn-ghost:hover { background: var(--soft); }
.btn-danger { background: #fbe9e7; color: var(--danger); }
.btn-in { background: var(--in); color: #fff; }
.btn-out { background: var(--out); color: #fff; }
.btn-in:hover, .btn-out:hover { filter: brightness(1.07); }

.punch-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.punch-btns .btn { min-height: 58px; font-size: 18px; border-radius: 12px; }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.alert-success { background: var(--in-soft); color: #0b6646; }
.alert-error { background: #fbe9e7; color: #9e2b22; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; vertical-align: middle; }
.pill-on { background: var(--in-soft); color: #0b6646; }
.pill-off { background: var(--soft-2); color: var(--muted); }
.pill-live { background: var(--in-soft); color: #0b6646; font-size: 13px; padding: 4px 12px; }
.pill-live i { width: 8px; height: 8px; border-radius: 50%; background: var(--in); box-shadow: 0 0 0 3px rgba(15,138,95,.2); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.actions { text-align: right; white-space: nowrap; }
.tbl td.actions form { display: inline; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px !important; }

/* ---------- admin ---------- */
.login { max-width: 400px; margin: 30px auto; }
.admin-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 2px; }
.tabs a { padding: 9px 16px; border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); white-space: nowrap; font-size: 14px; }
.tabs a.on { background: var(--brand); color: #fff; }
.grid-2 { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.grid-2 .card { margin: 0; }

.staff-list { list-style: none; margin: 0; padding: 0; }
.staff-list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.staff-list li:last-child { border-bottom: 0; }
.staff-list li.inactive { opacity: .6; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); color: var(--brand); display: grid; place-items: center; font-weight: 600; flex: none; }
.grow { flex: 1; min-width: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions form { margin: 0; }

details.edit { margin-top: 4px; }
details.edit summary { cursor: pointer; color: var(--brand-2); font-size: 13px; display: inline-block; }
.edit-form { display: grid; gap: 8px; margin-top: 8px; padding: 12px; background: var(--soft-3); border-radius: 10px; text-align: left; min-width: 240px; }
.edit-form label { font-size: 13px; display: grid; gap: 4px; }
.edit-form input { min-height: 38px; padding: 7px 10px; }
.check { display: flex !important; align-items: center; gap: 8px !important; grid-template-columns: none; }
.check input { width: auto; min-height: 0; }

.filters { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 12px; align-items: end; }
.filters .field { margin: 0; min-width: 0; }
.filters input, .filters select { min-width: 0; }
input[type=date], input[type=datetime-local] { -webkit-appearance: none; appearance: none; display: block; }
.filter-btns { display: flex; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat b { font-size: 26px; font-variant-numeric: tabular-nums; }
.stats-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .hero, .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filter-btns { grid-column: 1 / -1; }
  .filter-btns .btn { flex: 1; }
}
@media (max-width: 640px) {
  .brand > span:last-child { font-size: 14px; }
  .clock-card { padding: 22px 20px; }
  .card { padding: 16px; }
  .stats { gap: 8px; }
  .stats-4 { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 12px; }
  .stat b { font-size: 22px; }
  /* ตารางกลายเป็นการ์ดบนมือถือ */
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; }
  .tbl tr:has(.empty) { border: 0; }
  .tbl td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .tbl td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  .tbl td:first-child { display: block; text-align: left; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 2px; }
  .tbl td:first-child::before { display: none; }
  .tbl td.actions { justify-content: flex-end; flex-wrap: wrap; }
  .tbl td.empty { display: block; }
}

/* ---------- v2: ล็อกอิน / สมัครสมาชิก / โปรไฟล์ ---------- */
.alt-link { text-align: center; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.alert div + div { margin-top: 2px; }
.pill-wait { background: #fff4d6; color: #8a5b00; }
.pill-lock { background: #fbe9e7; color: #9e2b22; }
.pill-me { background: var(--soft); color: var(--brand); }
.warn { color: var(--danger); }
.me { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.me b { font-size: 17px; }
.status { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.status-on { background: var(--in-soft); color: #0b6646; }
.status-on i { width: 8px; height: 8px; border-radius: 50%; background: var(--in); box-shadow: 0 0 0 3px rgba(15,138,95,.2); flex: none; }
.status-off { background: var(--soft-2); color: var(--muted); }
.btn:disabled { opacity: .38; cursor: not-allowed; filter: grayscale(.4); }
.me-row td { background: var(--soft-3); }
@media (max-width: 640px) {
  .nav a { padding: 7px 9px; font-size: 13px; }
  .brand small { display: none; }
  .me-row { background: var(--soft-3); }
  .me-row td { background: transparent; }
}
.nav a { white-space: nowrap; }
@media (max-width: 520px) {
  .brand > span:last-child { display: none; }
  .topbar-in { justify-content: space-between; }
}

/* ---------- สรุปรอบสัปดาห์ ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.week-label { text-align: center; display: grid; gap: 2px; }
.week-label b { font-size: 17px; }
.week-label small { font-size: 12px; }
.week-jump { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.week-jump label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.week-jump input[type=date] { min-height: 34px; padding: 4px 10px; width: auto; }
.btn.disabled { opacity: .4; pointer-events: none; }
.pill-cut { background: #fff4d6; color: #8a5b00; }
.week-head { margin-bottom: 14px; }
@media (max-width: 640px) {
  .week-nav { flex-wrap: wrap; }
  .week-label { order: -1; width: 100%; }
  .week-nav .btn { flex: 1; }
}

/* ---------- กำหนดรอบตัดยอด / ช่วงเอง ---------- */
.cutoff-card { margin-bottom: 14px; }
.cutoff-form, .range-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 14px; }
.cutoff-title { display: grid; gap: 2px; flex: 1 1 100%; }
.cutoff-form label, .range-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.cutoff-form select, .cutoff-form input, .range-form input { min-height: 38px; padding: 6px 10px; width: auto; min-width: 0; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.chip { display: inline-block; padding: 5px 12px; border-radius: 999px; background: var(--soft-2); color: var(--ink); text-decoration: none; font-size: 13px; }
.chip:hover { background: var(--soft); }
@media (max-width: 640px) {
  .cutoff-form label, .range-form label { flex: 1 1 140px; }
  .cutoff-form select, .cutoff-form input, .range-form input { width: 100%; }
}

.split-lists { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 18px; margin-bottom: 18px; }
@media (max-width: 900px) { .split-lists { grid-template-columns: minmax(0, 1fr); } }
.split-lists .card { margin: 0; min-width: 0; }

.tbl tfoot td { border-top: 2px solid var(--line); background: var(--soft-3); padding-top: 10px; padding-bottom: 10px; }
.reward-form textarea { min-height: 260px; font-family: ui-monospace, Menlo, Consolas, monospace; line-height: 1.7; }
.reward-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.coin-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 4px; }
.reward-card { background: linear-gradient(150deg, #fff7fb, #ffe6f2); border: 1px solid var(--line); }
.reward-card .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }
.reward-card .bar { height: 10px; border-radius: 999px; background: var(--soft); overflow: hidden; margin: 8px 0 4px; }
.reward-card .bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff7ab8, #c42b83); border-radius: 999px; }
.reward-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 760px) { .reward-cols, .reward-grid { grid-template-columns: minmax(0, 1fr); } .coin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .tbl tfoot tr { background: var(--soft-3); } .tbl tfoot td:empty { display: none; } }
