/* ==========================================================================
   SIAM 09 — ธีมเลียนแบบ Materio Bootstrap Admin
   ค่าสีและระยะทั้งหมดอ้างอิงจาก demo จริงของ Materio
   ========================================================================== */

:root {
  --siam-primary: #8C57FF;
  --siam-primary-dark: #7B4DE6;
  --siam-primary-soft: rgba(140, 87, 255, .16);
  --siam-success: #56CA00;
  --siam-success-soft: rgba(86, 202, 0, .16);
  --siam-danger: #FF4C51;
  --siam-danger-soft: rgba(255, 76, 81, .16);
  --siam-warning: #FFB400;
  --siam-warning-soft: rgba(255, 180, 0, .16);
  --siam-info: #16B1FF;
  --siam-info-soft: rgba(22, 177, 255, .16);
  --siam-secondary: #8A8D93;
  --siam-secondary-soft: rgba(138, 141, 147, .16);

  --siam-body-bg: #F4F5FA;
  --siam-paper: #FFFFFF;
  --siam-text: #6D6777;
  --siam-heading: #2E263D;
  --siam-muted: #A8A3B1;
  --siam-border: rgba(46, 38, 61, .12);

  --siam-radius: 6px;
  --siam-shadow: 0 4px 10px 0 rgba(46, 38, 61, .12);
  --siam-shadow-sm: 0 2px 4px 0 rgba(46, 38, 61, .16);
  --siam-shadow-lg: 0 6px 18px 0 rgba(46, 38, 61, .18);

  --siam-menu-width: 260px;
  --siam-navbar-height: 64px;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--siam-body-bg);
  color: var(--siam-text);
  font-family: 'Inter', 'Noto Sans Thai', -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, .h5, .h6 { color: var(--siam-heading); font-weight: 500; }
a { color: var(--siam-primary); text-decoration: none; }
a:hover { color: var(--siam-primary-dark); }
.text-heading { color: var(--siam-heading) !important; }
.text-muted-2 { color: var(--siam-muted) !important; }
.fw-medium { font-weight: 500 !important; }

/* ── เมนูซ้าย (vertical menu) ─────────────────────────────────────────── */
.layout-menu {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--siam-menu-width);
  background: var(--siam-paper);
  box-shadow: 0 2px 10px rgba(46, 38, 61, .08);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
}

.menu-brand {
  display: flex;
  align-items: center;
  gap: .625rem;
  height: var(--siam-navbar-height);
  padding: 0 1.25rem;
  flex: 0 0 auto;
}
.menu-brand-logo {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 18px;
  background: linear-gradient(72deg, var(--siam-primary) 22%, rgba(140, 87, 255, .7) 76%);
  box-shadow: 0 2px 6px rgba(140, 87, 255, .35);
}
.menu-brand-text {
  font-size: 1.15rem; font-weight: 700; letter-spacing: .5px;
  color: var(--siam-heading);
}
.menu-brand-sub { font-size: .7rem; color: var(--siam-muted); letter-spacing: .4px; }

