/* ==========================================================================
   SARA — Design system "หมึกตรายาง"
   น้ำเงินหมึกราชการบนกระดาษสว่าง · แดงชาดสำหรับด่วน/ลับ · เลขทะเบียนเป็นกรอบตรายาง
   ========================================================================== */

/* ---------- Fonts (self-hosted) ---------- */
@font-face { font-family: "Noto Sans Thai"; font-weight: 400; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-thai-400-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 400; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 500; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-thai-500-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 500; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 600; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 600; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 700; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Noto Sans Thai"; font-weight: 700; font-display: swap; src: url("../fonts/noto-sans-thai/noto-sans-thai-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-thai-500-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-thai-600-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-thai-700-normal.woff2") format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 700; font-display: swap; src: url("../fonts/ibm-plex-sans-thai/ibm-plex-sans-thai-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap; src: url("../fonts/pdf/Sarabun-Regular.ttf") format("truetype"); }
@font-face { font-family: "Sarabun"; font-weight: 700; font-display: swap; src: url("../fonts/pdf/Sarabun-Bold.ttf") format("truetype"); }

/* ---------- Tokens ---------- */
:root {
  --ink: #1F2A44;          /* ตัวหนังสือหัวเรื่อง */
  --ink-2: #2B3A5C;
  --stamp: #1D4ED8;        /* น้ำเงินหลัก */
  --stamp-600: #1E40AF;
  --stamp-soft: #EAF0FD;
  --row-hover: rgba(29, 78, 216, .08);
  --seal: #E5484D;         /* แดง — ด่วน/ลับ */
  --seal-soft: #FDECEC;
  --gold: #D97706;
  --ok: #12A150;
  --ok-soft: #E6F7EE;
  --warn: #D97706;
  --warn-soft: #FEF4E2;
  --paper: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --line: #E4E8EF;
  --text: #1F2937;
  --muted: #5F6B7A;
  --sb-bg: #0B2559;          /* เมนูข้าง: น้ำเงินเข้มทึบ */
  --sb-text: #DCE4F5;
  --sb-muted: #91A3C9;
  --sb-hover: rgba(255, 255, 255, .07);
  --sb-active-bg: rgba(255, 255, 255, .13);
  --sb-active-text: #FFFFFF;
  --sb-line: rgba(255, 255, 255, .08);
  --sb-accent: #F5B301;      /* แถบทอง เมนูที่เลือก */
  --tone-blue: #2563EB;
  --tone-green: #16A34A;
  --tone-orange: #EA8C00;
  --tone-red: #DC2626;
  --tone-purple: #7C3AED;
  --school: var(--stamp);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px -12px rgba(16, 24, 40, .18);
  --sidebar-w: 268px;
  --topbar-h: 68px;
  --font-body: "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  --font-head: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;

  --bs-body-font-family: var(--font-body);
  --bs-body-font-size: 1rem;
  --bs-body-line-height: 1.65;
  --bs-body-color: var(--text);
  --bs-body-bg: var(--paper);
  --bs-primary: var(--stamp);
  --bs-primary-rgb: 29, 78, 216;
  --bs-danger: var(--seal);
  --bs-danger-rgb: 229, 72, 77;
  --bs-success: var(--ok);
  --bs-success-rgb: 18, 161, 80;
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--muted);
  --bs-link-color: var(--stamp);
  --bs-link-color-rgb: 29, 78, 216;
  --bs-link-hover-color: var(--stamp-600);
  --bs-border-radius: var(--radius-sm);
  --bs-tertiary-bg: var(--surface-2);
}

