/* ============================================================
   MhaewCRM — ธีมแนวเว็บภาครัฐ
   ข้อกำหนดทั้งหมด: .kiro/steering/ui-theme.md · mock: docs/design/mock-v2-gov-theme.html
   ห้ามตั้งสี/ฟอนต์/มุมโค้งใหม่ในหน้า — เพิ่มเป็น token ที่ :root ก่อนเสมอ
   ============================================================ */

:root {
  /* พื้น / หมึก / เส้น */
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --sunk: #F0F3F7;
  --ink: #1F2733;
  --ink2: #3F4A59;
  --muted: #5F6B7A;
  --line: #DCE1E8;
  --line2: #E9EDF2;
  --input-line: #AEB8C6;

  /* สีหลักเดียว: กรมท่า (กรมการจัดหางาน) */
  --navy: #0A336B;
  --navy-d: #072650;
  --navy-f: #E8EEF7;
  --navy-l: #C9D6EA;
  --on-navy: #DCE5F3;
  --on-navy-muted: #C9D6EA;

  /* ตกแต่งเท่านั้น (เส้นใต้แถบบน) */
  --gold: #FED03D;

  /* สถานะ — ใช้คู่กับข้อความเสมอ */
  --red: #B42318;  --red-f: #FDECEA; --red-l: #F3C4BE;
  --amb: #8A5A00;  --amb-f: #FFF4D6; --amb-l: #F1D58A; --amb-bar: #E0A92E;
  --ok: #146C43;   --ok-f: #E6F4EC;  --ok-l: #B7DEC8;

  /* ฟอนต์ */
  --head: "Prompt", "Sarabun", system-ui, sans-serif;
  --body: "Sarabun", "Prompt", system-ui, sans-serif;

  /* รูปทรง */
  --radius: 6px;
  --radius-lg: 8px;
  --radius-photo-sq: 12px;
  --shadow-pop: 0 6px 16px -4px rgba(16, 24, 40, .18);

  --container: 1200px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
}

h1, h2, h3 { font-family: var(--head); font-weight: 600; color: var(--ink); }

a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--navy-d); text-decoration: underline; text-underline-offset: 3px; }

:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: var(--radius); }

img { max-width: 100%; }

.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 100;
  background: var(--navy); color: #fff; padding: 8px 16px; border-radius: var(--radius);
}
.skip-link:focus { top: 12px; color: #fff; text-decoration: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.num { font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* ============================================================
   แถบบน (สีกรมท่า + เส้นทอง)
   ============================================================ */
.topbar {
  background: var(--navy);
  color: #fff;
  border-bottom: 3px solid var(--gold);
  position: sticky; top: 0; z-index: 40;
}
.topbar-in {
  max-width: var(--container);
  margin: 0 auto;
  min-height: 60px;
  padding: 0 24px;
  display: flex; align-items: center; gap: 20px;
}
.brand {
  font: 500 17px/1.2 var(--head);
  color: #fff;
  white-space: nowrap;
}
.brand small { display: block; font: 400 12px/1.3 var(--body); color: var(--on-navy-muted); }
.brand:hover { color: #fff; text-decoration: none; }

.topnav { display: flex; gap: 2px; }
.topnav a {
  color: var(--on-navy);
  padding: 8px 12px;
  border-radius: var(--radius);
  font: 400 15px/1.3 var(--head);
  white-space: nowrap;
}
.topnav a:hover { color: #fff; background: rgba(255, 255, 255, .10); text-decoration: none; }
.topnav a.on { color: #fff; background: rgba(255, 255, 255, .16); font-weight: 500; }

.topsearch {
  flex: 1; max-width: 360px; margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: var(--radius);
  height: 40px; padding: 0 10px; color: var(--muted);
}
.topsearch svg { width: 18px; height: 18px; flex: none; }
.topsearch input {
  border: 0; outline: 0; background: transparent; min-height: 0; height: 100%;
  padding: 0; width: 100%; font: 16px var(--body); color: var(--ink);
}
.topsearch input:focus { box-shadow: none; }
.topsearch:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
.topsearch kbd { font: 12px var(--body); border: 1px solid var(--line); padding: 0 6px; border-radius: 4px; color: var(--muted); }

.usermenu { position: relative; }
.usermenu summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 4px 8px; border-radius: var(--radius);
  color: #fff; font-size: 15px;
}
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: rgba(255, 255, 255, .10); }
.usermenu summary .ini {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: var(--navy); font: 500 13px var(--head);
}
.usermenu .un { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 220px; padding: 8px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.usermenu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line2); margin-bottom: 4px; }
.usermenu-pop .who b { display: block; font: 500 15px var(--head); }
.usermenu-pop .who span { font-size: 14px; color: var(--muted); }
.usermenu-pop a, .usermenu-pop button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; min-height: 40px; border: 0; border-radius: var(--radius);
  background: none; color: var(--ink); font: 15px var(--body); cursor: pointer;
}
.usermenu-pop a:hover, .usermenu-pop button:hover { background: var(--sunk); text-decoration: none; color: var(--ink); }
.usermenu-pop form { margin: 0; }

