/* ============================================================
   Incident Report — Rose Glassmorphism Theme
   รองรับ: Light/Dark Mode, Desktop/Tablet/Mobile, Print
   ============================================================ */

:root {
  --bg-grad: linear-gradient(165deg, #FDE7F0 0%, #F8D3E5 45%, #EBD5F2 100%);
  --glass: rgba(255, 255, 255, 0.55);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.85);
  --ink: #4B1528;
  --ink-head: #831843;
  --ink-soft: #9D5C77;
  --accent: #BE185D;
  --accent-deep: #9F1239;
  --on-accent: #FDF2F8;
  --line: rgba(159, 18, 57, 0.14);
  --danger: #B4232E;
  --danger-bg: rgba(244, 181, 181, 0.6);
  --warn: #8A5A00;
  --warn-bg: rgba(251, 231, 155, 0.75);
  --ok: #085041;
  --ok-bg: rgba(163, 224, 195, 0.6);
  --shadow: 0 8px 28px rgba(131, 24, 67, 0.14);
  --radius: 20px;
}

[data-theme="dark"] {
  --bg-grad: linear-gradient(165deg, #2A101E 0%, #331327 45%, #2B1533 100%);
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.11);
  --glass-border: rgba(255, 255, 255, 0.14);
  --ink: #F5DCE8;
  --ink-head: #F9A8CD;
  --ink-soft: #C79BAD;
  --accent: #EC5FA0;
  --accent-deep: #F472B6;
  --on-accent: #2A101E;
  --line: rgba(249, 168, 205, 0.16);
  --danger: #FF9B9B;
  --danger-bg: rgba(180, 35, 46, 0.3);
  --warn: #FBD879;
  --warn-bg: rgba(138, 90, 0, 0.35);
  --ok: #8FE3C3;
  --ok-bg: rgba(8, 80, 65, 0.4);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Prompt', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  font-size: 14.5px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- โครงหน้า: Sidebar (จอใหญ่) + Bottom nav (มือถือ) ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--glass-border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh; /* Safari iPad/iPhone: กันปุ่มล่างสุดหลุดเฟรมเพราะแถบเบราว์เซอร์ */
  transition: width 0.2s;
  overflow: hidden;
}
.sidebar.collapsed { width: 66px; }
.sidebar.collapsed .nav-text, .sidebar.collapsed .brand-text { display: none; }

/* ปุ่มออกจากระบบ ตรึงไว้ล่างสุดของเมนู */
.nav-logout { margin-top: auto; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; color: var(--ink-head); font-weight: 600; white-space: nowrap; }

/* ปุ่มย่อ/ขยายเมนู (สามขีด) — หน้าตาเป็นแถวเมนูแบบเดียวกับเมนูอื่น */
button.nav-item {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.nav-toggle {
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  margin-bottom: 12px;
}
.nav-toggle:hover { background: var(--glass-strong); color: var(--ink-head); }
.brand-icon {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px; margin-bottom: 4px;
  color: var(--ink); font-size: 14px; white-space: nowrap;
}
.nav-item:hover { background: var(--glass-strong); text-decoration: none; }
.nav-item.active { background: var(--accent); color: var(--on-accent); font-weight: 500; }
.nav-item .icon { width: 22px; text-align: center; flex-shrink: 0; }

.main { flex: 1; padding: 22px clamp(14px, 3vw, 36px) 90px; max-width: 1100px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; font-weight: 600; color: var(--ink-head); margin: 0; }
.topbar .sub { font-size: 12.5px; color: var(--ink-soft); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--glass-border);
  background: var(--glass); color: var(--ink-head); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.user-chip {
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--ink);
}