.menu-inner { flex: 1 1 auto; overflow-y: auto; padding: .5rem 1rem 1rem; }
.menu-section {
  font-size: .75rem; letter-spacing: .4px; text-transform: uppercase;
  color: var(--siam-muted); padding: 1rem .5rem .375rem;
}
.menu-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .625rem .9rem;
  border-radius: var(--siam-radius);
  color: var(--siam-text);
  font-size: .9375rem;
  margin-bottom: .25rem;
  transition: background .15s ease, color .15s ease;
  cursor: pointer;
}
.menu-link:hover { background: rgba(46, 38, 61, .06); color: var(--siam-heading); }
.menu-link i { font-size: 1.15rem; }
.menu-link.active {
  color: #fff;
  background: linear-gradient(72.47deg, var(--siam-primary) 22.16%, rgba(140, 87, 255, .7) 76.47%);
  box-shadow: 0 2px 6px rgba(140, 87, 255, .3);
}
.menu-link.active:hover { color: #fff; }
.menu-badge {
  margin-left: auto; font-size: .75rem; font-weight: 500;
  background: var(--siam-primary-soft); color: var(--siam-primary);
  border-radius: 20px; padding: .1rem .5rem;
}
.menu-link.active .menu-badge { background: rgba(255, 255, 255, .25); color: #fff; }

/* ── พื้นที่เนื้อหา + navbar บน ────────────────────────────────────────── */
.layout-page { margin-left: var(--siam-menu-width); min-height: 100vh; }

.layout-navbar {
  position: fixed; top: 0; right: 0; left: var(--siam-menu-width);
  height: var(--siam-navbar-height);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 8px rgba(46, 38, 61, .08);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.5rem;
  z-index: 1030;
}
.navbar-toggler-btn {
  display: none; border: 0; background: transparent;
  color: var(--siam-text); font-size: 1.4rem; padding: .25rem .4rem;
}
.navbar-search {
  display: flex; align-items: center; gap: .5rem;
  color: var(--siam-muted); flex: 1 1 auto; max-width: 420px;
}
.navbar-search input {
  border: 0; outline: 0; background: transparent;
  font-size: .95rem; color: var(--siam-heading); width: 100%;
}
.navbar-search input::placeholder { color: var(--siam-muted); }

.navbar-stat {
  display: flex; align-items: center; gap: .5rem;
  background: var(--siam-primary-soft); color: var(--siam-primary);
  border-radius: 20px; padding: .3rem .85rem;
  font-size: .8125rem; font-weight: 500; white-space: nowrap;
}

.content-wrapper {
  padding: calc(var(--siam-navbar-height) + 1.5rem) 1.5rem 2rem;
  max-width: 1440px;
}

.page-title { font-size: 1.35rem; font-weight: 500; margin: 0 0 .25rem; }
.page-subtitle { font-size: .9rem; color: var(--siam-muted); margin: 0 0 1.5rem; }

/* ── การ์ด ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--siam-paper);
  border: 0;
  border-radius: var(--siam-radius);
  box-shadow: var(--siam-shadow);
}
.card-header {
  background: transparent; border-bottom: 0;
  padding: 1.25rem 1.5rem .75rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.card-title { font-size: 1.0625rem; font-weight: 500; color: var(--siam-heading); margin: 0; }
.card-subtitle { font-size: .8125rem; color: var(--siam-muted); margin: .15rem 0 0; }
.card-body { padding: 1.25rem 1.5rem 1.5rem; }

/* ── การ์ดสถิติ ────────────────────────────────────────────────────────── */
.stat-card { display: flex; align-items: flex-start; gap: .875rem; padding: 1.25rem; height: 100%; }
.stat-icon {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 8px; display: grid; place-items: center; font-size: 1.35rem;
}
.stat-label { font-size: .8125rem; color: var(--siam-muted); margin: 0; }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--siam-heading); line-height: 1.25; margin: .15rem 0 0; }
.stat-hint { font-size: .75rem; color: var(--siam-muted); margin: .15rem 0 0; }

.bg-soft-primary   { background: var(--siam-primary-soft); color: var(--siam-primary); }
.bg-soft-success   { background: var(--siam-success-soft); color: var(--siam-success); }
.bg-soft-danger    { background: var(--siam-danger-soft); color: var(--siam-danger); }
.bg-soft-warning   { background: var(--siam-warning-soft); color: var(--siam-warning); }
.bg-soft-info      { background: var(--siam-info-soft); color: var(--siam-info); }
.bg-soft-secondary { background: var(--siam-secondary-soft); color: var(--siam-secondary); }