/* ---------- กระดิ่งแจ้งเตือน ---------- */
.bell { position: relative; }
.bell summary {
  list-style: none; cursor: pointer; position: relative;
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: var(--radius); color: #fff;
}
.bell summary::-webkit-details-marker { display: none; }
.bell summary:hover, .bell[open] summary { background: rgba(255, 255, 255, .10); }
.bell summary svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.bell-count {
  position: absolute; top: 4px; right: 2px;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 999px; border: 2px solid var(--navy);
  background: var(--red); color: #fff;
  font: 600 11px/1 var(--head); font-variant-numeric: tabular-nums;
}
.bell-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.bell-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line2); }
.bell-head b { font: 500 15px var(--head); }
.bell-head .muted { font-size: 14px; }
.bell-empty { margin: 0; padding: 20px 16px; color: var(--muted); }
.bell-list, .notice-list { list-style: none; margin: 0; padding: 0; }
.bell-list { max-height: 360px; overflow-y: auto; }
.bell-list a, .notice-list a {
  display: grid; grid-template-columns: 10px 1fr; gap: 0 12px; align-items: baseline;
  padding: 10px 16px; border-bottom: 1px solid var(--line2);
  color: var(--ink);
}
.bell-list a:hover, .notice-list a:hover { background: var(--sunk); text-decoration: none; color: var(--ink); }
.bell-list .bt, .notice-list .bt { font-weight: 600; font-size: 15px; }
.bell-list .bd, .notice-list .bd { grid-column: 2; font-size: 14px; color: var(--muted); }
.bell-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); align-self: center; grid-row: 1 / 3; }
.bell-dot.red { background: var(--red); }
.bell-dot.amb { background: var(--amb-bar); }
.bell-dot.info { background: var(--navy); }
.bell-all { display: block; padding: 12px 16px; font: 500 15px var(--head); text-align: center; }
.notice-list li:last-child a { border-bottom: 0; }
@media (min-width: 900px) {
  .notice-list { display: grid; grid-template-columns: 1fr 1fr; }
  .notice-list li:nth-child(odd) a { border-right: 1px solid var(--line2); }
}
@media (max-width: 900px) {
  .bell { order: 1; }
  .bell-pop { position: fixed; left: 16px; right: 16px; top: 64px; width: auto; }
}

.navtoggle {
  display: none;
  width: 44px; height: 44px; margin-right: -8px;
  place-items: center; border: 0; border-radius: var(--radius);
  background: rgba(255, 255, 255, .10); color: #fff; cursor: pointer;
}
.navtoggle svg, .photo-edit svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.topsearch svg { stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; }

@media (max-width: 1100px) {
  .topnav a { padding: 8px 8px; font-size: 14px; }
  .brand small { display: none; }
}

/* มือถือ/แท็บเล็ต: เมนูยุบใต้แถบ */
@media (max-width: 900px) {
  .topbar-in { flex-wrap: wrap; gap: 8px 12px; padding: 8px 16px; min-height: 56px; }
  .brand { font-size: 16px; margin-right: auto; }
  .navtoggle { display: grid; order: 3; }
  .usermenu { order: 2; }
  .usermenu .un { display: none; }
  .topsearch { order: 4; flex-basis: 100%; max-width: none; margin: 0 0 4px; }
  .topnav {
    order: 5; flex-basis: 100%;
    display: none; flex-direction: column; gap: 2px;
    padding: 4px 0 8px; border-top: 1px solid rgba(255, 255, 255, .14);
  }
  body.nav-open .topnav { display: flex; }
  .topnav a { padding: 12px; font-size: 16px; }
  .topsearch kbd { display: none; }
}

