:root {
  --brand: #2c5f8a;
  --brand-dark: #1e4463;
}

body {
  font-family: 'Sarabun', sans-serif;
  background-color: #f4f6f9;
}

.app-navbar {
  background-color: var(--brand-dark);
}

.app-sidebar {
  width: 250px;
  background: #fff;
  border-right: 1px solid #e3e6ea;
  min-height: calc(100vh - 56px);
}

.sidebar-inner {
  height: 100%;
}

@media (min-width: 992px) {
  .app-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    z-index: 1015;
    overflow-y: auto;
    min-height: 0;
  }

  .main-content {
    margin-left: 250px;
  }
}

.sidebar-inner .nav-header {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #8a94a6;
  margin: 14px 0 6px 8px;
  letter-spacing: .03em;
}

.sidebar-inner .nav-link {
  color: #33475b;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.92rem;
  white-space: nowrap;
}

.sidebar-inner .nav-link:hover {
  background: #eef3f8;
}

.sidebar-inner .nav-link.active {
  background: var(--brand);
  color: #fff;
}

.main-content {
  min-height: calc(100vh - 56px);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.main-content .table-responsive {
  max-width: 100%;
}

.stat-card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
}

.table thead th {
  font-size: 0.85rem;
  color: #5b6b79;
  border-bottom-width: 1px;
}

