/* สวัสดิการสหไทย — ธีมแดง
   Layout: ฝั่งพนักงาน = แอปมือถือ (คอลัมน์กว้างไม่เกิน 480px + แถบเมนูล่าง)
           ฝั่ง HR = แถบเมนูข้างแยกตามหมวดสวัสดิการ + พื้นที่ทำงาน */
:root {
  --red: #c8102e;
  --red-d: #9e0b23;
  --red-l: #e8435d;
  --rose-50: #fdf1f3;
  --rose-100: #fbe1e6;
  --rose-200: #f5c2cc;
  --ink: #2a1418;
  --muted: #7a5f65;
  --line: #efdde1;
  --bg: #fbf6f7;
  --card: #ffffff;
  --ok: #18794e;  --ok-bg: #e3f5ec;
  --warn: #9a5b00; --warn-bg: #fdf0d5;
  --bad: #b42318; --bad-bg: #fde5e2;
  --info: #3d4f8a; --info-bg: #e7ebf8;
  --f-display: "Anuphan", "IBM Plex Sans Thai", system-ui, sans-serif;
  --f-body: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  --r: 16px;
  --shadow: 0 6px 24px rgba(158, 11, 35, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--f-display); margin: 0; line-height: 1.3; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--red); }
:focus-visible { outline: 3px solid var(--rose-200); outline-offset: 2px; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- ปุ่ม / ฟอร์ม ---------- */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 10px 18px; background: var(--red); color: #fff; font-weight: 600; transition: background .15s, transform .1s; }
.btn:hover { background: var(--red-d); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--rose-50); color: var(--red-d); }
.btn.ghost:hover { background: var(--rose-100); }
.btn.line { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.line:hover { border-color: var(--rose-200); background: var(--rose-50); }
.btn.sm { padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn .ico { width: 18px; height: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; }
.in:focus { border-color: var(--red-l); outline: none; box-shadow: 0 0 0 3px var(--rose-100); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 14px; min-width: 52px; text-align: center; font-weight: 600; }
.chip.on { border-color: var(--red); background: var(--rose-50); color: var(--red-d); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; background: var(--rose-50); color: var(--red-d); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.grey { background: #f1eef0; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast.bad { background: var(--bad); }
@media (min-width: 901px) { body.hr #toast { left: auto; right: 24px; bottom: 24px; transform: none; width: 380px; } }
.toast.out { opacity: 0; transform: translateY(8px); }

/* =====================================================================
   ฝั่งพนักงาน
   ===================================================================== */
.emp { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: #fff; position: relative; box-shadow: 0 0 0 1px var(--line); }

/* หน้าเข้าสู่ระบบ: ส่วนบนขาว วงกลมโลโก้ ส่วนล่างแดงโค้ง */
.welcome { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: #fff; overflow: hidden; }
.welcome .top { flex: 0 0 auto; padding: 48px 24px 0; text-align: center; position: relative; z-index: 1; }
.welcome .brand-sm { font-size: 12.5px; letter-spacing: .08em; color: var(--muted); }
.welcome .logo { width: 132px; height: 132px; margin: 28px auto -66px; border-radius: 50%; background: var(--rose-100); border: 8px solid #fff; display: grid; place-items: center; color: var(--red); box-shadow: var(--shadow); position: relative; z-index: 2; }
.welcome .logo .ico { width: 60px; height: 60px; stroke-width: 1.4; }
.welcome .panel { flex: 1; background: var(--red); color: #fff; border-radius: 0 64px 0 0; padding: 92px 28px calc(36px + env(safe-area-inset-bottom, 0px)); position: relative; display: flex; flex-direction: column; gap: 18px; }
.welcome .panel::before { content: ""; position: absolute; left: -40px; top: 46%; width: 90px; height: 90px; border-radius: 50%; background: rgba(255,255,255,.08); }
.welcome .panel::after { content: ""; position: absolute; right: -30px; top: 20px; width: 70px; height: 70px; border-radius: 50%; background: rgba(255,255,255,.08); }
.welcome h1 { font-size: 30px; text-align: center; }
.welcome .sub { text-align: center; opacity: .85; margin: -10px 0 4px; font-size: 14px; }
.welcome .field > span { color: rgba(255,255,255,.85); }
.welcome .in { border: 0; padding: 13px 14px; font-size: 16px; }
.welcome .go { margin-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.welcome .go small { opacity: .85; font-size: 12.5px; line-height: 1.5; }
.welcome .round-btn { width: 56px; height: 56px; border-radius: 50%; border: 0; background: #fff; color: var(--red); display: grid; place-items: center; flex: none; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.welcome .round-btn:disabled { opacity: .6; }
.welcome .err { background: rgba(255,255,255,.16); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.welcome .config-warn { background: #fff; color: var(--bad); border-radius: 12px; padding: 12px; font-size: 13.5px; }

/* แถบบน */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: rgba(255,255,255,.94); backdrop-filter: blur(8px); display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.topbar .ttl { font-family: var(--f-display); font-weight: 600; font-size: 17px; flex: 1; text-align: center; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--rose-50); color: var(--red-d); display: grid; place-items: center; }
.icon-btn .ico { width: 20px; height: 20px; }

.page { padding: 18px 18px calc(110px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 20px; }
.sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.sec-h h2 { font-size: 18px; }
.sec-h h2::before { content: ""; display: inline-block; width: 6px; height: 18px; border-radius: 3px; background: var(--red); margin-right: 8px; vertical-align: -2px; }

.hello { display: flex; align-items: center; gap: 12px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--rose-100); color: var(--red); display: grid; place-items: center; font-family: var(--f-display); font-weight: 700; font-size: 18px; flex: none; }
.hello b { font-family: var(--f-display); font-size: 17px; display: block; }
.hello small { color: var(--muted); }

.hero { border-radius: 22px; background: linear-gradient(135deg, var(--red) 0%, var(--red-d) 100%); color: #fff; padding: 20px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -36px; bottom: -36px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.1); }
.hero h3 { font-size: 20px; }
.hero p { margin: 0; opacity: .9; font-size: 14px; }
.hero .btn { background: #fff; color: var(--red-d); align-self: flex-start; position: relative; z-index: 1; }
.hero.calm { background: var(--rose-50); color: var(--ink); }
.hero.calm::after { background: var(--rose-100); }
.hero.calm p { color: var(--muted); }

.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.cat { border: 0; background: var(--rose-50); border-radius: 18px; padding: 14px 8px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; min-width: 0; color: var(--ink); }
.cat .ic { width: 52px; height: 52px; border-radius: 16px; background: #fff; display: grid; place-items: center; color: var(--red); }
.cat .ic .ico { width: 28px; height: 28px; }
.cat b { font-size: 13.5px; line-height: 1.35; font-weight: 600; }
.cat .pill { font-size: 11px; padding: 1px 8px; }
.cat.wide { grid-column: 1 / -1; flex-direction: row; text-align: left; padding: 14px; gap: 14px; background: var(--rose-100); }
.cat.wide .tx { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cat.wide b { font-size: 16px; font-family: var(--f-display); }
.cat.wide small { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.cat.wide .go { color: var(--red); }
.cat.soon { opacity: .6; }
.cat.soon .ic { color: var(--muted); }

.prod-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.prod { border: 0; background: none; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 6px; min-width: 0; color: var(--ink); }
.prod .ph { aspect-ratio: 3 / 4; border-radius: 16px; background: var(--rose-100); overflow: hidden; max-width: 100%; }
.prod .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prod b { font-size: 14px; line-height: 1.4; font-weight: 600; }
.prod small { color: var(--muted); font-size: 12.5px; }
.tabs-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs-row button { flex: none; border: 0; border-radius: 999px; padding: 6px 14px; background: var(--rose-50); color: var(--muted); font-weight: 600; font-size: 13.5px; }
.tabs-row button.on { background: var(--red); color: #fff; }

.item { border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #fff; }
.item .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item h3 { font-size: 16px; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13.5px; color: var(--muted); }
.item .meta b { color: var(--ink); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .ico { width: 44px; height: 44px; color: var(--rose-200); }

.hist { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist .dot { width: 44px; height: 44px; border-radius: 14px; background: var(--rose-50); color: var(--red); display: grid; place-items: center; flex: none; }
.hist div { min-width: 0; }
.hist b { display: block; font-size: 14.5px; }
.hist small { color: var(--muted); }

/* แถบเมนูล่าง */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); width: min(452px, calc(100% - 28px)); background: var(--red); border-radius: 18px; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px; z-index: 10; box-shadow: 0 10px 28px rgba(158, 11, 35, .3); }
.tabbar button { border: 0; background: none; color: rgba(255,255,255,.75); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 4px; border-radius: 13px; font-size: 11.5px; font-weight: 600; }
.tabbar button.on { background: rgba(255,255,255,.18); color: #fff; }
.tabbar .ico { width: 21px; height: 21px; }

/* รายละเอียดแบบเสื้อ + แผ่นเลือกไซส์ */
.sheet-bg { position: fixed; inset: 0; background: rgba(42, 20, 24, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: min(480px, 100%); max-height: 92vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; animation: up .22s ease-out; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 0; }
.sheet h3 { font-size: 18px; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.detail-ph { aspect-ratio: 3 / 4; max-height: 52vh; border-radius: 20px; background: var(--rose-100); overflow: hidden; margin: 0 auto; width: 100%; max-width: 100%; }
.detail-ph img { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--rose-50); }
.dots { display: flex; justify-content: center; gap: 8px; }
.dots button { border: 0; border-radius: 999px; padding: 4px 12px; background: var(--rose-50); color: var(--muted); font-size: 13px; font-weight: 600; }
.dots button.on { background: var(--red); color: #fff; }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } * { transition: none !important; } }

/* =====================================================================
   ฝั่ง HR
   ===================================================================== */
.hr-login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 15% 10%, var(--rose-100), transparent 45%), var(--bg); }
.hr-login form { width: min(420px, 100%); background: #fff; border-radius: 24px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; border-top: 6px solid var(--red); }
.hr-login h1 { font-size: 24px; }
.hr-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.side { background: #fff; border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.side .brand .mark { width: 40px; height: 40px; border-radius: 12px; background: var(--red); color: #fff; display: grid; place-items: center; }
.side .brand b { font-family: var(--f-display); font-size: 16px; display: block; line-height: 1.25; }
.side .brand small { color: var(--muted); font-size: 12px; }
.side .grp { font-size: 11.5px; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.side a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.side a:hover { background: var(--rose-50); }
.side a.on { background: var(--red); color: #fff; }
.side a.soon { color: var(--muted); }
.side a .pill { margin-left: auto; font-size: 10.5px; padding: 0 7px; }
.side a .ico { width: 19px; height: 19px; }
.side .cat-h { display: flex; align-items: center; gap: 10px; padding: 9px 10px 3px; font-weight: 600; font-family: var(--f-display); font-size: 14.5px; }
.side .cat-h .ico { color: var(--red); width: 19px; height: 19px; }
.side .sub a { padding-left: 39px; font-size: 14px; }
.side .foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.main { padding: 22px 28px 60px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.mbar { display: none; }
.ph-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.ph-head h1 { font-size: 24px; }
.ph-head .crumb { font-size: 13px; color: var(--muted); }
.ph-head .acts { display: flex; flex-wrap: wrap; gap: 8px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card h2 { font-size: 17px; }
.card .card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi small { color: var(--muted); font-size: 13px; }
.kpi strong { font-family: var(--f-display); font-size: 28px; font-variant-numeric: tabular-nums; }
.kpi.red { background: var(--red); color: #fff; border-color: var(--red); }
.kpi.red small { color: rgba(255,255,255,.85); }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: var(--rose-50); color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl td.c, .tbl th.c { text-align: center; }
.tbl select.in, .tbl .in { padding: 5px 8px; border-radius: 8px; font-size: 13.5px; min-width: 70px; }
.tbl tr.low td { background: #fff7f8; }
.thumb { width: 40px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--rose-100); display: block; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .in { width: auto; min-width: 160px; }
.note { background: var(--rose-50); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--ink); }
.note.warn { background: var(--warn-bg); }
.note.info { background: var(--info-bg); }
.steps { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.steps span { padding: 4px 10px; border-radius: 999px; background: #f4eff0; color: var(--muted); }
.steps span.done { background: var(--rose-100); color: var(--red-d); }
.steps span.now { background: var(--red); color: #fff; font-weight: 600; }
.bar { height: 8px; border-radius: 4px; background: var(--rose-50); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--red); border-radius: 4px; }
.modal-bg { position: fixed; inset: 0; background: rgba(42,20,24,.45); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal h3 { font-size: 18px; }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.doc-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.doc-card { border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #fff; }
.doc-card .ic { width: 44px; height: 44px; border-radius: 12px; background: var(--rose-50); color: var(--red); display: grid; place-items: center; }

@media (max-width: 900px) {
  .hr-shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .mbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mbar b { font-family: var(--f-display); }
  .main { padding: 16px 16px 60px; }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
}
