/* DMVIS — ธีมระบบติดตามกรมการขนส่งทางบก: แถบหัวน้ำเงิน, เมนูข้างกรมท่า, การ์ดตัวเลขสีทึบ */

/* ฟอนต์ราชการ TH Sarabun New/PSK ถ้ามีในเครื่อง ไม่มีใช้ Sarabun จาก Google Fonts */
@font-face {
  font-family: "THSarabunLocal";
  src: local("TH Sarabun New"), local("THSarabunNew"), local("TH SarabunPSK"), local("THSarabunPSK");
  size-adjust: 128%;
}
@font-face {
  font-family: "THSarabunLocal";
  font-weight: 600 700;
  src: local("TH Sarabun New Bold"), local("THSarabunNew-Bold"), local("TH SarabunPSK Bold");
  size-adjust: 128%;
}

:root {
  --navy-900: #071d45;
  --navy-800: #0a2a63;
  --navy-700: #0f3a85;
  --blue: #1565d8;
  --blue-500: #1e88e5;
  --green: #22a447;
  --purple: #7b3fc4;
  --orange: #f39200;
  --red: #e53935;
  --teal: #0ea5a4;
  --yellow: #f5c518;
  --ink: #1b2a41;
  --muted: #6b7a90;
  --line: #dfe6f1;
  --bg: #eef3fa;
  --surface: #fff;

  --bs-body-font-family: "THSarabunLocal", "Sarabun", system-ui, sans-serif;
  --bs-body-font-size: .95rem;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--muted);
  --bs-link-color: var(--blue);
  --bs-link-color-rgb: 21, 101, 216;
  --bs-primary: var(--blue);
  --bs-primary-rgb: 21, 101, 216;
}