/* ── ปุ่ม ──────────────────────────────────────────────────────────────── */
.btn {
  border-radius: 4px; font-size: 13px; font-weight: 500;
  padding: .44rem .875rem; letter-spacing: .2px;
}
.btn-lg { font-size: .9375rem; padding: .6rem 1.25rem; }
.btn-primary {
  background: var(--siam-primary); border-color: var(--siam-primary);
  box-shadow: var(--siam-shadow-sm); color: #fff;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
  background: var(--siam-primary-dark) !important;
  border-color: var(--siam-primary-dark) !important;
  box-shadow: 0 2px 8px rgba(140, 87, 255, .4);
}
.btn-label-primary { background: var(--siam-primary-soft); color: var(--siam-primary); border: 0; }
.btn-label-primary:hover { background: var(--siam-primary); color: #fff; }
.btn-label-secondary { background: var(--siam-secondary-soft); color: var(--siam-secondary); border: 0; }
.btn-label-secondary:hover { background: var(--siam-secondary); color: #fff; }
.btn-label-danger { background: var(--siam-danger-soft); color: var(--siam-danger); border: 0; }
.btn-label-danger:hover { background: var(--siam-danger); color: #fff; }
.btn-outline-secondary { border-color: var(--siam-border); color: var(--siam-text); }
.btn-outline-secondary:hover { background: rgba(46, 38, 61, .06); color: var(--siam-heading); border-color: var(--siam-border); }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-grid; place-items: center; border-radius: 6px;
  border: 0; background: transparent; color: var(--siam-text); font-size: 1.05rem;
}
.btn-icon:hover { background: rgba(46, 38, 61, .07); color: var(--siam-heading); }
.btn-icon.text-primary:hover { background: var(--siam-primary-soft); color: var(--siam-primary) !important; }
.btn-icon.text-danger:hover { background: var(--siam-danger-soft); color: var(--siam-danger) !important; }

/* ── ฟอร์ม ─────────────────────────────────────────────────────────────── */
.form-label { font-size: .8125rem; color: var(--siam-heading); font-weight: 500; margin-bottom: .35rem; }
.form-label .req { color: var(--siam-danger); }
.form-control, .form-select {
  border: 1px solid var(--siam-border);
  border-radius: var(--siam-radius);
  color: var(--siam-heading);
  font-size: .9375rem;
  padding: .5rem .875rem;
  background-color: #fff;
}
/* padding ด้านบนทับค่า padding-right ของ Bootstrap — คืนที่ว่างให้ลูกศร ไม่ให้ทับข้อความ (รวม form-select-sm) */
.form-select {
  padding-right: 2.5rem;
  background-position: right .875rem center;
}
.form-control:focus, .form-select:focus {
  border-color: var(--siam-primary);
  box-shadow: 0 0 0 .15rem rgba(140, 87, 255, .16);
}
.form-control::placeholder { color: var(--siam-muted); }
.form-text { font-size: .75rem; color: var(--siam-muted); }
.input-group-text {
  background: #fff; border-color: var(--siam-border);
  color: var(--siam-muted); font-size: .875rem;
}

/* แถบพรีวิวค่าเคส */
.fee-preview {
  border-radius: var(--siam-radius);
  background: var(--siam-primary-soft);
  color: var(--siam-primary);
  padding: .875rem 1.125rem;
  display: flex; align-items: center; gap: .75rem;
  font-size: .9375rem;
}
.fee-preview.is-zero { background: var(--siam-warning-soft); color: #B37E00; }
.fee-preview .fee-amount { margin-left: auto; font-size: 1.35rem; font-weight: 700; }

/* ── ตาราง ─────────────────────────────────────────────────────────────── */
.table { color: var(--siam-text); margin: 0; min-width: 880px; }
.table > :not(caption) > * > * { padding: .75rem 1.25rem; border-bottom-color: var(--siam-border); }
.table thead th {
  font-size: .8125rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: .4px; color: var(--siam-muted);
  background: #FAFAFC; border-bottom: 1px solid var(--siam-border); white-space: nowrap;
}
.table tbody tr:hover { background: rgba(46, 38, 61, .03); }
.table tbody td { vertical-align: middle; font-size: .9375rem; }
.table tfoot td { font-weight: 600; color: var(--siam-heading); background: #FAFAFC; }
.table-responsive { border-radius: 0 0 var(--siam-radius) var(--siam-radius); }
.cell-title { color: var(--siam-heading); font-weight: 500; }
.cell-sub { font-size: .8125rem; color: var(--siam-muted); }

.badge-label {
  display: inline-block; border-radius: 4px;
  font-size: .75rem; font-weight: 500; padding: .25rem .5rem; white-space: nowrap;
}

/* ── แบ่งหน้า ──────────────────────────────────────────────────────────── */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; padding: 0 1.5rem 1rem;
}
.pagination-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; padding: 1rem 1.5rem;
}
.pagination { margin: 0; gap: .25rem; }
.page-link {
  border: 0; border-radius: 50%; width: 34px; height: 34px;
  display: grid; place-items: center;
  color: var(--siam-text); font-size: .875rem; background: transparent;
}
.page-link:hover { background: rgba(46, 38, 61, .07); color: var(--siam-heading); }
.page-item.active .page-link {
  background: var(--siam-primary); color: #fff;
  box-shadow: 0 2px 6px rgba(140, 87, 255, .35);
}
.page-item.disabled .page-link { color: var(--siam-muted); opacity: .5; }

/* ── โมดัล / toast ─────────────────────────────────────────────────────── */
.modal-content { border: 0; border-radius: var(--siam-radius); box-shadow: var(--siam-shadow-lg); }
.modal-header { border-bottom: 1px solid var(--siam-border); padding: 1.15rem 1.5rem; }
.modal-title { font-size: 1.0625rem; font-weight: 500; color: var(--siam-heading); }
.modal-body { padding: 1.5rem; }
.modal-footer { border-top: 1px solid var(--siam-border); padding: 1rem 1.5rem; }

.toast-stack { position: fixed; top: 80px; right: 24px; z-index: 1080; display: grid; gap: .5rem; }
.siam-toast {
  min-width: 280px; max-width: 380px;
  background: #fff; border-radius: var(--siam-radius);
  box-shadow: var(--siam-shadow-lg);
  padding: .875rem 1rem; display: flex; gap: .75rem; align-items: flex-start;
  border-left: 4px solid var(--siam-primary);
  animation: toast-in .2s ease;
  font-size: .9rem; color: var(--siam-heading);
}
.siam-toast.is-success { border-left-color: var(--siam-success); }
.siam-toast.is-error { border-left-color: var(--siam-danger); }
.siam-toast i { font-size: 1.15rem; }
.siam-toast.is-success i { color: var(--siam-success); }
.siam-toast.is-error i { color: var(--siam-danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ── สถานะว่าง / กำลังโหลด ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--siam-muted); }
.empty-state i { font-size: 2.5rem; opacity: .5; display: block; margin-bottom: .5rem; }
.loading-overlay {
  position: fixed; inset: 0; background: rgba(244, 245, 250, .75);
  display: none; place-items: center; z-index: 1090;
}
.loading-overlay.show { display: grid; }
.spinner-border.text-primary { color: var(--siam-primary) !important; }

.menu-backdrop {
  position: fixed; inset: 0; background: rgba(46, 38, 61, .5);
  z-index: 1035; display: none;
}
.menu-backdrop.show { display: block; }

/* ── จอเล็ก ────────────────────────────────────────────────────────────── */
@media (max-width: 1199.98px) {
  .layout-menu { transform: translateX(-100%); }
  .layout-menu.show { transform: none; }
  .layout-page { margin-left: 0; }
  .layout-navbar { left: 0; padding: 0 1rem; }
  .navbar-toggler-btn { display: inline-flex; }
  .content-wrapper { padding-left: 1rem; padding-right: 1rem; }
}
@media (max-width: 575.98px) {
  .navbar-search { display: none; }
  .toast-stack { left: 12px; right: 12px; top: 76px; }
  .siam-toast { max-width: none; }
  .card-header, .card-body, .table-toolbar, .pagination-bar { padding-left: 1rem; padding-right: 1rem; }
}

/* ── รายงานสำหรับพิมพ์ ─────────────────────────────────────────────────── */
.print-area { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }

  /* ซ่อนทั้ง .layout-page (ไม่ใช่แค่ลูกข้างใน) — มันมี min-height: 100vh ซึ่งตอนพิมพ์กลายเป็นหน้าเปล่า 1 หน้าก่อนรายงาน */
  .layout-menu, .layout-page, .menu-backdrop, .toast-stack,
  .loading-overlay, .modal, .modal-backdrop, .no-print {
    display: none !important;
  }
  body { background: #fff; color: #000; font-size: 11px; }

  .print-area { display: block !important; }

  .print-header { text-align: center; margin-bottom: 10px; }
  .print-title { font-size: 17px; font-weight: 700; color: #000; }
  .print-sub { font-size: 12px; margin-top: 2px; }

  .print-summary {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 6px; margin-bottom: 12px;
  }
  .print-stat { border: 1px solid #999; border-radius: 4px; padding: 6px 8px; }
  .print-stat-label { font-size: 10px; }
  .print-stat-value { font-size: 16px; font-weight: 700; color: #000; line-height: 1.2; }
  .print-stat-hint { font-size: 9px; color: #444; }

  .print-table { width: 100%; border-collapse: collapse; }
  .print-table th, .print-table td {
    border: 1px solid #999; padding: 3px 5px; font-size: 10.5px; vertical-align: top;
  }
  .print-table thead { display: table-header-group; }   /* ขึ้นหน้าใหม่ให้มีหัวตารางซ้ำ */
  .print-table thead th { background: #EEE; font-weight: 600; text-align: center; color: #000; }
  .print-table tbody tr { page-break-inside: avoid; }
  .print-table tfoot td { font-weight: 700; background: #F4F4F4; color: #000; }
  .print-table .num { text-align: right; white-space: nowrap; }
  .print-table .mid { text-align: center; white-space: nowrap; }

  .print-footnote { margin-top: 8px; font-size: 10px; }
  .print-sign { margin-top: 26px; display: flex; justify-content: flex-end; }
  .print-sign-box { text-align: center; font-size: 11px; width: 240px; }
  .print-sign-line { border-top: 1px dotted #333; margin-bottom: 3px; padding-top: 26px; }
}