/* ============================================================
   เนื้อหา
   ============================================================ */
.container-main {
  max-width: var(--container);
  margin: 0 auto;
  padding: 24px 24px 48px;
}
.app-footer {
  max-width: var(--container); margin: 0 auto;
  padding: 16px 24px 32px;
  color: var(--muted); font-size: 14px;
  border-top: 1px solid var(--line);
}
@media (max-width: 900px) {
  .container-main { padding: 16px 16px 96px; }   /* เผื่อปุ่มติดล่างจอ */
  .app-footer { padding: 16px; }
}

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 26px; line-height: 1.3; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 15px; margin-top: 4px; max-width: 70ch; }

.crumb { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.crumb a { color: var(--ink2); }

/* ---------- การ์ด ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  scroll-margin-top: 88px;
}
.card:has(> .table) { overflow-x: auto; }
.card > .card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line2);
  font: 500 17px/1.3 var(--head);
}
.card > .card-body { padding: 20px; }

.section-title {
  font: 500 15px/1.3 var(--head);
  color: var(--ink2);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line2);
  margin: 0 0 16px;
}
.section-title:not(:first-child) { margin-top: 32px; }

/* ---------- ฟอร์ม ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-9 { grid-column: span 9; }
.col-12 { grid-column: span 12; }
.align-end { display: flex; align-items: flex-end; }
@media (max-width: 760px) { .form-grid > [class*="col-"] { grid-column: span 12; } }

.field label {
  display: block;
  font-size: 15px;
  color: var(--ink2);
  margin-bottom: 4px;
  font-weight: 500;
}
.field label .req { color: var(--red); }
.field .hint { font-size: 14px; color: var(--muted); margin-top: 4px; }
.field.grow { flex: 1; min-width: 220px; }

input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--input-line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
}
textarea { min-height: 96px; }
input::placeholder, textarea::placeholder { color: #6F7B8A; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px var(--navy-f);
}
input[type=checkbox], input[type=radio] { accent-color: var(--navy); width: 18px; height: 18px; }
.field-validation-error, .text-danger { color: var(--red); font-size: 14px; }
input.input-validation-error, select.input-validation-error { border-color: var(--red); }

.input-group { display: flex; }
.input-group input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .addon {
  display: flex; align-items: center;
  padding: 0 12px;
  border: 1px solid var(--input-line); border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--sunk); color: var(--ink2);
  font-size: 15px; white-space: nowrap;
}

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid #B8C2D0;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: 500 15px/1.3 var(--head);
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { text-decoration: none; background: var(--sunk); color: var(--ink); }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-d); border-color: var(--navy-d); color: #fff; }
.btn-default { background: #fff; }
.btn-danger { border-color: var(--red-l); color: var(--red); background: #fff; }
.btn-danger:hover { background: var(--red-f); color: var(--red); }
.btn-sm { min-height: 34px; padding: 4px 14px; font-size: 14px; }
.btn-link { border-color: transparent; background: none; color: var(--navy); padding: 8px 6px; }
.btn-link:hover { background: none; color: var(--navy-d); text-decoration: underline; text-underline-offset: 3px; }
.btn-block { width: 100%; }
@media (max-width: 900px) { .btn { min-height: 44px; } .btn-sm { min-height: 40px; } }

/* ---------- ตาราง ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line2);
  vertical-align: middle;
}
.table thead th {
  font: 500 14px/1.3 var(--head);
  color: var(--ink2);
  background: var(--sunk);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #FAFBFD; }
.table .num { text-align: right; }
.table td.num { text-align: left; }   /* เลขเอกสาร/เบอร์: ชิดซ้ายเหมือนข้อความ แต่ใช้ตัวเลขกว้างเท่ากัน */
.table .cell-primary a, .cell-primary-link { font-weight: 600; color: var(--ink); }
.table .cell-primary a:hover, .cell-primary-link:hover { color: var(--navy); }
.table .muted-row td { color: var(--muted); text-align: center; padding: 40px 16px; }
.table td.gap-row { display: table-cell; white-space: nowrap; }
.table td.gap-row > * { margin-right: 8px; vertical-align: middle; }
.cell-person { display: flex; align-items: center; gap: 12px; }
.d-block { display: block; font-size: 14px; }
code { font-family: var(--body); font-size: 15px; color: var(--ink); }

/* ---------- badge สถานะทั่วไป ---------- */
.badge-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
}
.badge-status.valid   { background: var(--ok-f);  color: var(--ok);   border-color: var(--ok-l); }
.badge-status.near    { background: var(--amb-f); color: var(--amb);  border-color: var(--amb-l); }
.badge-status.expired { background: var(--red-f); color: var(--red);  border-color: var(--red-l); }
.badge-status.none    { background: var(--sunk);  color: var(--ink2); border-color: var(--line); }

