:root {
  /* โทนสีฟ้า/กรมท่า ตามภาพโบรชัวร์อ้างอิง (เดิมเป็นโทนส้ม) — ยังใช้ชื่อตัวแปร --orange เดิมไว้ (ไม่เปลี่ยนชื่อ)
     เพื่อไม่ต้องแก้จุดที่อ้างถึงตัวแปรนี้ทั่วทั้งเว็บ */
  --orange: #0EA5E9;
  --orange-dark: #0284C7;
  --orange-light: #E0F2FE;
  --navy: #16293F;
  --navy-dark: #0F1D2E;
  --blue: #2563EB;
  --blue-dark: #1D4ED8;
  --gray-900: #1F2937;
  --gray-700: #374151;
  --gray-500: #6B7280;
  --gray-200: #E5E7EB;
  --gray-100: #F3F4F6;
  --bg: #EEF1F5;
  --white: #FFFFFF;
  --green: #16A34A;
  --green-light: #ECFDF3;
  --red: #DC2626;
  --red-dark: #B91C1C;
  --red-light: #FEF2F2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

/* ป้ายบอกว่ารายการนี้ใช้ "รหัสเฉพาะ" (เช่น JS0007) แทนทะเบียนรถจริง — ใช้ร่วมกันหลายหน้า (staff/history/reports) */
.id-badge {
  display: inline-block; font-size: 10px; font-weight: 700; color: var(--blue);
  background: #EFF6FF; border: 1px solid var(--blue); border-radius: 6px; padding: 1px 8px; margin-left: 4px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Sarabun", "Segoe UI", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--gray-900);
}
a { color: inherit; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--orange) 0%, var(--orange-dark) 100%);
}
.login-card {
  background: var(--white);
  padding: 40px 36px;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 4px;
}
.login-logo { font-size: 40px; text-align: center; margin-bottom: 8px; }
.login-logo-img { width: 100%; max-width: 280px; height: auto; display: block; margin: 0 auto 16px; }
.login-card h1 { font-size: 19px; text-align: center; margin: 0 0 20px; color: var(--gray-900); }
.login-card label { font-size: 13px; color: var(--gray-500); margin-top: 12px; }
.login-card input {
  padding: 12px 14px; border: 1px solid var(--gray-200); border-radius: 8px;
  font-size: 15px; margin-top: 4px;
}
.alert-error {
  background: var(--red-light); color: var(--red);
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 8px;
}

/* ---------- Layout ---------- */
.topbar {
  background: var(--white); border-bottom: 1px solid var(--gray-200);
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 24px; position: sticky; top: 0; z-index: 10;
}
/* แถวบน (โลโก้/ชื่อ site/ผู้ใช้) แยกจากแถวเมนู (nav) เป็นคนละแถวกัน กันชื่อ site ที่จัดกึ่งกลางแบบ
   position: absolute ไปทับเมนูที่มีหลายลิงก์ (เมื่อก่อนอยู่แถวเดียวกับ nav แล้วข้อความยาวๆ ไปบังลิงก์ "สมาชิก"/"ประเภทรถ" ได้) */
.topbar-row1 { display: flex; align-items: center; justify-content: space-between; position: relative; }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--orange); font-size: 18px; }
/* ชื่อ site (เช่น "ตลาดเจริญศรี") จัดไว้กึ่งกลางแถวบนเสมอ ไม่ว่า brand/user ฝั่งซ้าย-ขวาจะกว้างเท่าไหร่ */
.topbar-site-center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-weight: 700; color: var(--gray-700); font-size: 22px; white-space: nowrap;
}
@media (max-width: 640px) { .topbar-site-center { display: none; } }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.topbar nav a {
  text-decoration: none; padding: 12px 16px; border-radius: 8px; font-size: 14px;
  color: var(--gray-700); font-weight: 500; display: inline-flex; align-items: center;
  min-height: 44px; box-sizing: border-box; touch-action: manipulation;
}
.topbar nav a.active, .topbar nav a:hover { background: var(--orange-light); color: var(--orange-dark); }
/* เมนูย่อยแบบ dropdown (เช่น "รายงาน" > รายงานการเงิน/รายงานรถเข้าออก) — ปุ่มเปิดหน้าตาเหมือนลิงก์เมนูปกติ
   ทุกอย่าง (ใช้ CSS class ชุดเดียวกัน) กดแล้วค่อยกางเมนูย่อยลงมาด้านล่าง ปิดเองเมื่อคลิกที่อื่น (ดู toggleNavDropdown ใน app.js) */
