/* ============================================================
   Loei Coffee Database System — App Stylesheet
   Bootstrap 5 customization + layout
============================================================ */

/* ── Font ── */
body {
  font-family: 'Sarabun', sans-serif;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ── Layout ── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}
.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem;
  overflow-x: hidden;
}

/* ── Sidebar ── */
#sidebar-desktop {
  position: sticky;
  top: 56px; /* navbar height */
  height: calc(100vh - 56px);
}
#sidebar-desktop .nav-link {
  color: #c8b8a8;
  border-radius: 8px;
  font-size: 0.875rem;
  padding: 0.45rem 0.85rem;
  transition: background 0.15s, color 0.15s;
}
#sidebar-desktop .nav-link:hover,
#sidebar-desktop .nav-link.active {
  background-color: rgba(200, 161, 101, 0.2);
  color: var(--coffee-accent);
}
#sidebar-desktop .nav-link.active {
  background-color: rgba(200, 161, 101, 0.3);
  font-weight: 600;
}
.nav-header {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c5a4e;
  padding: 0.75rem 0.85rem 0.2rem;
  font-weight: 700;
}

/* Offcanvas sidebar */
#sidebarOffcanvas .nav-link {
  color: #c8b8a8;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
}
#sidebarOffcanvas .nav-link.active,
#sidebarOffcanvas .nav-link:hover {
  background-color: rgba(200,161,101,0.2);
  color: var(--coffee-accent);
}

/* ── Navbar ── */
.navbar-brand img { border-radius: 6px; }

/* ── Cards ── */
.card {
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card-header {
  background-color: transparent;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  font-weight: 600;
}

/* ── Stat Cards ── */
.stat-card {
  border-radius: 12px;
  color: white;
  position: relative;
  overflow: hidden;
}
.stat-card .stat-icon {
  font-size: 3rem;
  opacity: 0.2;
  position: absolute;
  right: 1rem;
  bottom: 0.5rem;
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

/* ── Coffee Theme Colors ── */
.bg-coffee       { background-color: var(--coffee-primary) !important; }
.bg-coffee-sec   { background-color: var(--coffee-secondary) !important; }
.bg-coffee-acc   { background-color: var(--coffee-accent) !important; }
.bg-coffee-light { background-color: var(--coffee-light) !important; }
.text-coffee     { color: var(--coffee-primary) !important; }
.text-coffee-acc { color: var(--coffee-accent) !important; }
.border-coffee   { border-color: var(--coffee-accent) !important; }

/* ── Buttons ── */
.btn-coffee {
  background-color: var(--coffee-primary);
  border-color: var(--coffee-primary);
  color: white;
}
.btn-coffee:hover {
  background-color: var(--coffee-dark);
  border-color: var(--coffee-dark);
  color: white;
}
.btn-coffee-outline {
  border-color: var(--coffee-primary);
  color: var(--coffee-primary);
}
.btn-coffee-outline:hover {
  background-color: var(--coffee-primary);
  color: white;
}

/* ── Forms ── */
.form-control:focus,
.form-select:focus {
  border-color: var(--coffee-accent);
  box-shadow: 0 0 0 0.2rem rgba(200, 161, 101, 0.25);
}
.form-label { font-weight: 500; margin-bottom: 0.3rem; }
.form-text  { font-size: 0.78rem; }
.required-mark::after {
  content: ' *';
  color: #dc3545;
}

/* ── Map ── */
#map-picker,
#map-overview {
  height: 420px;
  border-radius: 10px;
  border: 2px solid var(--coffee-accent);
  z-index: 1;
}
.leaflet-popup-content { font-family: 'Sarabun', sans-serif; }

/* ── Leaflet + Bootstrap conflict fixes ──────────────────────
   Bootstrap sets img { max-width:100% } and box-sizing:border-box
   which breaks Leaflet tile positioning and sizing                */

/* 1. Reset box-sizing สำหรับทุก element ใน Leaflet container */
.leaflet-container *,
.leaflet-container *::before,
.leaflet-container *::after {
  box-sizing: content-box !important;
}

/* 2. Reset img rules ที่ Bootstrap override */
.leaflet-container img {
  max-width:  none    !important;
  max-height: none    !important;
  width:      auto    !important;
  height:     auto    !important;
  padding:    0       !important;
  border:     none    !important;
  box-shadow: none    !important;
}

/* 3. Lock tile size — 256×256 เสมอ */
.leaflet-tile {
  width:  256px !important;
  height: 256px !important;
  padding: 0    !important;
}

/* 4. Container ต้องมี position:relative + overflow:hidden */
.leaflet-container {
  position: relative !important;
  overflow: hidden   !important;
}

/* 5. Pane layers ต้องมี position:absolute + overflow:hidden */
.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile-pane,
.leaflet-overlay-pane,
.leaflet-shadow-pane,
.leaflet-marker-pane,
.leaflet-tooltip-pane,
.leaflet-popup-pane {
  position: absolute !important;
}
.leaflet-tile-container,
.leaflet-layer {
  position: absolute !important;
  left:     0        !important;
  top:      0        !important;
}

/* 6. ป้องกัน outline/border จาก Bootstrap focus style */
.leaflet-container:focus { outline: none; }
.leaflet-interactive:focus { outline: none; }

/* ── Tables ── */
.table th {
  background-color: var(--coffee-light);
  font-weight: 600;
  white-space: nowrap;
}
.table-hover tbody tr:hover {
  background-color: rgba(200, 161, 101, 0.08);
}

/* ── Badges ── */
.badge-coffee {
  background-color: var(--coffee-accent);
  color: var(--coffee-dark);
}

/* ── Page Header ── */
.page-header {
  padding: 1rem 0 1.25rem;
  border-bottom: 2px solid var(--coffee-accent);
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--coffee-dark);
}
.page-header .breadcrumb {
  font-size: 0.8rem;
  margin-bottom: 0;
}

/* ── PDPA Consent Page ── */
.pdpa-box {
  background: white;
  border: 2px solid var(--coffee-accent);
  border-radius: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 1.5rem;
  font-size: 0.88rem;
  line-height: 1.7;
}
.pdpa-box h5 { color: var(--coffee-primary); font-weight: 700; }

/* ── Auth Pages ── */
.auth-card {
  max-width: 450px;
  width: 100%;
  margin: auto;
}
.auth-logo {
  width: 80px;
  height: 80px;
  background: var(--coffee-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}

/* ── Photo Upload Preview ── */
.photo-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.photo-preview-item {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--coffee-accent);
}
.photo-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-preview-item .remove-photo {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(220,53,69,0.85);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Loading Spinner Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* ── Terrain type icons ── */
.terrain-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
}

/* ── Mobile responsive ── */
@media (max-width: 991.98px) {
  .main-content {
    padding: 1rem;
  }
  .stat-card .stat-value { font-size: 1.5rem; }
  #map-picker, #map-overview { height: 300px; }
}
@media (max-width: 575.98px) {
  .page-header h1 { font-size: 1.15rem; }
}

/* ── Print ── */
@media print {
  #sidebar-desktop, nav.navbar, .no-print { display: none !important; }
  .main-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ── Scrollbar (webkit) ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--coffee-accent); border-radius: 3px; }
