/* ============================================================
   PR-System — Modern Indigo Theme
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --brand:        #0d6efd;   /* น้ำเงิน — ปุ่ม/ลิงก์/โฟกัส (สีหลักของระบบ) */
  --brand-hover:  #0b5ed7;
  --brand-light:  #E7F1FF;   /* พื้นน้ำเงินอ่อน (hover แถว/chip) */
  --brand-muted:  rgba(13,110,253,.1);
  --navy:         #14213D;   /* กรมท่าเข้ม — แถบบน + sidebar */

  --text-primary:   #211C15;
  --text-secondary: #6E665A;
  --text-muted:     #9A9286;

  --bg-body:     #F7F8FA;   /* ขาวเกือบเต็ม — ให้การ์ดสีขาวคมขึ้นด้วย border/shadow */
  --bg-card:     #FFFFFF;
  --bg-subtle:   #FAF7F1;

  --border:        #E5E7EB;
  --border-radius: 12px;

  --success:     #3F7D3F;
  --success-bg:  #E7F2E7;
  --warning:     #C77B12;
  --warning-bg:  #FBEFD7;
  --danger:      #B42318;
  --danger-bg:   #FAE9E7;
  --info:        #1B5E8C;
  --info-bg:     #E4F0F7;
  --muted-bg:    #EFEBE3;
  --muted-color: #6E665A;

  --sidebar-width: 230px;
  --topnav-height: 52px;
}

/* --- Bootstrap variable bridge --- */
/* Map Bootstrap's own CSS vars to our tokens so overrides propagate everywhere */
:root {
  --bs-primary:          var(--brand);
  --bs-primary-rgb: 13, 110, 253;   /* = #0d6efd */
  --bs-body-color:       var(--text-primary);
  --bs-body-bg:          var(--bg-body);
  --bs-secondary-color:  var(--text-secondary);
  --bs-border-color:     var(--border);
  --bs-border-radius:    10px;
  --bs-border-radius-sm: 8px;
  --bs-border-radius-lg: 12px;
}

/* --- Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-body);
  margin: 0;
}



/* --- Cards --- */
.card {
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 10px rgba(15,23,42,.04);
  overflow: hidden;
}
.card > .card-body.p-0 {
  border-radius: inherit;
}
.card-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.25rem;
  font-weight: 600;
  font-size: 14px;
}

/* --- Page header --- */
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: var(--brand);
}
.page-header .text-muted {
  font-size: 13px;
}

/* --- Alerts --- */
.alert {
  font-size: 13px;
  border-radius: 8px;
}

/* --- Buttons --- */
.btn {
  font-size: 13px;
  border-radius: 8px;
  font-weight: 500;
}
.btn-sm {
  border-radius: 7px;
  font-size: 12px;
}
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}
.btn-outline-primary {
  color: var(--brand);
  border-color: var(--brand);
}
.btn-outline-primary:hover {
  background: var(--brand);
  border-color: var(--brand);
}
.btn-outline-secondary {
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-outline-secondary:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border);
}

/* --- Forms --- */
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-control, .form-select {
  font-size: 13px;
  border-color: var(--border);
  border-radius: 8px;
  background: #FAFAFA;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
  background: #fff;
}
.form-control-sm, .form-select-sm {
  border-radius: 7px;
}
.input-group-text {
  border-color: var(--border);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 15px;
}
.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}
.form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
}

/* --- Tables --- */
.table {
  font-size: 13px;
  margin-bottom: 0;
  --bs-table-bg: var(--bg-card);
}

/* cell padding — override table-sm tightness */
.table > :not(caption) > * > * {
  padding: .65rem .9rem;
  border-bottom-color: var(--border);
  vertical-align: middle;
}
.table-sm > :not(caption) > * > * {
  padding: .6rem .9rem;
}

