/* ใช้ฟอนต์ที่มีในเครื่อง ไม่โหลดจากอินเทอร์เน็ต เพื่อให้ใช้งานในเครือข่ายภายในได้ */
:root {
  --navy: #14214a;
  --primary: #1e3a8a;
  --primary-dark: #14286b;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #d9dee8;
  --input-border: #8993ad;
  --text: #17203a;
  --muted: #5a6480;
  --gold: #c9a24b;
  --warn-bg: #ffe9cc;
  --warn-fg: #7a3e00;
  --ok-bg: #d6ebfa;
  --ok-fg: #0b4a75;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.3; }
h2 { margin: 0 0 12px; font-size: 18px; }
a { color: var(--primary); }
.muted { color: var(--muted); margin: 0 0 20px; }
.help { color: var(--muted); font-size: 13px; margin-top: 4px; }
.help ul { margin: 4px 0 0; padding-left: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.95);
}

/* โครงหน้า: เมนูซ้าย + เนื้อหา (ย่อเป็นแนวตั้งบนจอแคบ) */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.sidebar {
  flex: 1 1 250px;
  background: var(--navy);
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.main { flex: 999 1 560px; min-width: 0; padding: 24px 32px 48px; }

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark {
  flex: none; width: 44px; height: 44px; border-radius: 10px;
  background: var(--gold); color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
.brand-title { font-weight: 600; font-size: 16px; }
.brand-sub { font-size: 13px; color: #c5cce3; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 44px; padding: 0 12px; border-radius: 8px;
  color: #fff; text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.1); }
.nav-link.active { background: rgba(255, 255, 255, 0.16); }
.nav-link.disabled { color: #aab3d0; cursor: default; }
.nav-link.disabled:hover { background: none; }
.nav-link small { font-size: 12px; }

.me { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.18); padding: 16px 8px 0; }
.me-name { font-weight: 600; font-size: 14px; }
.me-role { font-size: 13px; color: #c5cce3; margin-bottom: 10px; }

/* ปุ่ม */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 8px;
  border: 1px solid var(--input-border); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: #f3f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn-ghost-light { background: transparent; border-color: rgba(255, 255, 255, 0.5); color: #fff; width: 100%; }
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.12); }

/* การ์ดและฟอร์ม */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px 28px; }
.form-card { max-width: 640px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input[type="text"], .field input[type="password"], .field input[type="email"], .field select {
  width: 100%; min-height: 46px; padding: 0 12px;
  border: 1px solid var(--input-border); border-radius: 8px;
  font: inherit; color: var(--text); background: #fff;
}
.field input[type="checkbox"] { width: 20px; height: 20px; vertical-align: middle; margin-right: 8px; }
.error-text { color: #8a1c1c; font-size: 14px; margin-top: 4px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600; }
.alert.success { background: var(--ok-bg); color: var(--ok-fg); }
.alert.error { background: #fadcdc; color: #8a1c1c; }
.alert.warning, .alert.info { background: var(--warn-bg); color: var(--warn-fg); }

/* รายการผู้ใช้ */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 16px; }
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--input-border); border-radius: 999px;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px; background: #fff;
}
.chip.active { background: #e6ecfa; border-color: var(--primary); color: var(--primary-dark); }

.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; min-width: 760px; border-collapse: collapse; }
.table th { text-align: left; padding: 12px 20px; background: #f7f9fc; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.table td { padding: 12px 20px; border-bottom: 1px solid #e8ecf3; vertical-align: middle; }
.table .empty { text-align: center; color: var(--muted); padding: 40px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.pill { display: inline-block; padding: 2px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; margin-right: 4px; }
.pill-ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill-off { background: #e7eaf1; color: #3c4560; }
.pill-warn { background: var(--warn-bg); color: var(--warn-fg); }

.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { padding: 8px 0 8px 28px; border-top: 1px solid #e8ecf3; position: relative; color: var(--muted); }
.check-list li::before { content: "○"; position: absolute; left: 4px; }
.check-list li.done { color: var(--text); }
.check-list li.done::before { content: "●"; color: var(--primary); }

/* 2FA */
.steps { margin: 0 0 16px; padding-left: 22px; color: var(--muted); }
.steps li { margin-bottom: 6px; }
.qr { display: flex; justify-content: center; padding: 8px 0; }
.qr svg { width: 280px; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 1px; word-break: break-all; background: #f3f5f9; padding: 8px 12px; border-radius: 8px; }
.codes { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.codes li { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; letter-spacing: 2px; background: #f3f5f9; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; text-align: center; }
.row-actions form { display: inline; }

/* หน้าเข้าสู่ระบบ */
.login-wrap { display: flex; flex-wrap: wrap; min-height: 100vh; }
.login-hero {
  flex: 1 1 420px; background: var(--navy); color: #fff; padding: 56px 48px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 48px;
}
.login-hero h1 { font-size: 40px; line-height: 1.25; margin: 0; }
.login-hero p { margin: 16px 0 0; font-size: 17px; color: #c5cce3; max-width: 420px; }
.login-panel { flex: 1 1 420px; padding: 56px 48px; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-card h2 { font-size: 24px; margin-bottom: 20px; }

/* งานเอกสาร */
.section-gap { margin-top: 20px; }
.muted-inline { color: var(--muted); font-size: 13px; margin-left: 6px; }
.field textarea, .field input[type="file"] { width: 100%; font: inherit; color: var(--text); }
.field textarea { padding: 10px 12px; border: 1px solid var(--input-border); border-radius: 8px; background: #fff; }
.field input[type="file"] { min-height: 44px; padding: 8px 0; }
.picker-box { border: 0; padding: 0; margin: 0 0 18px; }
.picker { margin-bottom: 6px; }
.picker-box legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.chip { font: inherit; cursor: pointer; }
.people { list-style: none; margin: 0 0 8px; padding: 0; border: 1px solid var(--border); border-radius: 8px; max-height: 320px; overflow-y: auto; }
.people li { border-top: 1px solid #e8ecf3; }
.people li:first-child { border-top: 0; }
.people li[hidden] { display: none; }
.people label { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 12px; cursor: pointer; }
.people input[type="checkbox"] { width: 20px; height: 20px; }
.order-badge { min-width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.order-badge:empty { visibility: hidden; }
.file-list, .steps-list, .history { margin: 0; padding-left: 20px; }
.file-list li, .steps-list li, .history li { margin-bottom: 8px; }
.file-list { list-style: none; padding-left: 0; }
.nav-badge { min-width: 24px; height: 24px; padding: 0 8px; border-radius: 999px; background: var(--gold); color: var(--navy); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.subform { padding: 16px 0; border-top: 1px solid #e8ecf3; }
.subform:first-of-type { border-top: 0; padding-top: 0; }
.subform h3 { margin: 0 0 6px; font-size: 16px; }
.radio-group { border: 0; padding: 0; margin: 0 0 14px; }
.radio-group legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.radio[hidden] { display: none; }
.radio input { width: 20px; height: 20px; }

.brand { text-decoration: none; color: inherit; }
.me-links { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.me-links a { color: #dfe4f5; text-decoration: none; font-size: 14px; min-height: 40px; display: flex; align-items: center; border-radius: 6px; padding: 0 8px; margin: 0 -8px; }
.me-links a:hover, .me-links a[aria-current="page"] { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* ความเร่งด่วน: แยกด้วยตัวอักษร + สี (ไม่พึ่งสีอย่างเดียว) */
.pill-u1 { background: #fff1b8; color: #6b4e00; }
.pill-u2 { background: #ffd3b0; color: #7a2e00; }
.pill-u3 { background: #b3261e; color: #fff; }
.urgency-options { display: flex; flex-wrap: wrap; gap: 4px 22px; }

.btn-danger { background: #fff; border-color: #b3261e; color: #b3261e; }
.btn-danger:hover { background: #b3261e; color: #fff; }
form.actions .btn-danger { background: #b3261e; color: #fff; }
.manage-actions { margin: 0 0 16px; }
.search-form { max-width: 760px; }
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field input[type="date"] { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--input-border); border-radius: 8px; font: inherit; color: var(--text); background: #fff; }
@media (max-width: 600px) { .date-row { grid-template-columns: 1fr; } }

.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; padding: 14px 18px; margin-bottom: 14px; }
.filter-field { display: flex; flex-direction: column; gap: 4px; min-width: 170px; }
.filter-field label { font-weight: 600; font-size: 13px; color: var(--muted); }
.filter-field select { min-height: 40px; padding: 0 10px; border: 1px solid var(--input-border); border-radius: 8px; font: inherit; color: var(--text); background: #fff; }
.filter-actions { display: flex; gap: 8px; }
@media (max-width: 600px) { .filter-field { min-width: 100%; } }

.notice-stack { margin-bottom: 16px; display: grid; gap: 8px; }
.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-radius: 10px; background: #dff3e6; color: #0f4d27; border: 1px solid #9fd3b1; }
.notice-text { display: flex; flex-direction: column; gap: 2px; }
.notice-text small { font-weight: 400; color: #2f6b45; }
.notice-actions { display: flex; gap: 8px; }
.notice-actions form { margin: 0; }

.office-btn { margin-left: 8px; }
.office-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.office-frame { height: calc(100vh - 170px); min-height: 480px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }

/* นโยบายเก็บเอกสาร */
.pill-ret-warn { background: #fff1b8; color: #6b4e00; }
.pill-ret-danger { background: #b3261e; color: #fff; }
.retention-bar { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 15px; border: 1px solid var(--border); background: #eef1f6; color: #3c4560; }
.retention-bar.ret-warn, .retention-bar.ret-waiting { background: #fff6d6; color: #6b4e00; border-color: #f0d98a; }
.retention-bar.ret-danger { background: #fde4e2; color: #8a1c1c; border-color: #f2b8b5; font-weight: 600; }
.retention-bar.ret-purged { background: #e7eaf1; color: #3c4560; }

.ret-cell { white-space: nowrap; }

/* หน้ารายละเอียด: 2 คอลัมน์ (ซ้าย = ไฟล์/ดำเนินการ/ประวัติ, ขวา = ข้อความถึงผู้รับ) */
.doc-layout { display: grid; grid-template-columns: minmax(0, 640px) minmax(320px, 1fr); gap: 24px; align-items: start; }
.doc-main > .card:first-child { margin-top: 0; }
.doc-side { position: sticky; top: 20px; }
.msg-panel { padding: 20px 22px; border-top: 4px solid var(--gold); max-height: calc(100vh - 60px); overflow-y: auto; }
.msg-panel h2 { margin-top: 0; }
.msg { padding: 14px 0; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.msg-meta strong { color: var(--text); font-size: 15px; }
.msg-tag { background: #e7eaf1; color: #3c4560; border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 600; }
.msg-tag-new { background: var(--gold); color: #1b1300; }
.msg-text { font-size: 18px; line-height: 1.6; color: var(--text); font-weight: 500; word-break: break-word; }
.msg-latest .msg-text { font-size: 19px; }
.msg-returned .msg-text { color: #8a1c1c; }
@media (max-width: 1100px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-side { position: static; order: -1; }   /* จอแคบ: ข้อความขึ้นก่อน */
  .msg-panel { max-height: none; }
}
.filter-field input[type="text"] { min-height: 40px; padding: 0 10px; border: 1px solid var(--input-border); border-radius: 8px; font: inherit; color: var(--text); background: #fff; }
.pill { white-space: nowrap; }

/* ปุ่มลูกตาแสดง/ซ่อนรหัสผ่าน */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px !important; }
.pw-toggle { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; background: transparent; color: #4A5568; cursor: pointer; }
.pw-toggle:hover { background: #EEF1F7; color: #1F2D5C; }
.pw-toggle:focus-visible { outline: 2px solid #2C6EA3; outline-offset: 1px; }