[data-bs-theme="dark"] {
  --sb-bg: #0A1B3F;
  --sb-text: #D6DEEE;
  --sb-muted: #7D8AA6;
  --sb-hover: rgba(255,255,255,.06);
  --sb-active-bg: rgba(255,255,255,.12);
  --sb-active-text: #FFFFFF;
  --sb-line: rgba(255,255,255,.07);
  --ink: #0A1020;
  --ink-2: #121B31;
  --stamp: #6EA8FF;
  --stamp-600: #94BFFF;
  --stamp-soft: #1C2747;
  --row-hover: rgba(110, 168, 255, .14);
  --seal: #FF6B76;
  --seal-soft: #3A1C23;
  --gold: #E0B256;
  --ok: #4CC593;
  --ok-soft: #12322A;
  --warn: #F0A94B;
  --warn-soft: #382A14;
  --paper: #0D1322;
  --surface: #151D30;
  --surface-2: #1A2339;
  --line: #29344F;
  --text: #E7EBF4;
  --muted: #A2ADC4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -10px rgba(0, 0, 0, .5);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--paper);
  --bs-primary-rgb: 124, 149, 255;
  --bs-emphasis-color: #fff;
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-body); background: var(--paper); color: var(--text); font-size: 1rem; text-rendering: optimizeLegibility; }
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-family: var(--font-head); font-weight: 600; color: var(--text); line-height: 1.35; }
h1, .h1 { font-size: clamp(1.45rem, 1.2rem + 1vw, 1.85rem); }
.text-muted, .text-secondary { color: var(--muted) !important; }
.small, small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
a { text-underline-offset: 3px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--stamp) 55%, transparent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--stamp) 25%, transparent); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
  background: var(--sb-bg); color: var(--sb-text); display: flex; flex-direction: column; border-right: 1px solid var(--sb-line);
}
.sidebar .brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--sb-line); text-decoration: none; color: #fff; }
/* อักษรย่อใช้ Sarabun (มีหัว) อ่านง่ายกว่าตัวไม่มีหัวที่ขนาดเล็ก */
.brand-mark, .school-dot, .avatar { font-family: "Sarabun", var(--font-head) !important; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none;
  color: var(--stamp); font-family: var(--font-head); font-weight: 700; font-size: 1.2rem; background: #fff;
}
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 1.25rem; letter-spacing: .06em; line-height: 1; color: #fff; }
.brand-sub { font-size: .74rem; color: var(--sb-muted); line-height: 1.3; margin-top: .25rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .75rem 1.5rem; scrollbar-width: thin; }
.nav-section { font-size: .76rem; font-weight: 600; color: var(--sb-muted); padding: 1rem .8rem .35rem; }
.side-link {
  display: flex; align-items: center; gap: .8rem; padding: .6rem .8rem; margin: 2px 0; border-radius: 10px;
  color: var(--sb-text); text-decoration: none; font-weight: 500; font-size: .97rem; position: relative; transition: background .15s, color .15s;
}
.side-link i { font-size: 1.15rem; width: 1.3rem; text-align: center; color: var(--sb-muted); }
.side-link:hover { background: var(--sb-hover); color: #fff; }
.side-link.active { background: var(--sb-active-bg); color: var(--sb-active-text); font-weight: 600; }
.side-link.active::before { content: ""; position: absolute; left: -.75rem; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: var(--sb-accent); }
.side-link.active i { color: var(--sb-active-text); }
.side-link .count { margin-left: auto; background: var(--seal); color: #fff; font-size: .75rem; font-weight: 700; border-radius: 999px; padding: .05rem .5rem; min-width: 1.6rem; text-align: center; }
.sidebar-foot { padding: .9rem 1.25rem; border-top: 1px solid var(--sb-line); font-size: .78rem; color: var(--sb-muted); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1030; height: var(--topbar-h); display: flex; align-items: center; gap: .75rem;
  padding: 0 1.5rem; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.content { padding: 1.5rem; flex: 1; width: 100%; max-width: 2200px; margin-inline: auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .lead-sub { color: var(--muted); margin: .2rem 0 0; font-size: .95rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--stamp); }

/* School switcher */
.school-chip {
  display: flex; align-items: center; gap: .7rem; padding: .35rem .85rem .35rem .45rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-align: left; max-width: 420px; min-width: 0;
}
.school-chip:hover { border-color: color-mix(in srgb, var(--school) 45%, var(--line)); }
.school-dot { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-family: var(--font-head); background: var(--school); }
.school-chip .s-name { font-weight: 600; font-size: .95rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.school-chip .s-aff { font-size: .74rem; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.school-chip .bi-chevron-down { font-size: .8rem; color: var(--muted); }

.top-search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.top-search input { padding-left: 2.6rem; height: 44px; border-radius: 12px; background: var(--surface-2); border-color: var(--line); }
.top-search i { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-grid; place-items: center; position: relative; font-size: 1.2rem; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--stamp); }
.icon-btn .badge-dot {
  position: absolute; top: -5px; right: -5px; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 999px; background: var(--seal); color: #fff;
  font-size: .72rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface);
}
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; color: #fff; background: var(--stamp); flex: none; font-family: var(--font-head); }
.avatar-sm { width: 32px; height: 32px; font-size: .85rem; }
.user-btn { display: flex; align-items: center; gap: .6rem; background: none; border: 0; padding: .2rem; color: var(--text); text-align: left; }
.user-btn .u-name { font-weight: 600; font-size: .92rem; line-height: 1.2; }
.user-btn .u-role { font-size: .75rem; color: var(--muted); line-height: 1.2; }

/* Notification dropdown */
.notif-menu { width: min(400px, 94vw); padding: 0; border-radius: var(--radius); overflow: hidden; }
.notif-menu .n-head { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.notif-list { max-height: 420px; overflow-y: auto; }
.notif-item { display: flex; gap: .75rem; padding: .8rem 1rem; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line); }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: color-mix(in srgb, var(--stamp-soft) 60%, var(--surface)); }
.notif-item .n-ico { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--stamp-soft); color: var(--stamp); }
.notif-item .n-title { font-weight: 600; font-size: .92rem; }
.notif-item .n-body { font-size: .85rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-item .n-time { font-size: .75rem; color: var(--muted); }

/* ---------- Cards & surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); --bs-card-bg: var(--surface); --bs-card-border-color: var(--line); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.card-header h2, .card-header h3, .card-title { font-size: 1.07rem; margin: 0; display: flex; align-items: center; gap: .5rem; }
.card-header h2 i, .card-header h3 i { color: var(--stamp); }
.card-body { padding: 1.25rem; }
.dropdown-menu { --bs-dropdown-bg: var(--surface); --bs-dropdown-border-color: var(--line); --bs-dropdown-link-hover-bg: var(--surface-2); --bs-dropdown-link-active-bg: var(--stamp); box-shadow: var(--shadow-lg); border-radius: 12px; }
.dropdown-item { padding: .55rem 1rem; }
.modal-content { background: var(--surface); border-radius: 18px; border: 1px solid var(--line); }
.offcanvas { background: var(--surface); }

/* Stat tiles */
.stat {
  display: flex; align-items: center; gap: 1rem; padding: 1.1rem 1.2rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; color: var(--text); height: 100%; transition: transform .15s, border-color .15s;
}
a.stat:hover { transform: none; border-color: color-mix(in srgb, var(--stamp) 40%, var(--line)); color: var(--text); }
.stat .s-ico { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-size: 1.35rem; flex: none; background: var(--tone-blue); color: #fff; }
.stat .s-val { font-family: var(--font-head); font-size: 1.9rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .s-lbl { color: var(--muted); font-size: .9rem; font-weight: 500; }
.stat.tone-seal .s-ico { background: var(--tone-red); color: #fff; }
.stat.tone-ok .s-ico { background: var(--tone-green); color: #fff; }
.stat.tone-warn .s-ico { background: var(--tone-orange); color: #fff; }
.stat.tone-ink .s-ico { background: var(--tone-purple); color: #fff; }
.stat.is-alert { border-color: color-mix(in srgb, var(--seal) 45%, var(--line)); }

/* Welcome banner */
.hello {
  position: relative; border-radius: var(--radius); padding: 1.35rem 1.5rem; margin-bottom: 1.25rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.hello h1 { color: var(--text); margin: 0 0 .25rem; font-size: clamp(1.3rem, 1.1rem + .9vw, 1.65rem); }
.hello p { margin: 0; color: var(--muted); }
.hello .quick { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; position: relative; z-index: 1; }
.hello .btn-light { font-weight: 600; background: var(--stamp); border-color: var(--stamp); color: #fff; }
.hello .btn-light:hover { background: var(--stamp-600); border-color: var(--stamp-600); color: #fff; }
.hello .btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.hello .btn-ghost:hover { background: var(--surface); color: var(--stamp); border-color: color-mix(in srgb, var(--stamp) 40%, var(--line)); }

/* ---------- Signature: ตรายาง ---------- */
.reg-stamp {
  display: inline-flex; align-items: baseline; gap: .35rem; padding: .12rem .55rem; border: 2px solid var(--stamp); border-radius: 6px;
  color: var(--stamp); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.35; font-size: .95rem;
  background: color-mix(in srgb, var(--stamp-soft) 55%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--stamp) 20%, transparent);
}
.reg-stamp .reg-label { font-size: .72rem; font-weight: 600; opacity: .85; }
.reg-stamp-sm { font-size: .82rem; padding: .02rem .45rem; border-width: 1.5px; }
.reg-stamp-lg { font-size: 1.25rem; padding: .25rem .8rem; border-width: 2.5px; transform: rotate(-1.2deg); }
.seal {
  display: inline-flex; align-items: center; gap: .25rem; padding: .05rem .5rem; border: 2px solid var(--seal); color: var(--seal);
  border-radius: 5px; font-weight: 700; font-size: .78rem; letter-spacing: .02em; white-space: nowrap; line-height: 1.5; background: var(--seal-soft);
}
.seal-urgent.seal-l2 { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.seal-urgent.seal-l4 { outline: 1.5px solid var(--seal); outline-offset: 1.5px; }
.seal-secret { border-style: double; border-width: 3px; }

.status-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-registered .dot { background: #8A94A8; }
.status-in_progress { color: var(--stamp); border-color: color-mix(in srgb, var(--stamp) 30%, var(--line)); }
.status-in_progress .dot { background: var(--stamp); }
.status-returned { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.status-returned .dot { background: var(--warn); }
.status-completed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.status-completed .dot { background: var(--ok); }
.status-cancelled { color: var(--seal); }
.status-cancelled .dot { background: var(--seal); }
.status-archived .dot { background: var(--text); }

.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; padding: .1rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-weight: 500; white-space: nowrap; }
.chip-primary { background: var(--stamp-soft); color: var(--stamp); border-color: transparent; }
.due-over { color: var(--seal); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }

/* ---------- Document list ---------- */
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-row { display: grid; grid-template-columns: auto 1fr auto; gap: .35rem 1rem; align-items: start; padding: .95rem 1.25rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; position: relative; }
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--surface-2); color: var(--text); }
.doc-row.is-urgent::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--seal); }
.doc-row .d-subject { font-weight: 600; font-size: 1rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-row .d-meta { font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .15rem; }
.doc-row .d-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }
.doc-row .d-flags { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .35rem; }

/* Tables */
.table { --bs-table-bg: transparent; --bs-table-color: var(--text); --bs-table-border-color: var(--line); --bs-table-hover-bg: var(--row-hover); margin: 0; }
.table > thead th { font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: none; background: var(--surface-2); border-bottom-width: 1px; white-space: nowrap; padding: .7rem .9rem; }
.table > tbody td { padding: .8rem .9rem; vertical-align: middle; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Forms */
.form-label { font-weight: 600; font-size: .92rem; margin-bottom: .35rem; }
.form-control, .form-select { border-radius: 10px; border-color: var(--line); padding: .6rem .85rem; font-size: 1rem; background-color: var(--surface); color: var(--text); min-height: 46px; }
.form-select { padding-right: 2.4rem; } /* เว้นที่ให้ลูกศร — ข้อความยาวไม่ทับลูกศร (padding ด้านบนทับค่าของ Bootstrap) */
.form-control:focus, .form-select:focus { border-color: var(--stamp); box-shadow: 0 0 0 .22rem color-mix(in srgb, var(--stamp) 20%, transparent); background-color: var(--surface); color: var(--text); }
.form-text { color: var(--muted); }
.req::after { content: " *"; color: var(--seal); }
.form-section { font-family: var(--font-head); font-weight: 600; font-size: 1rem; color: var(--stamp); display: flex; align-items: center; gap: .5rem; margin: .25rem 0 1rem; }
.form-section::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.form-check-input { width: 1.2em; height: 1.2em; }
.form-check-input:checked { background-color: var(--stamp); border-color: var(--stamp); }

/* Buttons */
.btn { border-radius: 10px; font-weight: 600; padding: .55rem 1.05rem; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; }
.btn-sm { min-height: 36px; padding: .3rem .75rem; font-size: .88rem; }
.btn-lg { min-height: 52px; padding: .7rem 1.4rem; }
.btn-primary { --bs-btn-bg: var(--stamp); --bs-btn-border-color: var(--stamp); --bs-btn-hover-bg: var(--stamp-600); --bs-btn-hover-border-color: var(--stamp-600); --bs-btn-active-bg: var(--stamp-600); --bs-btn-disabled-bg: var(--stamp); --bs-btn-disabled-border-color: var(--stamp); }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0B1220; --bs-btn-hover-color: #0B1220; --bs-btn-active-color: #0B1220; }
.btn-outline-primary { --bs-btn-color: var(--stamp); --bs-btn-border-color: color-mix(in srgb, var(--stamp) 45%, var(--line)); --bs-btn-hover-bg: var(--stamp); --bs-btn-hover-border-color: var(--stamp); --bs-btn-active-bg: var(--stamp); }
.btn-soft { background: var(--stamp-soft); color: var(--stamp); border: 1px solid transparent; }
.btn-soft:hover { background: color-mix(in srgb, var(--stamp-soft) 70%, var(--stamp) 12%); color: var(--stamp); }
/* ปุ่มเลื่อนไปช่องเกษียณ (แถบล่างมือถือ) — สีส้ม ไม่ให้สับสนกับปุ่มเกษียณจริงสีน้ำเงิน */
.btn-go { --bs-btn-color: #C2410C; --bs-btn-bg: #FFEDD5; --bs-btn-border-color: #FED7AA; --bs-btn-hover-color: #9A3412; --bs-btn-hover-bg: #FED7AA; --bs-btn-hover-border-color: #FDBA74; --bs-btn-active-color: #9A3412; --bs-btn-active-bg: #FDBA74; --bs-btn-active-border-color: #FDBA74; }
[data-bs-theme="dark"] .btn-go { --bs-btn-color: #FDBA74; --bs-btn-bg: #3B2416; --bs-btn-border-color: #5C3519; --bs-btn-hover-color: #FED7AA; --bs-btn-hover-bg: #4A2C18; --bs-btn-hover-border-color: #7C4A1E; --bs-btn-active-color: #FED7AA; --bs-btn-active-bg: #5C3519; --bs-btn-active-border-color: #7C4A1E; }
.btn-light-line { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.btn-light-line:hover { background: var(--surface-2); color: var(--stamp); }
.btn-success { --bs-btn-bg: var(--ok); --bs-btn-border-color: var(--ok); }
.btn-danger { --bs-btn-bg: var(--seal); --bs-btn-border-color: var(--seal); }

/* Alerts & toast */
.alert { border-radius: 12px; border-width: 1px; display: flex; gap: .65rem; align-items: flex-start; }
.alert > i { font-size: 1.2rem; line-height: 1.3; }
.toast-zone { position: fixed; right: 1rem; bottom: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast-x { display: flex; gap: .7rem; align-items: flex-start; padding: .85rem 1rem; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow-lg); animation: toastIn .25s ease-out; }
.toast-x.t-success i { color: #6EE0A8; }
.toast-x.t-danger i { color: #FF8C95; }
.toast-x.t-warning i { color: #FFC56E; }
.toast-x i { font-size: 1.2rem; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Empty state */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .e-ico { width: 72px; height: 72px; margin: 0 auto .8rem; border-radius: 20px; display: grid; place-items: center; font-size: 2rem; background: var(--stamp-soft); color: var(--stamp); }
.empty h3 { font-size: 1.05rem; color: var(--text); margin-bottom: .25rem; }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--line) 70%, var(--surface)) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 8px; min-height: 1rem; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 17px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 1.1rem 3rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-ico { position: absolute; left: 0; top: 0; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line); color: var(--muted); font-size: .95rem; }
.tl-item.c-primary .tl-ico { border-color: var(--stamp); color: var(--stamp); background: var(--stamp-soft); }
.tl-item.c-success .tl-ico { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.tl-item.c-warning .tl-ico { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.tl-item.c-danger .tl-ico { border-color: var(--seal); color: var(--seal); background: var(--seal-soft); }
.tl-item.c-info .tl-ico { border-color: #2C8CB8; color: #2C8CB8; background: color-mix(in srgb, #2C8CB8 12%, var(--surface)); }
.tl-item.c-dark .tl-ico { border-color: var(--text); color: var(--text); }
.tl-time { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; font-size: .95rem; }
.tl-msg { font-size: .9rem; white-space: pre-line; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .75rem; margin-top: .35rem; }
.tl-who { font-size: .85rem; color: var(--muted); }

/* Workflow steps (builder + progress) */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.flow-step { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .7rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .85rem; font-weight: 500; }
.flow-step.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.flow-step.current { background: var(--stamp); color: #fff; border-color: transparent; box-shadow: 0 0 0 4px var(--stamp-soft); }
[data-bs-theme="dark"] .flow-step.current { color: #0D1322; }
.flow-step.skipped { text-decoration: line-through; opacity: .6; }
/* เส้นทาง Workflow แบบบรรทัดเดียว (หน้าแก้ไข Workflow) — เลื่อนแนวนอนได้ถ้าไม่พอดีจอ */
/* workflow.js ย่อทั้งแถบด้วย transform: scale() ให้พอดีความกว้าง (ย่อ font-size ไม่ได้ เพราะ Firefox มีขนาดอักษรไทยขั้นต่ำ) */
.wf-line { display: flex; align-items: flex-start; overflow: hidden; margin: .2rem 0 .3rem; padding: 3px 0; } /* flex-start: ไม่ยืดแถวในตามความสูงที่ตั้งหลังย่อ */
.wf-line-in { display: flex; align-items: center; flex-wrap: nowrap; flex: none; gap: .35rem; transform-origin: left top; }
.wf-line .flow-step { white-space: nowrap; flex: none; }
.wf-line .flow-step small { opacity: .75; font-weight: 400; }
.wf-line .wf-arrow { flex: none; color: var(--stamp); font-weight: 700; }
/* แถบคำอธิบายหน้าแก้ไข Workflow: ผังลำดับการเดินเรื่อง จุดมีเลข + เส้นเชื่อม (แนวนอน · .is-v = แนวตั้งเมื่อช่องแคบ) */
.wf-flow { --dot: 30px; margin: .35rem 0 .55rem; }
.wf-flow-list { display: flex; list-style: none; margin: 0; padding: 0; }
.wf-st { --c: var(--stamp); --soft: var(--stamp-soft); position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .4rem; padding: 0 .3rem; }
.wf-st.is-start, .wf-st.is-end { --c: var(--ok); --soft: var(--ok-soft); }
.wf-st + .wf-st::before { content: ''; position: absolute; top: calc(var(--dot) / 2 - 1px); right: calc(50% + var(--dot) / 2 + 4px); left: calc(-50% + var(--dot) / 2 + 4px); height: 2px; border-radius: 2px; background: color-mix(in srgb, var(--stamp) 40%, var(--line)); }
.wf-st + .wf-st::after { content: ''; position: absolute; top: calc(var(--dot) / 2 - 4px); right: calc(50% + var(--dot) / 2 + 3px); border: 4px solid transparent; border-left: 6px solid color-mix(in srgb, var(--stamp) 55%, var(--line)); border-right: 0; } /* หัวลูกศรปลายเส้น */
.wf-st-dot { position: relative; z-index: 1; flex: none; width: var(--dot); height: var(--dot); border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; font-size: .8rem; font-weight: 700; box-shadow: 0 0 0 4px var(--soft); }
[data-bs-theme="dark"] .wf-st-dot { color: #0D1322; }
.wf-st-body { display: flex; flex-direction: column; align-items: center; gap: .1rem; min-width: 0; }
.wf-st-name { font-size: .84rem; font-weight: 600; line-height: 1.35; color: var(--text); }
.wf-st.is-start .wf-st-name, .wf-st.is-end .wf-st-name { color: var(--ok); }
.wf-st-marks { display: inline-flex; gap: .3rem; font-size: .78rem; color: var(--stamp); opacity: .75; }
/* แนวตั้ง: จุดซ้าย ชื่อขวา เส้นเชื่อมลงล่าง */
.wf-flow.is-v .wf-flow-list { flex-direction: column; }
.wf-flow.is-v .wf-st { flex-direction: row; align-items: flex-start; text-align: left; gap: .65rem; padding: 0 0 1.1rem; }
.wf-flow.is-v .wf-st:last-child { padding-bottom: 0; }
.wf-flow.is-v .wf-st-body { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .1rem .5rem; min-height: var(--dot); }
.wf-flow.is-v .wf-st + .wf-st::before { display: none; }
.wf-flow.is-v .wf-st::after { display: none; }
.wf-flow.is-v .wf-st:not(:last-child)::after { display: block; content: ''; position: absolute; left: calc(var(--dot) / 2 - 1px); top: calc(var(--dot) + 6px); bottom: 2px; right: auto; width: 2px; border: 0; border-radius: 2px; background: color-mix(in srgb, var(--stamp) 40%, var(--line)); }
.wf-key-row { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; margin-top: -.1rem; } /* คำอธิบายสัญลักษณ์ + ข้อความ "สร้างอัตโนมัติ…" บรรทัดเดียวกัน */
.wf-key { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .8rem; color: var(--muted); }
.wf-key-row .form-text { font-size: .8rem; }
.wf-key .bi { color: var(--stamp); }
/* การ์ดขั้นตอนในรายการ Workflow: เลขขั้นวงกลม + ชื่อขั้น + ผู้รับ · สีวนตามลำดับขั้น */
.wf-card { --wf-tone: var(--tone-blue); display: inline-flex; align-items: center; gap: .5rem; flex: none; white-space: nowrap; padding: .35rem .85rem .35rem .4rem; border-radius: 12px; background: color-mix(in srgb, var(--wf-tone) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--wf-tone) 28%, transparent); }
.wf-card .wf-no { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--wf-tone); color: #fff; font-size: .78rem; font-weight: 700; }
.wf-card .wf-txt { display: flex; flex-direction: column; line-height: 1.3; }
.wf-card .wf-txt strong { color: var(--wf-tone); font-size: .86rem; }
.wf-card .wf-txt small { color: var(--muted); font-size: .74rem; }
.wf-t1 { --wf-tone: var(--tone-purple); } .wf-t2 { --wf-tone: var(--tone-orange); } .wf-t3 { --wf-tone: var(--tone-red); }
/* คำอธิบายใต้ช่องในการ์ดขั้นตอน: ซ่อนไว้ แสดงเป็นกล่องลอยเมื่อเอาเมาส์วาง หรือกดเข้าช่อง (มือถือ/คีย์บอร์ด) */
.wf-hint-host { position: relative; }
.wf-hint { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin-top: .25rem; padding: .45rem .65rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0, 0, 0, .12); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .4s, visibility .4s; }
.wf-hint-host:hover .wf-hint, .wf-hint-host:focus-within .wf-hint { opacity: 1; visibility: visible; }
/* ข้อความสำเร็จรูปส่วนตัว: ปุ่ม "เก็บข้อความนี้/จัดการข้อความ" ขอบประ แยกจากปุ่มข้อความ · แถวในหน้าต่างจัดการ */
.ph-box .ph-act { border-style: dashed; }
.ap-phrases .ph-act { color: var(--stamp); }
.ph-row { display: flex; align-items: center; gap: .3rem; margin-bottom: .4rem; }
.ph-row .form-control { flex: 1 1 auto; min-width: 0; }
.ph-row .btn { flex: none; padding: .2rem .5rem; }
.flow-step.wf-mid { background: var(--stamp-soft); color: var(--stamp); border-color: transparent; }
.flow-arrow { color: var(--muted); font-size: .8rem; }
/* ความคืบหน้า Workflow ในหน้าหนังสือ: ทุกขั้นอยู่บรรทัดเดียวเสมอ (ไม่ตกบรรทัด) ขนาดชิปเดิม — ถ้าไม่พอดีความกว้าง document.js ย่อทั้งแถบด้วย transform: scale()
   (Firefox ย่อ font-size อักษรไทยไม่ได้) และถ้าต้องย่อเกินไป (< 0.62) จะเลื่อนแนวนอนแทนเพื่อให้อ่านออก — ถอนกลับ: ลบบล็อกนี้ + ฟังก์ชัน fitFlow ใน document.js */
.flow-seg { display: inline-flex; align-items: center; gap: .4rem; flex: none; }
.flow-prog .flow { flex: 1 1 100%; display: block; overflow-x: hidden; overflow-y: hidden; padding: 3px 0; }
.flow-prog .flow.is-scroll { overflow-x: auto; }
.flow-prog .flow-in { display: flex; align-items: center; flex-wrap: nowrap; gap: .4rem; width: max-content; transform-origin: left top; }
.flow-prog .flow-step { white-space: nowrap; flex: none; }
.wf-step-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 1rem; position: relative; }
.wf-step-card .handle { cursor: grab; color: var(--muted); }
.wf-step-card .step-no { width: 32px; height: 32px; border-radius: 50%; background: var(--stamp); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.wf-sum { margin: -.45rem 0 .85rem calc(32px + .5rem + 1.25rem + .5rem); padding: .45rem .7rem; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: .84rem; line-height: 1.6; } /* ประโยคสรุปของขั้น (เยื้องตรงกับช่องชื่อขั้น) */
.wf-sum b { color: var(--text); font-weight: 600; }
.wf-sum b.is-next { color: var(--stamp); }
.wf-sum b.is-missing { color: var(--warn); }
@media (max-width: 575.98px) { .wf-sum { margin-left: 0; } }
.wf-connector { height: 22px; width: 2px; background: var(--line); margin: 0 auto; }

/* ---------- Document view ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 1.25rem; align-items: start; }
.doc-side { position: sticky; top: calc(var(--topbar-h) + 1rem); display: flex; flex-direction: column; gap: 1rem; }
.meta-grid { display: grid; grid-template-columns: 8.5rem 1fr; gap: .45rem .9rem; font-size: .93rem; margin: 0; }
.meta-grid dt { color: var(--muted); font-weight: 500; }
.meta-grid dd { margin: 0; font-weight: 500; word-break: break-word; }
.action-panel { border: 2px solid var(--stamp); }
.action-panel .card-header { background: var(--stamp-soft); }

/* PDF viewer */
.pdfv { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.pdfv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; padding: .55rem .75rem; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.pdfv-bar .btn { min-height: 38px; padding: .3rem .65rem; }
.pdfv-bar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 .2rem; }
.pdfv-bar .page-ind { font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pdfv-bar input.pg { width: 3.6rem; min-height: 38px; text-align: center; padding: .2rem; }
.pdfv-bar .find { width: 11rem; min-height: 38px; }
/* แถบเครื่องมือตัวดู PDF: จัดเป็นกลุ่ม (เวอร์ชัน · ซูม · เลขหน้า · ค้นหา · เครื่องมือ) ห่อบรรทัดเป็นกลุ่มไม่ฉีกกลางกลุ่ม ช่องค้นหายืดเต็มที่ว่าง เครื่องมือชิดขวา */
.pdfv-grp { display: flex; align-items: center; gap: .4rem; flex: none; min-width: 0; }
.pdfv-bar .pdfv-ver { flex: 0 1 auto; }
.pdfv-bar .pdfv-ver select { max-width: 100%; }
.pdfv-bar .pdfv-find { flex: 1 1 10rem; min-width: 9rem; }
.pdfv-bar .pdfv-find .find { width: auto; flex: 1 1 auto; min-width: 0; }
.pdfv-bar .pdfv-tools { margin-left: auto; }
/* พื้นที่แคบ (ตัวดูกว้าง ≤ 720px: มือถือ จอเล็ก หน้าต่างย่อ) — เหลือ 2 แถว จัดเป็นตาราง ขอบตรงกัน:
   แถว 1 ซูม + ค้นหา (ยืด) + เลขหน้า · แถว 2 เวอร์ชัน (ยืด) + เครื่องมือ — ถอนกลับ: ลบบล็อกนี้ */
.pdfv { container-type: inline-size; }
@container (max-width: 720px) {
  /* แถว 1: ซูม | ค้นหา (ยืดเต็มช่องกลาง ไม่มีที่ว่าง) | เลขหน้า · แถว 2: เวอร์ชัน (ยืดถึงปุ่ม) | เครื่องมือ (ขอบขวาตรงกับเลขหน้า) */
  .pdfv-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: .55rem .5rem; padding: .6rem .75rem; }
  .pdfv-bar .pdfv-zoom { grid-column: 1; grid-row: 1; }
  .pdfv-bar .pdfv-find { grid-column: 2; grid-row: 1; min-width: 0; }
  .pdfv-bar .pdfv-pg { grid-column: 3 / 5; grid-row: 1; justify-self: end; }
  .pdfv-bar .pdfv-ver { grid-column: 1 / 4; grid-row: 2; width: auto; contain: inline-size; }
  .pdfv-bar .pdfv-ver select { width: 100% !important; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } /* ทับ .w-auto ของ Bootstrap */
  .pdfv-bar .pdfv-tools { grid-column: 4; grid-row: 2; margin-left: 0; } /* ปุ่มชิดกันตามปกติ เวอร์ชันยืดมาถึงปุ่ม ขอบขวาตรงกับเลขหน้า */
  /* ไม่มีเวอร์ชันให้เลือก: แถว 2 เป็นปุ่มเครื่องมือ 3 ปุ่มกว้างเท่ากันเต็มแถว (ไม่เหลือที่ว่าง) */
  .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-tools { grid-column: 1 / -1; grid-row: 2; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
  .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-tools .btn { width: 100%; }
  .pdfv-bar #findInd:empty { display: none; } /* ช่องผลค้นหาว่าง ไม่กินช่องไฟ */
}
/* จอแคบมาก (≤ 420px): แถว 1 เวอร์ชัน (ถ้ามี) · แถว 2 ซูม | เลขหน้า · แถว 3 ค้นหา (ยืด) | เครื่องมือ */
@container (max-width: 420px) {
  .pdfv-bar { padding: .5rem .55rem; }
  .pdfv-bar .pdfv-grp { gap: .25rem; }
  .pdfv-bar .btn { padding: .3rem .5rem; }
  .pdfv-bar input.pg { width: 2.8rem; }
  .pdfv-bar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .pdfv-bar .pdfv-ver { grid-column: 1 / -1; grid-row: 1; }
  .pdfv-bar .pdfv-zoom { grid-column: 1; grid-row: 2; }
  .pdfv-bar .pdfv-pg { grid-column: 2 / 4; grid-row: 2; justify-self: end; }
  .pdfv-bar .pdfv-find { grid-column: 1 / 3; grid-row: 3; }
  .pdfv-bar .pdfv-tools, .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-tools { grid-column: 3; grid-row: 3; display: flex; }
  .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-tools .btn { width: auto; }
  .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-zoom, .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-pg { grid-row: 1; }
  .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-find, .pdfv-bar:not(:has(.pdfv-ver)) .pdfv-tools { grid-row: 2; }
}
.pdfv-stage { position: relative; overflow: auto; height: calc(100vh - var(--topbar-h) - 9rem); min-height: 480px; background: #E7EBF2; padding: 1rem; -webkit-overflow-scrolling: touch; }
[data-bs-theme="dark"] .pdfv-stage { background: #0A0F1C; }
.pdfv-page { position: relative; margin: 0 auto 1rem; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.pdfv-page canvas { display: block; width: 100%; height: 100%; }
.pdfv-page .textLayer { position: absolute; inset: 0; overflow: hidden; opacity: .25; line-height: 1; }
.pdfv-page .textLayer span { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; cursor: text; }
.pdfv-page .textLayer .hl { background: #FFC400; border-radius: 2px; }
.pdfv:fullscreen { border-radius: 0; }
.pdfv:fullscreen .pdfv-stage { height: calc(100vh - 56px); }
.pdfv-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.place-box { position: absolute; border: 2px dashed var(--stamp); background: color-mix(in srgb, var(--stamp) 10%, transparent); border-radius: 4px; cursor: move; touch-action: none; z-index: 5; }
.place-box .lbl { position: absolute; top: -1.6rem; left: -2px; background: var(--stamp); color: #fff; font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; white-space: nowrap; }
.place-box .rs { position: absolute; right: -8px; bottom: -8px; width: 18px; height: 18px; background: var(--stamp); border-radius: 4px; cursor: nwse-resize; }

/* Stamp designer */
.designer-page { position: relative; width: 100%; max-width: 520px; aspect-ratio: 210 / 297; margin: 0 auto; background: #fff; box-shadow: var(--shadow-lg); border-radius: 4px; overflow: hidden; touch-action: none; }
.designer-page .fake-lines { position: absolute; inset: 22% 10% 10% 10%; background: repeating-linear-gradient(180deg, #E9EDF3 0 6px, transparent 6px 18px); opacity: .9; }
.designer-stamp { position: absolute; cursor: move; text-align: left; line-height: 1.2; font-family: "Sarabun", var(--font-body); overflow: visible; user-select: none; }
.designer-stamp #stampText { height: 100%; overflow: hidden; }
.designer-stamp .rs { position: absolute; right: -8px; bottom: -8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; background: var(--stamp); cursor: nwse-resize; box-shadow: 0 1px 3px rgba(0,0,0,.3); }

/* Filters bar */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }

/* Permission matrix */
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }

.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.1rem; z-index: 2; pointer-events: none; }
.input-icon > .form-control { padding-left: 2.8rem; }

.test-banner { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); font-size: .85rem; padding: .4rem 1.5rem; display: flex; gap: .5rem; align-items: center; }

/* ---------- Mobile ---------- */
.bottom-nav { display: none; }
.mobile-actions { display: none; }

@media (max-width: 1199.98px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr) 370px; }
}
@media (max-width: 991.98px) {
  :root { --topbar-h: 60px; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; width: min(86vw, 300px); }
  .sidebar.show { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 32, .5); z-index: 1035; display: none; }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 .75rem; gap: .5rem; }
  .top-search { display: none; }
  .school-chip { max-width: none; flex: 1; border: 0; padding-left: .2rem; background: transparent; }
  .school-chip .school-dot { width: 30px; height: 30px; }
  .user-btn .u-meta { display: none; }
  .content { padding: 1rem .85rem; }
  .doc-layout { grid-template-columns: 1fr; }
  .doc-side { position: static; }
  .pdfv-stage { height: 72vh; min-height: 360px; padding: .5rem; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    background: var(--surface); border-top: 1px solid var(--line); padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 20px -12px rgba(20, 33, 61, .25);
  }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .35rem 0; font-size: .72rem; font-weight: 500; color: var(--muted); text-decoration: none; background: none; border: 0; position: relative; }
  .bottom-nav i { font-size: 1.35rem; }
  .bottom-nav .active { color: var(--stamp); }
  .bottom-nav .fab i { width: 50px; height: 50px; margin-top: -22px; border-radius: 16px; display: grid; place-items: center; background: var(--stamp); color: #fff; box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--stamp) 70%, transparent); font-size: 1.5rem; }
  .bottom-nav .bn-count { position: absolute; top: 0; left: 55%; background: var(--seal); color: #fff; border-radius: 999px; font-size: .66rem; padding: 0 .35rem; font-weight: 700; }
  .mobile-actions { display: flex; gap: .5rem; position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 1029; padding: .6rem .85rem; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
  .mobile-actions .btn { flex: 1; }
  .has-mobile-actions .main { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }
  .toast-zone { bottom: calc(80px + env(safe-area-inset-bottom)); left: .75rem; right: .75rem; max-width: none; }
}
@media (max-width: 575.98px) {
  .doc-row { grid-template-columns: 1fr; padding: .9rem 1rem; }
  .doc-row .d-side { flex-direction: row; align-items: center; justify-content: flex-start; text-align: left; }
  .doc-row .d-num { order: -1; }
  .stat { padding: .85rem .9rem; gap: .75rem; }
  .stat .s-ico { width: 42px; height: 42px; font-size: 1.2rem; border-radius: 12px; }
  .stat .s-val { font-size: 1.5rem; }
  .stat .s-lbl { font-size: .82rem; }
  .card-header, .card-body { padding: 1rem; }
  .meta-grid { grid-template-columns: 1fr; gap: .1rem; }
  .meta-grid dd { margin-bottom: .55rem; }
  .page-head .btn { flex: 1; }
  .hello { padding: 1.2rem; }
  .table-stack thead { display: none; }
  .table-stack tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .table-stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0 !important; padding: .25rem 1rem !important; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; font-weight: 500; }
}

/* Print */
@media print {
  .sidebar, .topbar, .bottom-nav, .mobile-actions, .no-print, .toast-zone, .test-banner { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .card { box-shadow: none; border: 0; }
  .content { padding: 0; max-width: none; }
}

/* ---------- Segmented choice (ชั้นความเร็ว/ลับ) ---------- */
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg-btn { display: inline-flex; align-items: center; gap: .35rem; min-height: 42px; padding: .4rem .9rem; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--text); user-select: none; transition: all .12s; }
.seg-btn:hover { border-color: color-mix(in srgb, var(--stamp) 45%, var(--line)); }
.btn-check:checked + .seg-btn { border-color: var(--stamp); background: var(--stamp-soft); color: var(--stamp); box-shadow: inset 0 0 0 1px var(--stamp); }
.btn-check:focus-visible + .seg-btn { outline: 3px solid color-mix(in srgb, var(--stamp) 50%, transparent); outline-offset: 2px; }
.btn-check:checked + .seg-p2 { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.btn-check:checked + .seg-p3, .btn-check:checked + .seg-p4,
.btn-check:checked + .seg-s2, .btn-check:checked + .seg-s3, .btn-check:checked + .seg-s4 { border-color: var(--seal); background: var(--seal-soft); color: var(--seal); box-shadow: inset 0 0 0 1px var(--seal); }

/* ---------- Dropzone ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: .25rem; padding: 1.6rem 1rem; border: 2px dashed color-mix(in srgb, var(--stamp) 35%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--stamp-soft) 45%, var(--surface)); cursor: pointer; transition: all .15s; width: 100%; }
.dropzone:hover, .dropzone.drag { border-color: var(--stamp); background: var(--stamp-soft); }
.dropzone.is-invalid { border-color: var(--seal); }
.dz-ico { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); color: var(--stamp); font-size: 1.6rem; box-shadow: var(--shadow); margin-bottom: .35rem; }
.dz-title { font-weight: 600; }
.dz-sub { font-size: .82rem; color: var(--muted); }
.dz-file { display: flex; align-items: center; gap: .75rem; padding: .75rem .9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.dz-file > i { font-size: 2rem; color: var(--seal); }
.sticky-submit { position: sticky; bottom: 1rem; }
@media (max-width: 991.98px) { .sticky-submit { position: static; } }

/* ---------- Mobile refinements ---------- */
@media (max-width: 991.98px) {
  .flow { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .35rem; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  .flow-step { white-space: nowrap; flex: none; }
  .mobile-actions { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .mobile-actions .btn-light-line { flex: 0 0 56px; }
  .has-mobile-actions .main { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .test-banner { padding: .35rem .85rem; font-size: .78rem; }
  .test-banner .tb-long { display: none; }
}

/* ---------- โลโก้ระบบ ---------- */
.brand-mark { overflow: hidden; padding: 3px; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-sub { font-size: .7rem; color: #C9D5EE; line-height: 1.35; margin-top: .3rem; }
.brand-en { font-size: .64rem; color: var(--sb-muted); line-height: 1.3; margin-top: .1rem; letter-spacing: .01em; }
.sidebar .brand { align-items: flex-start; }
.sidebar .brand .brand-mark { margin-top: 2px; }
.stamp-line { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; margin-bottom: .5rem; background: var(--surface); }
.stamp-line .handle { cursor: grab; }
/* การ์ดสำรองข้อมูล */
.bk-head { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.bk-ico { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 1.3rem; background: var(--tone-blue); color: #fff; }
/* เปิดจาก Telegram: ใช้งานได้เฉพาะหนังสือเรื่องเดียว */
.quick-banner { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .55rem 1.5rem; background: #E7F3FE; color: #0B4F8A; border-bottom: 1px solid #BFDDF8; font-size: .9rem; }
.quick-banner .bi-telegram { color: #229ED9; font-size: 1.1rem; }
.quick-banner .btn { margin-left: auto; }
.is-quick .sidebar-nav, .is-quick .bottom-nav, .is-quick .top-search, .is-quick #sidebarToggle { display: none !important; }
.is-quick .main { padding-bottom: 0; }
@media (max-width: 991.98px) { .is-quick.has-mobile-actions .mobile-actions { bottom: 0; } .is-quick.has-mobile-actions .main { padding-bottom: 80px; } }

/* ---------- หนังสือที่รอคุณ (หน้าหลัก) ---------- */
.my-queue { background: var(--surface); border: 2px solid color-mix(in srgb, var(--stamp) 35%, var(--line)); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.mq-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: 1.1rem 1.35rem; background: var(--stamp-soft); border-bottom: 1px solid var(--line); }
.mq-head h2 { font-size: 1.3rem; margin: 0; display: flex; align-items: center; gap: .55rem; }
.mq-head h2 > i { color: var(--stamp); }
.mq-head p { margin: .15rem 0 0; color: var(--muted); font-size: .95rem; }
.mq-count { display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; padding: 0 .55rem; border-radius: 999px; background: var(--seal); color: #fff; font-size: 1rem; font-weight: 700; }
.mq-list { display: flex; flex-direction: column; }
.mq-item { position: relative; display: flex; align-items: center; gap: 1rem; padding: 1rem 1.35rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; transition: background .12s; }
.mq-item:last-child { border-bottom: 0; }
.mq-item:hover { background: var(--surface-2); color: var(--text); }
.mq-item.is-new { background: color-mix(in srgb, var(--stamp-soft) 55%, var(--surface)); }
.mq-item.is-new::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--stamp); }
.mq-item.is-urgent::before { background: var(--seal); }
.mq-ico { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 1.25rem; color: #fff; flex: none; }
.q-blue { --q: var(--tone-blue); } .q-purple { --q: var(--tone-purple); } .q-green { --q: var(--tone-green); } .q-orange { --q: var(--tone-orange); } .q-red { --q: var(--tone-red); }
.mq-ico { background: var(--q, var(--tone-blue)); }
.mq-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.mq-tags { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.mq-what { font-weight: 700; font-size: .85rem; padding: .12rem .6rem; border-radius: 999px; color: var(--q); background: color-mix(in srgb, var(--q) 12%, var(--surface)); }
.mq-new { font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: var(--seal); color: #fff; }
.mq-subject { font-weight: 600; font-size: 1.05rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mq-item.is-new .mq-subject { font-weight: 700; }
.mq-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .9rem; font-size: .86rem; color: var(--muted); }
.mq-side { display: flex; flex-direction: column; align-items: flex-end; gap: .45rem; flex: none; }
.mq-time { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.mq-open { pointer-events: none; }
.mq-empty { padding: 1.5rem 1.35rem; color: var(--muted); font-size: 1rem; }
.mq-empty i { color: var(--ok); font-size: 1.2rem; }
@media (max-width: 575.98px) {
  .mq-head { padding: 1rem; }
  .mq-head h2 { font-size: 1.15rem; }
  .mq-item { padding: .9rem 1rem; gap: .75rem; align-items: flex-start; flex-wrap: wrap; }
  .mq-ico { width: 40px; height: 40px; font-size: 1.05rem; }
  .mq-side { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; padding-left: calc(40px + .75rem); }
}
.mq-count.is-zero { background: var(--line, #cbd5e1); color: var(--muted, #475569); }
.mq-more { display: block; padding: .85rem 1.25rem; border-top: 1px solid var(--line); text-align: center; color: var(--muted); text-decoration: none; font-size: .92rem; }
.mq-more:hover { background: var(--surface-2, rgba(37,99,235,.06)); color: var(--primary); }
.mq-more b { color: var(--primary); }
.my-queue.is-page .mq-head { padding-top: .8rem; padding-bottom: .8rem; } .my-queue.is-page .mq-head p { margin: 0; font-weight: 600; }
.table .row-action { position: relative; z-index: 2; }
/* ทะเบียน: สถานะแบบย่อ + ปุ่มลบ อยู่บรรทัดเดียวกัน */
.st-cell { display: flex; align-items: center; gap: .35rem; flex-wrap: nowrap; white-space: nowrap; }
.status-pill.status-sm { font-size: .78rem; padding: .18rem .55rem; gap: .3rem; }
.status-pill.status-sm .dot { width: 6px; height: 6px; }
.btn-icon-del { position: relative; z-index: 2; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: #c0392b; font-size: .85rem; line-height: 1; padding: 0; }
.btn-icon-del:hover, .btn-icon-del:focus-visible { background: #fdecea; border-color: #f3b4ad; }
/* ป้ายสถานะแบบย่อ: กว้างเท่ากันทุกแถว ปุ่มลบอยู่แนวเดียวกัน */
.status-pill.status-sm { display: inline-flex; align-items: center; justify-content: center; width: 6.4rem; min-height: 28px; box-sizing: border-box; }
.st-cell .btn-icon-del { flex: 0 0 28px; }
/* ออกแบบตราเกษียณ */
.note-preview-card { position: sticky; top: 90px; }
.note-preview-paper { background: #fff; border-radius: 12px; padding: 1.5rem; display: grid; place-items: center; overflow: auto; box-shadow: inset 0 0 0 1px var(--line); }
#notePreview { box-sizing: border-box; padding: 5px 8px 4px; font-family: Sarabun, sans-serif; background: #fff; max-width: 100%; }
#notePreview .np-head { font-weight: 700; padding-bottom: 2px; margin-bottom: 4px; }
#notePreview .np-sig span { display: inline-block; font-family: cursive; opacity: .55; font-size: 1.15em; padding: 4px 0; }
.note-role-card > .card-body:first-child { display: flex; flex-direction: column; }
.note-role-card > .card-body:last-child { flex: none; } /* ให้ปุ่มล่างตรงแนว: ส่วนบนเท่านั้นที่ยืด */
.note-role-name { margin-bottom: .6rem; line-height: 1.3; }
@media (min-width: 1200px) { .note-role-name { min-height: 2.6em; } } /* ชื่อยาวสองบรรทัด กล่องตัวอย่างยังตรงกัน */
.note-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: .85rem; border-radius: 12px; background: var(--surface-2); }
.note-fit { width: 100%; display: flex; align-items: flex-start; justify-content: center; overflow: hidden; }
.note-role-card .note-mini { flex: none; background: #fff; box-shadow: 0 6px 14px -10px rgba(15, 35, 80, .45); transform-origin: top center; }
/* ออกเลขหนังสือ: การ์ดเลือกชนิดเลข */
.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .75rem; }
.series-card { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s, background .15s; height: 100%; }
.series-card:hover { border-color: var(--primary); }
.btn-check:checked + .series-card { border-color: var(--primary); background: rgba(37, 99, 235, .06); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.btn-check:focus-visible + .series-card { outline: 2px solid var(--primary); outline-offset: 2px; }
.sc-ico { flex: 0 0 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--primary); font-size: 1.15rem; }
.btn-check:checked + .series-card .sc-ico { background: var(--primary); color: #fff; }
.sc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sc-title { font-weight: 700; line-height: 1.3; }
.sc-desc { font-size: .8rem; color: var(--muted); line-height: 1.35; }
.sc-next { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.sc-next-l { font-size: .7rem; color: var(--muted); }
.sc-no { font-weight: 700; font-size: .85rem; color: var(--primary); white-space: nowrap; }
.issue-box { border: 1.5px dashed var(--primary); border-radius: 14px; padding: 1rem 1.1rem; background: rgba(37, 99, 235, .04); text-align: center; }
.issue-no { font-size: 1.5rem; font-weight: 800; color: var(--primary); letter-spacing: .01em; }
.series-tag { margin-top: .3rem; font-size: .72rem; font-weight: 600; color: var(--muted); }
/* ตั้งค่าชนิดเลขทะเบียนส่ง */
.series-set { display: grid; gap: .6rem; }
.series-row { border: 1px solid var(--line); border-radius: 12px; padding: .75rem .9rem; background: var(--surface); }
.series-row .sr-head { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; margin-bottom: .5rem; }
/* การ์ดชนิดเลข: จัดแนวตั้ง อ่านง่าย */
.series-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.series-card { flex-direction: column; align-items: stretch; gap: .5rem; padding: .9rem 1rem; }
.series-card .sc-top { display: flex; align-items: center; gap: .6rem; }
.series-card .sc-ico { flex: 0 0 36px; height: 36px; }
.series-card .sc-next { flex-direction: row; align-items: baseline; justify-content: space-between; gap: .5rem; margin-top: auto; padding-top: .5rem; border-top: 1px dashed var(--line); }
.series-card .sc-no { font-size: .95rem; }
:root { --primary: var(--stamp); }
/* แผงรับหนังสือ / ออกเลข บนหน้าทะเบียน */
.intake { border: 1.5px solid rgba(37, 99, 235, .25); overflow: visible; }
.intake-head { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.15rem; flex-wrap: wrap; }
.intake-ico { flex: 0 0 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 1.3rem; }
.intake-title { flex: 1 1 260px; min-width: 0; }
.intake-title h2 { font-size: 1.15rem; font-weight: 800; margin: 0; }
.intake-title p { margin: 0; color: var(--muted); font-size: .88rem; }
.intake-next { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.intake-next span { font-size: .72rem; color: var(--muted); }
.intake-next b { font-size: 1.15rem; color: var(--primary); }
.intake-toggle .when-open { display: none; }
.intake-toggle[aria-expanded="true"] .when-open { display: inline; }
.intake-toggle[aria-expanded="true"] .when-closed { display: none; }
.intake-body { border-top: 1px solid var(--line); padding: 1.15rem; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.register-title { font-size: 1.05rem; font-weight: 800; margin: 1.5rem 0 .75rem; display: flex; align-items: center; gap: .5rem; }
.register-title span { font-size: .85rem; font-weight: 500; color: var(--muted); }
@media (max-width: 575.98px) { .intake-next { align-items: flex-start; } .intake-toggle { width: 100%; } }
/* หน้าต่างเลือกตำแหน่งตรา */
.pick-stage { position: relative; margin: 0 auto; max-width: 100%; box-shadow: 0 2px 14px rgba(15, 23, 42, .15); background: #fff; touch-action: none; }
.pick-stage canvas { display: block; }
.pick-stage .place-box { position: absolute; }
.place-mode { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.seg.seg-sm .seg-btn { padding: .35rem .7rem; font-size: .85rem; }
.intake-step { display: flex; align-items: center; gap: .5rem; padding: .25rem 1.15rem .75rem; font-weight: 700; }
.intake-step .step-no { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: .8rem; }
#intakeBody > .intake-step:first-child { border-top: 1px solid var(--line); padding-top: 1rem; }
/* การ์ดชนิดหนังสือแบบมีสีประจำชนิด (--c) */
.series-card { --c: #2563EB; position: relative; overflow: hidden; border: 1.5px solid color-mix(in srgb, var(--c) 22%, var(--line)); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 9%, var(--surface)) 0%, var(--surface) 55%); }
.series-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 45%, #fff)); }
.series-card .sc-ico { background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--c); }
.series-card .sc-title { color: color-mix(in srgb, var(--c) 55%, var(--text)); }
.series-card .sc-no { color: var(--c); }
.series-card:hover { border-color: var(--c); transform: translateY(-1px); box-shadow: 0 6px 18px color-mix(in srgb, var(--c) 18%, transparent); }
.btn-check:checked + .series-card { border-color: var(--c); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 16%, var(--surface)) 0%, color-mix(in srgb, var(--c) 5%, var(--surface)) 100%); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.btn-check:checked + .series-card .sc-ico { background: var(--c); color: #fff; }
.btn-check:checked + .series-card::after { content: "\F26E"; font-family: bootstrap-icons; position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: .8rem; }
.series-card { transition: border-color .15s, box-shadow .15s, transform .15s, background .15s; }
.series-tab { --c: var(--primary); }
.series-tab i { color: var(--c); }
.series-tab.active { background: var(--c) !important; color: #fff !important; }
.series-tab.active i { color: #fff; }
.series-tag { display: inline-block; color: var(--c, var(--muted)); background: color-mix(in srgb, var(--c, #64748B) 10%, transparent); padding: .05rem .45rem; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { .series-card, .series-card:hover { transition: none; transform: none; } }
/* ฟอร์มรับหนังสือแบบ 3 ขั้นตอน */
.rx { max-width: 880px; margin: 0 auto; display: grid; gap: 1rem; }
.rx-step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem 1.2rem; }
.rx-h { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.02rem; margin-bottom: .85rem; }
.rx-h .step-no { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: .85rem; }
.rx-more { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: .85rem 1.2rem; }
.rx-more summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.rx-more summary::-webkit-details-marker { display: none; }
.rx-more summary::after { content: "\F282"; font-family: bootstrap-icons; margin-left: auto; transition: transform .2s; }
.rx-more[open] summary::after { transform: rotate(180deg); }
.rx-more summary span { font-weight: 400; font-size: .82rem; color: var(--muted); }
.rx-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.rx-actions .btn { flex: 1 1 240px; }
.rx .dropzone { min-height: 120px; }
/* เลือกหลายรายการในทะเบียน */
.sel-col { width: 40px; }
.sel-col .form-check-input { position: relative; z-index: 2; width: 1.15rem; height: 1.15rem; cursor: pointer; }
tr.is-picked > td { background: color-mix(in srgb, var(--seal) 7%, var(--surface)) !important; }
.bulk-bar { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 1040; display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem .6rem 1.1rem; background: var(--text); color: #fff; border-radius: 999px; box-shadow: 0 10px 30px rgba(15, 23, 42, .3); white-space: nowrap; }
.bulk-bar .btn-light-line { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
@media (max-width: 991.98px) { .bulk-bar { bottom: calc(86px + env(safe-area-inset-bottom)); } }
/* ฟอร์มรับหนังสือ: เต็มความกว้าง 2 คอลัมน์บนจอใหญ่ */
.rx { max-width: none; }
@media (min-width: 992px) {
  .rx { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .rx .rx-actions { grid-column: 1 / -1; }
  .rx .dropzone { min-height: 190px; }
}
/* ฟอร์มรับหนังสือ: 2 คอลัมน์ การ์ดเรียงต่อกันไม่มีช่องโหว่ */
.rx-col { display: grid; gap: 1rem; align-content: start; min-width: 0; }
.rx-opt { font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: .05rem .55rem; }
@media (min-width: 992px) { .rx .dropzone { min-height: 150px; } }
/* หน้าต่างรับหนังสือ / ออกเลข */
.intake-btn { white-space: nowrap; }
.intake-modal .modal-content { border-radius: 18px; overflow: hidden; }
.intake-modal .intake-form { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
.intake-modal .modal-dialog-scrollable .intake-form { overflow: hidden; }
.intake-modal .modal-header { gap: .75rem; padding: 1rem 1.25rem; }
.intake-modal .modal-header .intake-ico { flex: 0 0 40px; height: 40px; font-size: 1.1rem; }
.intake-modal .modal-body { background: var(--surface-2); padding: 1.1rem 1.25rem; }
.intake-modal .modal-footer { gap: .5rem; padding: .85rem 1.25rem; }
.intake-modal .rx { gap: 1rem; }
@media (max-width: 991.98px) { .intake-modal .modal-content { border-radius: 0; } .intake-modal .modal-footer .btn { flex: 1 1 auto; } }
@media (max-width: 575.98px) { .intake-btn { width: 100%; } }
/* หน้าต่างรับหนังสือ/ออกเลข: ฟอร์มครอบทั้งหน้าต่าง → ให้ส่วนเนื้อหาเลื่อนได้ */
.intake-modal .modal-dialog-scrollable .modal-content { max-height: calc(100vh - 3.5rem); overflow: hidden; }
.intake-modal .intake-form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.intake-modal .intake-form > .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.intake-modal .intake-form > .modal-header, .intake-modal .intake-form > .modal-footer { flex: 0 0 auto; }
.intake-modal .modal-header { display: flex; align-items: center; gap: .85rem; }
.intake-modal .modal-header .intake-ico { width: 42px; min-width: 42px; height: 42px; flex: 0 0 42px; margin: 0; }
.intake-modal .modal-header > .flex-grow-1 { min-width: 0; }
@media (max-width: 991.98px) { .intake-modal .modal-dialog-scrollable .modal-content { max-height: 100%; height: 100%; } }
/* หน้าต่างรับหนังสือ: แถว 1 สองการ์ดสูงเท่ากัน · แถว 2–3 เต็มความกว้าง — ไม่มีช่องว่าง */
.rx.rx-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
.rx-grid .rx-step { margin: 0; }
.rx-file { display: flex; flex-direction: column; }
.rx-file .dropzone { flex: 1 1 auto; }
@media (min-width: 992px) {
  .rx.rx-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
  .rx-grid .rx-wide { grid-column: 1 / -1; }
}
/* หน้าต่างออกเลข: การ์ดชนิดแถวเดียว · การ์ดรายละเอียดเต็มกว้าง · ไฟล์/ส่งต่อ 2 ช่องเท่ากัน */
@media (min-width: 1200px) { .intake-modal .series-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 992px) { .rx.rx-send { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.rx-send .form-section { margin-top: .25rem; }
.issue-inline { display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
.issue-inline span { color: var(--muted); font-size: .85rem; }
.issue-inline b { color: var(--primary); font-size: 1.25rem; font-weight: 800; }
.issue-inline small { color: var(--muted); }
/* ภาพตัวอย่างตราในกล่องเลือกตำแหน่ง */
.place-box { background: rgba(255, 255, 255, .55) !important; }
.place-box .place-preview { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.place-box .np-mini { height: 100%; box-sizing: border-box; font-family: Sarabun, "Noto Sans Thai", sans-serif; background: rgba(255, 255, 255, .85); }

/* ตัวอย่างส่วนหัวหนังสือใต้ไฟล์ (ซูมได้) */
.dz-peek { margin-top: .75rem; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.dz-peek-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .35rem .6rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.dz-zoom { display: inline-flex; align-items: center; gap: .25rem; }
.dz-zoom b { min-width: 3rem; text-align: center; font-weight: 600; color: var(--text, inherit); }
.dz-zoom button { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; }
.dz-peek-view { height: 280px; overflow: auto; background: #fff; touch-action: none; user-select: none; }
.dz-peek-view canvas { display: block; max-width: none; margin: 0 auto; }
.dz-zoom input[type=range] { width: 110px; accent-color: var(--primary); }
/* รายการแนะนำใต้ช่องกรอก */
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 1080; margin-top: 4px; max-height: 260px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 28px rgba(15, 23, 42, .14); padding: .25rem; }
.suggest-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: .5rem .7rem; border-radius: 8px; font: inherit; color: inherit; }
.suggest-item:hover, .suggest-item.on { background: var(--surface-2); }
.dz-peek-view { scrollbar-gutter: stable; }

/* ตาราง "หนังสือรอดำเนินการ" ใช้สไตล์เดียวกับทะเบียนหนังสือ */
.mq-table thead th { font-size: .82rem; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.mq-table tbody td { padding-top: .6rem; padding-bottom: .6rem; }
.mq-table tr.is-new > td:first-child { box-shadow: inset 4px 0 0 var(--stamp), inset 0 0 0 9999px var(--bs-table-bg-state, transparent); }
.mq-table tr.is-urgent > td:first-child { box-shadow: inset 4px 0 0 var(--seal), inset 0 0 0 9999px var(--bs-table-bg-state, transparent); }
.mq-table .mq-t-subject { min-width: 240px; }
.mq-table .mq-link { color: var(--text); }
.mq-table .mq-what { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; font-size: .8rem; padding: .12rem .6rem; }
.mq-table .mq-due { font-size: .78rem; white-space: nowrap; }

/* แผงเกษียณ/พิจารณา: หัวข้อชัด ปุ่มข้อความสำเร็จรูปเล็ก รายชื่อแบบแถวเดียว */
.action-panel .ap-title { font-size: .8rem; font-weight: 700; letter-spacing: .02em; color: var(--muted); margin: 0 0 .4rem; }
.action-panel .ap-title label { margin: 0; font: inherit; color: inherit; }
.ap-phrases { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .6rem; }
.ap-chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: .15rem .65rem; font-size: .8rem; line-height: 1.5; cursor: pointer; transition: background .12s, border-color .12s; }
.ap-chip:hover { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); border-color: var(--primary); color: var(--primary); }
/* ปุ่มเลือกทั้งกลุ่มงาน: ยืดเต็มแถวเท่ากันทุกปุ่ม + สถานะ (ไม่เลือก / บางส่วน / ทั้งกลุ่ม) และจำนวนที่เลือก */
.ap-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .4rem; margin-bottom: .6rem; }
.ap-chip.ap-group { display: flex; align-items: center; gap: .45rem; width: 100%; border-radius: 10px; padding: .4rem .6rem; font-size: .82rem; text-align: left; }
.ap-group .ap-gn { flex: 1 1 auto; min-width: 0; }
.ap-groups .ap-group-all { grid-column: 1 / -1; font-weight: 600; }
.ap-group .ap-gc { flex: none; font-size: .7rem; font-weight: 700; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 .45rem; font-variant-numeric: tabular-nums; }
.ap-group[data-state="some"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); color: var(--primary); }
.ap-group[data-state="all"] { border-color: var(--primary); background: var(--primary); color: #fff; }
.ap-group[data-state="all"]:hover { background: var(--primary); color: #fff; }
.ap-group[data-state="all"] .ap-gc { color: #fff; background: rgba(255, 255, 255, .22); border-color: transparent; }
.ap-pick { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ap-pick > summary { list-style: none; display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; cursor: pointer; font-weight: 600; font-size: .9rem; }
.ap-pick > summary::-webkit-details-marker { display: none; }
.ap-pick-t { flex: 1; }
.ap-pick-n { font-size: .8rem; font-weight: 500; color: var(--muted); }
.ap-pick-n b { color: var(--primary); }
.ap-pick > summary > i { color: var(--muted); font-size: .8rem; transition: transform .15s; }
.ap-pick[open] > summary > i { transform: rotate(180deg); }
.ap-pick-body { padding: 0 .8rem .8rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.ap-pick-body > .form-control { margin-bottom: .6rem; }
.ap-people { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.ap-person { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: .6rem; align-items: center; padding: .35rem .6rem; border-bottom: 1px solid var(--line); cursor: pointer; margin: 0; }
.ap-person:last-child { border-bottom: 0; }
.ap-person:hover { background: var(--surface-2); }
.ap-person:has(input:checked) { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.ap-person .ap-pn { font-size: .9rem; font-weight: 600; line-height: 1.3; }
.ap-person .ap-pp { grid-column: 2; font-size: .76rem; color: var(--muted); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* แถบหลังลงรับเสร็จ: ปุ่ม "ลงรับเรื่องอื่นต่อ" เห็นชัด */
.reg-done { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; padding: .85rem 1.1rem; margin-bottom: 1rem; border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--line)); border-radius: 14px; background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.reg-done-ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--ok); color: #fff; font-size: 1.3rem; }
.reg-done-txt { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.reg-done-txt b { font-size: 1.05rem; }
.reg-done-txt span { font-size: .88rem; color: var(--muted); }

/* ชื่อเรื่อง + ป้ายสถานะหนังสือ (ด่วน/ลับ/เวียน) อยู่บรรทัดเดียวกัน */
.mq-line { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.mq-line .mq-link { flex: 0 1 auto; min-width: 0; }
.mq-line > .badge, .mq-line > .chip, .mq-line > .mq-due { flex: none; }

/* เอฟเฟกต์ชี้แถวตาราง: ไฮไลต์ทั้งแถวด้วยกลไกของ Bootstrap (ทำงานกับทุกตาราง ไม่ต้องมีคลาส table-hover) */
.table > tbody > tr > * { transition: box-shadow .15s ease; }
.table > tbody > tr:hover > * { --bs-table-bg-state: var(--bs-table-hover-bg); }
.table > tbody > tr:has(a.row-link) { cursor: pointer; }

.my-done-note { font-size: .95rem; line-height: 1.55; padding: .55rem .75rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); max-height: 150px; overflow: auto; }

/* หน้าหนังสือ (จอคอม): การ์ดซ้าย (ตัวดู PDF) กับการ์ดขวา (ข้อมูล + Timeline) สูงเท่ากันเสมอ — ความสูงตามการ์ดขวา
   ตัวดู PDF เต็มความสูงนั้น แสดงทุกหน้าเลื่อนดูในกรอบได้ (ขั้นต่ำเท่าหนึ่งจอ) · โหมดเต็มจอใช้ของ UA ตามเดิม — ถอนกลับ: ลบบล็อกนี้ แล้วคืนเป็น position: sticky + .pdfv-stage ความสูง calc(100vh - var(--topbar-h) - 7.5rem) */
.doc-main { min-width: 0; }
@media (min-width: 992px) {
  .doc-layout { align-items: stretch; }
  .doc-side { position: static; }
  .doc-main { position: relative; min-height: calc(100vh - var(--topbar-h) - 7.5rem); }
  .doc-main > .pdfv { position: absolute; inset: 0; }
  .doc-main .pdfv-stage { flex: 1 1 auto; height: auto; min-height: 0; }
  .doc-main .pdfv:fullscreen { position: fixed; inset: 0; }
}

/* ค้นหาขั้นสูงในหน้าเอกสาร */
.adv-search > summary { cursor: pointer; font-weight: 600; color: var(--primary); list-style: none; display: inline-flex; align-items: center; gap: .4rem; }
.adv-search > summary::-webkit-details-marker { display: none; }

/* แถบค้นหา/กรองหน้าทะเบียน: บรรทัดเดียว ตัวกรองเพิ่มเติมพับเก็บ */
.list-filter .lf-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.list-filter .lf-q { flex: 1 1 280px; min-width: 0; }
.list-filter .lf-bar .form-select { width: auto; min-width: 120px; }
.list-filter .lf-bar .btn, .list-filter .form-control, .list-filter .form-select { min-height: 40px; }
.list-filter .lf-more.has-adv { border-color: var(--primary); color: var(--primary); }
.list-filter .lf-n { display: inline-grid; place-items: center; min-width: 1.3rem; height: 1.3rem; padding: 0 .3rem; border-radius: 999px; background: var(--primary); color: #fff; font-size: .75rem; }
.list-filter .lf-adv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .5rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px dashed var(--line); }
.list-filter .lf-adv .form-select, .list-filter .lf-adv .form-control { width: 100%; }
.list-filter .lf-date { display: flex; align-items: center; gap: .4rem; margin: 0; font-size: .85rem; color: var(--muted); font-weight: 500; }
.list-filter .lf-date .form-control { flex: 1; min-width: 0; }
@media (max-width: 575.98px) { .list-filter .lf-bar .form-select { flex: 1 1 45%; } }
.list-filter .lf-adv .lf-f, .list-filter .lf-adv .lf-f select { width: 100%; }
#listResults.is-loading { opacity: .55; transition: opacity .15s; pointer-events: none; }

/* ตารางทะเบียน: ป้ายด่วน/ลับ อยู่บรรทัดเดียวกับเรื่อง */
.subj-line { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
.subj-line .seal { font-size: .72rem; padding: 0 .4rem; border-width: 1.5px; flex: none; }
.subj-line .seal-urgent.seal-l4 { outline: 0; }
.subj-line .seal-secret { border-width: 2px; }
.mq-line { align-items: baseline; }
.mq-line .seal { font-size: .72rem; padding: 0 .4rem; border-width: 1.5px; flex: none; }
.mq-line .seal-urgent.seal-l4 { outline: 0; }
.mq-line .seal-secret { border-width: 2px; }
.subj-text, .mq-line .mq-link { font-weight: 400; font-size: .9rem; }
.subj-line .seal, .mq-line .seal { font-size: .68rem; font-weight: 500; }
.subj-text, .mq-line .mq-link { font-size: inherit; }
.subj-line .seal, .mq-line .seal { font-size: inherit; }
.table-stack tbody td { font-size: .85rem; }
.table-stack tbody td .reg-stamp { font-size: .78rem; }
.table-stack .seal, .subj-line .seal, .mq-line .seal { font-size: .72rem; }
.table-stack .status-pill { font-size: .75rem; padding: .1rem .5rem; }
.tl-step { display: inline-block; font-size: .72rem; font-weight: 600; color: var(--stamp); background: var(--stamp-soft); border-radius: 999px; padding: 0 .5rem; margin-right: .35rem; vertical-align: 1px; }

/* รับหนังสือ: ช่องที่ระบบอ่านจาก PDF ให้ */
.form-control.is-auto { border-color: color-mix(in srgb, var(--warn) 60%, var(--line)); background: color-mix(in srgb, var(--warn-soft) 45%, var(--surface)); }
.pdf-auto-tag { font-size: .75rem; color: var(--warn); margin-top: .25rem; }
.pdf-read-note { color: var(--muted); }

/* Stat tiles (โฉมใหม่): ชื่อ + ไอคอนสีอ่อนด้านบน · ตัวเลขใหญ่ · แถบสีบาง ๆ ด้านบน · ค่า 0 จางลง */
.stat { --c: var(--tone-blue); position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: stretch; gap: .35rem; padding: 1rem 1.1rem .9rem; border-radius: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04); transition: border-color .15s, box-shadow .15s, transform .15s; }
.stat::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c); opacity: .85; }
.stat.tone-seal { --c: var(--tone-red); }
.stat.tone-ok { --c: var(--tone-green); }
.stat.tone-warn { --c: var(--tone-orange); }
.stat.tone-ink { --c: var(--tone-purple); }
.stat .s-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.stat .s-lbl { font-size: .85rem; font-weight: 600; color: var(--muted); line-height: 1.35; padding-top: .15rem; }
.stat .s-ico, .stat.tone-seal .s-ico, .stat.tone-ok .s-ico, .stat.tone-warn .s-ico, .stat.tone-ink .s-ico { width: 36px; height: 36px; border-radius: 10px; font-size: 1.05rem; background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: var(--c); }
.stat .s-val { font-size: 2rem; line-height: 1; color: var(--text); }
.stat.is-zero .s-val { color: color-mix(in srgb, var(--muted) 70%, var(--surface)); }
.stat .s-go { font-size: .75rem; font-weight: 600; color: var(--c); opacity: 0; transform: translateX(-4px); transition: opacity .15s, transform .15s; }
a.stat:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--c) 45%, transparent); transform: translateY(-2px); }
a.stat:hover .s-go, a.stat:focus-visible .s-go { opacity: 1; transform: none; }
.stat.is-alert { border-color: color-mix(in srgb, var(--seal) 45%, var(--line)); background: color-mix(in srgb, var(--seal-soft) 35%, var(--surface)); }
.stat.is-alert .s-val { color: var(--seal); }
@media (max-width: 575.98px) {
  .stat { padding: .85rem .9rem .75rem; }
  .stat .s-ico { width: 32px; height: 32px; font-size: .95rem; border-radius: 9px; }
  .stat .s-val { font-size: 1.6rem; }
  .stat .s-lbl { font-size: .8rem; }
  .stat .s-go { display: none; }
}

/* Stat tiles: สีชัดขึ้น + เอฟเฟกต์ (พื้นไล่สี ไอคอนทึบเรืองแสง ไอคอนจางมุมขวาล่าง แสงวิ่งตอนชี้ ตัวเลขนับขึ้น) */
.stat { background: linear-gradient(135deg, color-mix(in srgb, var(--c) 9%, var(--surface)) 0%, var(--surface) 62%); border-color: color-mix(in srgb, var(--c) 18%, var(--line)); padding: 1.05rem 1.15rem 1rem; gap: .5rem; isolation: isolate; }
.stat::before { height: 4px; opacity: 1; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 40%, #fff)); }
.stat::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 45%; background: linear-gradient(100deg, transparent, rgba(255,255,255,.55), transparent); transform: skewX(-18deg); pointer-events: none; z-index: 1; }
a.stat:hover::after { animation: stat-shine .75s ease; }
@keyframes stat-shine { to { left: 130%; } }
.stat .s-lbl { color: color-mix(in srgb, var(--text) 75%, var(--muted)); }
.stat .s-ico, .stat.tone-seal .s-ico, .stat.tone-ok .s-ico, .stat.tone-warn .s-ico, .stat.tone-ink .s-ico {
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.1rem; color: #fff;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 80%, #fff), var(--c));
  box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--c) 70%, transparent); transition: transform .2s;
}
a.stat:hover .s-ico { transform: rotate(-8deg) scale(1.08); }
.stat .s-val { font-size: 2.1rem; color: var(--text); position: relative; z-index: 2; }
.stat.is-zero .s-val { color: color-mix(in srgb, var(--text) 45%, var(--surface)); }
.stat .s-bg { position: absolute; right: -.4rem; bottom: -1rem; font-size: 4.6rem; line-height: 1; color: var(--c); opacity: .07; transform: rotate(-12deg); transition: opacity .2s, transform .25s; pointer-events: none; z-index: 0; }
a.stat:hover .s-bg { opacity: .13; transform: rotate(-4deg) scale(1.06); }
.stat .s-go { position: absolute; left: 1.15rem; bottom: .55rem; z-index: 2; }
a.stat:hover .s-val { transform: translateY(-6px); }
.stat .s-val { transition: transform .2s; }
.stat.is-alert { background: linear-gradient(135deg, color-mix(in srgb, var(--seal) 14%, var(--surface)), var(--surface) 70%); }
.stat.is-alert .s-ico { animation: stat-pulse 1.8s ease-out infinite; }
@keyframes stat-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 10px transparent; } }
@media (prefers-reduced-motion: reduce) { .stat, .stat * { animation: none !important; transition: none !important; } }
@media (max-width: 575.98px) { .stat .s-ico { width: 34px; height: 34px; } .stat .s-bg { font-size: 3.6rem; } a.stat:hover .s-val { transform: none; } }

/* การ์ดทักทาย: แบนเนอร์ไล่สี + ลูกบอลแสงลอย + ไอคอนตามช่วงเวลา + นาฬิกา + ปุ่มกระจก */
.hello { overflow: hidden; isolation: isolate; color: #fff; border: 0; padding: 1.5rem 1.6rem;
  background: linear-gradient(120deg, var(--stamp) 0%, color-mix(in srgb, var(--stamp) 70%, #7C3AED) 55%, color-mix(in srgb, var(--stamp) 55%, #06B6D4) 100%);
  background-size: 200% 200%; animation: hello-bg 14s ease-in-out infinite;
  box-shadow: 0 14px 30px -18px color-mix(in srgb, var(--stamp) 80%, transparent); }
@keyframes hello-bg { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.hello-blob { position: absolute; border-radius: 50%; filter: blur(2px); z-index: -1; pointer-events: none; background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.35), rgba(255,255,255,0) 70%); }
.hello-blob.b1 { width: 260px; height: 260px; right: -60px; top: -110px; animation: hello-float 9s ease-in-out infinite; }
.hello-blob.b2 { width: 180px; height: 180px; right: 22%; bottom: -120px; animation: hello-float 11s ease-in-out infinite reverse; }
@keyframes hello-float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-18px, 14px); } }
.hello-main { display: flex; align-items: center; gap: 1rem; }
.hello-ico { width: 54px; height: 54px; flex: none; border-radius: 16px; display: grid; place-items: center; font-size: 1.6rem;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3); backdrop-filter: blur(6px); animation: hello-bob 4s ease-in-out infinite; }
@keyframes hello-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.hello-text { flex: 1; min-width: 0; }
.hello h1 { color: #fff; }
.hello p { color: rgba(255,255,255,.85); }
.hello .wave { display: inline-block; transform-origin: 70% 70%; animation: hello-wave 2.4s ease-in-out 1s 2; }
@keyframes hello-wave { 0%, 60%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(16deg); } 20% { transform: rotate(-8deg); } 40% { transform: rotate(-4deg); } 50% { transform: rotate(10deg); } }
.hello-clock { flex: none; text-align: right; line-height: 1; padding: .55rem .8rem; border-radius: 14px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); backdrop-filter: blur(6px); }
.hello-clock b { font-family: var(--font-head); font-size: 1.6rem; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.hello-clock span { font-size: .8rem; margin-left: .2rem; opacity: .85; }
.hello .quick { margin-top: 1.15rem; }
.hello .btn-light { background: #fff; border-color: #fff; color: var(--stamp); box-shadow: 0 6px 16px -8px rgba(0,0,0,.35); transition: transform .15s, box-shadow .15s; }
.hello .btn-light:hover { background: #fff; border-color: #fff; color: var(--stamp-600); transform: translateY(-2px); box-shadow: 0 10px 20px -10px rgba(0,0,0,.45); }
.hello .btn-ghost { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.32); backdrop-filter: blur(6px); transition: transform .15s, background .15s; }
.hello .btn-ghost:hover { background: rgba(255,255,255,.26); color: #fff; border-color: rgba(255,255,255,.5); transform: translateY(-2px); }
@media (max-width: 575.98px) { .hello-clock { display: none; } .hello-ico { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 12px; } }
@media (prefers-reduced-motion: reduce) { .hello, .hello * { animation: none !important; } }

/* ตัวกรองละเอียด: ตาราง 4 คอลัมน์เท่ากัน มีหัวข้อกำกับ · ช่วงวันที่รวมเป็นช่องเดียวเต็มแถวที่เหลือ */
.list-filter .lf-adv { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem .75rem; margin-top: .85rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.list-filter .lf-cell { display: flex; flex-direction: column; gap: .25rem; margin: 0; min-width: 0; }
.list-filter .lf-cell > span { font-size: .75rem; font-weight: 600; color: var(--muted); }
.list-filter .lf-range { grid-column: span 3; }
.list-filter .lf-adv.is-all .lf-range { grid-column: span 2; }
.list-filter .lf-range > div { display: flex; align-items: center; gap: .5rem; }
.list-filter .lf-range > div .form-control { flex: 1; min-width: 0; }
.list-filter .lf-range > div .bi { color: var(--muted); font-size: .85rem; }
@media (max-width: 767.98px) {
  .list-filter .lf-adv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-filter .lf-range, .list-filter .lf-adv.is-all .lf-range, .list-filter .lf-adv:not(.is-all) .lf-cell:nth-child(5) { grid-column: 1 / -1; }
}

/* การ์ดทักทาย (เพิ่มลูกเล่น): ภาพประกอบเอกสาร+ตรายาง ลอย/ประทับ · ประกายดาว · ชื่อไล่สีวิบวับ · แถบงานวันนี้ */
.hello { min-height: 168px; padding-right: 260px; }
.hello-art { position: absolute; right: 120px; bottom: -10px; width: 250px; height: auto; z-index: -1; filter: drop-shadow(0 12px 18px rgba(15,23,42,.25)); }
.hello-art .ha-doc { animation: ha-float 6s ease-in-out infinite; transform-box: fill-box; }
.hello-art .d2 { animation-delay: -1.5s; } .hello-art .d3 { animation-delay: -3s; }
@keyframes ha-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.hello-art .ha-stamp { transform-box: fill-box; transform-origin: center; animation: ha-stamp 6s ease-in-out infinite; }
@keyframes ha-stamp { 0% { transform: translateY(-34px) scale(1.25) rotate(-14deg); opacity: 0; } 8% { transform: translateY(0) scale(.92) rotate(-14deg); opacity: 1; } 13%, 88% { transform: translateY(0) scale(1) rotate(-14deg); opacity: 1; } 100% { transform: translateY(0) scale(1) rotate(-14deg); opacity: 0; } }
.hello-spark { position: absolute; width: 10px; height: 10px; z-index: -1; background: #fff; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: hello-twinkle 3s ease-in-out infinite; }
.hello-spark.s1 { right: 360px; top: 22px; } .hello-spark.s2 { right: 96px; top: 70%; width: 7px; height: 7px; animation-delay: -1s; } .hello-spark.s3 { right: 44%; top: 18px; width: 6px; height: 6px; animation-delay: -2s; }
@keyframes hello-twinkle { 0%, 100% { opacity: 0; transform: scale(.4) rotate(0); } 50% { opacity: .95; transform: scale(1) rotate(90deg); } }
.hello-name { background: linear-gradient(90deg, #fff 0%, #FDE68A 30%, #fff 60%); background-size: 200% auto; -webkit-background-clip: text; background-clip: text; color: transparent; animation: hello-shimmer 4s linear infinite; }
@keyframes hello-shimmer { to { background-position: -200% center; } }
.hello-focus { display: inline-flex; align-items: center; gap: .45rem; margin-top: .65rem; padding: .3rem .8rem; border-radius: 999px; font-size: .88rem; color: #fff; text-decoration: none; background: rgba(15,23,42,.22); border: 1px solid rgba(255,255,255,.25); backdrop-filter: blur(6px); transition: background .15s; }
.hello-focus:hover { color: #fff; background: rgba(15,23,42,.32); }
.hello-focus b { font-size: 1rem; }
.hello-focus .bi-arrow-right { transition: transform .15s; } .hello-focus:hover .bi-arrow-right { transform: translateX(3px); }
.hello-focus .dot { width: 8px; height: 8px; border-radius: 50%; background: #FDE047; box-shadow: 0 0 0 0 rgba(253,224,71,.7); animation: hello-dot 1.6s ease-out infinite; }
@keyframes hello-dot { 70%, 100% { box-shadow: 0 0 0 8px rgba(253,224,71,0); } }
.hello-focus.is-clear { background: rgba(16,185,129,.28); }
.hello-clock { position: absolute; top: 1.2rem; right: 1.4rem; }
.hello-main { align-items: flex-start; }
@media (max-width: 991.98px) { .hello { padding-right: 8rem; } .hello-art { right: -30px; opacity: .35; } .hello-spark.s1 { display: none; } }
@media (max-width: 575.98px) { .hello-art, .hello-spark { display: none; } }
/* การ์ดทักทาย (มือถือ): ปุ่มลัดเรียงแถวเดียว 4 ช่องเท่ากัน ไอคอนบน ข้อความล่าง */
@media (max-width: 575.98px) {
  .hello .quick { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: .4rem; margin-top: .9rem; }
  .hello .quick .btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; padding: .45rem .2rem; font-size: .72rem; line-height: 1.2; white-space: nowrap; min-width: 0; border-radius: 12px; }
  .hello .quick .btn .bi { font-size: 1.05rem; margin: 0; }
  .hello { padding: 1.1rem 1.1rem 1rem; min-height: 0; }
  .hello-main { gap: .75rem; }
  .hello-focus { display: inline-block; font-size: .8rem; line-height: 1.5; }
}
/* การ์ดทักทาย: นาฬิกา + แถบงานวันนี้ รวมเป็นแผงเดียวมุมขวาบน */
.hello-side { position: absolute; top: 1.1rem; right: 1.3rem; display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; z-index: 2; }
.hello-side .hello-clock { position: static; }
.hello-side .hello-focus { margin-top: 0; }
.hello { padding-right: 300px; }
.hello-art { right: 30px; }
@media (max-width: 991.98px) { .hello { padding-right: 1.6rem; } .hello-side { position: static; flex-direction: row; align-items: center; justify-content: space-between; margin-top: .75rem; } .hello-main { flex-wrap: wrap; } .hello-side { flex-basis: 100%; } }
@media (max-width: 575.98px) {
  .hello-side .hello-clock { display: block; padding: .35rem .6rem; border-radius: 10px; }
  .hello-side .hello-clock b { font-size: 1.1rem; }
  .hello-side { gap: .5rem; }
}
/* แผงนาฬิกา+งานวันนี้: กล่องกระจกเดียว (นาฬิกาไม่มีกรอบแยก) */
.hello-side { padding: .7rem .9rem; border-radius: 16px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.28); backdrop-filter: blur(8px); gap: .35rem; min-width: 0; }
.hello-side .hello-clock { padding: 0; background: none; border: 0; backdrop-filter: none; }
.hello-side .hello-focus { background: none; border: 0; padding: 0; backdrop-filter: none; font-size: .85rem; white-space: normal; text-align: right; }
.hello-side .hello-focus:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
.hello-side .hello-focus.is-clear { background: none; color: #A7F3D0; }
.hello-art { right: 300px; }
@media (max-width: 1199.98px) { .hello-art { display: none; } }
@media (max-width: 991.98px) { .hello-side .hello-focus { text-align: left; flex: 1; min-width: 0; } .hello-side .hello-clock { order: 2; flex: none; } }
@media (max-width: 575.98px) { .hello-side { padding: .55rem .75rem; } .hello-side .hello-focus { font-size: .78rem; } }
@media (max-width: 991.98px) { .hello { padding-right: 1.6rem; } }
@media (max-width: 575.98px) { .hello { padding: 1.1rem 1.1rem 1rem; } }
.hello-side .hello-focus { display: block; }
.hello-side .hello-focus .dot { display: inline-block; vertical-align: 1px; margin-right: .3rem; }

/* ---------- บทบาทและสิทธิ์ (Permission Matrix) ---------- */
.rm-legend { list-style: none; margin: 0 0 .85rem; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: .85rem; color: var(--muted); }
.rm-legend li { display: inline-flex; align-items: center; gap: .45rem; }
.rm-key { width: 22px; height: 22px; border-radius: 7px; display: inline-grid; place-items: center; font-size: .72rem; }
.rm-key.k-std { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.rm-key.k-ovr { background: var(--stamp-soft); color: var(--stamp); }
.rm-key.k-own { background: color-mix(in srgb, #7C3AED 14%, var(--surface)); color: #7C3AED; }
.rm-key.k-cen { background: var(--warn-soft); color: var(--warn); }

.rm-table th, .rm-table td { vertical-align: middle; }
.rm-table .rm-perm-h { min-width: 260px; text-align: left; vertical-align: bottom; position: sticky; left: 0; z-index: 2; background: var(--surface); }
.rm-groups th { padding: .45rem .5rem; border-bottom: 0; }
.rm-grp.g-std { background: var(--surface-2); }
.rm-grp.g-own { background: color-mix(in srgb, #7C3AED 8%, var(--surface)); }
.rm-toggle { display: inline-flex; align-items: center; gap: .4rem; border: 0; background: transparent; font-weight: 700; font-size: .88rem; color: var(--text); padding: .2rem .5rem; border-radius: 8px; white-space: nowrap; }
.rm-toggle:hover { background: color-mix(in srgb, var(--stamp) 10%, transparent); color: var(--stamp); }
.rm-toggle .rm-n { min-width: 1.5rem; padding: 0 .4rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .75rem; font-weight: 600; color: var(--muted); }
.rm-ph { display: none; }
.rm-table.hide-std .col-std, .rm-table.hide-std .g-std:not(.rm-ph) { display: none; }
.rm-table.hide-std .ph-std { display: table-cell; }
.rm-table.hide-own .col-own, .rm-table.hide-own .g-own:not(.rm-ph) { display: none; }
.rm-table.hide-own .ph-own { display: table-cell; }
.rm-table td.rm-ph { background: var(--surface-2); min-width: 150px; }

.rm-roles th { min-width: 118px; font-size: .88rem; padding: .55rem .45rem .6rem; border-top: 3px solid transparent; }
.rm-roles th.m-standard { border-top-color: var(--line); }
.rm-roles th.m-override { border-top-color: var(--stamp); background: color-mix(in srgb, var(--stamp-soft) 70%, var(--surface)); }
.rm-roles th.m-custom { border-top-color: #7C3AED; background: color-mix(in srgb, #7C3AED 7%, var(--surface)); }
.rm-roles .rm-sub { font-size: .74rem; font-weight: 500; color: var(--muted); white-space: nowrap; }
.rm-roles .rm-lock { color: var(--muted); font-size: .75rem; }
.role-head { display: flex; align-items: center; justify-content: center; gap: .3rem; }
.rm-acts { margin-top: .35rem; }
.rm-act { display: inline-flex; align-items: center; gap: .25rem; border: 1px solid var(--line); background: var(--surface); color: var(--stamp); font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
.rm-act:hover { background: var(--stamp-soft); border-color: color-mix(in srgb, var(--stamp) 40%, var(--line)); }
.rm-act.is-danger { color: var(--seal); }
.rm-act.is-danger:hover { background: var(--seal-soft); border-color: color-mix(in srgb, var(--seal) 40%, var(--line)); }
.rm-table td.is-locked { background: var(--surface-2); }
.rm-table td.m-override { background: color-mix(in srgb, var(--stamp-soft) 35%, var(--surface)); }
.rm-table td.m-custom { background: color-mix(in srgb, #7C3AED 4%, var(--surface)); }
.rm-sec td { font-weight: 600; color: var(--stamp); background: var(--surface-2) !important; padding-top: .7rem; }

/* ช่องติ๊ก: ที่แก้ได้ต้องเห็นชัด ที่ล็อกจาง */
.rm-cb { width: 1.2em; height: 1.2em; cursor: pointer; border: 2px solid color-mix(in srgb, var(--stamp) 55%, var(--line)); }
.rm-cb:checked { background-color: var(--stamp); border-color: var(--stamp); }
.rm-cb:hover:not(:disabled) { box-shadow: 0 0 0 4px color-mix(in srgb, var(--stamp) 15%, transparent); }
.rm-cb:disabled { cursor: not-allowed; opacity: .55; border-width: 1px; border-color: var(--line); }
.rm-cb:disabled:checked { background-color: color-mix(in srgb, var(--muted) 70%, var(--surface)); border-color: transparent; }
.rm-roles th:first-child { position: static; text-align: center; background: inherit; }

/* หน้าหลัก "เรื่องที่รอคุณ": ปุ่มไปเมนูงาน / หนังสือเวียน */
.mq-split { display: flex; flex-wrap: wrap; gap: .5rem; }
.mq-go { display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .85rem; border-radius: 10px; font-size: .9rem; font-weight: 600; text-decoration: none; color: #fff; background: var(--stamp); transition: transform .15s, filter .15s; }
.mq-go b { min-width: 1.5rem; padding: 0 .4rem; border-radius: 999px; background: rgba(255,255,255,.22); text-align: center; }
.mq-go:hover { color: #fff; filter: brightness(1.08); transform: translateY(-1px); }
.mq-go.is-circ { background: #EA8C00; }

/* ---------- หน้ารวมรายงาน: การ์ดสีประจำรายงาน ---------- */
.rp-group { margin-bottom: 1.5rem; }
.rp-group-title { display: flex; align-items: center; gap: .5rem; font-size: 1.02rem; font-weight: 700; margin: 0 0 .75rem; }
.rp-group-title i { color: var(--stamp); }
.rp-group-title span { font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 .5rem; }
.rp-grid { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 1rem; }
.rp-card {
  --c: #2563EB;
  position: relative; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; gap: .3rem; min-height: 168px;
  padding: 1.1rem 1.15rem 1rem; border-radius: 16px; text-decoration: none; color: var(--text);
  background: radial-gradient(130% 110% at 100% 0%, color-mix(in srgb, var(--c) 16%, transparent) 0%, transparent 55%), var(--surface);
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--line)); box-shadow: 0 6px 16px -12px color-mix(in srgb, var(--c) 60%, transparent);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s, border-color .25s;
  animation: rp-in .5s cubic-bezier(.2,.8,.2,1) var(--d, 0ms) both;
}
.rp-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 35%, #fff)); }
.rp-card::after { content: ""; position: absolute; top: 0; bottom: 0; left: -70%; width: 45%; z-index: 2; pointer-events: none; background: linear-gradient(100deg, transparent, rgba(255,255,255,.45), transparent); transform: skewX(-18deg); }
.rp-card:hover { color: var(--text); transform: translateY(-4px); border-color: color-mix(in srgb, var(--c) 50%, var(--line)); box-shadow: 0 18px 30px -16px color-mix(in srgb, var(--c) 75%, transparent); }
.rp-card:hover::after { animation: rp-shine .8s ease; }
.rp-ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 1.25rem; color: #fff; margin-bottom: .45rem;
  background: linear-gradient(140deg, color-mix(in srgb, var(--c) 65%, #fff), var(--c)); box-shadow: 0 8px 16px -8px var(--c); transition: transform .3s; }
.rp-card:hover .rp-ico { transform: rotate(-8deg) scale(1.08); }
.rp-name { font-weight: 700; font-size: 1.02rem; line-height: 1.35; }
.rp-desc { font-size: .84rem; color: var(--muted); line-height: 1.45; flex: 1; }
.rp-go { margin-top: .35rem; font-size: .82rem; font-weight: 600; color: var(--c); display: inline-flex; align-items: center; gap: .3rem; }
.rp-go i { transition: transform .2s; }
.rp-card:hover .rp-go i { transform: translateX(4px); }
.rp-bg { position: absolute; right: -.6rem; bottom: -1.1rem; z-index: -1; font-size: 5.2rem; line-height: 1; color: var(--c); opacity: .07; transform: rotate(-12deg); transition: opacity .3s, transform .4s; }
.rp-card:hover .rp-bg { opacity: .14; transform: rotate(-4deg) scale(1.06); }
@keyframes rp-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes rp-shine { to { left: 130%; } }
[data-bs-theme="dark"] .rp-card::after { background: linear-gradient(100deg, transparent, rgba(255,255,255,.12), transparent); }
@media (max-width: 1199.98px) {
  .rp-grid { grid-template-columns: minmax(0, 1fr); gap: .6rem; }
  .rp-card { min-height: 0; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: .9rem; row-gap: .1rem; align-items: center; padding: .85rem 1rem; }
  .rp-ico { grid-row: 1 / 3; margin: 0; width: 42px; height: 42px; font-size: 1.1rem; }
  .rp-name { grid-column: 2; } .rp-desc { grid-column: 2; }
  .rp-go { grid-column: 3; grid-row: 1 / 3; margin: 0; font-size: 0; } .rp-go i { font-size: 1.1rem; }
  .rp-bg { font-size: 3.8rem; }
}
@media (prefers-reduced-motion: reduce) { .rp-card, .rp-card *, .rp-card::after { animation: none !important; transition: none !important; } }

/* Admin ทั้งระบบ: โรงเรียนที่กำลังเข้าดู (เมนูข้าง + แถบบน) */
.nav-school { --sc: #2446C7; position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .1rem .5rem; margin: 1rem .75rem .35rem; padding: .55rem .6rem .55rem .85rem; border-radius: 12px;
  background: color-mix(in srgb, var(--sc) 35%, rgba(255,255,255,.06)); border: 1px solid rgba(255,255,255,.18); box-shadow: inset 4px 0 0 var(--sc); }
.nav-school .ns-label { grid-column: 1; font-size: .68rem; font-weight: 700; letter-spacing: .04em; color: var(--sb-accent, #F5B301); }
.nav-school .ns-name { grid-column: 1; font-size: .86rem; font-weight: 700; color: #fff; line-height: 1.3; }
.nav-school form { grid-column: 2; grid-row: 1 / 3; margin: 0; }
.nav-school .ns-exit { width: 28px; height: 28px; border-radius: 8px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; display: grid; place-items: center; font-size: .8rem; }
.nav-school .ns-exit:hover { background: rgba(255,255,255,.25); }
.school-chip.is-viewing { box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 55%, transparent); }
.school-chip.is-viewing .s-aff { color: var(--warn); font-weight: 600; }
.school-chip.is-global .school-dot { background: linear-gradient(135deg, #1D4ED8, #7C3AED); color: #fff; }
/* ผู้ใช้งานทั้งระบบ: แถวโรงเรียนของผู้ใช้ */
.ua-school { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: .5rem; align-items: center; padding: .3rem 0; margin: 0; }
.ua-school + .ua-school { border-top: 1px dashed var(--line); }
.ua-dot { width: 10px; height: 10px; border-radius: 50%; grid-row: 1 / 3; }
.ua-name { font-weight: 600; font-size: .9rem; }
.ua-roles { grid-column: 2; font-size: .8rem; color: var(--muted); }
.ua-school .btn { grid-column: 3; grid-row: 1 / 3; }

/* ==========================================================================
   ส่งออกระบบ (admin/export): การ์ดเลือกชนิดไล่สี + ขั้นตอนคำสั่งบน Server
   ========================================================================== */
.xp-modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem; }
.xp-mode {
  --g1: #3B82F6; --g2: #1D4ED8; position: relative; display: flex; flex-direction: column; gap: .35rem; height: 100%; margin: 0;
  padding: 1.1rem 1.15rem; border-radius: 16px; cursor: pointer; color: #fff; background: linear-gradient(135deg, var(--g1), var(--g2));
  box-shadow: 0 10px 24px -16px var(--g2); opacity: .78; transition: transform .2s, box-shadow .2s, opacity .2s;
}
.xp-mode.tone-violet { --g1: #A78BFA; --g2: #6D28D9; }
.xp-mode.tone-orange { --g1: #FBBF24; --g2: #EA580C; }
.xp-mode:hover { opacity: 1; transform: translateY(-3px); box-shadow: 0 16px 30px -16px var(--g2); }
.btn-check:checked + .xp-mode { opacity: 1; box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--g2), 0 16px 30px -16px var(--g2); }
.btn-check:checked + .xp-mode::after { content: "\F26A"; font-family: "bootstrap-icons"; position: absolute; top: .9rem; right: 1rem; font-size: 1.25rem; }
.btn-check:focus-visible + .xp-mode { outline: 3px solid var(--g2); outline-offset: 4px; }
.xp-top { display: flex; align-items: center; gap: .5rem; }
.xp-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, .2); font-size: 1.25rem; }
.xp-badge { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: rgba(255, 255, 255, .25); }
.xp-mode b { font-size: 1.08rem; margin-top: .35rem; }
.xp-desc { font-size: .86rem; color: rgba(255, 255, 255, .9); line-height: 1.45; }
.xp-size { margin-top: auto; padding-top: .5rem; font-size: .8rem; color: rgba(255, 255, 255, .85); }
.xp-since { display: none; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-top: 1rem; padding: .8rem 1rem; border-radius: 12px; background: var(--warn-soft); }
.xp-since.is-open { display: flex; }
.xp-since .form-control { width: auto; }
.xp-file { display: flex; gap: .8rem; align-items: center; padding: .85rem 1rem; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.xp-file-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; color: #fff; font-size: 1.35rem; background: linear-gradient(135deg, #A78BFA, #6D28D9); }
.xp-file-ico.tone-blue { background: linear-gradient(135deg, #3B82F6, #1D4ED8); }
.xp-file-ico.tone-orange { background: linear-gradient(135deg, #FBBF24, #EA580C); }
.xp-safe { list-style: none; margin: 1.25rem 0 0; padding: 1rem 0 0; border-top: 1px dashed var(--line); display: grid; gap: .5rem; font-size: .88rem; color: var(--muted); }
.xp-safe i { color: var(--ok); margin-right: .35rem; }
.xp-steps { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .85rem; }
.xp-steps li { display: flex; gap: .75rem; align-items: flex-start; }
.xp-steps p { margin: .1rem 0 .35rem; font-weight: 600; font-size: .92rem; }
.xp-n { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: #fff; background: linear-gradient(135deg, #3B82F6, #7C3AED); }
.xp-cmd { display: flex; gap: .4rem; align-items: stretch; }
.xp-cmd code { flex: 1; min-width: 0; padding: .5rem .7rem; border-radius: 8px; background: #0F172A; color: #E2E8F0; font-size: .8rem; word-break: break-all; }
.min-w-0 { min-width: 0; }
@media (max-width: 991.98px) { .xp-modes { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { .xp-mode { transition: none; } .xp-mode:hover { transform: none; } }

/* ---------- สำรองข้อมูล: กู้คืน ---------- */
.bk-ico-restore { background: linear-gradient(135deg, #A78BFA, #6D28D9); }
.btn-restore { background: var(--warn-soft); color: var(--warn); border: 1px solid transparent; }
.btn-restore:hover { background: var(--warn); color: #fff; }
.rs-head { background: linear-gradient(135deg, #F59E0B, #DC2626); color: #fff; border-bottom: 0; gap: .8rem; }
.rs-head .modal-title { color: #fff; }
.rs-head .small { color: rgba(255, 255, 255, .85); word-break: break-all; }
.rs-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; background: rgba(255, 255, 255, .2); font-size: 1.25rem; }
.rs-warn { display: flex; gap: .7rem; padding: .85rem 1rem; border-radius: 12px; background: var(--seal-soft); color: var(--text); margin-bottom: .9rem; font-size: .92rem; }
.rs-warn > i { color: var(--seal); font-size: 1.15rem; }
.rs-safe { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .35rem; font-size: .88rem; color: var(--muted); }
.rs-safe i { color: var(--ok); margin-right: .35rem; }
.rs-safe li:last-child i { color: var(--warn); }
/* Admin โรงเรียน: การ์ดสำรองข้อมูลใบเดียวแบบแนวนอนเต็มแถว */
@media (min-width: 768px) {
  .bk-wide { flex-direction: row !important; align-items: center; gap: 1rem; }
  .bk-wide .bk-head { margin: 0; flex: 1; }
  .bk-wide .mt-auto { display: none; }
  .bk-wide .btn { width: auto !important; white-space: nowrap; }
}
.bk-acts { flex-wrap: wrap; }
.bk-acts .btn { white-space: nowrap; }
@media (min-width: 992px) { .bk-acts { flex-wrap: nowrap; } }

/* ---------- ตั้งค่าระบบ: ปิดบัญชีทดสอบ ---------- */
.ta-card { border-color: color-mix(in srgb, var(--seal) 35%, var(--line)); }
.ta-card .card-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: linear-gradient(135deg, var(--seal-soft), var(--warn-soft)); }
.ta-count { font-size: .82rem; font-weight: 600; color: var(--seal); background: var(--surface); border-radius: 999px; padding: .15rem .65rem; }
.ta-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.ta-chip { font-family: ui-monospace, monospace; font-size: .8rem; padding: .2rem .55rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.ta-chip.is-me { border-color: var(--warn); color: var(--warn); }
.ta-card.is-off { border-color: var(--line); }
.ta-card.is-off .card-header { background: linear-gradient(135deg, var(--ok-soft), var(--surface-2)); }
.ta-card.is-off .ta-count { color: var(--ok); }
.ta-chip.is-closed { text-decoration: line-through; opacity: .6; }

/* แก้ข้อความเกษียณ: แจ้งผู้รับงานถัดไป (ผู้แก้เลือกเอง) */
.note-notify { display: flex; gap: .6rem; margin-top: .9rem; padding: .75rem .9rem; border-radius: 12px; background: var(--stamp-soft); font-size: .9rem; }
.note-notify > i { color: var(--stamp); font-size: 1.1rem; }
/* การ์ด "คุณดำเนินการแล้ว": อธิบายความต่างของ แก้ไขข้อความ / เปิดเรื่องใหม่ */
.done-help { list-style: none; margin: .55rem 0 0; padding: .6rem .75rem; border-radius: 10px; background: var(--surface-2); font-size: .84rem; color: var(--muted); display: grid; gap: .3rem; }
.done-help b { color: var(--text); font-weight: 600; }

/* ---------- ล็อกหนังสือที่ปิดเรื่องแล้ว ---------- */
.chip-lock { background: #1F2937; color: #fff; }
.chip-unlock { background: var(--warn-soft); color: var(--warn); }
.lock-bar { display: flex; align-items: center; gap: .85rem; margin: 0 0 1rem; padding: .8rem 1rem; border-radius: 14px; color: #fff;
  background: linear-gradient(135deg, #334155, #0F172A); box-shadow: 0 10px 22px -16px rgba(15, 23, 42, .8); }
.lock-bar.is-temp { background: linear-gradient(135deg, #F59E0B, #D97706); }
.lock-bar .small { color: rgba(255, 255, 255, .8); }
.lock-ico { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; font-size: 1.15rem; background: rgba(255, 255, 255, .15); }
@media (max-width: 575.98px) { .lock-bar { flex-wrap: wrap; } }
[data-bs-theme="dark"] .chip-lock { background: #E5E7EB; color: #111827; }

/* ตั้งค่าโรงเรียน: ตัวช่วยประกอบรูปแบบเลข (กำหนดเอง) */
.fmt-builder { padding: .7rem .8rem; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface-2); }
.fb-parts { display: flex; flex-wrap: wrap; gap: .35rem; min-height: 32px; align-items: center; margin-bottom: .55rem; }
.fb-chip { display: inline-flex; align-items: center; gap: .25rem; padding: .2rem .25rem .2rem .6rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .85rem; }
.fb-chip.is-var { background: var(--stamp-soft); border-color: transparent; color: var(--stamp); font-weight: 600; }
.fb-chip button { border: 0; background: none; color: inherit; opacity: .6; width: 20px; height: 20px; border-radius: 50%; line-height: 1; padding: 0; }
.fb-chip button:hover { opacity: 1; background: rgba(0, 0, 0, .08); }
.fb-add { display: flex; flex-wrap: wrap; gap: .3rem; }
.fb-add > button, .fb-text button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: .2rem .55rem; font-size: .82rem; }
.fb-add > button:hover, .fb-text button:hover { border-color: var(--stamp); color: var(--stamp); }
.fb-text { display: inline-flex; gap: .25rem; }
.fb-text input { width: 110px; }
.fb-preview { margin-top: .55rem; font-size: .88rem; color: var(--muted); }
.fb-preview b { color: var(--text); font-family: var(--font-head); }
.fb-warn { color: var(--seal); }

/* Timeline: ไอคอนการแจ้งเตือน (กระดิ่ง / Telegram) */
.tl-notice { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.tl-nb { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; cursor: help; }
.tl-nb.is-bell { background: var(--warn-soft); color: var(--warn); }
.tl-nb.is-tg { background: #E6F4FB; color: #1C8ACB; }
.tl-nb.is-tg.is-wait { background: var(--surface-2); color: var(--muted); }
.tl-nb.is-tg.is-fail { background: var(--seal-soft); color: var(--seal); }
[data-bs-theme="dark"] .tl-nb.is-tg { background: #12303F; color: #5EC2F5; }

/* หนังสือรอพิจารณา: เลือกหลายเรื่อง → ทราบและปิดเรื่องพร้อมกัน */
.mq-chk { width: 42px; text-align: center; }
.mq-chk .form-check-input { position: relative; z-index: 2; width: 1.15rem; height: 1.15rem; cursor: pointer; }
.rv-bar { position: sticky; bottom: 12px; z-index: 30; margin-top: 1rem; padding: .85rem 1rem; border-radius: 16px; color: #fff;
  background: linear-gradient(135deg, #1D4ED8, #6D28D9); box-shadow: 0 18px 36px -18px rgba(29, 78, 216, .8); animation: rvIn .2s ease-out; }
@keyframes rvIn { from { transform: translateY(12px); opacity: 0; } }
.bb-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; margin-bottom: .55rem; }
.bb-head .small { color: rgba(255, 255, 255, .85); }
.bb-count { font-weight: 600; }
.bb-clear { color: #fff; margin-left: auto; text-decoration: underline; }
.bb-phr { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }
.bb-phr .chip-btn { border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .12); color: #fff; border-radius: 999px; padding: .15rem .65rem; font-size: .82rem; }
.bb-phr .chip-btn:hover { background: rgba(255, 255, 255, .25); }
.bb-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.bb-row textarea { flex: 1 1 260px; min-height: 42px; }
.bb-embed { margin: 0; color: #fff; white-space: nowrap; }
.bb-row .btn-primary { background: #fff; color: #1D4ED8; border: 0; font-weight: 600; }
.bb-row .btn-primary:hover { background: #EEF2FF; color: #1E40AF; }
.rv-bar .text-muted { color: rgba(255, 255, 255, .8) !important; }
@media (max-width: 767.98px) { .rv-bar { bottom: 76px; } }
@media (prefers-reduced-motion: reduce) { .rv-bar { animation: none; } }

/* ตั้งค่าระบบ: การ์ดในแถวเดียวกันสูงเท่ากัน ปุ่มบันทึกอยู่ต่อจากช่องกรอก (ไม่ดันลงล่าง) */
.sys-grid > [class*="col-"] > .card{margin-bottom:0}
.sys-grid > [class*="col-"] > .card > ul{flex:1 1 auto;display:flex;flex-direction:column}
.sys-grid > [class*="col-"] > .card > ul > li{flex:1 1 auto;align-items:center}
.sys-grid > [class*="col-"] > .card > ul > li:last-child{border-bottom:0!important}
/* รายการตรวจสุขภาพ 2 คอลัมน์ ให้การ์ดเตี้ยลงเท่าการ์ด "ทั่วไป" */
.sys-grid .sys-checks{display:grid!important;grid-template-columns:1fr;align-content:stretch}
.sys-grid .sys-checks > li{border-bottom:1px solid var(--bs-border-color)!important;min-width:0;gap:.5rem}
.sys-grid .sys-checks > li > span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sys-grid .sys-checks > li > span:last-child{flex:none;white-space:nowrap}
@media (min-width:576px){
  .sys-grid .sys-checks{grid-template-columns:1fr 1fr}
  .sys-grid .sys-checks > li:nth-child(odd){border-right:1px solid var(--bs-border-color)}
  .sys-grid .sys-checks > li:nth-last-child(-n+2):nth-child(odd),.sys-grid .sys-checks > li:last-child{border-bottom:0!important}
}
@media (min-width:576px){.sys-grid .sys-checks > li:last-child:nth-child(odd){grid-column:1/-1;border-right:0}}
.sys-grid > [class*="col-"] > .card > .card-body,.sys-grid > [class*="col-"] > form.card > .card-body{flex:0 0 auto}

/* Timeline แบบการ์ด (หน้ารายละเอียดหนังสือ): รวมการกระทำต่อเนื่องเป็นการ์ดเดียว · การแก้ไขแยกการ์ดสีเหลือง */
.tg-list::before{top:2.2rem}
.tg-day{position:relative;margin:0 0 .75rem;padding-left:3rem}
.tg-day:not(:first-child){margin-top:.25rem}
.tg-day span{display:inline-block;font-size:.76rem;font-weight:600;color:var(--muted);background:var(--surface-2);border:1px solid var(--line);border-radius:999px;padding:.1rem .65rem}
.tg-item{position:relative;padding:0 0 .9rem 3rem}
.tg-item:last-child{padding-bottom:0}
.tg-item.c-warning .tl-ico{border-color:var(--warn);color:var(--warn);background:var(--warn-soft)}
.tg-item.c-primary .tl-ico{border-color:var(--stamp);color:var(--stamp);background:var(--stamp-soft)}
.tg-item.c-success .tl-ico{border-color:var(--ok);color:var(--ok);background:var(--ok-soft)}
.tg-item.c-danger .tl-ico{border-color:var(--seal);color:var(--seal);background:var(--seal-soft)}
.tg-item.c-info .tl-ico{border-color:#2C8CB8;color:#2C8CB8;background:color-mix(in srgb,#2C8CB8 12%,var(--surface))}
.tg-item.c-dark .tl-ico{border-color:var(--text);color:var(--text)}
.tg-card{background:var(--surface);border:1px solid var(--line);border-left:3px solid var(--line);border-radius:12px;padding:.6rem .8rem;transition:box-shadow .2s,transform .2s}
.tg-item.c-primary .tg-card{border-left-color:var(--stamp)}
.tg-item.c-success .tg-card{border-left-color:var(--ok)}
.tg-item.c-info .tg-card{border-left-color:#2C8CB8}
.tg-item.c-dark .tg-card{border-left-color:var(--text)}
.tg-item.c-danger .tg-card{border-left-color:var(--seal)}
.tg-item.is-edit .tg-card{border-left-color:var(--warn);background:color-mix(in srgb,var(--warn) 6%,var(--surface))}
@media (hover:hover) and (prefers-reduced-motion:no-preference){.tg-card:hover{box-shadow:0 6px 18px rgba(15,23,42,.08);transform:translateX(2px)}}
.tg-head{display:flex;justify-content:space-between;align-items:baseline;gap:.5rem}
.tg-title{font-weight:700;font-size:.95rem}
.tg-time{font-size:.78rem;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}
.tg-who{font-size:.84rem;color:var(--muted);margin-bottom:.3rem}
.tg-lines{list-style:none;margin:0;padding:0;display:grid;gap:.3rem}
.tg-line{display:flex;align-items:flex-start;gap:.45rem;font-size:.88rem;line-height:1.45}
.tg-line.is-sys{color:var(--muted);font-size:.8rem}
.tg-tag{flex:none;font-size:.7rem;font-weight:600;border-radius:6px;padding:.08rem .4rem;margin-top:.12rem;background:var(--surface-2);color:var(--muted);min-width:4.2rem;text-align:center}
.tg-tag.t-primary{background:var(--stamp-soft);color:var(--stamp)}
.tg-tag.t-success{background:var(--ok-soft);color:var(--ok)}
.tg-tag.t-info{background:color-mix(in srgb,#2C8CB8 12%,var(--surface));color:#2C8CB8}
.tg-tag.t-warning{background:var(--warn-soft);color:var(--warn)}
.tg-tag.t-danger{background:var(--seal-soft);color:var(--seal)}
.tg-tag.t-dark{background:var(--surface-2);color:var(--text)}
.tg-text{min-width:0;overflow-wrap:anywhere}
.tg-quote{min-width:0;overflow-wrap:anywhere;white-space:pre-line;background:var(--surface-2);border-radius:8px;padding:.15rem .5rem;font-style:normal}
.tg-quote::before{content:"“";color:var(--muted)}
.tg-quote::after{content:"”";color:var(--muted)}
.tg-card .tl-notice{margin-top:.45rem}
/* ตำแหน่งผู้กระทำในการ์ด Timeline (สีตามบทบาท) */
.tg-who{display:flex;flex-wrap:wrap;align-items:center;gap:.25rem .45rem}
.tg-pos{font-size:.72rem;font-weight:600;border-radius:999px;padding:.05rem .55rem;background:var(--surface-2);color:var(--muted);border:1px solid var(--line)}
.tg-pos.r-director{background:#EDE9FE;color:#6D28D9;border-color:#DDD6FE}
.tg-pos.r-deputy{background:#E0E7FF;color:#4338CA;border-color:#C7D2FE}
.tg-pos.r-head{background:#DCFCE7;color:#15803D;border-color:#BBF7D0}
.tg-pos.r-clerk{background:#DBEAFE;color:#1D4ED8;border-color:#BFDBFE}
.tg-pos.r-admin{background:#FEF3C7;color:#B45309;border-color:#FDE68A}
[data-bs-theme="dark"] .tg-pos.r-director{background:#2E1F55;color:#C4B5FD;border-color:#4C3A8A}
[data-bs-theme="dark"] .tg-pos.r-deputy{background:#232A5C;color:#A5B4FC;border-color:#3A4390}
[data-bs-theme="dark"] .tg-pos.r-head{background:#13351F;color:#86EFAC;border-color:#1F5A33}
[data-bs-theme="dark"] .tg-pos.r-clerk{background:#172B52;color:#93C5FD;border-color:#284B85}
[data-bs-theme="dark"] .tg-pos.r-admin{background:#3A2A0E;color:#FCD34D;border-color:#5E4415}

/* Stamp Designer: ตั้งค่าซ้าย (แบ่งการ์ดตามหมวด) · หน้ากระดาษ A4 ขวา ตรึงไว้ขณะเลื่อน */
.sd-settings{display:flex;flex-direction:column;gap:1rem}
.sd-settings > .card{margin:0}
.sd-settings .card-header h2 .small{font-size:.8rem}
@media (min-width:992px){
  /* ตรึงใต้แถบหัว (ไม่ถูกบัง) และย่อกระดาษให้ทั้งแผ่นพอดีความสูงจอ — stamp-designer.js คำนวณสเกลจากความกว้างจริง */
  .sd-preview{position:sticky;top:calc(var(--topbar-h) + 1rem)}
  .sd-preview .designer-page{max-width:min(520px, calc((100vh - var(--topbar-h) - 4.5rem) * 210 / 297))}
}
.sd-hints{list-style:none;margin:.5rem 0 0;padding:0;display:grid;gap:.2rem}
.sd-hints i{width:1.1rem;display:inline-block}

/* ฟอนต์เดียวกับ PDF (mPDF ใช้ไฟล์ชุดนี้) — ตัวอย่างตราบนจอจึงตรงกับ PDF จริง · โหลดเฉพาะหน้าที่ใช้ */
@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap; src: url("../fonts/pdf/Sarabun-Regular.ttf") format("truetype"); }
@font-face { font-family: "Sarabun"; font-weight: 700; font-display: swap; src: url("../fonts/pdf/Sarabun-Bold.ttf") format("truetype"); }
/* HTML ตัวอย่างตรา (PdfService::stampHtml / noteStyledHtml) เขียนขนาดแบบ content-box ตาม mPDF — ไม่ใช้ border-box ของ Bootstrap */
.stamp-real, .stamp-real * { box-sizing: content-box; }
.stamp-real table { border-spacing: 0; }
.stamp-real td { padding-left: 0; } /* style ในแท็กที่กำหนด padding-left เองยังมีผลเหนือกว่า */
/* ปุ่มเฉดสีราชการ (Stamp Designer) */
.sd-official{display:flex;align-items:center;justify-content:center;gap:.5rem}
.sd-swatch{width:1rem;height:1rem;border-radius:4px;background:#1D3FBF;box-shadow:0 0 0 2px #fff,0 0 0 3px #1D3FBF}
.sd-official-ok{display:none;font-size:.8rem;font-weight:600;color:var(--ok)}
.sd-official.is-on .sd-official-ok{display:inline-flex;gap:.25rem;align-items:center}
@media (prefers-reduced-motion:no-preference){.sd-official{transition:transform .15s}.sd-official:active{transform:scale(.98)}}
/* หน้าตรา: หัวหมวด (ตรารับ / ตราเกษียณ) มีเส้นสีนำสายตา */
.stamp-sec{border-left:4px solid var(--stamp);padding-left:.85rem;margin-bottom:1rem}
/* หน้าตรา: แถบปุ่มท้ายการ์ดไม่ยืด → ปุ่ม "ออกแบบ" ชิดล่างระดับเดียวกันทุกใบ */
.stamp-sec + .row > [class*="col-"] > .card > .card-body.border-top { flex: 0 0 auto; }
/* Stamp Designer: ปุ่มเลือกแนว 2 กลุ่มในแถวเดียวกัน — ปุ่มกว้างเท่ากัน ย่อตามช่อง ไม่ล้นการ์ด */
.sd-align .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.sd-align .seg-btn { justify-content: center; text-align: center; white-space: nowrap; padding-left: .4rem; padding-right: .4rem; min-width: 0; }
@media (min-width:992px) and (max-width:1299.98px){ .sd-align .seg-btn i { display: none; } } /* จอแคบ: เหลือแต่ข้อความ ไม่เบียด */
/* ตราเกษียณ การ์ดข้อความ: ปุ่มจัดแนว 4 ปุ่มกว้างเท่ากันเต็มแถว */
.nd-body-align .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.nd-body-align .seg-btn { justify-content: center; text-align: center; white-space: nowrap; min-width: 0; padding-left: .4rem; padding-right: .4rem; }
/* ตราเกษียณ การ์ดข้อความ: สวิตช์เรียงเป็นช่องเท่ากัน สูงเท่าช่องกรอก */
.nd-switches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.nd-switches .form-check, .nd-switch-box .form-check { margin: 0; display: flex; align-items: center; gap: .55rem; min-height: calc(1.5em + .75rem + 2px); padding: .375rem .75rem; border: 1px solid var(--line); border-radius: var(--bs-border-radius, .5rem); background: var(--surface); }
.nd-switches .form-check-input, .nd-switch-box .form-check-input { float: none; margin: 0; flex: none; }
.nd-switches .form-check-label, .nd-switch-box .form-check-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 575.98px) { .nd-switches { grid-template-columns: 1fr; } }
/* ตราเกษียณ ส่วนลงนาม: รูปแบบวันที่ + จัดแนว แถวเดียวกัน ปุ่มยืดเต็มช่อง · ที่ไม่พอ (จอ 992–1399px) แยกแถว ยังยืดเต็ม */
.nd-sign-line { display: grid; grid-template-columns: 7fr 5fr; gap: 1rem; }
.nd-sign-line .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.nd-sign-line .seg-btn { justify-content: center; text-align: center; white-space: nowrap; min-width: 0; }
@media (max-width: 575.98px), (min-width: 992px) and (max-width: 1399.98px) { .nd-sign-line { grid-template-columns: 1fr; } }
/* ช่องสี + รหัสสี (หน้าออกแบบตรา) */
.color-hex { display: flex; gap: .4rem; }
.color-hex .form-control-color { width: 3.25rem !important; flex: none; padding: .3rem; }
.color-hex-code { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; text-transform: uppercase; letter-spacing: .02em; }

/* ===== ภาพรวม Server (admin/server) ===== */
:root { --srv-ok: #16A34A; --srv-warn: #D97706; --srv-bad: #DC2626; --srv-na: #94A3B8; }
[data-bs-theme="dark"] { --srv-ok: #4ADE80; --srv-warn: #FBBF24; --srv-bad: #F87171; --srv-na: #94A3B8; }
.srv-hero { --c: var(--srv-ok); display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 1.1rem 1.35rem; margin-bottom: 1rem; border-radius: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(120deg, color-mix(in srgb, var(--c) 92%, #000), color-mix(in srgb, var(--c) 70%, #2563EB)); box-shadow: 0 10px 28px color-mix(in srgb, var(--c) 28%, transparent); }
.srv-hero.is-warn { --c: var(--srv-warn); } .srv-hero.is-bad { --c: var(--srv-bad); } .srv-hero.is-na { --c: var(--srv-na); }
.srv-hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(255,255,255,.1); }
.srv-hero-ico { width: 3.2rem; height: 3.2rem; border-radius: 14px; display: grid; place-items: center; font-size: 1.6rem; background: rgba(255,255,255,.18); flex: none; }
.srv-hero-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.srv-hero-txt b { font-size: 1.25rem; }
.srv-hero-txt span { font-size: .85rem; opacity: .9; }
.srv-hero-sum { display: flex; gap: .4rem; flex-wrap: wrap; position: relative; z-index: 1; }
.srv-hero-sum .srv-pill { background: rgba(255,255,255,.92) !important; font-size: .78rem; padding: .25rem .65rem; margin: 0; }
@media (prefers-reduced-motion: no-preference) { .srv-hero.is-bad .srv-hero-ico { animation: srvBlink 1.6s ease-in-out infinite; } }
@keyframes srvBlink { 50% { background: rgba(255,255,255,.32); } }
.srv-pill { display: inline-flex; align-items: center; gap: .35rem; border-radius: 999px; font-weight: 700; white-space: nowrap; padding: .1rem .55rem; font-size: .72rem; }
.srv-dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; flex: none; }
.srv-pill.s-ok { color: var(--srv-ok); background: color-mix(in srgb, var(--srv-ok) 13%, transparent); }
.srv-pill.s-warn { color: var(--srv-warn); background: color-mix(in srgb, var(--srv-warn) 14%, transparent); }
.srv-pill.s-bad { color: var(--srv-bad); background: color-mix(in srgb, var(--srv-bad) 13%, transparent); }
.srv-pill.s-na { color: var(--srv-na); background: color-mix(in srgb, var(--srv-na) 15%, transparent); }
.srv-pill.is-old { opacity: .65; font-weight: 600; }
.srv-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 1199.98px) { .srv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 575.98px) { .srv-grid { grid-template-columns: 1fr; } }
.srv-tile { --c: var(--srv-ok); display: flex; flex-direction: column; gap: .55rem; padding: 1rem 1.1rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm, 0 1px 2px rgba(15,23,42,.05)); position: relative; overflow: hidden; min-width: 0; }
.srv-tile::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 55%, #fff), var(--c)); }
.srv-tile.s-warn { --c: var(--srv-warn); } .srv-tile.s-bad { --c: var(--srv-bad); } .srv-tile.s-na { --c: var(--srv-na); }
@media (prefers-reduced-motion: no-preference) { .srv-tile { transition: transform .2s, box-shadow .2s; } .srv-tile:hover { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(15,23,42,.09); } }
.srv-tile-top { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.srv-tile-top .srv-pill { margin-left: auto; }
.srv-ico { width: 2.3rem; height: 2.3rem; border-radius: 11px; display: grid; place-items: center; flex: none; color: #fff; font-size: 1.05rem; background: linear-gradient(135deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c)); }
.srv-title { font-weight: 700; font-size: .95rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srv-val { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.srv-bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.srv-bar.is-empty { visibility: hidden; }
.srv-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 60%, #fff), var(--c)); }
.srv-rows { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .3rem .75rem; margin: 0; font-size: .84rem; padding-top: .55rem; border-top: 1px dashed var(--line); }
.srv-rows dt { font-weight: 500; color: var(--muted); white-space: nowrap; }
.srv-rows dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.srv-foot { margin-top: auto; display: flex; flex-direction: column; gap: .45rem; }
.srv-note { font-size: .8rem; color: var(--c); background: color-mix(in srgb, var(--c) 10%, transparent); border-radius: 9px; padding: .35rem .6rem; }
.srv-link { font-size: .8rem; font-weight: 600; text-decoration: none; }
.srv-log .card-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.srv-log-row.s-bad td:first-child { box-shadow: inset 3px 0 0 var(--srv-bad); }
.srv-log-row.s-warn td:first-child { box-shadow: inset 3px 0 0 var(--srv-warn); }
.srv-log-row.s-ok td:first-child { box-shadow: inset 3px 0 0 var(--srv-ok); }
.srv-sub { margin: .15rem 0 0; font-size: .82rem; color: var(--muted); }
/* แท็บลิงก์แบบ seg (เช่น ประเภทรายงานหนังสือที่ต้องติดตาม) */
a.seg-btn { text-decoration: none; }
a.seg-btn.active { border-color: var(--stamp); background: var(--stamp-soft); color: var(--stamp); box-shadow: inset 0 0 0 1px var(--stamp); }
/* คิว Telegram */
.tq-count { display: inline-block; min-width: 1.6rem; padding: 0 .4rem; border-radius: 999px; background: var(--surface-2); font-size: .78rem; text-align: center; }
.tq-count.is-bad { color: var(--seal); }
.tq-text { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== ภาพรวม Server: เอฟเฟกต์ (ปิดทั้งหมดเมื่อผู้ใช้ตั้งค่าลดการเคลื่อนไหว) ===== */
.srv-hero-ico { position: relative; }
.srv-hero::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 12% 0%, rgba(255,255,255,.22), transparent 45%); pointer-events: none; }
.srv-tile:hover .srv-ico { box-shadow: 0 6px 16px color-mix(in srgb, var(--c) 40%, transparent); }
.srv-tile:hover { border-color: color-mix(in srgb, var(--c) 35%, var(--line)); }
@media (prefers-reduced-motion: no-preference) {
  /* แบนเนอร์: เลื่อนลง + แสงวิ่งผ่าน + วงแหวนรอบไอคอน */
  .srv-hero { animation: srvDrop .55s cubic-bezier(.2,.8,.2,1) both; }
  .srv-hero > * { position: relative; z-index: 1; }
  .srv-hero .srv-shine { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
  .srv-hero .srv-shine::after { content: ""; position: absolute; top: 0; bottom: 0; width: 40%; left: -50%; background: linear-gradient(100deg, transparent, rgba(255,255,255,.22), transparent); animation: srvShine 4.5s ease-in-out 1s infinite; }
  .srv-hero.is-ok .srv-hero-ico::after { content: ""; position: absolute; inset: -4px; border-radius: 17px; border: 2px solid rgba(255,255,255,.55); animation: srvRing 2.6s ease-out infinite; }
  .srv-hero-sum .srv-pill { animation: srvPop .4s cubic-bezier(.3,1.5,.6,1) both; }
  .srv-hero-sum .srv-pill:nth-child(2) { animation-delay: .08s; } .srv-hero-sum .srv-pill:nth-child(3) { animation-delay: .16s; }
  /* การ์ด: ลอยขึ้นทีละใบ · แถบเติม · ไอคอนเด้งเมื่อชี้ */
  .srv-tile { animation: srvRise .5s cubic-bezier(.2,.8,.2,1) both; }
  .srv-tile:nth-child(1) { animation-delay: .08s; } .srv-tile:nth-child(2) { animation-delay: .14s; } .srv-tile:nth-child(3) { animation-delay: .2s; }
  .srv-tile:nth-child(4) { animation-delay: .26s; } .srv-tile:nth-child(5) { animation-delay: .32s; } .srv-tile:nth-child(6) { animation-delay: .38s; }
  .srv-bar span { transform-origin: left; animation: srvFill 1.1s cubic-bezier(.2,.8,.2,1) .45s both; }
  .srv-tile:hover .srv-ico { animation: srvBounce .5s ease; }
  .srv-tile .srv-ico { transition: box-shadow .2s; }
  .srv-pill.s-warn:not(.is-old) .srv-dot { animation: srvPulse 2s infinite; }
  .srv-pill.s-ok:not(.is-old) .srv-dot { animation: srvPulse 2.8s infinite; }
  .srv-tile.s-warn .srv-note, .srv-tile.s-bad .srv-note { animation: srvFade .5s ease .6s both; }
  /* ตาราง log: แถวค่อย ๆ ปรากฏ */
  .srv-log { animation: srvRise .5s ease .45s both; }
  .srv-log-row { animation: srvFade .4s ease both; }
  .srv-log-row:nth-child(1) { animation-delay: .55s; } .srv-log-row:nth-child(2) { animation-delay: .6s; } .srv-log-row:nth-child(3) { animation-delay: .65s; }
  .srv-log-row:nth-child(4) { animation-delay: .7s; } .srv-log-row:nth-child(5) { animation-delay: .75s; } .srv-log-row:nth-child(n+6) { animation-delay: .8s; }
}
@keyframes srvDrop { from { opacity: 0; transform: translateY(-10px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes srvRise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes srvFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes srvFill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes srvPop { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: none; } }
@keyframes srvShine { 0% { left: -50%; } 45%, 100% { left: 130%; } }
@keyframes srvRing { 0% { opacity: .9; transform: scale(.92); } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes srvBounce { 0%, 100% { transform: none; } 35% { transform: translateY(-4px) rotate(-6deg); } 70% { transform: translateY(1px) rotate(3deg); } }
@keyframes srvPulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.srv-link.is-empty { visibility: hidden; }
/* ภาพรวม Server: ข้อความแจ้งเตือน + ลิงก์ อยู่ในแถบเดียวกัน ชิดล่างการ์ด */
.srv-foot { margin-top: auto; display: flex; align-items: center; gap: .5rem .75rem; flex-direction: row; font-size: .8rem; color: var(--c); background: color-mix(in srgb, var(--c) 10%, transparent); border-radius: 9px; padding: .4rem .6rem; }
.srv-foot.is-link-only { background: none; padding: 0; justify-content: flex-end; }
.srv-note-txt { flex: 1; min-width: 0; }
.srv-foot .srv-link { flex: none; white-space: nowrap; font-weight: 700; color: var(--c); padding: .15rem .55rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.srv-foot.is-link-only .srv-link { color: var(--stamp); background: var(--stamp-soft); }
@media (prefers-reduced-motion: no-preference) { .srv-foot .srv-link { transition: transform .15s, background .15s; } .srv-foot .srv-link:hover { transform: translateX(2px); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
  .srv-tile.s-warn .srv-foot, .srv-tile.s-bad .srv-foot { animation: srvFade .5s ease .6s both; } }

/* ===== ภาพรวม Server: การ์ดหัวไล่สี (แทนแบบเดิม) ===== */
.srv-tile { --g1: #22C55E; --g2: #0D9488; padding: 0; gap: 0; border: 0; border-radius: 18px; box-shadow: 0 2px 10px rgba(15,23,42,.06); }
.srv-tile.s-warn { --g1: #F59E0B; --g2: #EA580C; }
.srv-tile.s-bad { --g1: #EF4444; --g2: #BE123C; }
.srv-tile.s-na { --g1: #94A3B8; --g2: #64748B; }
.srv-tile::before { display: none; }
.srv-head { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: .55rem; padding: 1rem 1.1rem 1.05rem; color: #fff; background: linear-gradient(135deg, var(--g1), var(--g2)); }
.srv-head::after { content: ""; position: absolute; right: -40px; top: -50px; width: 150px; height: 150px; border-radius: 50%; background: rgba(255,255,255,.12); pointer-events: none; }
.srv-head-bg { position: absolute; right: .6rem; bottom: -.9rem; font-size: 5.2rem; opacity: .14; transform: rotate(-12deg); pointer-events: none; }
.srv-head > * { position: relative; z-index: 1; }
.srv-head .srv-ico { color: #fff; background: rgba(255,255,255,.22); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.srv-head .srv-title { color: #fff; }
.srv-head .srv-pill { background: rgba(255,255,255,.95) !important; }
.srv-head .srv-val { color: #fff; font-size: 1.85rem; text-shadow: 0 1px 2px rgba(0,0,0,.12); }
.srv-head .srv-bar { background: rgba(255,255,255,.28); }
.srv-head .srv-bar span { background: #fff; }
.srv-body { flex: 1; display: flex; flex-direction: column; gap: .7rem; padding: .85rem 1.1rem 1rem; }
.srv-body .srv-rows { border-top: 0; padding-top: 0; }
.srv-tile:hover .srv-ico { box-shadow: inset 0 0 0 1px rgba(255,255,255,.4), 0 6px 14px rgba(0,0,0,.15); }
.srv-tile:hover { box-shadow: 0 14px 30px color-mix(in srgb, var(--g2) 22%, transparent); }
@media (prefers-reduced-motion: no-preference) {
  .srv-head-bg { transition: transform .4s cubic-bezier(.2,.8,.2,1), opacity .3s; }
  .srv-tile:hover .srv-head-bg { transform: rotate(-4deg) scale(1.1); opacity: .2; }
}
[data-bs-theme="dark"] .srv-tile { box-shadow: 0 2px 10px rgba(0,0,0,.3); background: var(--surface); }
[data-bs-theme="dark"] .srv-tile.s-ok { --g1: #15803D; --g2: #0F766E; }
[data-bs-theme="dark"] .srv-tile.s-warn { --g1: #B45309; --g2: #C2410C; }
[data-bs-theme="dark"] .srv-tile.s-bad { --g1: #B91C1C; --g2: #9F1239; }
.srv-head > .srv-head-bg { position: absolute; z-index: 0; line-height: 1; }
/* ภาพรวม Server: การ์ดเตี้ยลง */
.srv-head { gap: .4rem; padding: .75rem 1rem .8rem; }
.srv-head .srv-val { font-size: 1.55rem; }
.srv-head .srv-ico { width: 2rem; height: 2rem; font-size: .95rem; border-radius: 10px; }
.srv-head .srv-bar { height: 5px; }
.srv-head-bg { font-size: 4.2rem; bottom: -.7rem; }
.srv-body { gap: .5rem; padding: .65rem 1rem .8rem; }
.srv-body .srv-rows { gap: .15rem .75rem; font-size: .82rem; }
.srv-foot { padding: .3rem .55rem; }
.srv-grid { gap: .85rem; }

/* ===== ใบสมัครใช้งาน (Admin ทั้งระบบ) ===== */
.ap-link { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; padding: 1rem 1.25rem; margin-bottom: 1rem; border-radius: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(120deg, #1D4ED8, #7C3AED 65%, #DB2777); box-shadow: 0 10px 26px rgba(37,99,235,.25); }
.ap-link::after { content: ""; position: absolute; right: -60px; top: -60px; width: 200px; height: 200px; border-radius: 50%; background: rgba(255,255,255,.12); }
.ap-link > * { position: relative; z-index: 1; }
.ap-link-ico { width: 2.8rem; height: 2.8rem; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; background: rgba(255,255,255,.2); flex: none; }
.ap-link-txt { flex: 1; min-width: 220px; display: flex; flex-direction: column; }
.ap-link-txt small { opacity: .85; } .ap-link-txt b { font-size: 1.05rem; word-break: break-all; }
.ap-link-acts { display: flex; gap: .5rem; flex-wrap: wrap; }
.ap-state { padding: .25rem .75rem; border-radius: 999px; font-weight: 700; font-size: .8rem; background: rgba(255,255,255,.92); }
.ap-state.is-on { color: #15803D; } .ap-state.is-off { color: #B91C1C; }
.ap-qr { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.ap-status { --t: #D97706; display: inline-flex; align-items: center; gap: .4rem; padding: .4rem 1rem; border-radius: 999px; font-weight: 700; color: var(--t); background: color-mix(in srgb, var(--t) 13%, transparent); }
.ap-status.tone-success { --t: #16A34A; } .ap-status.tone-danger { --t: #DC2626; } .ap-status.tone-info { --t: #0284C7; }
.ap-dl { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .45rem 1rem; margin: 0; }
.ap-dl dt { color: var(--muted); font-weight: 500; } .ap-dl dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 575.98px) { .ap-dl { grid-template-columns: 1fr; gap: .1rem; } .ap-dl dd { margin-bottom: .45rem; } }
.ap-slip { display: block; width: 100%; max-height: 420px; object-fit: contain; margin-top: .85rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.ap-slip-pdf { margin-top: .85rem; padding: 1rem; border-radius: 12px; background: var(--surface-2); color: var(--muted); }
.ap-decide { border-color: color-mix(in srgb, #16A34A 35%, var(--line)); }
.dx-apply { display: flex; align-items: center; gap: .85rem; padding: .85rem 1.1rem; margin-bottom: 1rem; border-radius: 16px; text-decoration: none; color: #fff;
  background: linear-gradient(120deg, #DB2777, #7C3AED); box-shadow: 0 10px 24px rgba(219,39,119,.25); }
.dx-apply .ico { width: 2.5rem; height: 2.5rem; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; background: rgba(255,255,255,.2); flex: none; }
.dx-apply .txt { flex: 1; display: flex; flex-direction: column; } .dx-apply .txt small { opacity: .9; }
.dx-apply .go { font-weight: 700; white-space: nowrap; padding: .3rem .8rem; border-radius: 999px; background: rgba(255,255,255,.2); }
@media (prefers-reduced-motion: no-preference) { .dx-apply .ico { animation: srvBlink 1.8s ease-in-out infinite; } .dx-apply { transition: transform .2s; } .dx-apply:hover { transform: translateY(-2px); color: #fff; } }
.ap-free { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; color: #7C3AED; background: color-mix(in srgb, #7C3AED 12%, transparent); }
.ap-free-card { border-color: color-mix(in srgb, #7C3AED 35%, var(--line)); }
/* ไฟล์แนบเพิ่มเติม: รายการไฟล์ที่เลือก (สะสมได้หลายรอบ) */
.mf-list { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.mf-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem .35rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: .88rem; }
.mf-list li > i { color: var(--muted); }
.mf-list .mf-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-list small { color: var(--muted); white-space: nowrap; }
.mf-del { border: 0; background: transparent; color: var(--muted); width: 1.8rem; height: 1.8rem; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }
.mf-del:hover, .mf-del:focus-visible { color: #DC2626; background: color-mix(in srgb, #DC2626 12%, transparent); }
@media (prefers-reduced-motion: no-preference) { .mf-list li { animation: mfIn .2s ease-out; } }
@keyframes mfIn { from { opacity: 0; transform: translateY(-3px); } }
.ap-state { white-space: nowrap; }
.card-header .ap-state { background: color-mix(in srgb, currentColor 12%, transparent); }
/* ไฟล์แนบเพิ่มเติมในแถวรายการ (attach_chips): ปุ่ม 📎 จำนวน + ดรอปดาวน์ชื่อไฟล์ — ไอคอนสีตามชนิดไฟล์ */
.att-col { width: 1%; white-space: nowrap; }
@media (max-width: 575.98px) { td.att-col:empty { display: none; } }
.att-btn { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; line-height: 1.5; text-decoration: none; color: var(--bs-primary); background: color-mix(in srgb, var(--bs-primary) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--bs-primary) 28%, transparent); }
.att-btn:hover, .att-btn:focus-visible, .att-btn[aria-expanded="true"] { color: #fff; background: var(--bs-primary); border-color: var(--bs-primary); }
.att-caret { font-size: .65em; }
.att-menu { min-width: 16rem; max-width: min(24rem, 90vw); max-height: 18rem; overflow-y: auto; padding: .35rem; border-radius: 12px; }
.att-menu .dropdown-item { display: flex; align-items: center; gap: .55rem; border-radius: 8px; padding: .45rem .6rem; font-size: .88rem; }
.att-menu .dropdown-item > i { font-size: 1.05rem; color: var(--c, var(--muted)); }
.att-menu .att-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.att-menu small { color: var(--muted); }
.att-file-earmark-pdf { --c: #0E7490; } .att-file-earmark-image { --c: #7C3AED; } .att-file-earmark-word { --c: #2563EB; }
.att-file-earmark-excel { --c: #15803D; } .att-file-earmark-ppt { --c: #EA580C; }
[data-bs-theme="dark"] .att-file-earmark-pdf { --c: #22D3EE; } [data-bs-theme="dark"] .att-file-earmark-image { --c: #A78BFA; } [data-bs-theme="dark"] .att-file-earmark-word { --c: #60A5FA; } [data-bs-theme="dark"] .att-file-earmark-excel { --c: #4ADE80; } [data-bs-theme="dark"] .att-file-earmark-ppt { --c: #FB923C; }
[data-bs-theme="dark"] .att-btn:hover, [data-bs-theme="dark"] .att-btn:focus-visible, [data-bs-theme="dark"] .att-btn[aria-expanded="true"] { color: #0B1220; }
@media (prefers-reduced-motion: no-preference) { .att-btn { transition: background .15s, color .15s, transform .15s; } .att-btn:hover { transform: translateY(-1px); } .att-menu.show { animation: attPop .16s ease-out; transform-origin: top right; } }
/* ห้ามใช้ transform ในแอนิเมชัน — Popper ใช้ transform วางตำแหน่งเมนูใต้ปุ่ม (ถ้าทับ เมนูจะเด้งมาจากบนหน้า) */
@keyframes attPop { from { opacity: 0; translate: 0 -4px; scale: .97; } }
/* รายการหนังสือ (doc_row): ป้ายด่วน/ลับ/เวียน อยู่หน้าชื่อเรื่องบรรทัดแรก */
.doc-row .d-subject .seal, .doc-row .d-subject .chip { font-size: .72rem; font-weight: 600; vertical-align: .12em; margin-right: .4rem; padding: 0 .4rem; }
.doc-row .d-subject .seal-urgent.seal-l4 { outline: 0; }
/* ตารางแบ่งหน้า (data-page-size): แถวว่างเติมให้ครบ + แถบเลขหน้า */
tr.pg-fill td { height: 2.65rem; padding: 0 !important; border-bottom: 1px dashed color-mix(in srgb, var(--line) 80%, transparent); background: transparent; }
tr.pg-fill:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table-hover > tbody > tr.pg-fill:hover > * { --bs-table-bg-state: transparent; }
.mq-table tr.mq-empty-row td { padding: 0; }
.pg-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; padding: .7rem 1.25rem; border-top: 1px solid var(--line); }
.pg-info { font-size: .85rem; color: var(--muted); }
.pg-nums { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.pg-btn { min-width: 2.1rem; height: 2.1rem; padding: 0 .55rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; font-size: .88rem; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; justify-content: center; }
.pg-btn:hover:not(:disabled):not(.is-on) { border-color: color-mix(in srgb, var(--bs-primary) 45%, var(--line)); color: var(--bs-primary); background: color-mix(in srgb, var(--bs-primary) 7%, var(--surface)); }
.pg-btn.is-on { color: #fff; border-color: transparent; background: linear-gradient(135deg, #1D4ED8, #7C3AED); box-shadow: 0 6px 14px -8px rgba(79, 70, 229, .8); }
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-dots { color: var(--muted); padding: 0 .2rem; }
[data-bs-theme="dark"] .pg-btn.is-on { background: linear-gradient(135deg, #4F8DF5, #A78BFA); color: #0B1220; }
@media (prefers-reduced-motion: no-preference) { .pg-btn { transition: background .15s, color .15s, border-color .15s, transform .15s; } .pg-btn:hover:not(:disabled):not(.is-on) { transform: translateY(-1px); } }
@media (max-width: 575.98px) { tr.pg-fill { display: none !important; } .pg-bar { justify-content: center; } }
/* หน้าใบสมัครใช้งาน: สองคอลัมน์ขอบล่างเสมอกัน — การ์ดสุดท้ายยืดเต็ม, ไม่มีใบสมัคร = ข้อความกลางการ์ด */
.ap-list { display: flex; flex-direction: column; }
.ap-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1rem; text-align: center; }
.ap-grow { display: flex; flex-direction: column; } .ap-grow > .card-body:not(.border-top) { flex: 1; }
/* ตั้งค่าอีเมลแจ้งผลอนุมัติ: วิธีสร้างรหัสผ่านแอป + กล่องตั้งค่าขั้นสูง */
.ml-help { font-size: .85rem; padding: .55rem .75rem; border-radius: 10px; background: color-mix(in srgb, var(--bs-primary) 6%, var(--surface)); border: 1px solid color-mix(in srgb, var(--bs-primary) 18%, var(--line)); }
.ml-help summary { cursor: pointer; color: var(--bs-primary); font-weight: 600; }
.ml-help ol { margin: .5rem 0 .25rem; padding-left: 1.2rem; } .ml-help li { margin-bottom: .2rem; }
.ml-adv { padding: .8rem .85rem .9rem; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--line); }
.ml-adv-title { font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: .55rem; }
/* อายุการใช้งาน / ต่ออายุ (SubscriptionService) — ok เขียว · soon ส้ม · expired แดง */
.sub-tag { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; color: var(--t, #15803D); background: color-mix(in srgb, var(--t, #15803D) 12%, transparent); }
.sub-tag.tone-ok { --t: #15803D; } .sub-tag.tone-soon { --t: #C2410C; } .sub-tag.tone-expired { --t: #DC2626; } .sub-tag.tone-free { --t: #7C3AED; }
[data-bs-theme="dark"] .sub-tag.tone-ok { --t: #4ADE80; } [data-bs-theme="dark"] .sub-tag.tone-soon { --t: #FB923C; } [data-bs-theme="dark"] .sub-tag.tone-expired { --t: #F87171; } [data-bs-theme="dark"] .sub-tag.tone-free { --t: #A78BFA; }
.sub-hero { --g1: #059669; --g2: #0D9488; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem 1.4rem; border-radius: 18px; color: #fff; background: linear-gradient(135deg, var(--g1), var(--g2)); box-shadow: 0 14px 30px -18px var(--g1); }
.sub-hero.tone-soon { --g1: #F59E0B; --g2: #EA580C; } .sub-hero.tone-expired { --g1: #EF4444; --g2: #BE185D; }
.sub-hero-main { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.sub-hero-ico { width: 52px; height: 52px; flex: none; border-radius: 16px; display: grid; place-items: center; font-size: 1.5rem; background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.3); }
.sub-hero-lbl { font-size: .9rem; opacity: .9; } .sub-hero-date { font-family: var(--font-head); font-size: 1.6rem; font-weight: 700; line-height: 1.25; } .sub-hero-note { font-size: .88rem; opacity: .92; }
.sub-hero-days { text-align: center; padding: .5rem 1.1rem; border-radius: 14px; background: rgba(255,255,255,.16); } .sub-hero-days b { display: block; font-family: var(--font-head); font-size: 2.2rem; line-height: 1.05; } .sub-hero-days span { font-size: .82rem; opacity: .92; }
.sub-none { display: flex; align-items: center; gap: .9rem; } .sub-none > i { font-size: 2rem; color: var(--bs-primary); }
.sub-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.sub-plan { --c: #15803D; position: relative; cursor: pointer; margin: 0; } .sub-plan.is-monthly { --c: #1D4ED8; }
[data-bs-theme="dark"] .sub-plan { --c: #4ADE80; } [data-bs-theme="dark"] .sub-plan.is-monthly { --c: #4F8DF5; }
.sub-plan input { position: absolute; opacity: 0; pointer-events: none; }
.sub-plan-box { display: block; height: 100%; padding: .7rem .9rem .75rem; border-radius: 14px; background: var(--surface); border: 2px solid var(--line); }
.sub-plan-top { display: flex; align-items: center; gap: .4rem; font-weight: 700; color: var(--c); } .sub-plan-ok { margin-left: auto; opacity: 0; transform: scale(.6); }
.sub-plan b { font-size: 1.6rem; color: var(--c); line-height: 1.3; } .sub-plan-unit { font-weight: 600; } .sub-plan small { display: block; color: var(--muted); }
.sub-plan:hover .sub-plan-box { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.sub-plan input:checked + .sub-plan-box { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); box-shadow: 0 10px 22px -16px var(--c); }
.sub-plan input:checked + .sub-plan-box .sub-plan-ok { opacity: 1; transform: none; }
.sub-plan input:focus-visible + .sub-plan-box { outline: 3px solid color-mix(in srgb, var(--c) 40%, transparent); outline-offset: 2px; }
.sub-plans.is-invalid .sub-plan-box { border-color: #DC2626; }
.sub-pay { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; margin-bottom: 1rem; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--line); }
.sub-bank { display: grid; grid-template-columns: auto 1fr; gap: .25rem .9rem; } .sub-bank dt { color: var(--muted); font-weight: 500; } .sub-bank dd { margin: 0; }
.sub-qr { width: 120px; height: 120px; object-fit: contain; border-radius: 10px; background: #fff; padding: 4px; border: 1px solid var(--line); }
.sub-hist { list-style: none; margin: 0; padding: .4rem 0; }
.sub-hist li { display: flex; align-items: center; gap: .75rem; padding: .65rem 1.25rem; border-bottom: 1px solid var(--line); } .sub-hist li:last-child { border-bottom: 0; }
.sub-hist-ico { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; color: #fff; background: #64748B; }
.sub-hist-ico.tone-success { background: #16A34A; } .sub-hist-ico.tone-danger { background: #DC2626; } .sub-hist-ico.tone-warning { background: #F59E0B; }
@media (prefers-reduced-motion: no-preference) { .sub-plan-box, .sub-plan-ok { transition: border-color .15s, background .15s, box-shadow .15s, opacity .15s, transform .2s; } .sub-hero { animation: mfIn .4s ease-out; } }
/* เมนูข้างแบบมีเมนูย่อย (details.side-group): กดเมนูหลักเพื่อกาง/หุบ */
.side-group > summary { list-style: none; cursor: pointer; user-select: none; }
.side-group > summary::-webkit-details-marker { display: none; }
.side-group > summary .side-caret { margin-left: auto; width: auto; font-size: .8rem; transition: transform .2s; }
.side-group > summary .count + .side-caret { margin-left: .45rem; }
.side-group[open] > summary .side-caret { transform: rotate(180deg); }
.side-group[open] > summary .count { display: none; } /* กางแล้วเห็นตัวเลขที่เมนูย่อยแทน ไม่ซ้ำ */
.side-group > summary.has-active { color: #fff; }
.side-group > summary.has-active i:first-child { color: var(--sb-accent); }
.side-sub { position: relative; margin: 2px 0 4px 1.35rem; padding-left: .55rem; border-left: 1px solid var(--sb-line); }
.side-sub .side-link { padding: .5rem .7rem; font-size: .92rem; }
.side-sub .side-link i { font-size: 1rem; }
.side-sub .side-link.active::before { left: calc(-.55rem - 2px); }
@media (prefers-reduced-motion: no-preference) { .side-group[open] > .side-sub { animation: mfIn .18s ease-out; } }
@media (prefers-reduced-motion: reduce) { .side-group > summary .side-caret { transition: none; } }
/* พื้นที่จัดเก็บไฟล์ (admin/storage) */
.fm-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.fm-stat { --c: #1D4ED8; display: flex; align-items: center; gap: .85rem; padding: .9rem 1.1rem; border-radius: 16px; color: #fff; background: linear-gradient(135deg, color-mix(in srgb, var(--c) 82%, #fff), var(--c)); box-shadow: 0 10px 22px -16px var(--c); }
.fm-stat.tone-violet { --c: #6D28D9; } .fm-stat.tone-amber { --c: #D97706; }
.fm-stat > i { width: 42px; height: 42px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; background: rgba(255,255,255,.2); }
.fm-stat small { display: block; opacity: .9; } .fm-stat b { font-family: var(--font-head); font-size: 1.45rem; line-height: 1.2; }
.fm-bar { flex: 1; min-width: 60px; height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.fm-bar span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #059669, #0D9488); }
.fm-cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.fm-cat { display: flex; flex-direction: column; gap: .1rem; padding: .65rem .85rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.fm-cat i { color: var(--bs-primary); font-size: 1.1rem; } .fm-cat span { font-size: .84rem; color: var(--muted); } .fm-cat b { font-family: var(--font-head); font-size: 1.1rem; }
.fm-cat:hover { border-color: color-mix(in srgb, var(--bs-primary) 45%, var(--line)); color: var(--text); }
.fm-cat.active { border-color: var(--bs-primary); background: color-mix(in srgb, var(--bs-primary) 7%, var(--surface)); box-shadow: 0 8px 18px -14px var(--bs-primary); }
.fm-rel { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; }
@media (prefers-reduced-motion: no-preference) { .fm-cat { transition: border-color .15s, transform .15s; } .fm-cat:hover { transform: translateY(-1px); } }
@media (max-width: 767.98px) { .fm-stats { grid-template-columns: 1fr; } }
/* พื้นที่จัดเก็บไฟล์ — รอบปรับหน้าตา: สีประจำหมวด · ปุ่มกรอง · ปุ่มลบ (ทับชุดแรกด้านบน) */
.c-all { --c: #475569; } .c-original { --c: #2563EB; } .c-processed { --c: #7C3AED; } .c-attachments { --c: #0D9488; }
.c-temp { --c: #D97706; } .c-stamps { --c: #DB2777; } .c-signatures { --c: #4F46E5; } .c-logos { --c: #0891B2; }
[data-bs-theme="dark"] .c-all { --c: #94A3B8; } [data-bs-theme="dark"] .c-original { --c: #60A5FA; } [data-bs-theme="dark"] .c-processed { --c: #A78BFA; } [data-bs-theme="dark"] .c-attachments { --c: #2DD4BF; }
[data-bs-theme="dark"] .c-temp { --c: #FBBF24; } [data-bs-theme="dark"] .c-stamps { --c: #F472B6; } [data-bs-theme="dark"] .c-signatures { --c: #818CF8; } [data-bs-theme="dark"] .c-logos { --c: #22D3EE; }
.fm-cats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; }
.fm-cat { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ico lbl" "ico val" "bar bar"; column-gap: .7rem; row-gap: .05rem; align-items: center; padding: .8rem .9rem .75rem; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--c) 22%, var(--line)); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 9%, var(--surface)), var(--surface) 70%); }
.fm-cat-ico { grid-area: ico; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.1rem; color: #fff; background: linear-gradient(140deg, color-mix(in srgb, var(--c) 75%, #fff), var(--c)); box-shadow: 0 6px 14px -8px var(--c); }
.fm-cat .fm-cat-ico i { color: #fff; font-size: 1.1rem; }
.fm-cat-lbl { grid-area: lbl; font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-cat b { grid-area: val; font-family: var(--font-head); font-size: 1.2rem; color: var(--text); line-height: 1.2; }
.fm-cat-bar { grid-area: bar; display: block; height: 5px; margin-top: .55rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 12%, transparent); overflow: hidden; }
.fm-cat-bar i { display: block; height: 100%; border-radius: 999px; background: var(--c); }
.fm-cat:hover { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); }
.fm-cat.active { border-color: var(--c); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 16%, var(--surface)), color-mix(in srgb, var(--c) 4%, var(--surface))); box-shadow: 0 10px 22px -16px var(--c), inset 0 0 0 1px var(--c); }
.fm-filters { display: flex; flex-wrap: wrap; gap: .45rem; }
.fm-filter { --c: #475569; display: inline-flex; align-items: center; gap: .4rem; padding: .42rem .85rem; border-radius: 999px; font-size: .88rem; font-weight: 600; text-decoration: none; color: var(--c); background: color-mix(in srgb, var(--c) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 25%, var(--line)); }
.fm-filter b { font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, transparent); }
.fm-filter.f-used { --c: #2563EB; } .fm-filter.f-free { --c: #15803D; }
[data-bs-theme="dark"] .fm-filter.f-all { --c: #94A3B8; } [data-bs-theme="dark"] .fm-filter.f-used { --c: #60A5FA; } [data-bs-theme="dark"] .fm-filter.f-free { --c: #4ADE80; }
.fm-filter:hover { color: var(--c); border-color: var(--c); }
.fm-filter.active { color: #fff; background: var(--c); border-color: var(--c); box-shadow: 0 8px 18px -12px var(--c); }
.fm-filter.active b { background: rgba(255,255,255,.22); }
[data-bs-theme="dark"] .fm-filter.active { color: #0B1220; }
.fm-purge { color: #fff; font-weight: 600; border: 0; background: linear-gradient(135deg, #16A34A, #0D9488); box-shadow: 0 8px 18px -12px #16A34A; }
.fm-purge:hover { color: #fff; filter: brightness(1.06); }
.fm-file { display: flex; align-items: center; gap: .7rem; }
.fm-file-ico { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; font-size: 1rem; color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.fm-table tr.is-safe > td { background: color-mix(in srgb, #16A34A 5%, transparent); }
.fm-table tr.is-safe > td:first-child { box-shadow: inset 4px 0 0 #16A34A; }
.fm-tag { display: inline-block; padding: .08rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 700; color: var(--t); background: color-mix(in srgb, var(--t) 12%, transparent); }
.fm-tag.t-used { --t: #2563EB; } .fm-tag.t-locked { --t: #7C3AED; } .fm-tag.t-unused, .fm-tag.t-deleted_doc { --t: #15803D; } .fm-tag.t-system { --t: #64748B; } .fm-tag.t-busy { --t: #D97706; }
[data-bs-theme="dark"] .fm-tag.t-used { --t: #60A5FA; } [data-bs-theme="dark"] .fm-tag.t-locked { --t: #A78BFA; } [data-bs-theme="dark"] .fm-tag.t-unused, [data-bs-theme="dark"] .fm-tag.t-deleted_doc { --t: #4ADE80; } [data-bs-theme="dark"] .fm-tag.t-system { --t: #94A3B8; } [data-bs-theme="dark"] .fm-tag.t-busy { --t: #FBBF24; }
.fm-del { display: inline-flex; align-items: center; gap: .3rem; height: 30px; padding: 0 .6rem; border-radius: 9px; font-size: .82rem; font-weight: 600; color: var(--muted); background: transparent; border: 1px solid var(--line); }
.fm-del:hover, .fm-del:focus-visible { color: #DC2626; border-color: color-mix(in srgb, #DC2626 45%, var(--line)); background: color-mix(in srgb, #DC2626 8%, transparent); }
.fm-del.is-safe { color: #fff; border-color: transparent; background: linear-gradient(135deg, #16A34A, #0D9488); box-shadow: 0 6px 14px -10px #16A34A; }
.fm-del.is-safe:hover, .fm-del.is-safe:focus-visible { color: #fff; filter: brightness(1.08); }
.fm-lock { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; color: var(--muted); background: var(--surface-2); }
.min-w-0 { min-width: 0; }
@media (prefers-reduced-motion: no-preference) { .fm-filter, .fm-del, .fm-purge { transition: background .15s, color .15s, border-color .15s, transform .15s, filter .15s; } .fm-filter:hover, .fm-del.is-safe:hover, .fm-purge:hover { transform: translateY(-1px); } }
.fm-del, .fm-filter, .fm-purge { white-space: nowrap; }

/* รับหนังสือ: ช่อง "หน้าที่มีลายเซ็นผู้ส่ง" — ป้ายเม็ดยาสีส้มข้างชื่อ + ขอบซ้ายส้ม (ตราเกษียณประทับบนหน้านี้) */
.sig-attn .form-label { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.sig-pill { display: inline-flex; align-items: center; padding: .1rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; line-height: 1.5; color: #B45309; background: #FEF3C7; border: 1px solid #FCD34D; }
.sig-attn .form-control { border-left: 4px solid #F59E0B; }
.sig-attn .form-control:focus { border-color: #F59E0B; box-shadow: 0 0 0 .2rem rgba(245, 158, 11, .2); }
[data-bs-theme="dark"] .sig-pill { color: #FCD34D; background: rgba(245, 158, 11, .14); border-color: rgba(245, 158, 11, .4); }
[data-bs-theme="dark"] .sig-attn .form-control { border-left-color: #D97706; }

/* ทะเบียน: ป้ายด่วน/ลับ อยู่บรรทัดเดียวกับชื่อเรื่อง ข้อความยาวค่อยขึ้นบรรทัดใหม่ · กลุ่มงานไม่ตกบรรทัด · ปุ่มลบคอลัมน์ท้ายสุด */
.subj-line { display: block; }
.subj-line .seal { display: inline-block; margin-right: .35rem; vertical-align: .08em; }
.table td.owner-col { min-width: 190px; } .owner-col .text-primary { white-space: nowrap; }
.act-col { width: 1%; text-align: center; }
@media (max-width: 575.98px) { td.act-col:empty { display: none; } }
.th-wrap .tw { white-space: nowrap; }

/* เรื่องที่รอคุณ: ไอคอนเล็กบอกว่าหนังสือถูกตีกลับ */
.mq-returned { display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: 50%; background: #FDECEA; color: #DC2626; font-size: .72rem; align-self: center; }
[data-bs-theme="dark"] .mq-returned { background: rgba(239, 68, 68, .18); color: #F87171; }

/* หน้ารายละเอียด: แจ้งตีกลับแบบกะทัดรัด ไม่เบียดช่องความเห็น (คำแนะนำอยู่ใน title) */
.ap-returned { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .75rem; padding: .45rem .65rem; border-radius: 10px; border-left: 3px solid #DC2626; background: #FEF2F2; color: #991B1B; font-size: .8rem; line-height: 1.45; }
.ap-returned > .bi { margin-top: .1rem; }
.ap-ret-why { white-space: pre-line; color: #7F1D1D; }
[data-bs-theme="dark"] .ap-returned { background: rgba(239, 68, 68, .12); color: #FCA5A5; border-left-color: #EF4444; }
[data-bs-theme="dark"] .ap-ret-why { color: #FECACA; }

/* ===== ไล่ทำเรื่องที่รอคุณ: เรื่องก่อนหน้า/ถัดไป · ไปเรื่องถัดไปอัตโนมัติ ===== */
.q-nav { display: inline-flex; align-items: center; gap: .15rem; padding: .15rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .85rem; }
.q-nav a, .q-nav .q-off { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 50%; color: var(--stamp); text-decoration: none; transition: background .15s, transform .15s; }
.q-nav a:hover { background: color-mix(in srgb, var(--stamp) 12%, transparent); transform: scale(1.08); }
.q-nav .q-off { color: var(--muted); opacity: .45; }
.q-nav .q-pos { padding: 0 .35rem; color: var(--muted); white-space: nowrap; }
.q-nav .q-pos b { color: var(--text); }
.q-back { margin-left: .5rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.go-next { display: flex; align-items: center; gap: .5rem; margin: .25rem 0 .65rem; font-size: .9rem; }
.go-next .form-check-input { cursor: pointer; }
.my-next { display: flex; gap: .5rem; border-top: 1px solid var(--line); }
.my-next .btn-primary { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; gap: .4rem; flex-wrap: wrap; background-image: linear-gradient(135deg, #2563eb, #1d4ed8); transition: transform .15s, box-shadow .15s; }
.my-next .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37, 99, 235, .3); }
.my-next .btn-primary small { width: 100%; font-weight: 400; opacity: .85; font-size: .75rem; line-height: 1.1; }
.my-next .btn-primary .bi-arrow-right { transition: transform .2s; }
.my-next .btn-primary:hover .bi-arrow-right { transform: translateX(3px); }
.my-next .btn-light-line { flex: 0 0 auto; display: flex; align-items: center; gap: .35rem; }
.my-next-empty { flex: 1 1 auto; display: flex; align-items: center; gap: .4rem; font-weight: 600; color: var(--ok); }
@media (prefers-reduced-motion: reduce) { .q-nav a, .my-next .btn-primary, .my-next .btn-primary .bi-arrow-right { transition: none; transform: none !important; } }

/* ทะเบียนหนังสือรับ: คอลัมน์ "จาก" กว้างพอให้ชื่อหน่วยงานสั้น ๆ อยู่บรรทัดเดียว (ชื่อยาวมากยังตัดบรรทัดได้) */
@media (min-width: 576px) { .col-from { min-width: 10rem; } }

/* ---------- Telegram: ประเภทแจ้งเตือนจัดกลุ่ม + ผู้รับ (admin/telegram) ---------- */
.tg-types { display: flex; flex-direction: column; gap: .6rem; }
.tg-group { margin: 0; padding: .55rem .8rem .4rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.tg-group legend { float: none; width: auto; display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; margin: 0 0 .25rem; padding: 0; font-size: .88rem; font-weight: 700; color: var(--ink); }
.tg-group legend .bi { color: #229ED9; }
.tg-group legend small { font-weight: 400; font-size: .78rem; color: var(--muted); }
.tg-row { display: flex; align-items: center; gap: .55rem; margin: 0; padding: .32rem .35rem; border-radius: 8px; cursor: pointer; transition: background .15s; }
.tg-row + .tg-row { border-top: 1px dashed var(--line); }
.tg-row:hover { background: color-mix(in srgb, #229ED9 8%, transparent); }
.tg-row .form-check-input { flex: none; margin: 0; }
.tg-lbl { flex: 1 1 auto; min-width: 0; font-size: .9rem; color: var(--text); }
.tg-rcv { flex: none; max-width: 55%; text-align: right; font-size: .78rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .tg-row { transition: none; } }
[data-bs-theme="dark"] .tg-types { --ink: var(--text); }
.tg-linked { margin-bottom: 0; }
.tg-linked > ul { flex: 1 1 auto; display: flex; flex-direction: column; }
.tg-empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; padding: 1.2rem 1rem; text-align: center; color: var(--muted); }
.tg-empty .bi { font-size: 1.6rem; color: #229ED9; }
.tg-empty b { color: var(--text); font-size: .9rem; }

/* ภาพรวม Server — โทนเดียวกับระบบ (น้ำเงินกรมท่า→คราม เหมือนการ์ดทักทาย) · สีสถานะเหลือแค่ชิป แถบ และกล่องข้อแนะนำ */
.srv-hero, .srv-hero.is-ok, .srv-hero.is-warn, .srv-hero.is-na { background: linear-gradient(120deg, #0B1F4D 0%, #12348A 45%, #1D4ED8 75%, #4338CA 100%); box-shadow: 0 10px 28px rgba(29,78,216,.25); }
.srv-hero.is-bad { background: linear-gradient(120deg, #7F1D1D, #B91C1C 60%, #DC2626); box-shadow: 0 10px 28px rgba(220,38,38,.3); }
.srv-hero-ico { box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.srv-hero.is-ok .srv-hero-ico { color: #86EFAC; } .srv-hero.is-warn .srv-hero-ico { color: #FCD34D; } .srv-hero.is-na .srv-hero-ico { color: #CBD5E1; }
.srv-tile, .srv-tile.s-ok, .srv-tile.s-warn, .srv-tile.s-bad, .srv-tile.s-na { --g1: #12348A; --g2: #4338CA; }
.srv-head { background: radial-gradient(120% 90% at 100% 0%, rgba(99,102,241,.55) 0%, transparent 60%), linear-gradient(140deg, #0B1F4D 0%, #1D4ED8 100%); }
.srv-tile { --lt: #4ADE80; } .srv-tile.s-warn { --lt: #FBBF24; } .srv-tile.s-bad { --lt: #F87171; } .srv-tile.s-na { --lt: #CBD5E1; }
.srv-head .srv-bar { background: rgba(255,255,255,.18); }
.srv-head .srv-bar span { background: linear-gradient(90deg, color-mix(in srgb, var(--lt) 60%, #fff), var(--lt)); box-shadow: 0 0 10px color-mix(in srgb, var(--lt) 60%, transparent); }
.srv-tile.s-warn, .srv-tile.s-bad { box-shadow: 0 2px 10px rgba(15,23,42,.06), inset 0 -3px 0 var(--c); }
.srv-tile:hover { box-shadow: 0 14px 30px rgba(29,78,216,.2); }
.srv-tile.s-warn:hover, .srv-tile.s-bad:hover { box-shadow: 0 14px 30px rgba(29,78,216,.2), inset 0 -3px 0 var(--c); }
[data-bs-theme="dark"] .srv-hero:not(.is-bad) { background: linear-gradient(120deg, #0A1636 0%, #10296B 45%, #1E40AF 75%, #3730A3 100%); }
[data-bs-theme="dark"] .srv-tile, [data-bs-theme="dark"] .srv-tile.s-ok, [data-bs-theme="dark"] .srv-tile.s-warn, [data-bs-theme="dark"] .srv-tile.s-bad { --g1: #10296B; --g2: #3730A3; }
[data-bs-theme="dark"] .srv-head { background: radial-gradient(120% 90% at 100% 0%, rgba(79,70,229,.45) 0%, transparent 60%), linear-gradient(140deg, #0A1636 0%, #1E40AF 100%); }
@media (prefers-reduced-motion: no-preference) {
  .srv-head::before { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 45%; z-index: 1; pointer-events: none; background: linear-gradient(100deg, transparent, rgba(255,255,255,.28), transparent); transform: skewX(-18deg); }
  .srv-tile:hover .srv-head::before { animation: srvSweep .8s ease; }
  .srv-head-bg { animation: srvFloat 6s ease-in-out infinite; }
  .srv-tile:nth-child(2n) .srv-head-bg { animation-delay: -3s; }
}
@keyframes srvSweep { from { left: -60%; } to { left: 130%; } }
@keyframes srvFloat { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }

/* ===== สำรองขึ้น Google Drive (admin/backups) ===== */
.gd-card { overflow: hidden; }
.gd-body { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
.gd-info { display: flex; align-items: center; gap: .9rem; min-width: 0; flex: 1 1 320px; }
.gd-ico { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 1.3rem; color: #fff;
  background: conic-gradient(from 200deg, #4285F4, #34A853, #FBBC05, #EA4335, #4285F4); box-shadow: 0 6px 16px -6px rgba(66, 133, 244, .6); transition: transform .35s ease; }
.gd-card:hover .gd-ico { transform: rotate(-12deg) scale(1.06); }
.gd-chip { font-size: .75rem; font-weight: 500; padding: .1rem .55rem; border-radius: 999px; background: var(--paper); color: var(--muted); border: 1px solid var(--line); }
.gd-chip.is-on { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.gd-acts { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.gd-go { display: flex; gap: .5rem; margin: 0; }
.gd-go .form-select { width: auto; }
.gd-go .btn, .gd-acts > .btn, .gd-acts .btn { white-space: nowrap; }
.gd-device { border-top: 1px dashed var(--line); padding: 1rem 1.25rem; display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem;
  background: linear-gradient(90deg, var(--stamp-soft), transparent); animation: gdIn .35s ease; }
.gd-steps { display: grid; gap: .4rem; }
.gd-n { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--stamp); color: #fff; font-size: .8rem; margin-right: .35rem; }
.gd-code { font: 700 1.9rem/1 ui-monospace, "SFMono-Regular", Menlo, monospace; letter-spacing: .18em; padding: .55rem 1rem; border-radius: var(--radius-sm);
  border: 2px dashed var(--stamp); background: var(--surface); color: var(--ink); cursor: copy; transition: background .2s, color .2s; }
.gd-code.is-copied { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.gd-client { border-top: 1px solid var(--line); padding: .7rem 1.25rem; }
.gd-client summary { cursor: pointer; color: var(--muted); font-size: .875rem; }
.gd-client-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: .75rem; align-items: end; margin-top: .75rem; }
@media (max-width: 767.98px) { .gd-client-form { grid-template-columns: 1fr; } .gd-acts, .gd-acts > form, .gd-acts .btn, .gd-go .form-select { width: 100%; } .gd-go { flex-wrap: wrap; } }
.gd-run { border-top: 1px solid var(--line); padding: .75rem 1.25rem; background: var(--stamp-soft); color: var(--stamp); font-weight: 500; }
.gd-tag { display: flex; align-items: center; gap: .3rem; margin-top: .3rem; font-size: .78rem; color: var(--muted); }
.gd-tag.is-done { color: var(--ok); }
.gd-tag.is-done a { color: inherit; }
.gd-tag.is-failed { color: var(--seal); }
.gd-tag.is-queued, .gd-tag.is-uploading { color: var(--stamp); }
.gd-tag.is-uploading i { animation: gdPulse 1.2s ease-in-out infinite; }
@keyframes gdIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes gdPulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .gd-ico, .gd-device, .gd-tag i { transition: none; animation: none; } .gd-card:hover .gd-ico { transform: none; } }
/* สำรองอัตโนมัติ (การ์ด Google Drive) */
.gd-auto { border-top: 1px solid var(--line); padding: .85rem 1.25rem; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.25rem; }
.gd-auto-sw { display: flex; align-items: center; gap: .5rem; min-width: 10rem; }
.gd-auto-sw .form-check-input { cursor: pointer; }
.gd-auto-f { display: flex; align-items: center; gap: .45rem; font-size: .875rem; color: var(--muted); }
.gd-auto-f label { white-space: nowrap; margin: 0; }
.gd-auto-f .form-control, .gd-auto-f .form-select { width: auto; }
.gd-keep { width: 4.5rem !important; }
.gd-auto-note { flex-basis: 100%; }
.gd-auto:has(.gd-auto-sw input:not(:checked)) .gd-auto-f { opacity: .55; }
.gd-tag.is-pruned { color: var(--muted); }
@media (max-width: 767.98px) { .gd-auto-f { flex: 1 1 100%; } .gd-auto-f .form-control:not(.gd-keep), .gd-auto-f .form-select { flex: 1; } .gd-auto .btn { width: 100%; } }
.gd-go .form-select, .gd-auto-f .form-select { min-width: 10.5rem; padding-right: 2.4rem; }
@media (max-width: 767.98px) { .gd-auto-f label { min-width: 5.5rem; } }

/* ภาพรวม Server: การ์ดความจุระบบ (CapacityService) — หัวไล่สีตามสถานะ · แถบใช้ไปแล้วรายส่วน · แผงความเร็วอินเทอร์เน็ต */
.cap { --g1: #4F46E5; --g2: #7C3AED; border-radius: 18px; background: var(--surface); box-shadow: 0 2px 10px rgba(15,23,42,.06); overflow: hidden; margin-bottom: 1rem; }
.cap.s-warn { --g1: #F59E0B; --g2: #EA580C; } .cap.s-bad { --g1: #EF4444; --g2: #BE123C; } .cap.s-na { --g1: #94A3B8; --g2: #64748B; }
.cap-head { position: relative; overflow: hidden; display: flex; align-items: center; gap: .75rem; padding: .65rem 1.1rem; color: #fff; background: linear-gradient(135deg, var(--g1), var(--g2)); }
.cap-head::after { content: ""; position: absolute; right: -50px; top: -70px; width: 200px; height: 200px; border-radius: 50%; background: rgba(255,255,255,.12); pointer-events: none; }
.cap-head-bg { position: absolute; right: 1.2rem; bottom: -.8rem; font-size: 4rem; line-height: 1; opacity: .14; transform: rotate(-10deg); pointer-events: none; }
.cap-ico { position: relative; z-index: 1; width: 2.3rem; height: 2.3rem; border-radius: 11px; display: grid; place-items: center; flex: none; font-size: 1.1rem; background: rgba(255,255,255,.2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.cap-head-txt { position: relative; z-index: 1; display: flex; flex-direction: column; min-width: 0; }
.cap-head h2 { margin: 0; font-size: .82rem; font-weight: 700; color: #fff; opacity: .95; }
.cap-head h2 small { font-weight: 500; opacity: .8; }
.cap-big { font-size: .98rem; font-weight: 600; line-height: 1.3; }
.cap-big b { font-size: 1.5rem; font-weight: 800; margin: 0 .2rem; text-shadow: 0 1px 2px rgba(0,0,0,.15); }
.cap-sub { font-size: .78rem; opacity: .92; }
.cap-body { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
@media (max-width: 991.98px) { .cap-body { grid-template-columns: 1fr; } }
.cap-parts { display: flex; flex-direction: column; gap: .35rem; padding: .85rem 1rem; }
.cap-row { --c: var(--srv-ok); display: flex; gap: .75rem; align-items: center; padding: .55rem .7rem; border-radius: 12px; border: 1px solid transparent; }
.cap-row.s-warn { --c: var(--srv-warn); } .cap-row.s-bad { --c: var(--srv-bad); } .cap-row.s-na { --c: var(--srv-na); }
.cap-row.is-min { background: color-mix(in srgb, var(--c) 8%, transparent); border-color: color-mix(in srgb, var(--c) 30%, transparent); }
.cap-row-ico { width: 2.2rem; height: 2.2rem; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff; background: linear-gradient(135deg, color-mix(in srgb, var(--c) 65%, #fff), var(--c)); }
.cap-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.cap-row-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .92rem; }
.cap-row-val { margin-left: auto; font-size: .88rem; color: var(--muted); white-space: nowrap; }
.cap-row-val b { color: var(--text, inherit); font-size: 1.05rem; }
.cap-chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .7rem; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border-radius: 999px; padding: .08rem .5rem; }
.cap-bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.cap-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 55%, #fff), var(--c)); }
.cap-row.s-na .cap-bar { background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, transparent 6px 12px); }
.cap-row-sub { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cap-net { display: flex; flex-direction: column; gap: .6rem; padding: .95rem 1.1rem; border-left: 1px dashed var(--line); background: color-mix(in srgb, var(--g1) 4%, transparent); }
@media (max-width: 991.98px) { .cap-net { border-left: 0; border-top: 1px dashed var(--line); } }
.cap-net-title { font-weight: 700; font-size: .92rem; }
.cap-net-title i { color: var(--g1); }
.cap-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.cap-stats > div { display: flex; flex-direction: column; align-items: center; padding: .5rem .25rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.cap-stats span { font-size: .72rem; color: var(--muted); }
.cap-stats b { font-size: 1.35rem; font-weight: 800; line-height: 1.2; color: var(--g1); }
.cap-stats small { font-size: .7rem; color: var(--muted); }
.cap-test { width: 100%; background: linear-gradient(135deg, var(--g1), var(--g2)); border: 0; font-weight: 600; }
.cap-test:hover, .cap-test:focus-visible { background: linear-gradient(135deg, var(--g2), var(--g1)); }
.cap-msg { font-size: .8rem; color: var(--srv-warn); min-height: 0; }
.cap-msg:empty { display: none; }
.cap-msg.is-err { color: var(--srv-bad); }
.cap-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: .25rem .5rem; }
.cap-form label { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); }
.cap-net-foot { margin-top: auto; font-size: .74rem; color: var(--muted); }
.cap-foot { border-top: 1px solid var(--line); padding: .6rem 1.25rem; font-size: .8rem; color: var(--muted); }
.cap-foot summary { cursor: pointer; }
.cap-foot ul { margin: .5rem 0 .2rem; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .2rem; }
[data-bs-theme="dark"] .cap { box-shadow: 0 2px 10px rgba(0,0,0,.3); --g1: #6366F1; --g2: #7C3AED; }
[data-bs-theme="dark"] .cap.s-warn { --g1: #B45309; --g2: #C2410C; }
[data-bs-theme="dark"] .cap.s-bad { --g1: #B91C1C; --g2: #9F1239; }
[data-bs-theme="dark"] .cap.s-na { --g1: #475569; --g2: #334155; }
[data-bs-theme="dark"] .cap-stats b { color: #A5B4FC; }
@media (max-width: 575.98px) { .cap-head { padding: .6rem .9rem; } .cap-big b { font-size: 1.35rem; } .cap-row-val { margin-left: 0; width: 100%; } }
@media (prefers-reduced-motion: no-preference) {
  .cap { animation: srvRise .5s cubic-bezier(.2,.8,.2,1) .4s both; }
  .cap-bar span { transform-origin: left; animation: srvFill 1.1s cubic-bezier(.2,.8,.2,1) .7s both; }
  .cap-row { transition: transform .2s, background .2s; }
  .cap-row:hover { transform: translateX(3px); background: color-mix(in srgb, var(--c) 6%, transparent); }
  .cap-row.is-min .cap-chip i { animation: srvPulse 2s infinite; }
  .cap-head-bg { transition: transform .4s cubic-bezier(.2,.8,.2,1); }
  .cap:hover .cap-head-bg { transform: rotate(-3deg) scale(1.08); }
  .cap-test { transition: transform .15s, box-shadow .2s; }
  .cap-test:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 8px 18px color-mix(in srgb, var(--g2) 35%, transparent); }
}

/* ภาพรวม Server: แจ้งเตือนผู้บุกรุก (SecurityService) */
.sec-card { margin-top: 1rem; scroll-margin-top: 80px; }
.sec-card .card-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.sec-card h2 { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sec-tools { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sec-new-chip { font-size: .72rem; font-weight: 700; color: #fff; background: linear-gradient(135deg, #EF4444, #BE123C); border-radius: 999px; padding: .12rem .55rem; }
.sec-tg { border-bottom: 1px solid var(--line); padding: .6rem 1.25rem; background: linear-gradient(90deg, color-mix(in srgb, #229ED9 7%, transparent), transparent); }
.sec-tg summary { cursor: pointer; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.sec-tg summary .bi-telegram { color: #229ED9; }
.sec-tg-body { padding-top: .6rem; display: flex; flex-direction: column; gap: .5rem; }
.sec-tg-row { display: flex; align-items: center; gap: .5rem .75rem; flex-wrap: wrap; }
.sec-tg-row > span { flex: 1; min-width: 220px; }
.sec-steps { margin: 0; padding-left: 1.2rem; color: var(--muted); }
.sec-tg-form { display: flex; gap: .5rem; flex-wrap: wrap; max-width: 640px; }
.sec-tg-form .form-control { flex: 1; min-width: 220px; }
.sec-link { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.sec-lv { --c: var(--srv-na); display: inline-flex; align-items: center; gap: .35rem; font-size: .74rem; font-weight: 700; white-space: nowrap; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); border-radius: 999px; padding: .12rem .55rem; }
.sec-lv.s-bad { --c: var(--srv-bad); } .sec-lv.s-warn { --c: var(--srv-warn); } .sec-lv.s-low { --c: #CA8A04; }
.sec-row td:first-child { box-shadow: inset 3px 0 0 transparent; }
.sec-row.s-bad td:first-child { box-shadow: inset 3px 0 0 var(--srv-bad); }
.sec-row.s-warn td:first-child { box-shadow: inset 3px 0 0 var(--srv-warn); }
.sec-row.s-low td:first-child { box-shadow: inset 3px 0 0 #CA8A04; }
.sec-row.is-new.s-bad { background: color-mix(in srgb, var(--srv-bad) 6%, transparent); }
.sec-row:not(.is-new) { opacity: .78; }
.sec-ev { font-weight: 600; }
.sec-ev i { color: var(--muted); }
.sec-detail { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-ip { font-size: .82rem; color: var(--text, inherit); background: var(--surface-2); padding: .1rem .4rem; border-radius: 6px; }
.sec-tag { font-size: .7rem; font-weight: 600; color: var(--stamp); background: var(--stamp-soft); border-radius: 999px; padding: .05rem .45rem; white-space: nowrap; }
.sec-tag.is-block { color: var(--srv-bad); background: color-mix(in srgb, var(--srv-bad) 12%, transparent); }
.sec-done { white-space: nowrap; }
.sec-card .dropdown-menu { min-width: 11rem; }
.sec-blocks { border-top: 1px solid var(--line); padding: .7rem 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.sec-blocks-head { display: flex; align-items: center; gap: .5rem .75rem; flex-wrap: wrap; font-size: .9rem; }
.sec-blocks-head b i { color: var(--srv-bad); }
.sec-add { margin-left: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.sec-add .form-control { width: 210px; } .sec-add .form-select { width: auto; }
.sec-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.sec-chip { display: inline-flex; align-items: center; gap: .45rem; margin: 0; padding: .25rem .4rem .25rem .6rem; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--srv-bad) 30%, var(--line)); background: color-mix(in srgb, var(--srv-bad) 6%, var(--surface)); }
.sec-chip .btn-close { font-size: .55rem; }
.sec-hero-pill { text-decoration: none; }
@media (max-width: 575.98px) { .sec-add { margin-left: 0; width: 100%; } .sec-add .form-control { flex: 1; width: auto; } }
@media (prefers-reduced-motion: no-preference) {
  .sec-row.is-new.s-bad { animation: secGlow 2.4s ease-in-out infinite; }
  .sec-new-chip, .sec-hero-pill { animation: srvPop .4s cubic-bezier(.3,1.5,.6,1) both; }
  .sec-chip { transition: transform .15s; } .sec-chip:hover { transform: translateY(-1px); }
}
@keyframes secGlow { 0%, 100% { background: color-mix(in srgb, var(--srv-bad) 5%, transparent); } 50% { background: color-mix(in srgb, var(--srv-bad) 13%, transparent); } }
.sec-cell { display: block; min-width: 0; }
@media (max-width: 767.98px) { .sec-table .sec-cell { text-align: right; } .sec-table .sec-detail { max-width: 220px; margin-left: auto; } }

/* เมนูผู้ใช้: ชื่อยาว (เช่น นายผู้ดูแลระบบ SARA) ไม่ตกบรรทัด — เมนูกว้างตามชื่อ ยาวเกินจอจึงตัด … */
.user-menu { min-width: 13rem; max-width: min(22rem, calc(100vw - 2rem)); }
.user-menu-head > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Audit Log: ลบประวัติเก่า + ระยะลบอัตโนมัติ */
.ad-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.ad-keep { display: flex; align-items: center; gap: .45rem; }
.ad-keep .form-select { width: auto; }
.btn-purge { background: var(--seal-soft); color: var(--seal); border: 1px solid transparent; }
.btn-purge:hover, .btn-purge:focus-visible { background: var(--seal); color: #fff; }
.pg-opts { display: grid; gap: .5rem; }
.pg-opt { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.pg-opt input { flex: none; }
.pg-opt-txt { flex: 1; min-width: 0; }
.pg-opt-n { font-weight: 700; text-align: right; line-height: 1.1; }
.pg-opt-n small { display: block; font-size: .72rem; font-weight: 400; color: var(--muted); }
.pg-opt:has(input:checked) { border-color: var(--seal); background: var(--seal-soft); }
.pg-opt.is-off { opacity: .55; cursor: not-allowed; }
@media (prefers-reduced-motion: no-preference) { .pg-opt { transition: border-color .15s, background .15s; } }
@media (max-width: 575.98px) { .ad-actions, .ad-keep { width: 100%; } .ad-keep .form-select { flex: 1; } }
.rs-safe.pg-safe li i { color: var(--ok); }
.ad-keep-badge { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .85rem; border-radius: 999px; font-size: .85rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); cursor: help; }
.ad-keep-badge.is-on { background: var(--stamp-soft); color: var(--stamp); border-color: color-mix(in srgb, var(--stamp) 30%, transparent); }

/* ---------- Effect ทั่วระบบ: สั้นและเบา (ผู้ใช้เลือกแบบนี้แล้ว) ----------
   เหลือแค่เนื้อหาจางเข้า .4 วินาทีตอนเปิดหน้า · ห้ามใส่ loop ตกแต่ง, blur ที่ขยับ, transform กับตัวอักษร, View Transitions (กระตุก/เต้นบน Safari และทำให้เวียนหัว)
   แถบบนต้องนิ่ง: ทึบ ไม่เบลอเนื้อหาที่เคลื่อนใต้แถบ และจองที่แถบเลื่อนไว้เสมอ ไม่ให้ทั้งแถบขยับซ้ายขวาเมื่อเปลี่ยนหน้า */
html:has(.app) { scrollbar-gutter: stable; }
.topbar { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; animation: none; transition: none; transform: none; }

/* loop ตกแต่งปิดหมด เหลือเฉพาะที่บอกสถานะจริง (เกินกำหนด/มีปัญหา/กำลังโหลด) */
.hello, .hello-blob, .hello-spark, .hello-name, .hello-focus .dot, .hello-art .ha-doc, .hello-art .ha-stamp, .hello-ico,
.srv-hero .srv-shine::after, .srv-pill.s-ok:not(.is-old) .srv-dot, .srv-head-bg { animation: none !important; }
.srv-hero.is-ok .srv-hero-ico::after { display: none; }
.stat.is-alert .s-ico, .srv-pill.s-warn:not(.is-old) .srv-dot, .cap-row.is-min .cap-chip i { animation-iteration-count: 1 !important; }
@keyframes srvRise { from { opacity: 0; } }

@media (prefers-reduced-motion: no-preference) {
  .content > .page-head, .content > .alert,
  .content > :is(.card, section, .row, .fm-stats, .fm-cats, .table-wrap):not([class*="dx-"]):not(:has(canvas, iframe, .dz-peek-view, .pdfv, #sigMove, #proposePlace)) { animation: sa-fade .4s ease-out backwards; }
}
@keyframes sa-fade { from { opacity: 0; } }

/* ---------- มือถือ/แท็บเล็ต: จัดหน้าให้กระชับและกดง่าย ---------- */
@media (max-width: 991.98px) {
  /* แถบบน: ชื่อโรงเรียนบรรทัดเดียว ตัดด้วย … เพื่อให้ปุ่มธีมและกระดิ่งมีที่พอ */
  .topbar { gap: .35rem; }
  .topbar .icon-btn { flex: none; }
  .school-chip { flex: 1 1 0; min-width: 0; overflow: hidden; }
  .school-chip > :not(.school-dot):not(i) { flex: 1 1 auto; min-width: 0; }
  .school-chip * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .school-chip .school-dot { flex: none; overflow: visible; }
  .content { padding: .9rem .8rem 1.25rem; }
  .form-control, .form-select { font-size: 16px; } /* ต่ำกว่านี้ iPhone จะซูมหน้าเองตอนแตะช่องกรอก */

  /* หัวหน้า: ชื่อกับปุ่มอยู่บรรทัดเดียว */
  .page-head { align-items: center; gap: .55rem .75rem; margin-bottom: .85rem; }
  .page-head > div:first-child { flex: 1 1 55%; min-width: 0; }
  .page-head h1 { font-size: 1.4rem; line-height: 1.25; }
  .page-head .lead-sub { font-size: .84rem; line-height: 1.4; margin-top: .1rem; }
  .page-head .btn { flex: 0 1 auto; }
  .page-head .btn:only-child { min-height: 40px; padding-inline: .8rem; }

  /* การ์ด */
  .card { border-radius: 16px; box-shadow: 0 8px 20px -18px rgba(15, 35, 80, .5); }
  .card-header { flex-wrap: wrap; gap: .5rem; }
  .card-header h2, .card-header h3 { font-size: 1rem; }

  /* การ์ดเริ่มงาน เช่น ออกเลขหนังสือ */
  .intake { border: 0; background: linear-gradient(135deg, color-mix(in srgb, var(--stamp) 13%, var(--surface)), var(--surface) 75%); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--stamp) 22%, var(--line)); }
  .intake-head { gap: .75rem; padding: .9rem; }
  .intake-ico { flex: 0 0 42px; height: 42px; border-radius: 12px; font-size: 1.15rem; }
  .intake-title { flex: 1 1 0; }
  .intake-title h2 { font-size: 1.05rem; }
  .intake-title p { font-size: .8rem; line-height: 1.35; }
  .intake-btn { flex: 1 0 100%; min-height: 46px; font-size: 1rem; }

  /* แท็บ: เลื่อนได้ถึงขอบจอ */
  .content > .nav-pills { margin-inline: -.8rem; padding-inline: .8rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-padding-inline: .8rem; }
  .content > .nav-pills::-webkit-scrollbar { display: none; }
  .content > .nav-pills .nav-link { min-height: 40px; padding: .4rem .85rem; font-size: .9rem; display: flex; align-items: center; gap: .3rem; border-radius: 999px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
  .content > .nav-pills .nav-link.active { background: var(--stamp); color: #fff; box-shadow: none; }
  .register-title { font-size: 1.02rem; margin-bottom: .6rem; }

  /* ค้นหา: ช่องค้นหาเต็มแถว ที่เหลือสองช่องเท่ากัน */
  .list-filter .card-body { padding: .75rem; }
  .list-filter .lf-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .list-filter .lf-q { grid-column: 1 / -1; }
  .list-filter .lf-f, .list-filter .lf-f .form-select, .list-filter .lf-bar .form-select { width: 100%; min-width: 0; }
  .list-filter .lf-bar .btn, .list-filter .form-control, .list-filter .form-select { min-height: 44px; }
  .list-filter .lf-bar > a.btn { grid-column: 1 / -1; }

  /* แถบเมนูล่าง */
  .main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav { border-radius: 18px 18px 0 0; border-top: 0; box-shadow: 0 -8px 24px -14px rgba(15, 35, 80, .35); }
  .bottom-nav .active { font-weight: 700; }
  .bottom-nav a, .bottom-nav button { min-width: 0; white-space: nowrap; font-size: clamp(.62rem, 2.9vw, .72rem); }
  /* ป้ายทุกเมนูอยู่แนวเดียวกัน: ชิดล่าง และปุ่ม + ลอยขึ้นโดยไม่ดันป้าย */
  .bottom-nav a, .bottom-nav button { justify-content: flex-end; }
  .bottom-nav .fab { position: relative; padding-bottom: calc(.35rem + 10px); }
  .bottom-nav .fab i { position: absolute; left: 50%; top: -26px; margin: 0 0 0 -25px; border-radius: 50%; box-shadow: 0 0 0 4px var(--surface), 0 10px 18px -8px var(--stamp); }
}
@media (max-width: 991.98px) {
  /* กันล้นจอทุกหน้า: เมนู/รูป/หน้าต่างต้องไม่กว้างกว่าจอ */
  .main, .content { min-width: 0; }
  .content img, .content canvas, .content svg { max-width: 100%; }
  .dropdown-menu { max-width: calc(100vw - 1.5rem); min-width: min(11rem, calc(100vw - 1.5rem)); }
  .topbar .dropdown-menu { min-width: min(300px, calc(100vw - 1.5rem)) !important; }
  .modal-dialog:not(.modal-fullscreen-lg-down) { margin: .6rem; }
  .modal-footer { flex-wrap: wrap; gap: .4rem; }
  .modal-footer > .btn { flex: 1 1 auto; margin: 0; }
}
@media (max-width: 575.98px) {
  /* ตาราง: แต่ละแถวเป็นการ์ดแยกใบ · ยกเลิกความกว้างขั้นต่ำของคอลัมน์ที่ตั้งไว้สำหรับจอคอม */
  .table-stack td, .table-stack th { min-width: 0 !important; max-width: none !important; }
  .table-stack td { overflow-wrap: anywhere; }
  .table-stack td > * { min-width: 0; }
  .table-stack td::before { flex: none; max-width: 42%; }
  .ap-link-txt, .sec-tg-row > span, .sec-tg-form .form-control, .su-pay-info { flex-basis: 100%; min-width: 0; }
  .table-stack tbody { display: flex; flex-direction: column; gap: .55rem; padding: .6rem; }
  .table-stack tr { border: 1px solid var(--line); border-radius: 13px; padding: .45rem 0; background: var(--surface); }
  .table-stack td:first-child { font-weight: 600; }
  .stat { border-radius: 14px; }
}

/* การ์ด Telegram: เมื่อถูกเลื่อนมาหลังกดเชื่อมต่อ ต้องไม่ถูกแถบบนบัง และเห็นชัดว่าต้องทำต่อที่นี่ */
#telegram { scroll-margin-top: calc(var(--topbar-h) + .75rem); }
#telegram:target { border-color: #229ED9; box-shadow: 0 0 0 3px color-mix(in srgb, #229ED9 22%, transparent); }

/* สวิตช์ในการ์ดโหมดทดลอง (ตั้งค่าระบบ) */
.fit-sw-txt { margin-left: auto; margin-right: .5rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.fit-sw { position: relative; flex: none; width: 36px; height: 20px; border-radius: 999px; background: #9AA3B2; transition: background .15s; }
.fit-sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.fit-toggle[aria-checked="true"] .fit-sw-txt { color: var(--ok); }
.fit-toggle[aria-checked="true"] .fit-sw { background: var(--ok); }
.fit-toggle[aria-checked="true"] .fit-sw::after { left: 18px; }

/* แถบเลื่อนแนวนอนลอยล่างจอ (app.js) */
.hs-bar { position: fixed; bottom: 0; z-index: 1020; height: 16px; overflow-x: auto; overflow-y: hidden; background: var(--surface); border-top: 1px solid var(--line); }
.hs-bar > div { height: 1px; }
@media print { .hs-bar { display: none !important; } }

/* สถานะผูก Telegram ในรายชื่อผู้ใช้ */
.usr-tg { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.usr-tg.is-on { color: var(--ok); font-weight: 600; }

/* ปุ่มตาเปิดดูรหัสผ่าน */
.pw-reveal { position: relative; display: block; }
.pw-reveal .form-control { padding-right: 2.75rem; }
.pw-reveal-btn { position: absolute; top: 0; right: 0; bottom: 0; width: 2.6rem; border: 0; background: none; color: var(--muted); }
.pw-reveal-btn:hover { color: var(--text); }

/* แบนเนอร์ภาพรวม Server บนจอแคบ: ไอคอนคู่หัวข้อ ป้ายสถานะขึ้นแถวใหม่ */
@media (max-width: 767.98px) {
  .srv-hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .7rem .8rem; padding: .9rem 1rem; }
  .srv-shine { position: absolute; }
  .srv-hero-ico { width: 2.6rem; height: 2.6rem; font-size: 1.3rem; border-radius: 12px; align-self: start; }
  .srv-hero-txt b { font-size: 1.1rem; }
  .srv-hero-txt span { font-size: .8rem; }
  .srv-hero-sum { grid-column: 1 / -1; }
}

/* ข้อความ "ไม่มีเรื่องรอคุณ" จัดกลาง */
.mq-empty { text-align: center; text-wrap: balance; }
.mq-table tr.mq-empty-row td { display: block; text-align: center; }
.mq-table tr.mq-empty-row td::before { display: none; }

/* การ์ดสถานะ Telegram บนมือถือ: ชื่อซ้าย ค่าขวา แถวละรายการ ปุ่มเต็มกว้าง */
@media (max-width: 767.98px) {
  .tg-status .meta-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0; margin-bottom: 0; }
  .tg-status .meta-grid dt, .tg-status .meta-grid dd { margin: 0; padding: .55rem 0; border-bottom: 1px solid var(--line); }
  .tg-status .meta-grid dt { font-weight: 500; color: var(--muted); }
  .tg-status .meta-grid dd { text-align: right; font-weight: 600; }
  .tg-status .meta-grid dt:nth-last-of-type(1), .tg-status .meta-grid dd:nth-last-of-type(1) { border-bottom: 0; }
  .tg-status form, .tg-status form .btn { flex: 1 1 100%; width: 100%; }
}

/* ฟอร์มรับหนังสือบนมือถือ: ขั้น 4 พับได้ ปุ่มหลักเต็มกว้างด้านบนสุดของแถบล่าง */
@media (max-width: 991.98px) {
  .intake-modal .modal-header { padding: .7rem .9rem; }
  .intake-modal .modal-body { padding: .7rem; }
  .rx-step { padding: .85rem .9rem .95rem; }
  .rx-h { margin-bottom: .6rem; }
  .rx .dropzone { min-height: 92px; padding: .7rem; }
  .rx .dz-ico { width: 38px; height: 38px; font-size: 1.1rem; border-radius: 11px; }
  .rx-more .rx-h { cursor: pointer; }
  .rx-more .rx-h::after { content: "\F282"; font-family: bootstrap-icons; margin-left: auto; font-weight: 400; color: var(--muted); transition: transform .15s; }
  .rx-more:not(.is-folded) .rx-h::after { transform: rotate(180deg); }
  .rx-more.is-folded { padding-bottom: .85rem; }
  .rx-more.is-folded .rx-h { margin-bottom: 0; }
  .rx-more.is-folded > :not(.rx-h) { display: none; }
  .rx-foot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: .45rem; padding: .55rem .7rem calc(.55rem + env(safe-area-inset-bottom)); }
  .rx-foot > .btn { margin: 0; padding-inline: .3rem; font-size: .88rem; }
  .rx-foot > .btn-primary { grid-column: 1 / -1; grid-row: 1; padding-block: .6rem; font-size: 1rem; }
}

.dz-peek-msg { margin: 0; padding: 1.4rem 1rem; text-align: center; color: var(--muted); font-size: .9rem; }

/* การ์ดผู้ใช้บนมือถือ: ชื่อคู่สถานะ ตำแหน่ง ข้อมูลสามช่อง ปุ่มจัดการ */
@media (max-width: 991.98px) {
  .us-table.table-stack tr { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .55rem .4rem; padding: .8rem .9rem; }
  .us-table.table-stack td { display: block; padding: 0 !important; text-align: left; font-size: .84rem; }
  .us-table.table-stack td::before { display: block; max-width: none; font-size: .72rem; line-height: 1.3; }
  .us-table.table-stack td:nth-child(1) { grid-column: 1 / 5; grid-row: 1; font-weight: 600; }
  .us-table.table-stack td:nth-child(6) { grid-column: 5 / 7; grid-row: 1; display: flex; justify-content: flex-end; align-items: flex-start; }
  .us-table.table-stack td:nth-child(1)::before, .us-table.table-stack td:nth-child(2)::before, .us-table.table-stack td:nth-child(6)::before, .us-table.table-stack td:nth-child(7)::before { display: none; }
  .us-table.table-stack td:nth-child(2) { grid-column: 1 / -1; color: var(--muted); }
  .us-table.table-stack td:nth-child(2) > div { display: inline; }
  .us-table.table-stack td:nth-child(2) > div::before { content: " · "; }
  .us-table.table-stack td:nth-child(3), .us-table.table-stack td:nth-child(4), .us-table.table-stack td:nth-child(5) { grid-column: span 2; padding: .35rem .5rem !important; border-radius: 9px; background: var(--surface-2); }
  .us-table.table-stack td:nth-child(7) { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: .4rem; text-align: right; }
  .us-table .avatar { flex: none; }
}

/* แถบบนมือถือ: ชื่อโรงเรียนหดในที่ว่าง ตัดด้วย ... ไม่ลอดใต้ปุ่มด้านขวา */
@media (max-width: 991.98px) {
  .topbar > .dropdown:has(> .school-chip) { flex: 1 1 0; min-width: 0; }
  .topbar > .dropdown > .school-chip { display: flex; width: 100%; max-width: 100%; }
  .topbar > .d-flex { flex: none; }
}
@media (max-width: 991.98px) and (orientation: landscape) { /* แนวนอน: กว้างตามชื่อ ไม่ยืดเต็มแถบ */
  .topbar > .dropdown:has(> .school-chip) { flex: 0 1 auto; }
  .topbar > .dropdown > .school-chip { width: auto; }
}

/* มือถือแนวตั้ง: ย้ายปุ่มสลับธีมเข้าเมนูผู้ใช้ เพื่อให้ชื่อโรงเรียนแสดงเต็ม · แนวนอนกลับอยู่แถบบน */
.theme-menu-item { display: none; }
@media (max-width: 991.98px) and (orientation: portrait) { #themeToggle { display: none; } .theme-menu-item { display: block; } }


/* บทบาทและสิทธิ์ บนมือถือ: 1) แตะเลือกบทบาท 2) เห็นรายการสิทธิ์พร้อมสวิตช์ 3) บันทึก (แถบบันทึกค้างด้านล่าง) */
.rm-rolelist { list-style: none; margin: 0; padding: 0; }
.rm-rolelist li { border-bottom: 1px solid var(--line); }
.rm-rolelist li:last-child { border-bottom: 0; }
.rl-open { width: 100%; display: flex; align-items: center; gap: .75rem; padding: 1rem 1.1rem; border: 0; background: transparent; text-align: left; color: var(--text); }
.rl-open:active { background: var(--surface-2); }
.rl-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rl-main b { font-size: 1.02rem; }
.rl-main small { color: var(--muted); font-size: .8rem; }
.rl-count { font-size: .78rem; font-weight: 600; color: var(--stamp); background: var(--stamp-soft); padding: .2rem .6rem; border-radius: 999px; white-space: nowrap; }
.rl-open > .bi { color: var(--muted); }
.rm-rolelist li.m-custom .rl-main b { color: #7C3AED; }
.rm-detail-head { padding: .75rem 1.1rem 1rem; border-bottom: 1px solid var(--line); }
.rd-back { border: 0; background: transparent; color: var(--stamp); font-weight: 600; padding: .25rem 0; margin-bottom: .4rem; }
.rd-info h2 { font-size: 1.2rem; margin: 0; }
.rd-info .rd-sub { margin: .1rem 0 .5rem; color: var(--muted); font-size: .85rem; }
.rd-info .rd-note { margin: 0 0 .6rem; font-size: .88rem; padding: .6rem .75rem; border-radius: 10px; background: var(--surface-2); }
@media (max-width: 767.98px) {
  .rm-legend { display: none; }
  #rmCard.rm-list-mode .table-wrap, #rmCard.rm-list-mode .rm-detail-head, #rmCard.rm-list-mode .rm-foot { display: none; }
  #rmCard:not(.rm-list-mode) .rm-rolelist { display: none; }
  #rmCard.rm-ro .rm-foot { display: none; }
  .rm-table, .rm-table tbody { display: block; width: 100%; }
  .rm-table thead, .rm-table .rm-ph, .rm-table [data-rid]:not(.rm-sel) { display: none !important; }
  .rm-table tr { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); }
  .rm-table tr.rm-sec { display: block; padding: .5rem 1.1rem; background: var(--surface-2); }
  .rm-table td { border: 0 !important; padding: 0 !important; background: transparent !important; }
  .rm-table tr.rm-sec td { display: block; }
  .rm-table td:first-child { position: static; flex: 1; min-width: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .rm-table td[data-rid] { flex: none; }
  /* สวิตช์เปิด/ปิด */
  .rm-table .rm-cb { -webkit-appearance: none; appearance: none; width: 3rem; height: 1.8rem; margin: 0; border: 0; border-radius: 999px; background-color: #CBD5E1; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: left center; background-size: contain; transition: background-position .15s, background-color .15s; }
  .rm-table .rm-cb:checked { background-color: var(--stamp); background-position: right center; }
  .rm-table .rm-cb:disabled { opacity: .5; }
  .rm-table .rm-cb:disabled:checked { background-color: var(--muted); }
  /* แถบบันทึกค้างเหนือเมนูล่าง */
  .rm-foot { position: sticky; bottom: 76px; z-index: 5; background: var(--surface); box-shadow: 0 -6px 14px -10px rgba(15, 35, 80, .5); }
  .rm-foot .rm-foot-note { display: none; }
  .rm-foot .btn { width: 100%; min-height: 46px; }
}