body { background: var(--bg); }
a {text-decoration: none;}
h1, h2, h3, h4, h5, h6, .h5, .h6 { font-weight: 700; color: var(--navy-800); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- โครงหน้า ---------- */
.app { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 1040;
  display: flex; align-items: center; gap: .75rem; padding: .55rem 1.25rem;
  background: linear-gradient(90deg, var(--navy-900) 0%, var(--navy-700) 55%, var(--blue) 100%);
  color: #fff; box-shadow: 0 2px 8px rgba(7, 29, 69, .25);
}
.org { display: flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; min-width: 0; }
.org strong { display: block; font-size: 1.3rem; line-height: 1.15; }
.org small { display: block; color: #cfe0ff; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 52px; height: 52px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.85); }
.logo-placeholder { display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #ffe27a, #d9a400); color: var(--navy-900); font-weight: 700; border: 2px solid #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.clock { align-items: center; gap: .5rem; font-size: .9rem; }
.clock span { line-height: 1.15; }
.clock small { display: block; color: #cfe0ff; }
.user-btn { display: flex; align-items: center; gap: .4rem; background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: .35rem .75rem; }
.user-btn .bi { font-size: 1.25rem; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.6rem; padding: 0 .25rem; }

/* offcanvas-lg ตั้งพื้นโปร่งใสบนจอกว้าง ต้องบังคับสีกลับ */
.sidebar { background: var(--navy-800) !important; color: #c9d6ee; }
@media (min-width: 992px) { .sidebar { position: sticky; top: 62px; height: calc(100vh - 62px); overflow-y: auto; } }
.sidebar-body { padding: .5rem 0 1.5rem; }
.nav-group { margin: 1rem 1.1rem .3rem; font-size: .8rem; color: #8ea4cc; }
.sidebar ul { list-style: none; margin: 0; padding: 0 .5rem; }
.sidebar li a { display: flex; align-items: center; gap: .65rem; padding: .5rem .7rem; border-radius: 8px; color: #e3ebfa; text-decoration: none; line-height: 1.25; }
.sidebar li a .bi { font-size: 1.05rem; width: 1.2rem; text-align: center; color: #9fb7e6; }
.sidebar li a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar li a[aria-current="page"] { background: var(--blue); color: #fff; font-weight: 600; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.sidebar li a[aria-current="page"] .bi { color: #fff; }

.page { padding: 1.25rem 1.5rem 2.5rem; min-width: 0; }
.no-app .page { padding: 0; }
.page-title { font-size: 1.45rem; margin: 0 0 1rem; padding-left: .7rem; border-left: 5px solid var(--blue); }

@media (max-width: 991.98px) {
  .app { display: block; }
  .menu-btn { display: block; }
  .sidebar.offcanvas-lg { --bs-offcanvas-bg: var(--navy-800); --bs-offcanvas-color: #fff; --bs-offcanvas-width: 17rem; }
  .org strong { font-size: 1.1rem; }
  .org small { max-width: 52vw; }
  .page { padding: 1rem .9rem 2rem; }
}

/* ---------- การ์ดตัวเลข ---------- */
.tile {
  display: flex; align-items: center; gap: .9rem; height: 100%;
  padding: 1rem 1.1rem; border-radius: 12px; color: #fff;
  box-shadow: 0 4px 12px rgba(21, 60, 130, .18);
}
.tile > .bi { font-size: 2rem; width: 3.1rem; height: 3.1rem; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.2); flex: none; }
.tile-label { font-size: .95rem; opacity: .95; }
.tile-value { font-size: 2.1rem; font-weight: 700; line-height: 1.1; }
.tile-value small { font-size: 1rem; font-weight: 500; }
.tile-sub { font-size: .85rem; opacity: .9; }
.tile-blue { background: linear-gradient(135deg, #1e88e5, #1565c0); }
.tile-green { background: linear-gradient(135deg, #2bb24c, #1b8a3a); }
.tile-purple { background: linear-gradient(135deg, #8e4fd6, #6a2fb3); }
.tile-orange { background: linear-gradient(135deg, #ffa726, #f08100); }
.tile-red { background: linear-gradient(135deg, #f0524f, #d32f2f); }
.tile-teal { background: linear-gradient(135deg, #17b8b6, #0b8f8e); }
.tile-navy { background: linear-gradient(135deg, var(--navy-700), var(--navy-900)); }

/* การ์ดตัวเลขแบบพื้นอ่อน (แถวล่าง) */
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; height: 100%; }
.mini-label { color: var(--muted); font-size: .88rem; }
.mini-value { font-size: 1.65rem; font-weight: 700; line-height: 1.2; }
.mini-value small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.mini .bi { margin-right: .3rem; }

/* ---------- กล่องเนื้อหา ---------- */
.panel { background: var(--surface); border-radius: 12px; border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(21, 60, 130, .06); height: 100%; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 1.08rem; margin: 0; }
.panel-body { padding: 1rem 1.1rem; flex: 1; min-width: 0; }
.panel-dark { background: linear-gradient(160deg, var(--navy-700), var(--navy-900)); color: #fff; border: 0; }
.panel-dark .panel-head { border-color: rgba(255,255,255,.15); }
.panel-dark .panel-head h2 { color: #fff; }
.card { border-color: var(--line); border-radius: 12px; }

/* ประเภทระบบในกล่องน้ำเงิน */
.type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr)); gap: .5rem; }
.type-box { border-radius: 10px; padding: .55rem .6rem; text-align: center; }
.type-box b { display: block; font-size: .95rem; }
.type-box span { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.15; }
.type-box small { opacity: .9; }

/* รายการแจ้งเตือนตามระดับ */
.sev-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.sev-list a { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; border-radius: 8px; background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sev-list a:hover { background: rgba(255,255,255,.16); }
.sev-list .dot { width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center; font-size: .85rem; }
.sev-list b { margin-left: auto; font-size: 1.15rem; }

/* legend โดนัท */
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.legend li { display: grid; grid-template-columns: .9rem 1fr auto auto; gap: .55rem; align-items: center; }
.legend i { width: .8rem; height: .8rem; border-radius: 50%; }
.legend b { text-align: right; }
.legend small { color: var(--muted); min-width: 3.5rem; text-align: right; }

/* ---------- ตาราง ---------- */
.table { --bs-table-bg: transparent; --bs-table-hover-bg: #f4f8ff; margin-bottom: 0; }
.table > thead th { background: #f3f7fd; color: var(--navy-800); font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td, .table th { vertical-align: middle; }
.table-responsive { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.panel .table-responsive { border: 0; border-radius: 0; }

/* ---------- ป้ายสถานะ ---------- */
.chip { display: inline-flex; align-items: center; gap: .35em; font-size: .82rem; font-weight: 600; line-height: 1.3; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; background: #e9eef6; color: var(--ink); }
.chip::before { content: ""; width: .5em; height: .5em; border-radius: 50%; background: currentColor; }
.chip-success { background: #e3f6e8; color: #17803a; }
.chip-warning { background: #fff3d6; color: #a86a00; }
.chip-orange { background: #ffe6cc; color: #c25e00; }
.chip-danger { background: #fde4e4; color: #c62828; }
.chip-info { background: #e1efff; color: var(--blue); }
.chip-secondary { background: #eceff4; color: var(--muted); }
.grade { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 6px; font-weight: 700; color: #fff; }
.grade-A { background: var(--green); } .grade-B { background: var(--blue-500); } .grade-C { background: var(--orange); } .grade-D { background: var(--red); }

/* รหัสระบบ */
.plate { display: inline-flex; font-weight: 600; color: var(--navy-800); background: #eef4ff; border: 1px solid #cddcf5; border-radius: 6px; padding: 0 .2rem; white-space: nowrap; text-decoration: none; font-variant-numeric: tabular-nums; }
.plate .seg { padding: .05rem .12rem; }
.plate .seg + .seg { border-left: 1px dotted #a9bde0; }
a.plate:hover { background: #dce9ff; }
.plate-lg { font-size: clamp(1.3rem, 4.5vw, 2.1rem); background: #fff; border: 2px solid var(--navy-800); border-radius: 10px; padding: 0; }
.plate-lg .seg { padding: .5rem .7rem .7rem; display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.plate-lg .seg small { font-weight: 400; font-size: .75rem; color: var(--muted); }
.code { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- ฟอร์ม/ปุ่ม ---------- */
.form-control, .form-select { background-color: var(--surface); border-color: #cfd9e8; border-radius: 8px; }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 .2rem rgba(21, 101, 216, .2); }
.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { --bs-btn-bg: var(--blue); --bs-btn-border-color: var(--blue); --bs-btn-hover-bg: var(--navy-700); --bs-btn-hover-border-color: var(--navy-700); }
.btn-outline-primary { --bs-btn-color: var(--blue); --bs-btn-border-color: var(--blue); --bs-btn-hover-bg: var(--blue); --bs-btn-hover-border-color: var(--blue); }
.filter-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.filter-chips a { padding: .2rem .75rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font-size: .88rem; }
.filter-chips a.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.pagination { --bs-pagination-active-bg: var(--blue); --bs-pagination-active-border-color: var(--blue); }

/* แถบสัดส่วนหลายช่วง */
.stack-bar { display: flex; height: 2.1rem; border-radius: 8px; overflow: hidden; background: #e8eef7; }
.stack-bar span { display: grid; place-items: center; color: #fff; font-weight: 600; font-size: .85rem; min-width: 0; overflow: hidden; }
.progress { --bs-progress-bar-bg: var(--blue); }

/* แผนที่ */
.map { height: 360px; border-radius: 10px; background: #dfe9f7; }
.map-lg { height: 560px; }
.leaflet-container { font-family: inherit; background: #dfe9f7; }
.map-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .85rem; margin-top: .5rem; }
.map-legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }

.chart-box { position: relative; height: 260px; }
.alert-row-danger > td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.alert-row-warning > td:first-child { box-shadow: inset 4px 0 0 var(--orange); }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(20rem, 1fr); }
.login-intro { background: linear-gradient(140deg, var(--navy-900), var(--navy-700) 60%, var(--blue)); color: #dbe7ff; padding: clamp(2rem, 6vw, 5rem); display: flex; flex-direction: column; justify-content: center; gap: 1.5rem; }
.login-intro .org-line { display: flex; align-items: center; gap: .8rem; color: #fff; }
.login-intro .org-line strong { font-size: 1.5rem; display: block; }
.login-intro h1 { color: #fff; font-size: clamp(1.8rem, 3.6vw, 2.7rem); line-height: 1.2; margin: 0; max-width: 20ch; }
.login-intro p { max-width: 46ch; margin: 0; }
.login-intro .plate-lg { align-self: flex-start; color: var(--navy-800); }
.login-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; background: var(--bg); }
.login-form form { width: 100%; max-width: 23rem; background: #fff; padding: 2rem; border-radius: 14px; box-shadow: 0 8px 24px rgba(21, 60, 130, .12); }
.login-form h2 { font-size: 1.4rem; margin-bottom: 1.25rem; }
@media (max-width: 767.98px) {
  .login { grid-template-columns: 1fr; }
  .login-intro p, .login-intro .plate-lg { display: none; }
  .login-form form { padding: 1.5rem; }
}

/* Mobile: ฟอร์มผู้ช่วยนายช่าง ช่องกรอกใหญ่ แตะง่าย */
@media (max-width: 767.98px) {
  .touch-form .form-control, .touch-form .form-select { min-height: 48px; font-size: 1.1rem; }
  .touch-form .btn-submit { width: 100%; min-height: 52px; font-size: 1.15rem; }
}
/* Tablet ขึ้นไป: หน้า PM/CM แบ่งซ้าย-ขวา */
@media (min-width: 768px) {
  .split { display: grid; grid-template-columns: minmax(260px, 2fr) 3fr; gap: 1rem; align-items: start; }
  .split > .split-side { position: sticky; top: 76px; }
}
.stat-card .value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-card .label { color: var(--muted); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
.pager { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; margin-top: .75rem; }

/* ---------- ส่วนหัว: หน่วยงาน, ผู้ใช้ ---------- */
.unit { margin-left: auto; padding: 0 1.25rem; border-left: 1px solid rgba(255,255,255,.25); line-height: 1.25; }
.unit strong { display: block; font-size: 1rem; }
.unit small { color: #cfe0ff; font-size: .85rem; }
.unit + .topbar-right { margin-left: 0; }
.user-btn b { display: block; font-weight: 600; font-size: .9rem; line-height: 1.15; }
.user-btn small { display: block; font-size: .75rem; color: #cfe0ff; max-width: 14rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* เมนูข้าง: การ์ดสายด่วนชิดล่าง */
@media (min-width: 992px) { .sidebar { display: flex; flex-direction: column; } .sidebar-body { flex: 1; } }
.hotline { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; align-items: center; margin: 1rem .75rem 1.25rem; padding: .85rem 1rem; border-radius: 12px; background: linear-gradient(135deg, var(--blue), var(--navy-700)); color: #fff; text-decoration: none; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.hotline .bi { font-size: 1.6rem; }
.hotline strong { display: block; font-size: 1.2rem; line-height: 1.1; }
.hotline small { color: #cfe0ff; }
.hotline em { grid-column: 1 / -1; font-style: normal; font-size: .85rem; text-align: center; color: #e3ecff; margin-top: .3rem; }
.hotline:hover { color: #fff; filter: brightness(1.08); }

/* ---------- ธีมพื้นเข้ม (Dashboard) ---------- */
.theme-dark {
  --bg: #061331; --surface: #0c2152; --line: #1c3770; --ink: #e8efff; --muted: #9db1d8;
  --bs-body-bg: var(--bg); --bs-body-color: var(--ink); --bs-border-color: var(--line); --bs-secondary-color: var(--muted);
  --bs-link-color: #6fb1ff; --bs-link-color-rgb: 111, 177, 255;
  background: radial-gradient(1200px 600px at 70% -10%, #0d2a66 0%, transparent 60%), var(--bg);
}
.theme-dark .topbar { background: linear-gradient(90deg, #04102b, #0a2257 60%, #0c2f74); }
.theme-dark .sidebar { background: #051231 !important; border-right: 1px solid var(--line); }
.theme-dark .page-title { color: #fff; border-left-color: #2f8cff; }
.theme-dark h1, .theme-dark h2, .theme-dark h3, .theme-dark .h5, .theme-dark .h6 { color: #fff; }
.theme-dark .panel { background: linear-gradient(180deg, #0e2558, #0b1f4a); border-color: var(--line); box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.theme-dark .panel-head { border-color: var(--line); }
.theme-dark .table { --bs-table-color: var(--ink); --bs-table-hover-bg: rgba(255,255,255,.04); --bs-table-hover-color: var(--ink); --bs-table-border-color: var(--line); }
.theme-dark .table > thead th { background: rgba(255,255,255,.04); color: #b9caeb; border-color: var(--line); }
.theme-dark .text-secondary { color: var(--muted) !important; }
.theme-dark .form-select, .theme-dark .form-control { background-color: #0a1c45; border-color: var(--line); color: var(--ink); }
.theme-dark .btn-outline-primary { --bs-btn-color: #8cc2ff; --bs-btn-border-color: #3a6fc4; }
.theme-dark .mini { background: var(--surface); border-color: var(--line); }
.theme-dark .chip-secondary { background: rgba(255,255,255,.08); color: var(--muted); }
.theme-dark .legend small { color: var(--muted); }
.theme-dark .map, .theme-dark .leaflet-container { background: #0a1c45; }
.theme-dark .plate { background: rgba(111,177,255,.12); border-color: #2d5aa8; color: #cfe2ff; }

/* ---------- องค์ประกอบ Dashboard ตามแบบ ---------- */
.age-bars { display: grid; gap: .7rem; }
.age-row { display: grid; grid-template-columns: minmax(8rem, 1.3fr) 2fr auto; gap: .75rem; align-items: center; font-size: .9rem; }
.age-row .track { height: .55rem; border-radius: 99px; background: rgba(127,150,190,.25); overflow: hidden; }
.age-row .track i { display: block; height: 100%; border-radius: 99px; }
.age-row b { white-space: nowrap; font-weight: 600; }
.age-row b small { color: var(--muted); font-weight: 400; }
.counter { display: flex; gap: .6rem; align-items: flex-start; }
.counter > .bi { font-size: 1.6rem; line-height: 1; }
.counter .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.counter .l { font-size: .82rem; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.feed a { display: grid; grid-template-columns: 4.6rem 1fr auto; gap: .7rem; align-items: center; padding: .55rem .7rem; border-radius: 10px; background: rgba(127,150,190,.1); color: inherit; text-decoration: none; }
.feed a:hover { background: rgba(127,150,190,.2); }
.feed .sev { text-align: center; color: #fff; font-weight: 700; font-size: .82rem; border-radius: 6px; padding: .3rem .2rem; }
.feed .meta { font-size: .8rem; color: var(--muted); }
.feed .desc { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sev-P1 { background: #e53935; } .sev-P2 { background: #f57c00; } .sev-P3 { background: #f5c518; color: #2a2000 !important; } .sev-P4 { background: #1e88e5; }
.event-card { display: flex; gap: .9rem; align-items: center; }
.event-card .icon { width: 3.3rem; height: 3.3rem; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 1.7rem; background: linear-gradient(135deg, #1e88e5, #0d47a1); color: #fff; }
.map-total { position: absolute; left: 1rem; bottom: 1rem; z-index: 500; background: rgba(6,19,49,.85); color: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .55rem .85rem; font-size: .85rem; }
.map-total b { font-size: 1.15rem; }
.map-wrap { position: relative; }
.leaflet-tooltip { font-family: inherit; }

/* แถวบนของ Dashboard: 3 การ์ด + ประเภทระบบ + บริษัท */
.dash-top { display: grid; gap: 1rem; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.7fr) minmax(0, 1.1fr); }
.dash-top > * { min-width: 0; }
@media (max-width: 1399.98px) { .dash-top { grid-template-columns: repeat(3, minmax(0, 1fr)); } .dash-top > .tile-navy { grid-column: span 2; } }
@media (max-width: 767.98px) { .dash-top { grid-template-columns: 1fr; } .dash-top > .tile-navy { grid-column: auto; } }
.panel.flex-grow-0, .panel.flex-grow-1 { height: auto; }
.min-w-0 { min-width: 0; }
.sev-list .dot.sev-P3 { color: #2a2000; }

/* การ์ดแถวบนแคบ: ลดขนาดไอคอน/ตัวเลขให้ไม่ตัดบรรทัด */
.dash-top .tile { padding: .9rem; gap: .7rem; }
.dash-top .tile > .bi { width: 2.6rem; height: 2.6rem; font-size: 1.45rem; }
.dash-top .tile-label { font-size: .88rem; line-height: 1.3; }
.dash-top .tile-value { font-size: 1.9rem; }
.dash-top .type-box span { font-size: 1.4rem; }
.dash-top .type-box small { font-size: .72rem; }

/* หน้าลืม/ตั้งรหัสผ่านใหม่ และข้อความแจ้งบนหน้าที่ยังไม่เข้าสู่ระบบ */
.auth-page { min-height: 100vh; }
.login-form .auth-card { width: 100%; max-width: 23rem; background: #fff; padding: 2rem; border-radius: 14px; box-shadow: 0 8px 24px rgba(21, 60, 130, .12); }
.no-app .page > .alert { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 1080; width: min(30rem, calc(100% - 2rem)); box-shadow: 0 6px 18px rgba(0,0,0,.15); }
.forgot-link { font-size: .88rem; }

/* ไฟล์หลักฐานแนบ */
.attach-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.attach-list li { display: grid; grid-template-columns: auto 1fr auto; gap: .1rem .5rem; align-items: center; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.attach-list li > .bi { font-size: 1.3rem; color: var(--blue); grid-row: span 2; }
.attach-list li > a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-list li > small { grid-column: 2; }
.attach-list li > form { grid-column: 3; grid-row: 1 / span 2; }
.attach-chip { display: inline-flex; align-items: center; gap: .2rem; font-size: .8rem; padding: .05rem .45rem; border-radius: 99px; background: #e8f0fe; text-decoration: none; white-space: nowrap; }

/* ================= รองรับมือถือ / iPad / PC ================= */
pre, pre code { white-space: pre-wrap; word-break: break-all; }

/* จอสัมผัส: ปุ่มเล็กยังแตะง่าย */
@media (pointer: coarse) {
  .btn-sm, .page-link, .filter-chips a { min-height: 2.25rem; display: inline-flex; align-items: center; justify-content: center; }
  .sidebar li a { padding-top: .65rem; padding-bottom: .65rem; }
}

/* iPad แนวตั้ง / มือถือแนวนอน (ต่ำกว่า 992px เมนูข้างเป็นแบบเลื่อนออก) */
@media (max-width: 991.98px) {
  .page-title { font-size: 1.25rem; }
  .panel-head { padding: .7rem .9rem; }
  .panel-body { padding: .8rem .9rem; }
  .map-lg { height: 420px; }
}

/* มือถือ */
@media (max-width: 767.98px) {
  .topbar { padding: .45rem .75rem; gap: .5rem; }
  .logo { width: 40px; height: 40px; }
  .org strong { font-size: 1rem; }
  .org small { font-size: .72rem; max-width: 46vw; }
  .user-btn { padding: .3rem .5rem; }
  .page { padding: .85rem .7rem 2rem; }
  .page-title { font-size: 1.12rem; margin-bottom: .75rem; }

  /* การ์ดตัวเลขแบบกะทัดรัด: ไอคอนเล็ก ตัวเลขเล็กลง ไม่กินจอ */
  .tile { padding: .65rem .8rem; gap: .6rem; border-radius: 10px; }
  .tile > .bi { width: 2.2rem; height: 2.2rem; font-size: 1.15rem; }
  .tile-label { font-size: .82rem; line-height: 1.25; }
  .tile-value { font-size: 1.45rem; }
  .tile-sub { font-size: .75rem; }
  .mini { padding: .6rem .75rem; }
  .mini-value { font-size: 1.3rem; }
  .row.g-3 { --bs-gutter-x: .6rem; --bs-gutter-y: .6rem; }

  /* Dashboard แถวบน: 2 คอลัมน์ กล่องประเภทระบบเต็มแถวไว้ท้าย */
  .dash-top { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .dash-top > a { order: 4; }
  .dash-top > .tile-navy { order: 5; grid-column: 1 / -1; }
  .type-box span { font-size: 1.2rem; }

  .map { height: 300px; }
  .map-lg { height: 340px; }
  .chart-box { height: 220px !important; }
  .legend li { grid-template-columns: .8rem 1fr auto; }
  .legend small { display: none; }
  .age-row { grid-template-columns: 1fr auto; }
  .age-row .track { grid-column: 1 / -1; order: 3; }
  .feed a { grid-template-columns: 4rem 1fr; }
  .feed a > .bi { display: none; }
  .pager { justify-content: center; }
  .pager > span { width: 100%; text-align: center; }
  .modal-dialog { margin: .75rem; }

  /* ตาราง → การ์ดทีละแถว ชื่อคอลัมน์อยู่ซ้าย ค่าอยู่ขวา */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: .55rem .75rem; border-bottom: 1px solid var(--line); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .18rem 0; border: 0; text-align: right; min-height: 1.6rem; }
  .table-stack td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); }
  .table-stack td[data-label=""]::before { content: none; }
  .table-stack td[data-label=""] { justify-content: flex-end; }
  .table-stack td[colspan] { display: block; text-align: left; padding-top: 0; }
  .table-stack td > .form-control, .table-stack td > .form-select { flex: 1; min-width: 0; max-width: 60%; }
  .table-stack td > form { flex: 1; text-align: right; }
  .table-stack tr.alert-row-danger { box-shadow: inset 4px 0 0 var(--red); }
  .table-stack tr.alert-row-warning { box-shadow: inset 4px 0 0 var(--orange); }
  .table-stack tr.alert-row-danger > td:first-child, .table-stack tr.alert-row-warning > td:first-child { box-shadow: none; }
  /* แถวรายละเอียดที่ตามหลังแถวหลัก (colspan) ให้อยู่การ์ดเดียวกัน */
  .table-stack tr:has(+ tr > td[colspan]) { border-bottom: 0; padding-bottom: 0; }
  .table-stack tr:has(> td[colspan]) td:first-child:empty { display: none; }
}
@media (max-width: 767.98px) {
  .dash-top .tile > .bi { display: none; }
  .dash-top .tile-value { font-size: 1.6rem; }
  .dash-top .tile { padding: .7rem .8rem; }
}

/* ตารางคอลัมน์มาก (.table-wide): เป็นการ์ดตั้งแต่จอเล็กกว่า 1200px, iPad แสดง 2 การ์ดต่อแถว */
@media (max-width: 1199.98px) {
  .table-wide.table-stack thead { display: none; }
  .table-wide.table-stack, .table-wide.table-stack tr, .table-wide.table-stack td { display: block; width: 100%; }
  .table-wide.table-stack tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: .6rem; padding: .6rem; }
  .table-wide.table-stack tr { padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
  .table-wide.table-stack td { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .18rem 0; border: 0; text-align: right; min-height: 1.6rem; }
  .table-wide.table-stack td > * { min-width: 0; overflow-wrap: anywhere; }
  .table-wide.table-stack td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); }
  .table-wide.table-stack td[data-label=""]::before { content: none; }
  .table-wide.table-stack tr.alert-row-danger { box-shadow: inset 4px 0 0 var(--red); }
  .table-wide.table-stack tr.alert-row-danger > td:first-child { box-shadow: none; }
  .table-wide.table-stack tr:has(> td[colspan]) { grid-column: 1 / -1; }
}
/* ช่องที่มีบรรทัดรอง (<div class="small">) ในโหมดการ์ด: บรรทัดรองขึ้นบรรทัดใหม่ ชิดขวา */
@media (max-width: 767.98px) { .table-stack td { flex-wrap: wrap; } .table-stack td > div { flex-basis: 100%; text-align: right; } }
@media (max-width: 1199.98px) { .table-wide.table-stack td { flex-wrap: wrap; } .table-wide.table-stack td > div { flex-basis: 100%; text-align: right; } }

/* มือถือ/แท็บเล็ต: เมนู offcanvas สูงเท่าจอ ให้ส่วนรายการเมนูเลื่อนได้เอง (ไม่งั้นเมนูล่างๆ ถูกตัด) */
@media (max-width: 991.98px) {
  .sidebar.offcanvas-lg { display: flex; flex-direction: column; }
  .sidebar-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
}

/* Dashboard: ส่วนต่างๆ ซ่อน/แสดงได้ (ปุ่ม x) ส่วนที่เหลือจัดเรียงใหม่เต็มพื้นที่อัตโนมัติ */
.dash-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
.dash-grid > .dash-item { min-width: 0; }
.dash-grid > .dash-item[hidden] { display: none; }
.dash-grid > .dash-item > .panel { height: 100%; }
/* จำนวนคอลัมน์ตามความกว้างจอ: 1 (มือถือ) / 2 / 3 — ความกว้าง/สูงที่ผู้ใช้เลือก (data-w, data-h) ใช้ได้เท่าที่จอรองรับ */
@media (min-width: 768px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid > .dash-item[data-w="2"], .dash-grid > .dash-item[data-w="3"] { grid-column: span 2; }
  .dash-grid > .dash-item[data-h="2"] { grid-row: span 2; }
}
@media (min-width: 1600px) {
  .dash-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-grid > .dash-item[data-w="3"] { grid-column: span 3; }
}
.dash-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.dash-tool { border: 0; background: transparent; color: inherit; opacity: .7; width: 1.9rem; height: 1.9rem; border-radius: 6px; display: inline-grid; place-items: center; flex: 0 0 auto; }
.dash-tool:hover, .dash-tool:focus-visible { opacity: 1; background: rgba(255,255,255,.12); }
.dash-grid:not(.editing) .dash-tool { display: none; }
.dash-drag { cursor: grab; touch-action: none; }
.dash-grid.editing > .dash-item > .panel { outline: 2px dashed rgba(120,170,255,.55); outline-offset: 2px; }
.dash-ghost { opacity: .35; }
.dash-close { margin-left: .25rem; border: 0; background: transparent; color: inherit; opacity: .55; width: 1.9rem; height: 1.9rem; border-radius: 6px; display: inline-grid; place-items: center; flex: 0 0 auto; }
.dash-close:hover, .dash-close:focus-visible { opacity: 1; background: rgba(255,255,255,.12); }
.panel-head > h2 { margin-right: auto; }
.dash-restore:not([hidden]) { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.dash-chip { border-radius: 999px; }
/* จอเล็กเป็นคอลัมน์เดียว ปุ่มปรับกว้าง/สูงไม่มีผล จึงซ่อนไว้ (ยังลากย้ายและซ่อนได้) */
@media (max-width: 767.98px) { .dash-grid .dash-tool[data-width], .dash-grid .dash-tool[data-height] { display: none; } }