/* ---------- ป้ายจำนวนวัน (องค์ประกอบเด่นเดียว — สร้างผ่าน Ui.DaysBadge) ---------- */
.days {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 12px;
  border: 1px solid;
  border-radius: var(--radius);
  font-family: var(--head);
  white-space: nowrap;
}
.days .n { font-size: 22px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.days .u { font-size: 13px; font-weight: 500; }
.days.amb { color: var(--amb); background: var(--amb-f); border-color: var(--amb-l); }
.days.red { color: var(--red); background: var(--red-f); border-color: var(--red-l); }
.days.ok  { color: var(--ok);  background: var(--ok-f);  border-color: var(--ok-l); }
.days.sm { padding: 2px 10px; }
.days.sm .n { font-size: 17px; }
.t-red { color: var(--red) !important; }
.t-amb { color: var(--amb) !important; }

/* ---------- alert ---------- */
.alert {
  padding: 12px 16px;
  border: 1px solid transparent; border-left-width: 4px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 15px;
}
.alert-ok     { background: var(--ok-f);   color: var(--ok);     border-color: var(--ok-l); }
.alert-warn   { background: var(--amb-f);  color: var(--amb);    border-color: var(--amb-l); }
.alert-danger { background: var(--red-f);  color: var(--red);    border-color: var(--red-l); }
.alert-info   { background: var(--navy-f); color: var(--navy-d); border-color: var(--navy-l); }

/* ---------- toolbar ค้นหา/กรอง ---------- */
.toolbar {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.toolbar .field { margin: 0; }
.toolbar input, .toolbar select { min-width: 200px; }
@media (max-width: 560px) { .toolbar .field, .toolbar input, .toolbar select { width: 100%; min-width: 0; } }

/* ---------- definition list ---------- */
.dl { display: grid; grid-template-columns: 200px 1fr; gap: 12px 24px; margin: 0; }
.dl dt { color: var(--muted); font-size: 15px; }
.dl dd { margin: 0; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; gap: 0; } .dl dd { margin-bottom: 12px; } }

/* ---------- รหัสผ่านแสดงครั้งเดียว ---------- */
.credential {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--navy); color: #fff;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
}
.credential .label { font-size: 13px; color: var(--on-navy-muted); }
.credential .value { font: 500 20px/1.3 var(--head); letter-spacing: .04em; word-break: break-all; }

/* ---------- เอกสาร toggle (ฟอร์มลูกจ้าง) ---------- */
.doc-item { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 16px; margin-bottom: 12px; background: #fff; }
.doc-item.on { border-color: var(--navy-l); background: var(--navy-f); }
.doc-head { display: flex; align-items: center; gap: 12px; }
.doc-head label { font: 500 16px var(--head); margin: 0; cursor: pointer; }
.doc-head .badge-status { margin-left: auto; }
.doc-body { display: none; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--navy-l); }
.doc-item.on .doc-body { display: block; }