.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.template-section table { border-collapse: collapse; width: 100%; margin-bottom: 10px; }
.template-section table th, .template-section table td { border: 1px solid #555; padding: 6px 8px; }

@media print {
  @page { size: A4; margin: 15mm 12mm; }

  .app-navbar, .app-sidebar, .no-print { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }

  body { font-size: 11pt; color: #000; background: #fff; }

  /* ป้องกันตารางถูกตัดขอบตอนพิมพ์ (.table-responsive ใช้ overflow-x:auto สำหรับสกอลล์บนจอ
     แต่หน้ากระดาษพิมพ์ไม่สามารถสกอลล์ได้ จึงต้องปิดการตัดเนื้อหาส่วนนี้) */
  .table-responsive {
    overflow-x: visible !important;
  }
  table {
    width: 100% !important;
    font-size: 10pt;
  }
  table th, table td {
    word-break: break-word;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    page-break-inside: avoid;
  }

  tr, .list-group-item {
    page-break-inside: avoid;
  }

  /* บังคับให้สีพื้นหลัง badge/สถานะพิมพ์ออกมาด้วย (เบราว์เซอร์บางตัวตัดสีพื้นหลังออกเป็นค่าเริ่มต้นตอนพิมพ์) */
  .badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-adjust: exact;
    border: 1px solid rgba(0,0,0,.15);
  }

  /* แก้บั๊กสำคัญ: พื้นที่พิมพ์จริงบนกระดาษ A4 (หักระยะขอบแล้ว) กว้างประมาณ 700px ซึ่ง "แคบกว่า" จุดเปลี่ยน
     ของ Bootstrap ("md" = 768px) ทำให้คอลัมน์ col-md-* ที่ควรเรียงข้างกัน (เช่น หัวเอกสาร/ข้อมูลลูกค้า-โปรเจ็ค)
     ยุบลงมาเรียงต่อกันในแนวตั้งทีละบรรทัดแทน เพราะ Bootstrap กำหนดสัดส่วนความกว้างของ col-md-* ไว้เฉพาะภายใน
     @media (min-width:768px) เท่านั้น ส่วนโครงสร้าง flex/padding/box-sizing อื่นๆ ของ .row ใช้ได้อยู่แล้วทุกขนาดหน้าจอ
     จึงแก้แค่ระบุสัดส่วนความกว้างเดิมของ Bootstrap ให้มีผลตอนพิมพ์เสมอ โดยไม่ไปแตะโครงสร้างอื่นเพื่อไม่ให้ล้นหน้ากระดาษ */
  .col-md-1  { flex: 0 0 auto !important; width: 8.3333%  !important; }
  .col-md-2  { flex: 0 0 auto !important; width: 16.6667% !important; }
  .col-md-3  { flex: 0 0 auto !important; width: 25%      !important; }
  .col-md-4  { flex: 0 0 auto !important; width: 33.3333% !important; }
  .col-md-5  { flex: 0 0 auto !important; width: 41.6667% !important; }
  .col-md-6  { flex: 0 0 auto !important; width: 50%      !important; }
  .col-md-7  { flex: 0 0 auto !important; width: 58.3333% !important; }
  .col-md-8  { flex: 0 0 auto !important; width: 66.6667% !important; }
  .col-md-9  { flex: 0 0 auto !important; width: 75%      !important; }
  .col-md-10 { flex: 0 0 auto !important; width: 83.3333% !important; }
  .col-md-11 { flex: 0 0 auto !important; width: 91.6667% !important; }
}
.hover-shadow { transition: box-shadow .15s ease, transform .15s ease; }
.hover-shadow:hover { box-shadow: 0 .5rem 1rem rgba(0,0,0,.1); transform: translateY(-2px); }


/* เมนูนำทาง: breadcrumb + แถบปุ่มลัดบนมือถือ */
.page-nav .breadcrumb { background: transparent; padding: 0; }
.mobile-quickbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; justify-content: space-around; background: #fff; border-top: 1px solid #dfe3e8;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.mobile-quickbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: #444; text-decoration: none; flex: 1; padding: 2px 0; }
.mobile-quickbar a i { font-size: 1.3rem; }
.mobile-quickbar a:nth-child(2) { color: #0d6efd; font-weight: 700; }
@media (max-width: 991.98px) { body { padding-bottom: 64px; } }
@media print { .mobile-quickbar, .page-nav { display: none !important; } }

/* อากรแสตมป์ในหน้าสัญญา */
.stamp-card{overflow:hidden;border-color:#c9d6ee}
.stamp-head{background:linear-gradient(90deg,#1d4f91,#3b78c9);color:#fff;padding:.7rem 1rem}
.stamp-head .btn-light{color:#1d4f91}
.stamp-tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:.6rem}
.stamp-tile{border-radius:.5rem;padding:.55rem .8rem;border:1px solid transparent}
.stamp-tile span{display:block;font-size:.75rem;opacity:.85}
.stamp-tile b{font-size:1.1rem;font-variant-numeric:tabular-nums}
.t-blue{background:#e3eefc;color:#0b3d82;border-color:#bcd5f5}
.t-violet{background:#ece6fb;color:#4a2b9a;border-color:#d3c7f3}
.t-green{background:#e0f4e8;color:#14683a;border-color:#b7e2c8}
.t-amber{background:#fff0d1;color:#8a5200;border-color:#f5d996}
.t-gray{background:#eef1f4;color:#4b5866;border-color:#d8dee5}
.stamp-form{background:#f3f7fd;border:1px dashed #b6c8e6;border-radius:.5rem;padding:.8rem;margin-left:0;margin-right:0}

/* ===== มือถือ / PWA ===== */
@media (max-width: 991.98px) {
  .app-navbar { padding-top: max(.25rem, env(safe-area-inset-top)); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .app-navbar .container-fluid { flex-wrap: nowrap; gap: .25rem; }
  .app-navbar .navbar-brand { font-size: 1rem; margin-right: 0; min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-navbar .btn { padding: .25rem .5rem; white-space: nowrap; flex: 0 0 auto; }
  .app-navbar a[href*="lang="] .bi { display: none; }
  .main-content { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
}
.is-standalone .page-nav .breadcrumb { display: none; }
.pwa-ios-hint { position: fixed; left: 8px; right: 8px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 1060; background: #1e4a73; color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: 14px; }
.pwa-ios-hint button { background: transparent; border: 0; color: #fff; font-size: 24px; line-height: 1; }
/* ตารางแบบการ์ดบนมือถือ (เฉพาะตารางที่ใส่คลาส table-cards) */
@media (max-width: 767.98px) {
  table.table-cards, table.table-cards tbody { display: block; width: 100%; }
  table.table-cards thead { display: none; }
  table.table-cards tbody tr { display: block; margin-bottom: .75rem; padding: .35rem .25rem; background: #fff; border: 1px solid #dfe5ec; border-radius: .75rem; box-shadow: 0 1px 2px rgba(16,40,64,.06); }
  table.table-cards tbody tr.tc-empty { border: 0; box-shadow: none; background: transparent; }
  table.table-cards tbody td { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border: 0 !important; padding: .3rem .6rem; text-align: right; background: transparent !important; box-shadow: none !important; }
  table.table-cards tbody td[data-label]::before { content: attr(data-label); flex: 0 0 34%; max-width: 40%; text-align: left; color: #667587; font-size: .8rem; font-weight: 600; padding-top: .1rem; }
  table.table-cards tbody td.tc-actions { justify-content: flex-end; border-top: 1px dashed #e3e9f0 !important; margin-top: .2rem; padding-top: .45rem; }
  table.table-cards tbody td:first-child { font-weight: 600; }
  .table-responsive:has(> table.table-cards) { overflow: visible; }
}
