/**
 * ==============================================================================
 * Stylesheet: parcel_infomation_table.css
 * System: DOAE GEOPLOTS Digital Parcel Platform
 * Description: Styling for Parcel Information Summary Table & SLD Legend Badges
 * ==============================================================================
 */

:root {
  --primary-color: #1b5e20;
  --primary-light: #2e7d32;
  --primary-dark: #0f3e13;
  --accent-color: #2e7d32;
  --bg-main: #f4f6f9;
  --card-bg: #ffffff;
  --text-dark: #2c3e50;
  --text-muted: #6c757d;
  --border-color: #e2e8f0;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --border-radius: 12px;
}

body {
  font-family: 'Prompt', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

.page-content {
  padding-top: 15px;
  padding-bottom: 40px;
}

/* Page Header Card */
.dashboard-header-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8fbf9 100%);
  border: 1px solid rgba(46, 125, 50, 0.15);
  border-radius: var(--border-radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.badge-app-tag {
  background-color: #e8f5e9;
  color: #1b5e20;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #c8e6c9;
  display: inline-flex;
  align-items: center;
}

.dashboard-main-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a3321;
}

.dashboard-main-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Filter Card */
.filter-card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.filter-header {
  background: #fbfcfd;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.95rem;
}

.form-label-custom {
  font-weight: 600;
  font-size: 0.85rem;
  color: #344767;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
}

.form-control-custom, .form-select-custom {
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s ease-in-out;
}

.form-control-custom:focus, .form-select-custom:focus {
  border-color: #2e7d32;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

/* Color dot indicator */
.crop-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Action Buttons */
.btn-search-primary {
  background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%);
  color: #ffffff;
  border: none;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(46, 125, 50, 0.25);
  transition: all 0.2s;
}

.btn-search-primary:hover {
  background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.35);
  transform: translateY(-1px);
}

.btn-reset-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-reset-secondary:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.btn-export-excel {
  background: #ffffff;
  color: #107c41;
  border: 1px solid #107c41;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-export-excel:hover {
  background: #107c41;
  color: #ffffff;
}

/* KPI Summary Cards */
.kpi-row {
  margin-bottom: 20px;
}

