/* ทะเบียนเรื่องร้องเรียน — ธีม "สมุดทะเบียนราชการ" สีเหลืองประจำหน่วยงาน
   Kanit = หัวเรื่อง/เลขรับเรื่อง, Sarabun = เนื้อหา */
:root {
  --yellow: #f5c400;
  --yellow-deep: #d9a400;
  --yellow-pale: #fff3b8;
  --paper: #faf6ea;
  --card: #ffffff;
  --ink: #2b240a;
  --sub: #7a6c3f;
  --line: #e8dfc2;
  --new: #1668b3;
  --pending: #b3691f;
  --progress: #8a6d00;
  --done: #2e7d32;
  --reject: #b3261e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Sarabun', sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
}
h1, h2, .ticket, .brand-mark { font-family: 'Kanit', sans-serif; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.2rem 0 .5rem; }
a { color: inherit; }
.muted { color: var(--sub); }
.sm { font-size: .85rem; }

/* ---------- แถบบน ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--ink); color: #fff;
  padding: .6rem 1.2rem;
  border-bottom: 4px solid var(--yellow);
}
.brand-mark { font-weight: 600; letter-spacing: .02em; }
.brand-org { margin-left: .8rem; color: var(--yellow-pale); font-size: .9rem; }
.topbar-right { display: flex; align-items: center; gap: .8rem; }
.me { font-size: .85rem; color: #d9d2b8; }

/* ---------- ปุ่ม/ฟอร์ม ---------- */
.btn {
  font-family: 'Kanit', sans-serif; font-size: .95rem;
  border: none; border-radius: 8px; padding: .6rem 1.1rem; cursor: pointer;
}
.btn.primary { background: var(--yellow); color: var(--ink); font-weight: 600; }
.btn.primary:hover { background: var(--yellow-deep); }
.btn.ghost { background: transparent; color: #fff; border: 1px solid #6b6347; }
.btn.outline { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.outline:hover { background: var(--yellow-pale); border-color: var(--yellow-deep); }

/* ปุ่มดำเนินการในตารางเจ้าหน้าที่ — แยกสีตามความหมาย */
.btn.info    { background: #eaf2fb; color: #1668b3; border: 1px solid #c7dcf3; }
.btn.info:hover    { background: #dbe9f9; }
.btn.purple  { background: #f2ecfb; color: #6b3fa0; border: 1px solid #ddccf0; }
.btn.purple:hover  { background: #e6d9f7; }
.btn.success { background: #eaf6ea; color: var(--done); border: 1px solid #c9e6c9; }
.btn.success:hover { background: #dbf0db; }
.btn.warn    { background: #fdf3e2; color: #9a6a00; border: 1px solid #f3ddac; }
.btn.warn:hover    { background: #fbe9c9; }
.btn.danger  { background: #fdecea; color: var(--reject); border: 1px solid #f0c8c4; }
.btn.danger:hover  { background: #fbdedb; }
.btn.teal    { background: #e3f6f4; color: #147d75; border: 1px solid #b8e5df; }
.btn.teal:hover    { background: #d0efec; }
.btn.sm { padding: .3rem .7rem; font-size: .8rem; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }
input, select, textarea {
  font: inherit; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 3px solid var(--yellow); outline-offset: 1px;
}
.alert {
  background: #fdecea; color: var(--reject);
  border: 1px solid #f5c6c2; border-radius: 8px; padding: .6rem .8rem;
}
.alert.ok { background: #eaf6ea; color: var(--done); border-color: #c9e6c9; }

/* ---------- ตารางเจ้าหน้าที่ ---------- */
.staff-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.staff-table th {
  text-align: left; font-family: 'Kanit'; font-weight: 500; font-size: .8rem;
  color: var(--sub); border-bottom: 2px solid var(--yellow); padding: .5rem .4rem;
}
.staff-table td { padding: .6rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.staff-table tr.row-disabled { opacity: .5; }
.row-actions { display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.reset-row { display: none; gap: .4rem; margin-top: .3rem; }
.reset-row.show { display: flex; }
.reset-row input { padding: .3rem .5rem; font-size: .82rem; border-radius: 6px; border: 1px solid var(--line); width: 150px; }

.edit-row { display: none; flex-direction: column; gap: .35rem; margin-top: .3rem; width: 220px; }
.edit-row.show { display: flex; }
.edit-row input, .edit-row select { padding: .3rem .5rem; font-size: .82rem; border-radius: 6px; border: 1px solid var(--line); }

.role-badge {
  font-family: 'Kanit'; font-size: .74rem; padding: .12rem .55rem; border-radius: 999px;
  background: var(--yellow-pale); color: var(--progress);
}
.role-badge.role-admin { background: var(--ink); color: var(--yellow-pale); }
.role-badge.role-executive { background: #e8e2d0; color: var(--sub); }

.dept-scope-badge {
  display: inline-block; font-size: .85rem; color: var(--progress);
  background: var(--yellow-pale); border: 1px solid #f3e3a0;
  border-radius: 8px; padding: .5rem .9rem; margin-bottom: .9rem;
}

/* ---------- หน้า login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  width: min(420px, 100%);
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  border-top: 6px solid var(--yellow);
  padding: 2rem; box-shadow: 0 10px 30px rgba(90, 70, 0, .08);
}
.login-seal {
  display: inline-block; font-family: 'Kanit'; font-size: .8rem; font-weight: 500;
  background: var(--yellow-pale); color: var(--progress);
  border-radius: 999px; padding: .25rem .8rem; margin-bottom: .8rem;
}
.login-card h1 { margin-bottom: .2rem; }
.login-card form { margin-top: 1.2rem; }

/* ---------- โครงหน้า ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 1.4rem 1rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .8rem; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.back { display: inline-block; margin-bottom: .8rem; color: var(--sub); text-decoration: none; }
.back:hover { color: var(--ink); }

/* ---------- แถบกรองสถานะ ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  font-family: 'Kanit'; font-size: .82rem; text-decoration: none;
  padding: .3rem .75rem; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); color: var(--sub);
}
.chip.active { background: var(--ink); color: var(--yellow-pale); border-color: var(--ink); }

/* ---------- ทะเบียนเรื่อง (signature: แถวสมุดทะเบียนมีสันสี) ---------- */
.ledger { display: flex; flex-direction: column; gap: .6rem; }
.case-row {
  display: flex; gap: 1rem; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .8rem 1rem .8rem .8rem;
  border-left: 6px solid var(--sub);
  transition: transform .06s ease, box-shadow .06s ease;
}
.case-row:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(90,70,0,.10); }
.status-new { border-left-color: var(--new); }
.status-pending_info { border-left-color: var(--pending); }
.status-accepted, .status-in_progress, .status-awaiting_review { border-left-color: var(--yellow-deep); }
.status-resolved { border-left-color: var(--done); }
.status-rejected { border-left-color: var(--reject); }

.case-no { min-width: 150px; display: flex; flex-direction: column; gap: .35rem; }
.ticket {
  font-weight: 600; letter-spacing: .03em; font-size: .95rem;
  background: var(--yellow-pale); border-radius: 6px; padding: .15rem .5rem; width: fit-content;
}
.ticket.big { font-size: 1.6rem; padding: .2rem .7rem; }
.case-title { font-weight: 500; margin-bottom: .3rem; }
.case-meta { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .82rem; color: var(--sub); }
.overdue { color: var(--reject); font-weight: 700; }
.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: 10px;
  padding: 2rem; text-align: center; color: var(--sub);
}

/* ---------- ป้ายสถานะ ---------- */
.badge {
  font-family: 'Kanit'; font-size: .72rem; font-weight: 500;
  padding: .12rem .55rem; border-radius: 999px; width: fit-content; color: #fff;
  background: var(--sub);
}
.badge.lg { font-size: .85rem; padding: .2rem .8rem; }
.badge.new { background: var(--new); }
.badge.pending_info { background: var(--pending); }
.badge.accepted, .badge.in_progress, .badge.awaiting_review { background: var(--progress); }
.badge.resolved { background: var(--done); }
.badge.rejected { background: var(--reject); }

/* ---------- หน้ารายละเอียด ---------- */
.case-head {
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  border-top: 6px solid var(--yellow);
  padding: 1rem 1.2rem; margin-bottom: 1rem;
}
.case-head .badge { margin-top: .5rem; }
.case-head-meta { font-size: .9rem; display: flex; flex-direction: column; gap: .25rem; color: var(--sub); }
.case-head-meta b { color: var(--ink); font-weight: 600; }

.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.2rem;
}
.card h2:first-child { margin-top: 0; }
.detail-text { white-space: pre-wrap; line-height: 1.7; }
.kv { display: flex; flex-direction: column; gap: .35rem; font-size: .92rem; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.photos img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line);
}

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1.1rem; border-left: 3px solid var(--yellow); }
.timeline li { position: relative; padding: 0 0 1rem .8rem; }
.timeline li::before {
  content: ''; position: absolute; left: -1.65rem; top: .3rem;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--yellow); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--yellow-deep);
}
.timeline .tl-resolved::before { background: var(--done); box-shadow: 0 0 0 2px var(--done); }
.timeline .tl-rejected::before { background: var(--reject); box-shadow: 0 0 0 2px var(--reject); }
.tl-when { font-size: .78rem; color: var(--sub); }
.tl-who { font-size: .78rem; color: var(--sub); }

@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
  .case-row { flex-direction: column; gap: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .case-row { transition: none; }
}

/* ---------- หน้ารายงานสรุป ---------- */
.report-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .8rem; margin-bottom: 1.4rem;
}
.report-card {
  background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--yellow);
  border-radius: 10px; padding: 1rem 1.1rem; text-align: center;
  display: block; text-decoration: none; color: inherit;
}
.report-card-clickable { cursor: pointer; transition: transform .1s, box-shadow .1s; }
.report-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,.08); border-top-color: var(--progress); }
.report-card-num { font-family: 'Kanit'; font-size: 1.9rem; font-weight: 700; color: var(--ink); }
.report-card-label { font-size: .8rem; color: var(--sub); margin-top: .2rem; }

.month-chart {
  display: flex; align-items: flex-end; gap: .6rem; height: 140px; margin-top: .5rem;
  border-bottom: 1px solid var(--line); padding-bottom: 4px;
}
.month-bar-wrap { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; justify-content: flex-end; }
.month-bar {
  width: 100%; max-width: 34px; background: var(--yellow); border-radius: 4px 4px 0 0;
  min-height: 4px; position: relative; display: flex; justify-content: center;
}
.month-bar-n { position: absolute; top: -1.3em; font-size: .72rem; color: var(--sub); }
.month-bar-label { font-size: .68rem; color: var(--sub); margin-top: .3rem; white-space: nowrap; }

/* ---------- กล่องข้อความ (แชท) ---------- */
.thread { display: flex; flex-direction: column; gap: .5rem; max-height: 340px; overflow-y: auto; padding: .3rem; }
.thread-msg { max-width: 60%; width: fit-content; }
.thread-msg.in { align-self: flex-start; }
.thread-msg.out { align-self: flex-end; }
.thread-bubble {
  padding: .45rem .75rem; border-radius: 12px; font-size: .88rem; line-height: 1.45; white-space: pre-wrap;
  width: fit-content; max-width: 100%;
}
.thread-msg.in .thread-bubble { background: var(--yellow-pale); border: 1px solid #f3e3a0; border-bottom-left-radius: 3px; }
.thread-msg.out .thread-bubble { background: var(--ink); color: #fff; border-bottom-right-radius: 3px; }
.thread-meta { font-size: .72rem; color: var(--sub); margin-top: .25rem; }
.thread-msg.out .thread-meta { text-align: right; }

/* ---------- เทียบชื่อโปรไฟล์ LINE จริงกับชื่อที่พิมพ์เอง ---------- */
.line-verify {
  display: flex; align-items: center; gap: .6rem; margin-top: .3rem;
  background: #faf6ea; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem;
  font-size: .88rem;
}
.line-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.line-match { display: inline-block; margin-left: .5rem; font-size: .78rem; padding: .08rem .5rem; border-radius: 999px; }
.line-match.ok { background: #eaf6ea; color: var(--done); }
.line-match.warn { background: #fdf3e2; color: #9a6a00; }

.line-id {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: .78rem; background: var(--yellow-pale); padding: .05rem .4rem; border-radius: 4px;
}

.thread-bubble { position: relative; }
.thread-del { display: inline; position: absolute; top: -6px; right: -6px; opacity: 0; transition: opacity .15s; }
.thread-msg:hover .thread-del { opacity: 1; }
.thread-del button {
  border: none; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25);
  border-radius: 50%; width: 22px; height: 22px; font-size: .7rem; cursor: pointer; line-height: 1;
}

/* ---------- ป้ายตัวเลขแจ้งเตือนบนปุ่ม (เช่น จำนวนข้อความยังไม่อ่าน) ---------- */
.badge-count {
  position: absolute; top: -6px; right: -6px;
  background: #d32f2f; color: #fff; font-size: .68rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px; border: 2px solid var(--ink); line-height: 1;
}

.thread-img { max-width: 140px; max-height: 140px; border-radius: 8px; display: block; cursor: zoom-in; }

.thread-file { color: inherit; text-decoration: underline; font-weight: 600; }

/* ---------- แถวคลิกได้ในตารางรายงาน (เช่น กดแถวสถานะเพื่อดูรายการ) ---------- */
.report-row-clickable { cursor: pointer; transition: background .1s; }
.report-row-clickable:hover { background: var(--yellow-pale); }

/* ---------- จำกัดความสูงรายการในหน้ากล่องข้อความ ไม่ให้ยาวไม่รู้จบ (เฉพาะหน้านี้ ไม่กระทบทะเบียนเรื่องหลัก) ---------- */
#inbox-ledger {
  max-height: 50vh;
  overflow-y: auto;
  padding-right: .4rem;
}

/* ---------- ข้อความเติมพื้นที่ว่างใต้รายการกล่องข้อความ ---------- */
.inbox-placeholder {
  text-align: center; color: var(--sub); padding: 2.5rem 1rem;
  border: 1px dashed var(--line); border-radius: 12px; margin-top: 1rem;
}
.inbox-placeholder-icon { font-size: 2rem; opacity: .4; margin-bottom: .4rem; }