/* ---------- segmented (โหมดอีเมล) ---------- */
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--input-line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; background: #fff; }
.segmented label {
  display: flex; align-items: center;
  min-height: 40px; padding: 4px 16px; margin: 0;
  border-right: 1px solid var(--line);
  font: 400 15px var(--head); color: var(--ink2);
  cursor: pointer;
}
.segmented label:last-child { border-right: 0; }
.segmented label:hover { background: var(--sunk); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + label { background: var(--navy); color: #fff; font-weight: 500; }
.segmented input:focus-visible + label { outline: 2px solid var(--navy); outline-offset: -3px; }

/* ---------- combobox ค้นหาได้ ---------- */
.combo { position: relative; }
.combo-list {
  list-style: none; margin: 4px 0 0; padding: 4px;
  position: absolute; z-index: 20; left: 0; right: 0;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  max-height: 260px; overflow-y: auto; display: none;
  box-shadow: var(--shadow-pop);
}
.combo-list.open { display: block; }
.combo-list li { padding: 8px 12px; cursor: pointer; border-radius: 4px; }
.combo-list li:hover, .combo-list li.active { background: var(--navy-f); }

/* ============================================================
   รูปโปรไฟล์ (partial _Avatar)
   ============================================================ */
.avatar {
  position: relative; flex: none;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  background: #D3DCE9; color: var(--navy);
  font-family: var(--head); font-weight: 500;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.avatar .ini { line-height: 1; }
.avatar.sq { border-radius: var(--radius-photo-sq); }
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.avatar-md { width: 44px; height: 44px; font-size: 15px; }
.avatar-lg { width: 64px; height: 64px; font-size: 20px; }
.avatar-xl { width: 128px; height: 128px; font-size: 40px; border: 4px solid #fff; }
.avatar .dot {
  position: absolute; right: 0; bottom: 2px;
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff;
}
.avatar .dot.red { background: var(--red); }
.avatar .dot.amb { background: var(--amb-bar); }
.avatar .dot.ok  { background: var(--ok); }

/* ============================================================
   แฟ้ม (profile) ลูกจ้าง / นายจ้าง
   ============================================================ */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.profile {
  display: flex; align-items: center; gap: 24px;
  padding: 24px 32px 20px;
}
.profile-photo { position: relative; flex: none; }
.photo-form { margin: 0; }
.photo-edit {
  position: absolute; right: 4px; bottom: 6px;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; border: 1px solid var(--line); color: var(--ink2);
  cursor: pointer;
}
.photo-edit:hover { color: var(--navy); border-color: var(--navy-l); }
.photo-edit svg { width: 18px; height: 18px; }
.photo-edit input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.photo-edit:focus-within { outline: 2px solid var(--navy); outline-offset: 2px; }
.profile-text { min-width: 0; padding-bottom: 4px; }
.profile-text h1 { font-size: 28px; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.profile-text .local { font-size: 17px; color: var(--ink2); }
.profile-text .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 2px; font-size: 15px; color: var(--muted); }
.profile-text .meta b { color: var(--ink); font-weight: 500; }
.profile-acts { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 6px; }
.profile-acts form { margin: 0; }
.profile-counts {
  display: flex; gap: 8px 32px; flex-wrap: wrap;
  padding: 12px 32px;
  border-top: 1px solid var(--line);
  font-size: 15px; color: var(--muted);
}
.profile-counts b { font: 600 19px var(--head); color: var(--ink); margin-right: 6px; font-variant-numeric: tabular-nums; }
.profile-tabs {
  display: flex; gap: 4px;
  padding: 0 32px;
  border-top: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap;
}
.profile-tabs a { padding: 12px 14px; color: var(--ink2); font: 400 15px var(--head); }
.profile-tabs a:hover { color: var(--navy); text-decoration: none; }
.profile-tabs a.on { color: var(--navy); font-weight: 500; box-shadow: inset 0 -3px 0 var(--navy); }

.profile-body {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px; align-items: start;
  margin-bottom: 24px;
  scroll-margin-top: 88px;
}

@media (max-width: 900px) {
  .profile { flex-direction: column; align-items: flex-start; gap: 8px; padding: 20px 16px 16px; }
  .avatar-xl { width: 96px; height: 96px; font-size: 30px; }
  .profile-text h1 { font-size: 23px; }
  .profile-acts { margin-left: 0; }
  .profile-counts { padding: 10px 16px; gap: 4px 20px; }
  .profile-tabs { padding: 0 8px; }
  .profile-body { grid-template-columns: 1fr; }
}
@media (min-width: 600px) and (max-width: 900px) {
  .profile-body .side { display: grid; grid-template-columns: 1fr 1fr; }
  .profile-body .side .side-cap { grid-column: 1 / -1; }
}

/* ---------- แผงงาน (ทุกงานใช้โครงเดียว) ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  scroll-margin-top: 88px;
}
.p-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line2);
}
.p-head h2 { font-size: 18px; line-height: 1.3; margin: 0; }
.p-head .sub { font-size: 14px; color: var(--muted); }
.p-head .days, .p-head .push { margin-left: auto; }
.p-body { padding: 20px; }

.cycle {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line2); border-radius: var(--radius); overflow: hidden;
}
.cycle > div { padding: 12px 16px; border-right: 1px solid var(--line2); background: var(--sunk); }
.cycle > div:last-child { border-right: 0; }
.cycle .k { font-size: 14px; color: var(--muted); }
.cycle .v { font: 500 17px/1.4 var(--head); }
@media (max-width: 560px) {
  .cycle { grid-template-columns: 1fr 1fr; }
  .cycle > div:nth-child(2) { border-right: 0; }
  .cycle > div:nth-child(3) { grid-column: 1 / -1; border-top: 1px solid var(--line2); }
}

.bar { height: 10px; margin: 18px 0 4px; background: var(--line2); border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 5px; background: var(--navy); }
.bar i.amb { background: var(--amb-bar); }
.bar i.red { background: var(--red); }
.bar i.ok  { background: var(--ok); }
.bar-l { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); }

.record {
  margin-top: 20px; padding: 16px;
  background: var(--navy-f);
  border: 1px solid var(--navy-l);
  border-radius: var(--radius);
}
.record h3 { margin: 0 0 12px; font-size: 16px; font-weight: 500; }
.record-foot { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; margin-top: 16px; font-size: 15px; }
.record-foot b { font-weight: 600; }

.hist { margin-top: 24px; }
.hist h3 { margin: 0 0 8px; font-size: 15px; font-weight: 500; color: var(--ink2); }
.timeline { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line2); }
.timeline li {
  display: grid; grid-template-columns: 120px 1fr auto;
  gap: 16px; align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--line2);
  font-size: 15px;
}
.timeline .d { font-weight: 500; }
@media (max-width: 560px) {
  .timeline li { grid-template-columns: 1fr auto; gap: 2px 12px; }
  .timeline li > span:nth-child(2) { grid-column: 1 / -1; grid-row: 2; color: var(--ink2); }
}
.tag { font-size: 13px; padding: 1px 10px; border-radius: 999px; background: var(--sunk); color: var(--ink2); white-space: nowrap; }
.tl-acts { display: inline-flex; align-items: baseline; gap: 12px; white-space: nowrap; }
.tl-acts a { font-size: 14px; }

/* ---------- ตัวเลือกแบบ radio ในฟอร์ม ---------- */
.field-set { border: 0; padding: 0; margin: 20px 0 0; }
.field-set legend { font-size: 15px; font-weight: 500; color: var(--ink2); margin-bottom: 8px; padding: 0; }
.choice { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; cursor: pointer; }
.choice input { margin-top: 4px; }
.danger-zone { border-color: var(--red-l); margin-top: 32px; }
.mt-16 { margin-top: 16px; }
.tag.late { background: var(--red-f); color: var(--red); }

.schedule { margin-top: 12px; }
.schedule summary { cursor: pointer; color: var(--navy); font: 500 15px var(--head); padding: 8px 0; min-height: 40px; }
.schedule form { margin-top: 8px; }

/* ---------- แผงย่อยด้านข้าง ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side-cap { margin: 0; font: 500 14px var(--head); color: var(--muted); }
.mini {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--ink);
}
a.mini:hover { border-color: var(--navy-l); text-decoration: none; color: var(--ink); }
.mini .t { font: 500 15px var(--head); }
.mini .s { grid-column: 1; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.mini .days, .mini .na { grid-column: 2; grid-row: 1 / 3; }
.mini .na { font-size: 14px; color: var(--navy); }

/* ---------- รายการลูกจ้างที่ต้องรายงาน (แฟ้มนายจ้าง) ---------- */
.due-group {
  padding: 8px 20px;
  font: 500 14px var(--head); color: var(--ink2);
  background: var(--sunk);
  border-bottom: 1px solid var(--line2);
}
.due-list { list-style: none; margin: 0; padding: 0; }
.due-list li {
  display: grid; grid-template-columns: 44px 1fr auto auto;
  gap: 14px; align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line2);
}
.due-list li:last-child { border-bottom: 0; }
.due-list .nm { font: 500 16px var(--head); color: var(--ink); }
.due-list .nm:hover { color: var(--navy); }
.due-list .sub { font-size: 14px; color: var(--muted); }
@media (max-width: 560px) {
  .due-list li { grid-template-columns: 44px 1fr auto; padding: 12px 16px; }
  .due-list li .btn { grid-column: 2 / -1; justify-self: start; }
}

.roster {
  list-style: none; margin: 0; padding: 20px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.roster a { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--ink); font-size: 14px; }
.roster a:hover { color: var(--navy); text-decoration: none; }
.roster .rn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend { margin: 0; padding: 0 20px 16px; font-size: 13px; color: var(--muted); }

/* ---------- ปุ่มติดล่างจอ (มือถือ) ---------- */
.sticky-action { display: none; }
@media (max-width: 900px) {
  .sticky-action {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: #fff; border-top: 1px solid var(--line);
  }
  .sticky-action .btn { flex: 1; min-height: 48px; font-size: 16px; }
}

/* ============================================================
   แดชบอร์ด (งานวันนี้)
   ============================================================ */
.dash-section { margin-bottom: 32px; }
.dash-section > h2 { font-size: 16px; font-weight: 500; color: var(--ink2); margin: 0 0 12px; }

.attn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.attn {
  display: block;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--ink);
}
a.attn:hover { border-color: var(--navy-l); text-decoration: none; color: var(--ink); }
.attn .tag-l { font: 500 13px var(--head); color: var(--muted); }
.attn .tag { background: none; padding: 0; font: 500 13px var(--head); color: var(--muted); }
.attn .num { display: block; font: 600 36px/1.15 var(--head); margin: 4px 0; font-variant-numeric: tabular-nums; }
.attn .label { font-size: 15px; color: var(--ink2); }
.attn.expired { border-left-color: var(--red); }
.attn.expired .tag, .attn.expired .num { color: var(--red); }
.attn.near { border-left-color: var(--amb-bar); }
.attn.near .tag, .attn.near .num { color: var(--amb); }
.attn.is-zero { border-left-color: var(--ok); }
.attn.is-zero .tag, .attn.is-zero .num { color: var(--ok); }

.count-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.count-row a { display: block; padding: 16px 20px; border-right: 1px solid var(--line2); color: var(--ink); }
.count-row a:last-child { border-right: 0; }
.count-row a:hover { background: #FAFBFD; text-decoration: none; color: var(--ink); }
.count-row .num { font: 600 26px/1.2 var(--head); font-variant-numeric: tabular-nums; }
.count-row .label { font-size: 15px; color: var(--muted); }

.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 1000px) { .dash-cols { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .attn-grid { grid-template-columns: 1fr; }
  .count-row { grid-template-columns: repeat(2, 1fr); }
  .count-row a:nth-child(2) { border-right: 0; }
  .count-row a:nth-child(-n+2) { border-bottom: 1px solid var(--line2); }
}

/* ============================================================
   หน้าก่อนล็อกอิน (login / เปลี่ยนรหัสบังคับ / ไม่มีสิทธิ)
   ============================================================ */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; }
.auth-side {
  background: var(--navy); color: #fff;
  border-bottom: 3px solid var(--gold);
  padding: 16px 24px;
}
.auth-side .brand { display: block; max-width: var(--container); margin: 0 auto; }
.auth-note { display: none; }
.auth-main { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
}
.auth-card h1 { font-size: 24px; line-height: 1.3; margin: 0 0 8px; }
.auth-card > p.muted { margin: 0 0 24px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .hint { margin-top: 24px; font-size: 14px; color: var(--muted); }
@media (max-width: 560px) { .auth-main { padding: 24px 16px; } .auth-card { padding: 24px 20px; } }

/* ---------- ช่องวันที่ พ.ศ. (thai-datepicker.js) ---------- */
.tdp { position: relative; display: flex; }
.tdp-input { border-radius: var(--radius) 0 0 var(--radius) !important; font-variant-numeric: tabular-nums; }
.tdp-btn {
  flex: none; width: 44px; min-height: 42px;
  display: grid; place-items: center;
  border: 1px solid var(--input-line); border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--sunk); color: var(--ink2); cursor: pointer;
}
.tdp-btn:hover, .tdp-btn[aria-expanded=true] { background: var(--navy-f); color: var(--navy); }
.tdp-btn svg, .tdp-nav svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.tdp-input:disabled + input + .tdp-btn { opacity: .5; pointer-events: none; }

.tdp-pop {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0;
  width: 320px; padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.tdp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.tdp-head select { width: auto; min-width: 0; min-height: 36px; padding: 4px 8px; font-size: 15px; }
.tdp-month { flex: 1.4 1 0; }
.tdp-year { flex: 1 1 0; }
.tdp-nav {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink2); cursor: pointer;
}
.tdp-nav:hover { background: var(--sunk); }
.tdp-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.tdp-grid th { font: 500 13px var(--head); color: var(--muted); padding: 4px 0; text-align: center; }
.tdp-grid th:first-child { color: var(--red); }
.tdp-grid td { padding: 1px; text-align: center; }
.tdp-day {
  width: 100%; height: 38px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: var(--ink);
  font: 15px var(--body); font-variant-numeric: tabular-nums; cursor: pointer;
}
.tdp-day:hover { background: var(--navy-f); }
.tdp-day.out { color: #8A94A3; }
.tdp-day.today { border-color: var(--navy-l); font-weight: 600; }
.tdp-day.sel, .tdp-day.sel:hover { background: var(--navy); color: #fff; font-weight: 600; }
.tdp-day:disabled { color: #B6BEC9; background: none; cursor: not-allowed; text-decoration: line-through; }
.tdp-day:focus-visible { outline: 2px solid var(--navy); outline-offset: 0; }
.tdp-foot { display: flex; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line2); }
.tdp-foot button {
  min-height: 36px; padding: 4px 12px; border: 0; border-radius: var(--radius);
  background: none; color: var(--navy); font: 500 14px var(--head); cursor: pointer;
}
.tdp-foot button:hover { background: var(--navy-f); }
.tdp-foot button:disabled { color: #8A94A3; background: none; cursor: not-allowed; }
.tdp-close { margin-left: auto; }
@media (max-width: 560px) {
  /* มือถือ: ปฏิทินติดล่างจอ กดด้วยนิ้วโป้งได้ */
  .tdp-pop {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .tdp-day { height: 44px; }
}

/* ---------- สร้างอีเมลจากแฟ้มลูกจ้าง ---------- */
.email-create {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line2);
}
.email-create .field { flex: 1; min-width: 260px; margin: 0; }
.email-create .lead { font: 500 15px var(--head); color: var(--ink); margin-bottom: 2px; }
.email-link { padding: 4px 20px 16px; border-bottom: 1px solid var(--line2); }
.email-link summary { cursor: pointer; color: var(--navy); font: 500 15px var(--head); padding: 8px 0; min-height: 40px; }
.email-link form { margin-top: 8px; }
.doc-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--line2); }

/* ---------- ตารางผู้ใช้ ---------- */
.role-form { margin: 0; }
.role-form select { min-width: 140px; min-height: 38px; padding: 4px 8px; }

/* ---------- utility ---------- */
.muted { color: var(--muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gap-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.gap-row form { margin: 0; }
.required-note { font-size: 14px; color: var(--muted); }

/* ---------- motion: เฉพาะการเปลี่ยนสถานะ ---------- */
@media (prefers-reduced-motion: no-preference) {
  .btn, input, select, textarea, .topnav a, .mini, .attn, .count-row a, .table tbody tr, .photo-edit {
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
  }
}

/* ---------- หน้าจัดการกล่องอีเมล (ผู้บริหาร) ---------- */
.quota-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.meter { flex: 0 1 240px; min-width: 120px; height: 8px; background: var(--line2); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--navy); }
.meter.full i { background: var(--red); }
.mb-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
.mb-actions form { margin: 0; }
.mb-act summary { list-style: none; cursor: pointer; }
.mb-act summary::-webkit-details-marker { display: none; }
.mb-act[open] { flex-basis: 100%; }
.mb-act[open] summary { margin-bottom: 8px; }
.mb-act form { display: grid; gap: 12px; padding: 12px; max-width: 360px; background: var(--sunk); border: 1px solid var(--line); border-radius: var(--radius); }
.mb-act form .field { margin: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; }