.kpi-card {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease-in-out;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.kpi-card.kpi-total::before { background: #2e7d32; }
.kpi-card.kpi-tam::before { background: #0284c7; }
.kpi-card.kpi-5km-in::before { background: #d97706; }
.kpi-card.kpi-5km-out::before { background: #dc2626; }
.kpi-card.kpi-forest::before { background: #7c3aed; }

.kpi-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.kpi-number-parcels {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2;
}

.kpi-number-rai {
  font-size: 1.05rem;
  font-weight: 600;
  color: #475569;
}

.kpi-unit {
  font-size: 0.75rem;
  color: #94a3b8;
  font-weight: 400;
  margin-left: 2px;
}

/* ========================================================
   OFFICIAL PDF REPORT TABLE STYLING (#40826D TEAL THEME)
   Matching download/กทภ_สารสนเทศผังแปลงเกษตรกรรมดิจิทัล-2567
   ======================================================== */

/* Table section wrapper: Constrained strictly to A4 Portrait width */
.a4-portrait-table-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 8px;
  margin-bottom: 30px;
}

.pdf-table-container {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  padding: 14px 16px;
  position: relative;
  width: 100%;
  max-width: 860px; /* Exact A4 Portrait paper width (210mm) */
  margin: 0 auto;
}

.pdf-report-title-bar {
  background: linear-gradient(135deg, #f8fbf9 0%, #edf5f0 100%);
  border: 1px solid rgba(64, 130, 109, 0.2);
  border-left: 5px solid #40826D;
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 16px;
}

.pdf-table-main-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a3e31;
  font-family: 'Prompt', sans-serif;
}

.pdf-table-sub-title {
  font-size: 0.8rem;
  color: #557268;
}

/* Mode Toggle Buttons */
.btn-mode-toggle {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 6px 14px;
  transition: all 0.2s ease;
}

.btn-mode-toggle:hover {
  background-color: #e2e8f0;
  color: #1e293b;
}

.btn-mode-toggle.active {
  background: linear-gradient(135deg, #40826D 0%, #2e6353 100%);
  color: #ffffff !important;
  border-color: #275245 !important;
  box-shadow: 0 2px 6px rgba(64, 130, 109, 0.35);
}


/* The Table - Designed to fit parcelPdfTable exactly with NO internal scroll */
.a4-portrait-table-wrapper .table-responsive,
.table-responsive.pdf-table-scroll,
.pdf-table-scroll {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
  border: 1px solid #7F9F9D;
  border-radius: 6px;
  position: relative;
  background: #ffffff;
}

table.dataTable.pdf-official-table,
table.pdf-official-table {
  width: 100% !important;
  max-width: 100% !important;
  table-layout: fixed !important;
  font-size: 0.69rem !important;
  font-family: 'Sarabun', 'Prompt', -apple-system, sans-serif;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0 !important;
}

/* Header Styling - Exact PDF Teal (#40826D) - Natural Flow (Not Fixed / Not Sticky) */
.pdf-official-table thead {
  position: static !important;
}

.pdf-official-table thead th,
.pdf-official-table thead tr th {
  background-color: #40826D !important;
  color: #ffffff !important;
  font-weight: 600;
  border: 1px solid #356B5A !important;
  padding: 3px 2px !important;
  vertical-align: middle !important;
  text-align: center !important;
  line-height: 1.2;
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-official-table thead tr:first-child th {
  font-weight: 700;
  font-size: 0.72rem;
  border-bottom: 1px solid #2e6151 !important;
  letter-spacing: 0.1px;
  text-align: center !important;
  vertical-align: middle !important;
}

.pdf-official-table thead tr:last-child th {
  font-size: 0.63rem;
  font-weight: 600;
  background-color: #387561 !important;
  border-top: none !important;
  padding: 2.5px 1px !important;
  text-align: center !important;
  vertical-align: middle !important;
}

.pdf-official-table thead .th-prov {
  font-size: 0.74rem;
  background-color: #387561 !important;
}

.th-unit {
  font-size: 0.58rem;
  font-weight: 400;
  color: #e3f3ec;
  opacity: 0.95;
  display: inline-block;
}

/* Table Body Styling - Scaled for A4 Portrait */
.pdf-official-table tbody td {
  padding: 2.5px 3px !important;
  vertical-align: middle;
  border: 1px solid #E2E8F0;
  line-height: 1.3;
  font-size: 0.69rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Row 1: Grand Total (รวม) - Light Green (#E2EFDA) */
.pdf-official-table tbody tr.pdf-row-total,
.pdf-official-table tbody tr.pdf-row-total td {
  background-color: #E2EFDA !important;
  color: #0F3E13 !important;
  font-weight: 700 !important;
  border-top: 2px solid #7F9F9D !important;
  border-bottom: 2px solid #7F9F9D !important;
}

/* SSK Regional Rows (สสก. 1 - 6) - Light Mint (#F2F7F2) */
.pdf-official-table tbody tr.pdf-row-ssk,
.pdf-official-table tbody tr.pdf-row-ssk td {
  background-color: #F2F7F2 !important;
  color: #1B5E20 !important;
  font-weight: 600 !important;
  border-top: 1px solid #94A3B8 !important;
  border-bottom: 1px solid #CBD5E1 !important;
}

/* Province Rows */
.pdf-official-table tbody tr.pdf-row-prov td {
  background-color: #ffffff;
  color: #1e293b;
}

.pdf-official-table tbody tr.pdf-row-prov:nth-child(even) td {
  background-color: #fcfefc;
}

.pdf-official-table tbody tr.pdf-row-prov:hover td {
  background-color: #eaf3ed !important;
}

/* Province Cell Indentation & Badges */
.prov-name-cell {
  display: flex;
  align-items: center;
  gap: 3px;
}

.prov-indent {
  padding-left: 5px !important;
  font-weight: 500;
  font-size: 0.69rem;
}

.badge-ssk-tag {
  background-color: #2E7D32;
  color: #ffffff;
  font-size: 0.6rem;
  padding: 1px 3px;
  border-radius: 2px;
  font-weight: 600;
  margin-right: 3px;
  display: inline-block;
}

.badge-total-tag {
  background-color: #0F3E13;
  color: #ffffff;
  font-size: 0.6rem;
  padding: 1px 4px;
  border-radius: 2px;
  font-weight: 700;
  margin-right: 3px;
  display: inline-block;
}

/* Number formatting - Compact for A4 Portrait */
.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-family: 'Sarabun', 'Prompt', sans-serif;
  font-size: 0.69rem;
  letter-spacing: -0.2px;
}

.dash-val {
  color: #94A3B8;
  font-weight: 400;
  text-align: center;
  display: block;
}

/* Footer Styling */
.pdf-official-table tfoot th {
  background-color: #E2EFDA !important;
  color: #0F3E13 !important;
  font-weight: 700;
  border: 1px solid #7F9F9D !important;
  border-top: 2px solid #40826D !important;
  padding: 3px 3px !important;
  font-size: 0.69rem;
}

/* A4 Portrait Page & Print Styles */
@page {
  size: A4 portrait;
  margin: 6mm 4mm;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 6mm 4mm;
  }
  body {
    background: #fff !important;
    font-size: 7.5pt !important;
  }
  .a4-portrait-wrapper {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .dashboard-header-card, .filter-card, .kpi-row,
  .dataTables_length, .dataTables_filter, .dt-buttons,
  .dataTables_info, .dataTables_paginate, #table_loading_overlay, #progress-loading {
    display: none !important;
  }
  .pdf-table-container {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .pdf-table-scroll {
    max-height: none !important;
    overflow: visible !important;
    border: 0.5pt solid #000 !important;
  }
  table.dataTable.pdf-official-table,
  table.pdf-official-table {
    width: 100% !important;
    table-layout: fixed !important;
  }
  .pdf-official-table th, .pdf-official-table td {
    padding: 1.5px 1.5px !important;
    font-size: 6.5pt !important;
    line-height: 1.15 !important;
    border: 0.5pt solid #555 !important;
  }
}

/* SLD Badge */
.badge-sld-crop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #ffffff;
  border: 1px solid #e2e8f0;
}

/* Loading Overlay */
#table_loading_overlay {
  display: none;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(2px);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  border-radius: var(--border-radius);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
}

/* Responsive adjustments */
@media (max-width: 992px) {
  .dashboard-main-title {
    font-size: 1.25rem;
  }
  .kpi-number-parcels {
    font-size: 1.15rem;
  }
  .pdf-official-table {
    font-size: 0.8rem;
  }
}

/* ========================================================
   PDF PAGE 6 & PAGE 7 ENHANCED STYLING
   Matching PDF download/กทภ_สารสนเทศผังแปลงเกษตรกรรมดิจิทัล-2567
   ======================================================== */

.pdf-page6-card {
  border-top: 4px solid #3B7E6F;
}

.pdf-page6-header-bar {
  background: #3B7E6F;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.pdf-page6-activity {
  letter-spacing: 0.5px;
}

.pdf-page6-page-no {
  font-size: 0.9rem;
}

.pdf-page6-main-title {
  color: #1a3e31;
  font-weight: 700;
  font-size: 1.25rem;
}

.pdf-page6-sub-title {
  font-size: 0.9rem;
}

/* Page 6 Table: Exactly 4 columns */
.pdf-table-page6 {
  border: 1px solid #7F9F9D !important;
  margin-top: 6px;
  border-collapse: collapse !important;
}

.pdf-table-page6 thead th {
  background-color: #3B7E6F !important;
  color: #ffffff !important;
  font-weight: 600;
  text-align: center;
  border: 1px solid #528b7e !important;
  padding: 8px 10px !important;
  font-size: 0.82rem !important;
}

.pdf-table-page6 tbody td {
  border: 1px solid #cfded8 !important;
  padding: 7px 12px !important;
  font-size: 0.82rem !important;
}

.pdf-table-page6 tbody tr:hover {
  background-color: #f1f8f5;
}

.pdf-table-page6 tbody tr:first-child {
  background-color: #edf6f0;
}

/* ========================================================
   PARCEL MAP COMPONENT STYLES (DOAE Map Platform Embed)
   ======================================================== */
.map-section-wrapper {
  margin-top: 0;
  transition: all 0.3s ease;
}

.parcel-map-card {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06) !important;
}

.map-header-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background-color: #ecfdf5;
  border: 1px solid #a7f3d0;
  font-size: 17px;
  flex-shrink: 0;
}

#map_card_body {
  height: 860px;
  background-color: #f8fafc;
  position: relative;
  overflow: hidden;
}

#doae_map_iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.parcel-map-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(248, 250, 252, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.2s ease;
}

/* Fullscreen Map Mode */
.parcel-map-card.is-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  z-index: 99999 !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

.parcel-map-card.is-fullscreen #map_card_body {
  height: calc(100vh - 60px) !important;
}

@media (max-width: 768px) {
  #map_card_body {
    height: 600px;
  }
}