/* header — override Bootstrap table-light via CSS vars */
.table > thead > tr > th,
.table > thead.table-light > tr > th {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text-secondary);
  /*background: #E3E4F8 !important;*/
  background: var(--bs-card-cap-bg);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 2px solid var(--brand) !important;
  padding: .6rem .9rem;
}

/* hover row */
.table-hover > tbody > tr:hover > * {
  --bs-table-accent-bg: var(--brand-light);
  background-color: var(--brand-light) !important;
  transition: background .1s;
}

/* tbody row divider */
.table > tbody > tr > td {
  border-bottom: 1px solid var(--border);
}

/* last row — no double border with card edge */
.table > tbody > tr:last-child > td {
  border-bottom: none;
}

/* --- Badges (Bootstrap override → pill + soft colors) --- */
.badge {
  border-radius: 20px;
  padding: .3em .75em;
  font-weight: 500;
  font-size: 11px;
}
.badge.bg-primary              { background: var(--brand)       !important; color: #fff !important; }
.badge.bg-secondary            { background: #E4E4E7            !important; color: var(--muted-color) !important; }
.badge.bg-success              { background: var(--success-bg)  !important; color: var(--success) !important; }
.badge.bg-danger               { background: var(--danger-bg)   !important; color: var(--danger) !important; }
.badge.bg-warning              { background: var(--warning-bg)  !important; color: var(--warning) !important; }
.badge.bg-warning.text-dark    { background: var(--warning-bg)  !important; color: var(--warning) !important; }
.badge.bg-info                 { background: var(--info-bg)     !important; color: var(--info) !important; }
.badge.bg-info.text-dark       { background: var(--info-bg)     !important; color: var(--info) !important; }
.badge.bg-light                { background: var(--muted-bg)    !important; color: var(--muted-color) !important; }
.badge.bg-dark                 { background: #27272A            !important; color: #fff !important; }

/* --- Buttons — consistent radius + refined variants --- */
.btn-dark {
  background: #18181B;
  border-color: #18181B;
  border-radius: 8px;
}
.btn-dark:hover {
  background: #27272A;
  border-color: #27272A;
}
.btn-secondary {
  background: #E4E4E7;
  border-color: #E4E4E7;
  color: var(--text-primary);
  border-radius: 8px;
}
.btn-secondary:hover {
  background: #D4D4D8;
  border-color: #D4D4D8;
  color: var(--text-primary);
}
.btn-outline-danger {
  color: var(--danger);
  border-color: #FECACA;
  border-radius: 8px;
}
.btn-outline-danger:hover {
  background: var(--danger-bg);
  border-color: #FECACA;
  color: var(--danger);
}
.btn-outline-warning {
  color: var(--warning);
  border-color: #FDE68A;
  border-radius: 8px;
}
.btn-outline-warning:hover {
  background: var(--warning-bg);
  border-color: #FDE68A;
  color: var(--warning);
}
.btn-outline-success {
  color: var(--success);
  border-color: #A7F3D0;
  border-radius: 8px;
}
.btn-outline-success:hover {
  background: var(--success-bg);
  border-color: #A7F3D0;
  color: var(--success);
}
.btn-success {
  background: var(--success);
  border-color: var(--success);
  border-radius: 8px;
}
.btn-info {
  background: var(--info);
  border-color: var(--info);
  border-radius: 8px;
}

/* --- Custom status badges --- */
.badge-draft     { background: var(--muted-bg);    color: var(--muted-color); border-radius: 20px; }
.badge-pending   { background: var(--warning-bg);  color: var(--warning);     border-radius: 20px; }
.badge-approved  { background: var(--success-bg);  color: var(--success);     border-radius: 20px; }
.badge-rejected  { background: var(--danger-bg);   color: var(--danger);      border-radius: 20px; }
.badge-cancelled { background: var(--muted-bg);    color: var(--text-muted);  border-radius: 20px; }

/* --- Nav pills --- */
.nav-pills .nav-link {
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.nav-pills .nav-link.active {
  background: var(--brand);
}

/* --- Approval step dots --- */
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.dot-done   { background: var(--success-bg); color: var(--success); }
.dot-active { background: var(--brand);      color: #fff; box-shadow: 0 0 0 4px rgba(13,110,253,.12); }
.dot-wait   { background: var(--muted-bg);   color: var(--text-muted); border: 1px solid var(--border); }
.dot-reject { background: var(--danger-bg);  color: var(--danger); }

/* --- Top Navbar --- */
.topnav {
  background: var(--brand);
  height: var(--topnav-height);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.topnav-brand {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}
.topnav-brand:hover { color: #fff; }
.topnav-nav {
  display: flex;
  gap: 2px;
  margin-left: .5rem;
  min-width: 0;
}
.topnav-nav a {
  color: rgba(255,255,255,.65);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: all .15s;
}
.topnav-nav a i {
  font-size: 15px;
  margin-right: 0 !important;
}
.topnav-nav a:hover  { background: rgba(255,255,255,.12); color: #fff; }
.topnav-nav a.active { background: rgba(255,255,255,.2);  color: #fff; font-weight: 500; }

/* กลุ่มเมนู (dropdown) บน topnav — ลิงก์ toggle ใช้สไตล์เดียวกับลิงก์เดี่ยวด้านบนอยู่แล้ว (.topnav-nav a)
   ใช้ display:'static' (ปิด Popper) แล้วคุมตำแหน่งเองด้วย CSS ตรงๆ เพื่อไม่ให้ถูกคลิปบน mobile
   ตอนแถบเมนู scroll แนวนอน (.topnav-nav มี overflow-y:hidden) */
.topnav-dropdown { display: flex; position: relative; }
.topnav-dropdown .dropdown-toggle::after { margin-left: 6px; vertical-align: .1em; opacity: .8; }
.topnav-nav .dropdown-menu {
  margin-top: 6px;
  min-width: 190px;
  padding: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.topnav-nav .dropdown-item {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text-primary);
}
.topnav-nav .dropdown-item i { font-size: 14px; color: var(--text-muted); width: 18px; }
.topnav-nav .dropdown-item:hover { background: var(--brand-light); color: var(--brand); }
.topnav-nav .dropdown-item:hover i { color: var(--brand); }
.topnav-nav .dropdown-item.active { background: var(--brand); color: #fff; }
.topnav-nav .dropdown-item.active i { color: #fff; }
.topnav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  color: rgba(255,255,255,.85);
  font-size: 13px;
  flex-shrink: 0;
  white-space: nowrap;
}
.topnav-right a {
  color: rgba(255,255,255,.6);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  text-decoration: none;
  transition: color .15s;
}
.topnav-right a:hover { color: #fff; }
.topnav-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.22);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; margin-right: 6px; flex-shrink: 0;
}

/* ปุ่มแฮมเบอร์เกอร์ + แผงเมนูมือถือ — ซ่อนบน desktop เสมอ, โชว์เฉพาะ mobile ใน media query ด้านล่าง */
.topnav-toggler {
  display: none; flex: none; background: none; border: none; color: #fff;
  width: 40px; height: 40px; align-items: center; justify-content: center;
  font-size: 20px; border-radius: 8px; cursor: pointer;
}
.topnav-toggler:hover { background: rgba(255,255,255,.12); }
.topnav-mobile-panel { display: none; }
.topnav-badge {
  position: absolute; top: -4px; right: -8px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: #ef4444; color: #fff; font-size: 9.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1; pointer-events: none;
  animation: topnav-badge-pulse 2s ease-out infinite;
}
@keyframes topnav-badge-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70%  { box-shadow: 0 0 0 7px rgba(0,0,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); }
}

/* --- Card hover --- */
.card-hover {
  transition: transform .15s ease, box-shadow .15s ease;
}
.card-hover:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(13,110,253,.1);
}

/* --- Content wrap --- */
.wrap {
/*  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem 2rem;*/


  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  /*background: rgb(0 0 0 / 7%);*/
/*  border-radius: 20px;
  margin-top: 10px;*/
}

/* --- Sidebar (admin layout) --- */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh; /* ล็อกเท่าจอ ให้ .sidebar-nav เลื่อนภายในแทน — min-height ทำให้กล่อง fixed ยืดเกินจอแล้วเลื่อนไม่ได้ */
  background: var(--navy);
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.sidebar-brand {
  padding: 1.25rem;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-brand span {
  opacity: .5;
  font-size: 11px;
  display: block;
  font-weight: 400;
  margin-top: 2px;
}
.sidebar-nav {
  padding: .5rem 0;
  flex: 1;
  overflow-y: auto;
}
.sidebar-nav .nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 13px;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav .nav-item a:hover {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.9);
}
.sidebar-nav .nav-item a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-weight: 500;
  border-left-color: rgba(255,255,255,.6);
}
.sidebar-nav .nav-item a i { font-size: 16px; opacity: .85; }
.sidebar-section {
  padding: 1.25rem 1.25rem .35rem;
  font-size: 10px;
  color: rgba(255,255,255,.3);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
}
.sidebar-footer {
  padding: .85rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-footer .user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer .logout-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,.5);
  font-size: 12px;
  text-decoration: none;
  margin-top: 6px;
  transition: color .15s;
}
.sidebar-footer .logout-link:hover { color: #fff; }

.main-wrap {
  margin-left: var(--sidebar-width);
  padding: 1.5rem 2rem;
}

/* --- Login --- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(13,110,253,.1) 0%, var(--bg-body) 65%);
  padding: 1rem;
}
.login-box {
  width: 100%;
  max-width: 400px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,.06), 0 20px 60px rgba(13,110,253,.2);
}
.login-header {
  background: linear-gradient(155deg, #0F2747 0%, #16335A 50%, #23467A 100%);
  padding: 2.5rem 1.75rem 2.25rem;
  text-align: center;
}
.login-header-icon {
  width: 60px;
  height: 60px;
  background: rgba(255,255,255,.18);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  backdrop-filter: blur(4px);
}
.login-header-icon i {
  font-size: 30px;
  color: #fff;
}
.login-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 .35rem;
  letter-spacing: -.01em;
}
.login-header p {
  font-size: 12.5px;
  color: rgba(255,255,255,.65);
  margin: 0;
  letter-spacing: .04em;
}
.login-body {
  background: var(--bg-card);
  padding: 2rem 1.75rem;
}
.login-btn {
  padding: .8rem 1rem;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  border-radius: 10px;
  transition: transform .1s, box-shadow .2s;
}
.login-btn:hover {
  box-shadow: 0 6px 20px rgba(13,110,253,.35);
}
.login-btn:active {
  transform: translateY(1px);
}
.login-toggle {
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s;
}
.login-toggle:hover {
  color: var(--brand);
}
.login-footer {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: .75rem 1rem;
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: .02em;
}
@media (max-width: 767.98px) {
  .login-wrapper {
    align-items: flex-start;
    padding-top: 2rem;
  }
}

/* --- Pill selection group --- */
.pill-group { display:flex; flex-wrap:wrap; gap:8px; }
.pill-radio  { position:absolute; opacity:0; width:0; height:0; }
.pill-label  {
  display:inline-flex; align-items:center;
  padding:6px 16px; border:1.5px solid var(--border); border-radius:20px;
  cursor:pointer; font-size:13px; color:var(--text-secondary);
  transition:all .15s; user-select:none; line-height:1.4;
}
.pill-radio:checked + .pill-label {
  background:var(--brand); border-color:var(--brand);
  color:#fff; font-weight:600;
}
.pill-label:hover { border-color:var(--brand); color:var(--brand); }
.pill-radio:checked + .pill-label:hover { color:#fff; }
.pill-tag {
  background:rgba(255,255,255,.25); color:inherit;
  font-size:9px; font-weight:600; padding:1px 5px;
  border-radius:8px; margin-left:4px;
}
.pill-radio:not(:checked) + .pill-label .pill-tag { display:none; }

/* --- Item search-to-add row --- */
.item-row { padding:10px 0; border-bottom:1px solid var(--border); }
.item-row:first-child { padding-top:2px; }
.item-row:last-child { border-bottom:none; padding-bottom:2px; }
.item-field-label {
  display:block; font-size:10.5px; color:var(--text-muted);
  margin-bottom:2px; font-weight:500;
}

/* --- Signature pad --- */
.sig-wrapper {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: #fff;
  position: relative;
  height: 180px;
  transition: border-color .2s;
}
.sig-wrapper:hover, .sig-wrapper:focus-within {
  border-color: var(--brand);
}
.sig-wrapper::before {
  content: '✕';
  position: absolute;
  left: 20px;
  bottom: 48px;
  font-size: 14px;
  color: #ccc;
  pointer-events: none;
  z-index: 0;
}
.sig-wrapper::after {
  content: 'ลงชื่อ / Sign here';
  position: absolute;
  left: 40px;
  right: 20px;
  bottom: 45px;
  border-bottom: 1.5px dashed #ccc;
  font-size: 10px;
  color: #ccc;
  text-align: right;
  padding-bottom: 4px;
  pointer-events: none;
  z-index: 0;
}
.sig-wrapper canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
  z-index: 1;
}

/* --- Utilities --- */
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.text-brand { color: var(--brand); }
.bg-brand   { background: var(--brand); color: #fff; }

/* --- Table row number --- */
.table > thead > tr > .row-num,
.table > tbody > tr > .row-num {
  width: 36px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding-left: .5rem;
  padding-right: .5rem;
}

/* --- Site mobile card (shared across site pages) --- */
.site-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  transition: box-shadow .15s;
}
.site-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); color: inherit; }
.site-card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.site-card-date { font-weight: 600; color: var(--brand); font-size: 13px; }
.site-card-title { font-weight: 500; font-size: 13px; }
.site-card-meta { font-size: 11px; color: var(--text-secondary); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.site-card-body { font-size: 12px; color: var(--text-secondary); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.site-card-divider { height: .5px; background: var(--border); margin: 8px 0; }
.site-card-foot { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--text-muted); }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 48px;
  opacity: .2;
  margin-bottom: .75rem;
  display: block;
}
.empty-state p {
  font-size: 14px;
  margin: 0;
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */

@media (max-width: 767.98px) {
  :root { --topnav-height: 56px; }

  .topnav {
    padding: 0 .5rem;
    gap: .35rem;
    overflow: hidden;
  }
  .topnav-brand {
    width: 40px;
    height: 40px;
    justify-content: center;
    border-radius: 8px;
    gap: 0;
    font-size: 0;
  }
  .topnav-brand i { font-size: 18px; }

  /* เมนูแบบ dropdown-ในแถบเลื่อนแนวนอนของ desktop ซ่อนบนมือถือทั้งหมด — ใช้ปุ่มแฮมเบอร์เกอร์ + แผงเมนูแนวตั้งแทน
     (เดิมกดแล้วบางครั้งไม่เปิด เพราะแตะใกล้ขอบแถบเลื่อนโดนตีความเป็นท่าทางเลื่อนหน้าจอแทนการแตะ) */
  .topnav-nav { display: none; }
  .topnav-toggler { display: flex; margin-left: auto; }
  .topnav-right {
    margin-left: 8px;
    gap: 4px;
  }
  .topnav-right span { display: none; }
  .topnav-right a {
    width: 38px;
    height: 40px;
    justify-content: center;
    border-radius: 8px;
    font-size: 0;
  }
  .topnav-right a i { font-size: 16px; }

  /* แผงเมนูมือถือ — position:fixed ให้พ้นการคลิปของ .topnav (overflow:hidden) เสมอ ไม่ต้องพึ่งการคำนวณตำแหน่งแบบ Popper */
  .topnav-mobile-panel {
    display: none;
    position: fixed;
    top: var(--topnav-height, 56px);
    left: 0; right: 0;
    max-height: calc(100vh - var(--topnav-height, 56px));
    overflow-y: auto;
    background: var(--bg-card, #fff);
    border-top: 1px solid var(--border);
    box-shadow: 0 12px 24px rgba(0,0,0,.15);
    z-index: 1050;
    padding: 6px;
  }
  .topnav-mobile-panel.show { display: block; }
  .topnav-mobile-user {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; font-size: 13px; font-weight: 600; color: var(--text-primary);
    border-bottom: 1px solid var(--border); margin-bottom: 6px;
  }
  .topnav-mobile-user .topnav-avatar { background: var(--brand); }
  .topnav-mobile-label {
    padding: 8px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: .03em;
    color: var(--text-muted); text-transform: uppercase;
  }
  .topnav-mobile-link {
    display: flex; align-items: center; gap: 4px;
    padding: 10px 12px; border-radius: 8px; font-size: 14px;
    color: var(--text-primary); text-decoration: none;
  }
  .topnav-mobile-link.topnav-mobile-sublink { padding-left: 26px; font-size: 13.5px; }
  .topnav-mobile-link:active, .topnav-mobile-link:hover { background: var(--bg-subtle); }
  .topnav-mobile-link.active { background: var(--brand-light); color: var(--brand); font-weight: 600; }

  .wrap {
    max-width: 100%;
    padding: 1.1rem 1rem;
  }
  .page-header { margin-bottom: 1rem; }
  .page-header h1 { font-size: 18px; }
  .page-header .text-muted { font-size: 12px; line-height: 1.45; }

  #archiveTabs {
    display: flex;
    flex-wrap: nowrap;
    gap: .35rem;
    overflow-x: auto;
    padding-bottom: .15rem;
    scrollbar-width: none;
  }
  #archiveTabs::-webkit-scrollbar { display: none; }
  #archiveTabs .nav-link {
    white-space: nowrap;
    font-size: 12px;
    padding: .45rem .7rem;
    border-radius: 8px;
  }

  .doc-card { border-radius: 9px; }
  .doc-card .card-body { padding: .75rem .9rem !important; }
  .doc-card .card-body > .d-flex:first-child { align-items: flex-start !important; gap: .5rem; }
  .doc-card .fw-600 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }
  .doc-card .small { line-height: 1.45; overflow-wrap: anywhere; }

  /* Sidebar → top bar on mobile */
  .sidebar {
    width: 100%;
    min-height: 0;
    height: 56px;
    position: sticky;
    flex-direction: row;
    align-items: center;
    padding: 0 .5rem;
    gap: .35rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
  }
  .sidebar-brand {
    flex: 0 0 42px;
    width: 42px;
    height: 40px;
    justify-content: center;
    padding: 0;
    border-bottom: 0;
    border-radius: 8px;
    gap: 0;
  }
  .sidebar-brand div { display: none; }
  .sidebar-brand i { font-size: 18px; }
  .sidebar-nav {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .sidebar-section { display: none; }
  .sidebar-nav .nav-item { flex: 0 0 auto; }
  .sidebar-nav .nav-item a {
    height: 40px;
    padding: 4px 8px;
    gap: 4px;
    border-left: 0;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.15;
    white-space: nowrap;
  }
  .sidebar-nav .nav-item a.active { border-left-color: transparent; }
  .sidebar-nav .nav-item a i { font-size: 15px; }
  .sidebar-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding: 0;
    border-top: 0;
  }
  .sidebar-footer .user-name { display: none; }
  .sidebar-footer .logout-link {
    width: 38px;
    height: 40px;
    justify-content: center;
    margin-top: 0;
    border-radius: 8px;
    font-size: 0;
  }
  .sidebar-footer .logout-link i { font-size: 16px; }

  .main-wrap {
    margin-left: 0;
    padding: 1.1rem 1rem;
  }
  .main-wrap .page-header.d-flex { align-items: flex-start !important; flex-wrap: wrap; gap: .75rem; }
  .main-wrap .page-header h1 { font-size: 18px; }
  .main-wrap .page-header .btn { flex-shrink: 0; }
  .main-wrap > .d-flex.gap-2,
  .main-wrap .mb-3 > .d-flex.flex-wrap.gap-2 {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    padding-bottom: .15rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .main-wrap > .d-flex.gap-2::-webkit-scrollbar,
  .main-wrap .mb-3 > .d-flex.flex-wrap.gap-2::-webkit-scrollbar { display: none; }
  .main-wrap .nav-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: .35rem;
    padding-bottom: .15rem;
    scrollbar-width: none;
  }
  .main-wrap .nav-pills::-webkit-scrollbar { display: none; }
  .main-wrap .nav-pills .nav-link {
    white-space: nowrap;
    font-size: 12px;
    padding: .45rem .7rem;
    border-radius: 8px;
  }
  .main-wrap .card { border-radius: 9px; }
  .main-wrap .card-header.d-flex { align-items: flex-start !important; flex-wrap: wrap; gap: .5rem; }
  .main-wrap .card > .card-body.p-0 {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .main-wrap .card > .card-body.p-0 > .table { min-width: 720px; }
  .main-wrap .card-body > form .d-flex.gap-2.align-items-center { flex-wrap: wrap; }
  .main-wrap .card-body > form .d-flex.gap-2.align-items-center > .form-select,
  .main-wrap .card-body > form .d-flex.gap-2.align-items-center > .form-control,
  .main-wrap .card-body > form .d-flex.gap-2.align-items-center > .btn {
    flex: 1 1 100%;
    min-width: 0 !important;
  }
}

@media (max-width: 380px) {
  .topnav-nav a { min-width: 52px; padding-inline: 6px; font-size: 10px; }
  .sidebar-nav .nav-item a { padding-inline: 6px; font-size: 10px; }
  .wrap, .main-wrap { padding-inline: .75rem; }
}

/* --- Approval timeline connector --- */
.approval-step { position: relative; }
.approval-step + .approval-step { padding-top: 4px; }
.approval-step + .approval-step::before {
  content: '';
  position: absolute;
  left: 22px;
  top: -10px;
  width: 2px;
  height: 14px;
  background: var(--border);
}
.approval-step.step-done + .approval-step::before,
.approval-step.step-done + .approval-step.step-done::before { background: var(--success); }

/* --- Approval: urgent button pulse --- */
@keyframes _urgentGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180,35,24,.3); }
  50%       { box-shadow: 0 0 0 5px rgba(180,35,24,.08); }
}
.btn-urgent-pulse {
  animation: _urgentGlow 2s ease-in-out infinite;
}

/* --- Approval view: mobile responsive --- */
@media (max-width: 767.98px) {
  /* sig pad shorter on small screens */
  .sig-wrapper { height: 140px; }

  /* approval page summary strip wraps cleanly */
  .approval-summary-total {
    border-top: 1px solid rgba(13,110,253,.15);
    padding-top: .5rem;
    margin-top: .25rem;
  }
}


/* ============================================================
   Bootstrap utility patch — ผูก subtle/text utility ของ Bootstrap
   เข้ากับ token กลาง (Bootstrap ไม่ได้ผูก .bg-*-subtle/.text-* กับ
   CSS var ของเราโดยอัตโนมัติ จึงต้อง override ให้ตรงกันที่นี่)
   ============================================================ */
.bg-primary-subtle { background-color: color-mix(in srgb, var(--brand) 15%, white) !important; }
.text-primary      { color: var(--brand) !important; }
.bg-success-subtle { background-color: #E7F2E7 !important; }
.text-success      { color: #3F7D3F !important; }
.bg-warning-subtle { background-color: #FBEFD7 !important; }