.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  text-decoration: none; padding: 12px 16px; border-radius: 8px; font-size: 14px;
  color: var(--gray-700); font-weight: 500; display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; box-sizing: border-box; touch-action: manipulation;
  background: none; border: none; cursor: pointer; font-family: inherit;
}
.nav-dropdown-toggle.active, .nav-dropdown-toggle:hover { background: var(--orange-light); color: var(--orange-dark); }
.nav-dropdown-menu {
  display: none; flex-direction: column; gap: 2px;
  position: absolute; top: 100%; left: 0; margin-top: 4px;
  background: #fff; border: 1px solid var(--gray-200); border-radius: 10px;
  box-shadow: var(--shadow); min-width: 190px; padding: 6px; z-index: 20;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; }
.nav-dropdown-menu a { justify-content: flex-start; }
.topbar .user { font-size: 13px; color: var(--gray-500); display: flex; align-items: center; gap: 10px; }
.topbar .user a { color: var(--orange); text-decoration: none; font-weight: 600; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--gray-500); font-size: 14px; margin: 0 0 20px; }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat-card .label { font-size: 13px; color: var(--gray-500); }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card.orange .value { color: var(--orange); }
.stat-card.green .value { color: var(--green); }

.section-title { font-size: 16px; font-weight: 700; margin: 28px 0 12px; display: flex; align-items: center; gap: 8px; }
.badge-count { background: var(--orange); color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 6px; }