/* ---------- การ์ดแก้ว ---------- */
.glass {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.glass h2 { font-size: 15.5px; font-weight: 600; color: var(--ink-head); margin: 0 0 12px; }
.glass { overflow-wrap: break-word; min-width: 0; }
.main { min-width: 0; max-width: min(1500px, 100%); overflow-x: hidden; }

.grid { display: grid; gap: 14px; }
/* minmax(0,1fr) = ยอมให้คอลัมน์หดตามจอ กันเนื้อหาดันหน้าให้กว้างเกินจอมือถือ */
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > * { min-width: 0; }

.metric { text-align: center; padding: 18px 10px; }
.metric .num { font-size: 28px; font-weight: 600; color: var(--ink-head); line-height: 1.2; }
.metric .lbl { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.metric.danger .num, .metric.danger .lbl { color: var(--danger); }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-head); margin: 8px 0 4px; }
label .req { color: var(--danger); }
input[type=text], input[type=password], input[type=date], input[type=time],
input[type=datetime-local], input[type=number], input[type=file], select, textarea {
  width: 100%;
  min-height: 42px; /* ทุกช่องสูงเท่ากันทุกอุปกรณ์ */
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
}
/* select: ปิดหน้าตาของแต่ละเบราว์เซอร์ ใช้ลูกศรเดียวกันหมด ขนาดจึงตรงกับช่องอื่น */
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
textarea { min-height: 70px; resize: vertical; }

/* iPad/iPhone (Safari): ปิดหน้าตา native ของช่องวันที่/เวลา
   ที่แสดงเป็นเม็ดเล็กๆ กลางช่อง ให้เป็นกล่องเต็มความกว้างเหมือนบนคอม */
input[type=date], input[type=time], input[type=datetime-local] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 42px;
  display: block;
}
input::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.3em;
  margin: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: 12px; color: var(--ink-soft); margin: 4px 0 0; }