/* ---------- Vehicle queue cards ---------- */
.queue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 16px; }
.vcard {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; border: 1px solid var(--gray-200);
}
.vcard .thumb { width: 100%; height: 150px; background: var(--gray-100) center/cover no-repeat; display:flex; align-items:center; justify-content:center; color: var(--gray-500); font-size: 13px; }
.vcard .body { padding: 14px; }
.vcard .plate { font-size: 20px; font-weight: 700; }
.vcard .meta { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.vcard .row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.vcard select { padding: 11px 10px; border-radius: 8px; border: 1px solid var(--gray-200); font-size: 15px; min-height: 44px; touch-action: manipulation; }
.vcard .price { font-size: 18px; font-weight: 700; color: var(--orange); }
.vcard .actions { display: flex; gap: 8px; margin-top: 12px; }
.tag { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 600; }
.tag-unregistered { background: var(--red-light); color: var(--red); }
.tag-pending { background: var(--orange-light); color: var(--orange-dark); }
.tag-paid { background: var(--green-light); color: var(--green); }
.tag-manual { background: var(--gray-100); color: var(--gray-500); }

/* ---------- Buttons ---------- */
/* ขนาดปุ่มปรับให้กดง่ายบนจอทัชสกรีน (touch target ขั้นต่ำ ~44px) ทุกหน้า
   touch-action: manipulation กันดีเลย์ 300ms ที่เบราว์เซอร์มือถือรอดูว่าจะ double-tap ซูมไหม */
.btn {
  border: none; border-radius: 99px; padding: 12px 18px; font-size: 15px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  min-height: 44px; touch-action: manipulation;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-outline { background: var(--white); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-outline:hover { background: var(--gray-100); }
.btn-block { width: 100%; margin-top: 22px; padding: 14px; font-size: 16px; min-height: 48px; }
.btn-sm { padding: 9px 14px; font-size: 13px; min-height: 38px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--gray-100); }
th { background: var(--gray-100); color: var(--gray-500); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
/* checkbox ในตาราง (เช่นเลือกรายการออกรายงาน PDF) — ขยายให้แตะง่ายขึ้นบนจอทัชสกรีน */
td input[type="checkbox"], th input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
/* min-width: 0 กัน CSS Grid บังคับให้คอลัมน์กว้างเกิน 1fr ตาม min-content ของ label/input ยาวๆ (เช่น "รหัสประเภท * (เช่น A, 6W, PICKUP)")
   ซึ่งทำให้ฟอร์มล้นกรอบ modal ออกไป — ไม่มีบรรทัดนี้ label ยาวจะดันกล่องล้นแทนที่จะตัดคำ/ห่อบรรทัดตามปกติ */
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field label { font-size: 13px; color: var(--gray-500); font-weight: 600; }
.form-field input, .form-field select { padding: 12px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 15px; min-height: 44px; box-sizing: border-box; touch-action: manipulation; }
.card-block { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 11px 12px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 15px; min-height: 44px; box-sizing: border-box; touch-action: manipulation; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); font-size: 14px; }

/* ---------- Print slip ---------- */
.slip { width: 58mm; margin: 0 auto; padding: 8px; font-family: monospace; font-size: 12px; }
/* ประกาศขนาดกระดาษเป็นม้วนใบเสร็จ 58mm ให้เครื่องพิมพ์ความร้อนจริงตัดขอบกระดาษเปล่าออก
   (ช่วยลดพื้นที่หัว-ท้ายกระดาษที่บางเบราว์เซอร์ใส่ URL/วันที่ให้อัตโนมัติเวลาพิมพ์ไปด้วย
   แต่ปิดข้อความหัว-ท้ายกระดาษของเบราว์เซอร์เองแบบเต็มที่ต้องไปปิดที่ตัวเลือก "Headers and footers"
   ในหน้าต่างสั่งพิมพ์ของเบราว์เซอร์เอง หน้าเว็บสั่งปิดให้แทนไม่ได้) */
@media print { @page { size: 58mm auto; margin: 3mm; } }
.slip h2 { text-align: center; font-size: 14px; margin: 4px 0; }
.slip .line { border-top: 1px dashed #000; margin: 6px 0; }
.slip .row { display: flex; justify-content: space-between; margin: 3px 0; }
.slip .total { font-size: 15px; font-weight: 700; }
.slip-datetime { text-align: center; font-size: 10px; font-weight: 700; margin-bottom: 4px; white-space: nowrap; }
.slip-contact { text-align: center; font-size: 11px; margin-top: 6px; }
@media print { .no-print { display: none; } body { background: #fff; } }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar nav { display: none; }
}

/* =====================================================================
   หลังบ้านสไตล์ FlowAccount (ใช้กับทุกหน้าที่ include includes/header.php ผ่าน body.admin-layout)
   แถบไอคอนซ้ายสุด (.rail) + แถบเมนูย่อย (.subnav) + พื้นที่เนื้อหา (.app-main)
   หน้าเก็บเงินหน้าตู้ (staff.php) ไม่ได้ใช้ header.php จึงไม่ได้รับผลจากบล็อกนี้
   ===================================================================== */
body.admin-layout {
  --fa-blue: #1E93D0;
  --fa-blue-dark: #0F78B5;
  --fa-blue-light: #E8F4FB;
  --fa-green: #6FB326;
  --fa-green-dark: #5A9A1B;
  background: #EEF3F7;
}
.app-shell { display: flex; min-height: 100vh; }

.rail {
  width: 58px; flex: 0 0 58px; background: linear-gradient(180deg, #1B9AD8 0%, #0E76B5 100%);
  display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.rail-logo {
  width: 36px; height: 36px; border-radius: 50%; background: #fff; color: var(--fa-blue-dark);
  font-weight: 800; font-size: 20px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px;
  overflow: hidden;
}
/* assets/logo-icon.png = ตัดมาจากโลโก้เต็ม (assets/logo.png) เฉพาะส่วนสัญลักษณ์โลก (ไม่รวมตัวหนังสือ TARADFLOW)
   ตัดเป็นภาพสี่เหลี่ยมจัตุรัสไว้แล้ว จึงแค่ย่อให้เต็มวงกลมนี้ตรงๆ */
.rail-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; width: 100%; }
.rail-item {
  display: flex; align-items: center; justify-content: center; height: 48px; width: 100%;
  color: rgba(255,255,255,.85); text-decoration: none; touch-action: manipulation;
}
.rail-item:hover { background: rgba(255,255,255,.14); color: #fff; }
.rail-item.active { background: rgba(255,255,255,.22); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.rail-logout { flex: 0 0 auto; }

.subnav {
  width: 210px; flex: 0 0 210px; background: #fff; border-right: 1px solid #E3EAF0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.subnav-title { font-size: 20px; font-weight: 700; color: var(--gray-700); padding: 22px 20px 12px; }
.subnav-links { display: flex; flex-direction: column; padding: 0 0 8px; flex: 1; overflow-y: auto; }
.subnav-links a {
  text-decoration: none; color: #696969; font-size: 14px; padding: 11px 20px;
  border-left: 3px solid transparent;
}
.subnav-links a:hover { background: var(--fa-blue-light); }
.subnav-links a.active { background: #EEF1F5; font-weight: 700; color: #111; border-left-color: var(--fa-blue); }
.subnav-foot { padding: 14px 20px; border-top: 1px solid #EDF1F5; font-size: 12px; color: var(--gray-500); display: flex; flex-direction: column; gap: 3px; }
.subnav-site { font-weight: 700; color: var(--gray-700); font-size: 13px; }
.subnav-logout { color: var(--fa-blue); text-decoration: none; font-weight: 600; margin-top: 4px; }

.app-main { flex: 1; min-width: 0; }
body.admin-layout .container { max-width: none; padding: 24px 1cm; }

/* หัวเรื่องหน้า + breadcrumb (breadcrumb เติมด้วย JS ใน app.js) */
body.admin-layout .page-title { font-size: 28px; font-weight: 400; color: var(--fa-blue); margin: 0 0 2px; }
.crumb { font-size: 12px; color: var(--gray-500); margin: 0 0 18px; }
body.admin-layout .page-sub { color: var(--gray-500); }
body.admin-layout .section-title { color: var(--gray-700); }

/* ปุ่ม: หลัก = เขียว (แบบปุ่ม "สร้างใหม่"), รอง = ขอบฟ้า */
body.admin-layout .btn { border-radius: 6px; }
body.admin-layout .btn-primary { background: var(--fa-green); }
body.admin-layout .btn-primary:hover { background: var(--fa-green-dark); }
body.admin-layout .btn-outline { background: #fff; color: var(--fa-blue-dark); border-color: #BBD9EC; }
body.admin-layout .btn-outline:hover { background: var(--fa-blue-light); }

/* ตาราง: หัวตารางสีฟ้า ตัวอักษรขาว */
body.admin-layout .table-wrap { border-radius: 8px; box-shadow: none; border: 1px solid #DCE6EE; background: #fff; }
body.admin-layout th {
  background: var(--fa-blue); color: #fff; font-size: 13px; font-weight: 600; text-transform: none; padding: 12px 16px; white-space: nowrap;
}
body.admin-layout td { border-bottom: 1px solid #EDF1F5; padding: 14px 16px; }
body.admin-layout tbody tr:hover td { background: #F6FAFD; }
body.admin-layout .stat-card, body.admin-layout .card-block { box-shadow: none; border: 1px solid #DCE6EE; }
body.admin-layout .badge-count { background: var(--fa-blue); }

/* ตัวแบ่งหน้าใต้ตาราง (สร้างโดย setupTablePagination ใน app.js สำหรับ tbody[data-paginate]) */
.table-pager { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-top: 1px solid #EDF1F5; flex-wrap: wrap; font-size: 13px; color: var(--gray-700); }
.table-pager button {
  min-width: 34px; height: 34px; border: 1px solid #D5E3EE; background: #fff; border-radius: 6px; cursor: pointer; color: var(--fa-blue-dark);
  font-family: inherit; font-size: 13px; padding: 0 8px;
}
.table-pager button:hover:not(:disabled) { background: var(--fa-blue-light); }
.table-pager button.active { background: var(--fa-blue); border-color: var(--fa-blue); color: #fff; }
.table-pager button:disabled { opacity: .4; cursor: default; }
.table-pager .pp-size { margin-left: 14px; display: flex; align-items: center; gap: 6px; }
.table-pager select { height: 34px; border: 1px solid #D5E3EE; border-radius: 6px; padding: 0 6px; font-family: inherit; }
.table-pager .pp-total { margin-left: auto; color: var(--gray-500); }

/* มือถือ/จอแคบ: แถบไอคอนกลายเป็นแถบบน เมนูย่อยเป็นแถวเลื่อนแนวนอน */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .rail { width: 100%; flex: none; height: auto; flex-direction: row; padding: 6px 8px; position: sticky; top: 0; z-index: 30; }
  .rail-logo { margin: 0 8px 0 0; }
  .rail-nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .rail-item { height: 44px; width: 48px; flex: 0 0 auto; }
  .rail-item.active { box-shadow: inset 0 -3px 0 #fff; }
  .subnav { width: 100%; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid #E3EAF0; }
  .subnav-title, .subnav-foot { display: none; }
  .subnav-links { flex-direction: row; overflow-x: auto; padding: 0; }
  .subnav-links a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .subnav-links a.active { border-bottom-color: var(--fa-blue); }
  body.admin-layout .container { padding: 16px; }
}

body.admin-layout a.btn { text-decoration: none; }