/* ---------- กล่องค้นหารายเดือน (Dashboard) — ทรงแคปซูลแก้ว โทนธีม ---------- */
.month-filter-row { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.month-filter {
  display: flex; align-items: center; gap: 8px; margin: 0;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 6px 8px 6px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.month-filter .mf-icon { font-size: 13px; color: var(--accent-deep); line-height: 1; }
.month-filter label { margin: 0; font-size: 12.5px; font-weight: 500; color: var(--ink-head); white-space: nowrap; }
.month-filter input[type="month"] {
  width: auto; margin: 0; padding: 7px 12px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--glass); color: var(--ink); font-family: inherit;
}
.month-filter input[type="month"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.month-filter .btn { margin: 0; padding: 7px 18px; font-size: 12.5px; border-radius: 999px; }
.month-filter .mf-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 13px; text-decoration: none; line-height: 1;
}
.month-filter .mf-clear:hover { color: var(--accent-deep); border-color: var(--accent); text-decoration: none; }
.month-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(190, 24, 93, 0.12); color: var(--accent-deep);
  border: 1px solid rgba(190, 24, 93, 0.25);
  border-radius: 999px; padding: 5px 14px; font-size: 12.5px; font-weight: 500;
}
[data-theme="dark"] .month-chip { background: rgba(236, 95, 160, 0.16); color: #F0A5C4; border-color: rgba(236, 95, 160, 0.35); }
@media (max-width: 640px) {
  .month-filter-row { justify-content: stretch; }
  .month-filter { width: 100%; justify-content: space-between; padding-left: 12px; }
}

.btn {
  display: inline-block; border: none; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  border-radius: 12px; padding: 11px 24px;
  font-family: inherit; font-size: 14px; font-weight: 500;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: var(--glass-strong); color: var(--ink-head); border: 1px solid var(--line); }
.btn.small { padding: 6px 14px; font-size: 12.5px; border-radius: 10px; }
.btn.danger { background: var(--danger); color: #fff; }

.checkline { display: flex; align-items: center; gap: 9px; font-size: 13.5px; margin: 8px 0; color: var(--ink); }
.checkline input { width: auto; }

/* ---------- ป้ายกำกับ (Badge) ---------- */
.badge { display: inline-block; font-size: 11.5px; padding: 3px 11px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.tp-crisis    { background: #6B0E22; color: #FDE7F0; }
.tp-emergency { background: var(--danger-bg); color: var(--danger); }
.tp-major     { background: var(--warn-bg); color: var(--warn); }
.tp-minor     { background: var(--ok-bg); color: var(--ok); }
.tp-event     { background: var(--glass-strong); color: var(--ink-soft); border: 1px solid var(--line); }

.st-open     { background: var(--glass-strong); color: var(--ink-head); border: 1px solid var(--line); }
.st-assigned { background: var(--warn-bg); color: var(--warn); }
.st-progress { background: rgba(190, 24, 93, 0.16); color: var(--accent-deep); }
.st-resolved { background: var(--ok-bg); color: var(--ok); }
.st-closed   { background: var(--glass-strong); color: var(--ink-soft); }
.st-overdue  { background: rgba(225, 29, 72, 0.16); color: #E11D48; border: 1px solid rgba(225, 29, 72, 0.35); font-weight: 700; }
[data-theme="dark"] .st-overdue { color: #FF5A6E; border-color: rgba(255, 90, 110, 0.4); }

.over-rto { color: var(--danger); font-weight: 600; }

/* ---------- ไฟสถานะแบบจุด (เขียว/เหลือง/แดง) ---------- */
.st-dot {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.st-dot.st-green  { background: #22C55E; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18), 0 0 6px rgba(34, 197, 94, 0.55); }
.st-dot.st-yellow { background: #F59E0B; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18), 0 0 6px rgba(245, 158, 11, 0.55); }
.st-dot.st-red    { background: #EF4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18), 0 0 6px rgba(239, 68, 68, 0.55); }
.rp-sec { font-weight: 600; font-size: 12.5px; color: var(--accent-deep); margin: 14px 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
.tl-over { color: var(--danger); font-weight: 700; white-space: nowrap; }
.tl-soon { color: var(--warn); font-weight: 600; white-space: nowrap; }
.tl-ok { color: var(--ok); white-space: nowrap; }
.countdown { font-variant-numeric: tabular-nums; }
.rto-big { font-size: 13.5px; color: #E11D48; font-weight: 700; line-height: 1; vertical-align: middle; }
[data-theme="dark"] .rto-big { color: #FF5A6E; }

/* ---------- ตาราง ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl .code-link { font-size: 12.5px; }
.tbl th { text-align: left; font-size: 12px; color: var(--ink-soft); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.row-danger td { background: var(--danger-bg); }
.tbl tr.row-warn td { background: var(--warn-bg); }
/* เคสรอคัดกรอง: แถบจางเตือนว่ายังไม่เข้ากระบวนการ */
.tbl tr.row-pending td { background: rgba(251, 231, 155, 0.32); }
[data-theme="dark"] .tbl tr.row-pending td { background: rgba(138, 90, 0, 0.18); }
.table-wrap { overflow-x: auto; }

/* ---------- กราฟวงกลมใน Dashboard (ลดขนาด 50%) ---------- */
.chart-box { max-width: min(172px, 100%); margin: 0 auto; }

/* ---------- การ์ดวิเคราะห์อัตโนมัติ ---------- */
.auto-card {
  background: rgba(159, 18, 57, 0.08);
  border: 1px solid rgba(159, 18, 57, 0.25);
  border-radius: 16px; padding: 12px 16px; margin-top: 14px;
}
[data-theme="dark"] .auto-card { background: rgba(236, 95, 160, 0.1); border-color: rgba(236, 95, 160, 0.3); }
.auto-card .title { font-size: 12.5px; font-weight: 600; color: var(--accent-deep); margin-bottom: 8px; }
.auto-card .chips { display: flex; gap: 6px; flex-wrap: wrap; }
/* Role พนักงาน: ป้าย "ระดับ" ขนาด 21.5px ตัวอักษรขยายแบบ Extended จัดกึ่งกลางแนวตั้ง ชิดขวาของกรอบ */
.auto-card .ac-flex { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.auto-card .ac-type-wrap { display: flex; align-items: center; justify-content: flex-end; align-self: center; }
.badge.badge-lg {
  font-size: 21.5px;
  padding: 8px 24px;
  font-weight: 600;
  letter-spacing: 0.14em;   /* ขยายระยะตัวอักษรแบบ Extended */
  font-stretch: expanded;
}

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ''; position: absolute; left: -7px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--glass-border);
}
.timeline .when { font-size: 11.5px; color: var(--ink-soft); }
.timeline li.tl-rto-over { color: #E11D48; font-weight: 600; }
.timeline li.tl-rto-over::before { background: #E11D48; box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.2); }
.timeline li.tl-rto-over .when { color: #E11D48; opacity: 0.85; }
[data-theme="dark"] .timeline li.tl-rto-over,
[data-theme="dark"] .timeline li.tl-rto-over .when { color: #FF5A6E; }
[data-theme="dark"] .timeline li.tl-rto-over::before { background: #FF5A6E; box-shadow: 0 0 0 3px rgba(255, 90, 110, 0.2); }

.flash { border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; font-size: 13.5px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--danger-bg); color: var(--danger); }

/* ---------- สวิตช์เปิด/ปิด (Toggle Switch) ---------- */
.switch-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--glass-strong); border: 1px solid var(--line);
  border-radius: 999px; transition: .2s;
}
.switch .slider::before {
  content: ''; position: absolute; width: 18px; height: 18px;
  left: 2px; top: 2px; background: var(--ink-soft);
  border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--on-accent); }

/* ---------- Loading state ของปุ่ม ---------- */
.btn[disabled] { opacity: .7; cursor: not-allowed; }
.btn .spin {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: currentColor;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast แจ้งผล ---------- */
.toast-wrap {
  position: fixed; top: 16px; right: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; cursor: pointer;
  min-width: 240px; max-width: 340px;
  padding: 12px 16px; border-radius: 14px; font-size: 13.5px;
  backdrop-filter: blur(12px); box-shadow: var(--shadow);
  border: 1px solid var(--glass-border);
  animation: toastIn .25s ease;
}
.toast.ok  { background: var(--ok-bg); color: var(--ok); }
.toast.err { background: var(--danger-bg); color: var(--danger); }
.toast.hide { opacity: 0; transform: translateX(20px); transition: .3s; }
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }
@media (max-width: 720px) {
  .toast-wrap { top: auto; bottom: 92px; left: 16px; right: 16px; }
  .toast { max-width: none; }
}

/* ---------- Bottom nav (มือถือ) ---------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--glass-strong); backdrop-filter: blur(14px);
  border-top: 1px solid var(--glass-border);
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
}
.bottom-nav a { text-align: center; color: var(--ink-soft); font-size: 10.5px; }
.bottom-nav a.active { color: var(--accent); font-weight: 500; }
.bottom-nav .icon { font-size: 19px; display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  /* มือถือ: ยังคงการ์ดในแถวเดียว แต่บีบให้พอดีจอ */
  .grid-4, .grid-5 { gap: 6px; }
  .metric { padding: 12px 4px; border-radius: 14px; }
  .metric .num { font-size: 20px; }
  .metric .lbl { font-size: 10px; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .bottom-nav { display: grid; }
  .main { padding-bottom: 110px; }
}

/* ---------- รายการเคสบนมือถือ: Table -> Card (จอ < 768px) ---------- */
@media (max-width: 768px) {
  .tbl .thead-row { display: none; }

  table.tbl, .tbl tbody { display: block; width: 100%; }

  .tbl tr.case-row {
    display: flex;
    flex-wrap: wrap;
    position: relative;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 14px 14px 42px;
    margin-bottom: 10px;
  }
  .tbl tr.case-row.row-pending { background: rgba(254, 249, 195, 0.45); }

  .tbl tr.case-row td {
    display: block;
    width: 100%;
    border: none;
    padding: 3px 0;
  }
  /* ป้ายกำกับเล็กเหนือค่า (เฉพาะช่องที่มี data-label) */
  .tbl tr.case-row td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--ink-soft);
  }

  /* ลำดับการอ่านในการ์ด */
  .td-code     { order: 1; }
  .td-cat      { order: 2; }
  .td-type     { order: 3; width: auto !important; padding-right: 8px !important; }
  .td-status   { order: 4; width: auto !important; }
  .td-reporter { order: 5; }
  .td-date     { order: 6; width: auto !important; padding-right: 22px !important; }
  .td-rto      { order: 7; width: auto !important; }

  /* ซ่อนช่องที่ไปดูต่อในหน้ารายละเอียด (เวลาที่เหลือ/ผู้ปิดงาน/รวมใช้เวลา) */
  .td-left, .td-resolver, .td-duration { display: none !important; }

  .td-code .code-link { font-size: 15.5px; font-weight: 700; }

  /* ทั้งการ์ดกดได้ (ยืดพื้นที่ลิงก์เลขเคสให้คลุมการ์ด) */
  .tbl tr.case-row .code-link::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  /* แถบ "ดูรายละเอียด ›" ท้ายการ์ด */
  .tbl tr.case-row::after {
    content: 'ดูรายละเอียด ›';
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
  }

  /* การ์ดกว้างเต็มจอ ไม่มี scroll แนวนอน */
  .table-wrap { overflow-x: visible; }
}

/* ---------- แท็บจัดการข้อมูล (หน้าตั้งค่า) ---------- */
.tabbar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--glass-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--ink-head); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--glass-border);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}
.tab-btn.active .tab-count { background: var(--accent); color: var(--on-accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

@media (max-width: 768px) {
  .tab-btn { padding: 9px 12px; font-size: 13px; }
}

/* ---------- Import Wizard ---------- */
.wizard-steps { display: flex; gap: 8px; flex-wrap: wrap; }
.wstep {
  flex: 1 1 auto; text-align: center;
  padding: 8px 10px; border-radius: 10px;
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  color: var(--ink-soft); font-size: 13px; font-weight: 500; white-space: nowrap;
}
.wstep.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.wstep.done { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-bg); }

.import-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pill { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill.ok   { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err  { background: var(--danger-bg); color: var(--danger); }

.tbl tr.imp-ok   td { background: rgba(220, 252, 231, 0.35); }
.tbl tr.imp-warn td { background: rgba(254, 249, 195, 0.45); }
.tbl tr.imp-err  td { background: rgba(254, 226, 226, 0.5); }

/* ---------- Print: บีบรายงานให้ลง 1 หน้า A4 ---------- */
@page { size: A4 portrait; margin: 9mm; }
@media print {
  body { background: #fff; color: #000; font-size: 9.5px; }
  .sidebar, .bottom-nav, .topbar, .btn, .no-print { display: none !important; }
  .glass { background: #fff; border: 1px solid #aaa; box-shadow: none; backdrop-filter: none;
           break-inside: avoid; padding: 6px 10px; margin-bottom: 6px; border-radius: 4px; }
  .main { padding: 0; max-width: 100%; }
  a { color: #000; text-decoration: none; }
  h2 { font-size: 11px; margin: 0 0 4px; }
  .grid { gap: 6px; }
  /* บังคับจำนวนคอลัมน์ตอนพิมพ์ ไม่ให้กติกาจอแคบมายุบเป็นแถวเดียวจนรายงานยาว */
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)) !important; }
  .metric { padding: 5px 4px; }
  .metric .num { font-size: 15px; }
  .metric .lbl { font-size: 8px; }
  .tbl { font-size: 8.5px; }
  .tbl th { padding: 2px 6px; font-size: 8px; }
  .tbl td { padding: 3px 6px; }
  .badge { padding: 1px 6px; font-size: 7.5px; }
  .hint { font-size: 7.5px; margin: 2px 0; }
}
