/* Kuruvai Report — shared dashboard & district report styles */
:root {
  --ksp-primary: #1b5e20;
  --ksp-primary-light: #2e7d32;
  --ksp-accent: #ff8f00;
  --ksp-bg: #f4f6f9;
  --ksp-card: #ffffff;
  --ksp-border: #e0e6ed;
  --ksp-text: #1a2332;
  --ksp-muted: #6b7a90;
  --ksp-success: #2e7d32;
  --ksp-info: #0277bd;
  --ksp-warning: #f57c00;
  --ksp-danger: #c62828;
  --ksp-shadow: 0 4px 18px rgba(27, 94, 32, 0.08);
}

body {
  background: var(--ksp-bg);
  font-family: 'Source Sans 3', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  color: var(--ksp-text);
  -webkit-font-smoothing: antialiased;
}

body.ksp-report {
  background: var(--ksp-bg);
  color: var(--ksp-text);
  font-family: 'Source Sans 3', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  padding-top: 56px;
}

.navbar-custom {
  background: linear-gradient(135deg, var(--ksp-primary) 0%, var(--ksp-primary-light) 100%) !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.navbar-custom .navbar-brand {
  color: #fff !important;
  font-family: 'Montserrat', 'Source Sans 3', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.ksp-navbar {
  background: linear-gradient(135deg, var(--ksp-primary) 0%, var(--ksp-primary-light) 100%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.ksp-navbar .navbar-brand {
  color: #fff !important;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.ksp-navbar .nav-link {
  color: rgba(255, 255, 255, 0.9) !important;
}

.report-page {
  max-width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.report-page .row {
  margin-left: -10px;
  margin-right: -10px;
}

.report-page .row > [class*="col-"] {
  padding-left: 10px;
  padding-right: 10px;
}

.report-hero {
  background: linear-gradient(135deg, #ffffff 0%, #e8f5e9 100%);
  border: 1px solid var(--ksp-border);
  border-radius: 12px;
  padding: 28px 32px;
  margin-bottom: 28px;
  box-shadow: var(--ksp-shadow);
}

.report-hero h1 {
  font-family: 'Montserrat', 'Source Sans 3', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--ksp-primary);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.report-hero p {
  margin: 0;
  color: var(--ksp-muted);
  font-size: 1.05rem;
}

.report-breadcrumb {
  background: transparent;
  padding: 0;
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.report-breadcrumb a {
  color: var(--ksp-primary-light);
  text-decoration: none;
}

.report-breadcrumb a:hover {
  text-decoration: underline;
}

/* KPI summary cards */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--ksp-card);
  border-radius: 10px;
  padding: 18px 20px;
  border: 1px solid var(--ksp-border);
  box-shadow: var(--ksp-shadow);
  border-left: 4px solid var(--ksp-primary);
  transition: transform 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
}

.kpi-card .kpi-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ksp-muted);
  margin-bottom: 6px;
}

.kpi-card .kpi-value {
  font-family: 'Montserrat', 'Source Sans 3', sans-serif;
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.2;
}

.kpi-card .kpi-sub {
  font-size: 0.92rem;
  color: var(--ksp-muted);
  margin-top: 4px;
}

.kpi-card.kpi-approved { border-left-color: var(--ksp-success); }
.kpi-card.kpi-approved .kpi-value { color: var(--ksp-success); }
.kpi-card.kpi-pending { border-left-color: var(--ksp-warning); }
.kpi-card.kpi-pending .kpi-value { color: var(--ksp-warning); }
.kpi-card.kpi-distributed { border-left-color: var(--ksp-info); }
.kpi-card.kpi-distributed .kpi-value { color: var(--ksp-info); }
.kpi-card.kpi-rejected { border-left-color: var(--ksp-danger); }
.kpi-card.kpi-rejected .kpi-value { color: var(--ksp-danger); }

/* Component cards (dashboard) */
.comp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.comp-card {
  background: var(--ksp-card);
  border-radius: 12px;
  border: 1px solid var(--ksp-border);
  box-shadow: var(--ksp-shadow);
  overflow: hidden;
}

.comp-card-header {
  background: linear-gradient(135deg, var(--ksp-primary) 0%, #388e3c 100%);
  color: #fff;
  padding: 16px 20px;
  font-weight: 600;
  font-size: 1.1rem;
}

.comp-card-body {
  padding: 20px;
}

.stat-table {
  width: 100%;
  margin-bottom: 16px;
}

.stat-table th,
.stat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ksp-border);
  font-size: 1rem;
}

.stat-table th {
  text-align: left;
  color: var(--ksp-muted);
  font-weight: 500;
  width: 45%;
}

.stat-table td.num {
  text-align: right;
  font-weight: 700;
  color: var(--ksp-text);
}

.stat-table td.area {
  text-align: right;
  font-weight: 600;
  color: var(--ksp-success);
}

.comp-chart-wrap {
  height: 200px;
  margin: 12px 0 16px;
  position: relative;
}

.comp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.comp-actions .btn {
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
}

.btn-ksp-primary {
  background: var(--ksp-primary);
  border-color: var(--ksp-primary);
  color: #fff;
}

.btn-ksp-primary:hover {
  background: var(--ksp-primary-light);
  border-color: var(--ksp-primary-light);
  color: #fff;
}

.btn-ksp-outline {
  background: transparent;
  border: 1px solid var(--ksp-primary);
  color: var(--ksp-primary);
}

.btn-ksp-outline:hover {
  background: var(--ksp-primary);
  color: #fff;
}

/* Chart panels */
.chart-panel {
  background: var(--ksp-card);
  border-radius: 12px;
  border: 1px solid var(--ksp-border);
  box-shadow: var(--ksp-shadow);
  padding: 20px;
  margin-bottom: 24px;
  height: 100%;
}

.chart-panel h4 {
  font-family: 'Montserrat', 'Source Sans 3', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ksp-text);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e8f5e9;
}

.chart-canvas-wrap {
  position: relative;
  height: 280px;
}

.chart-canvas-wrap.tall {
  height: 340px;
}

/* Section headers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 32px 0 16px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--ksp-primary);
}

.section-header h3 {
  margin: 0;
  font-family: 'Montserrat', 'Source Sans 3', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ksp-primary);
  letter-spacing: -0.01em;
}

.section-badge {
  background: #e8f5e9;
  color: var(--ksp-primary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.92rem;
  font-weight: 600;
}

.report-scroll-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -8px 0 10px;
  padding: 8px 12px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ksp-muted);
  background: #fff;
  border: 1px dashed var(--ksp-border);
  border-radius: 8px;
}

.report-scroll-hint i {
  color: var(--ksp-primary-light);
}

/* Report table wrappers — horizontal + vertical scroll */
.report-table-wrap {
  width: 100%;
  max-height: min(560px, 70vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  border: 1px solid var(--ksp-border);
  border-radius: 10px;
  background: var(--ksp-card);
  box-shadow: var(--ksp-shadow);
  margin-bottom: 28px;
  position: relative;
}

.report-table-wrap::after {
  content: '';
  position: sticky;
  right: 0;
  top: 0;
  width: 24px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(to left, rgba(255, 255, 255, 0.95), transparent);
  float: right;
  margin-top: -100%;
}

.report-table {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: 15px;
  font-weight: 500;
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  margin: 0;
}

.report-table th,
.report-table td {
  border: 1px solid #d8dee6;
  padding: 10px 12px;
  white-space: nowrap;
  vertical-align: middle;
  line-height: 1.4;
}

.report-table thead th {
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.06);
}

.report-table tbody td,
.report-table tfoot td {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.report-table td.sticky-col-1,
.report-table th.sticky-col-1 {
  text-align: center;
  font-weight: 600;
}

.report-table td.sticky-col-2,
.report-table th.sticky-col-2 {
  text-align: left;
  font-weight: 600;
}

.report-table .sticky-col-1 {
  position: sticky;
  left: 0;
  z-index: 13;
  min-width: 52px;
  width: 52px;
  max-width: 52px;
  background: #f4f6f8;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.04);
}

.report-table .sticky-col-2 {
  position: sticky;
  left: 52px;
  z-index: 12;
  min-width: 165px;
  background: #f4f6f8;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.04);
}

.report-table thead .sticky-col-1,
.report-table thead .sticky-col-2 {
  z-index: 16;
}

.report-table thead tr:nth-child(1) th {
  position: sticky;
  top: 0;
  z-index: 12;
}

.report-table thead tr:nth-child(2) th {
  position: sticky;
  top: 38px;
  z-index: 11;
}

.report-table thead tr:nth-child(3) th {
  position: sticky;
  top: 76px;
  z-index: 10;
}

.report-table thead tr:nth-child(1) th.sticky-col-1,
.report-table thead tr:nth-child(1) th.sticky-col-2 { z-index: 18; top: 0; }
.report-table thead tr:nth-child(2) th.sticky-col-1,
.report-table thead tr:nth-child(2) th.sticky-col-2 { z-index: 17; top: 38px; }
.report-table thead tr:nth-child(3) th.sticky-col-1,
.report-table thead tr:nth-child(3) th.sticky-col-2 { z-index: 16; top: 76px; }

.report-table tbody tr:nth-child(even) td {
  background-color: #f8fafb;
}

.report-table tbody tr:nth-child(even) td.sticky-col-1,
.report-table tbody tr:nth-child(even) td.sticky-col-2 {
  background-color: #f0f3f6;
}

.report-table tbody tr:hover td {
  background-color: #e8f5e9 !important;
}

.report-table tbody tr:hover td.sticky-col-1,
.report-table tbody tr:hover td.sticky-col-2 {
  background-color: #dcefdc !important;
}

.report-table tfoot tr td {
  position: sticky;
  bottom: 0;
  z-index: 9;
  background-color: var(--ksp-success) !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 15px;
  border-top: 2px solid var(--ksp-primary);
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.08);
}

.report-table tfoot td.sticky-col-1,
.report-table tfoot td.sticky-col-2 {
  z-index: 15;
  background-color: var(--ksp-success) !important;
}

.report-table tfoot td.sticky-col-2 {
  text-align: left;
}

.report-table a {
  color: #01579b;
  font-weight: 600;
  text-decoration: none;
}

.report-table a:hover {
  text-decoration: underline;
}

.report-table .text-right {
  text-align: right !important;
}

.report-table .text-center {
  text-align: center !important;
}

.report-table .pct-cell {
  font-weight: 700;
  background: #fff8e1 !important;
  color: #e65100;
}

/* Header group colors — district report tables */
#reportTbl1 .bg-primary, #reportTbl2 .bg-primary,
.report-table .bg-primary {
  background-color: #1565c0 !important;
  color: #fff !important;
}

#reportTbl1 .bg-info, #reportTbl2 .bg-info,
.report-table .bg-info {
  background-color: #00838f !important;
  color: #fff !important;
}

#reportTbl1 .bg-success, #reportTbl2 .bg-success,
.report-table .bg-success {
  background-color: #2e7d32 !important;
  color: #fff !important;
}

#reportTbl1 .bg-danger, #reportTbl2 .bg-danger,
.report-table .bg-danger {
  background-color: #c62828 !important;
  color: #fff !important;
}

#reportTbl1 .bg-dark, #reportTbl2 .bg-dark,
.report-table .bg-dark {
  background-color: #37474f !important;
  color: #fff !important;
}

#reportTbl1 thead th, #reportTbl2 thead th,
.report-table thead.bg-dark th {
  color: #fff !important;
}

.ksp-district-report {
  padding-top: 72px;
  overflow-x: hidden;
}

.ksp-district-report .report-page {
  padding-left: 16px;
  padding-right: 16px;
}

.loading-overlay {
  text-align: center;
  padding: 60px 20px;
  color: var(--ksp-muted);
}

/* Tablet */
@media (max-width: 992px) {
  .report-table-wrap {
    max-height: min(480px, 65vh);
  }

  .chart-canvas-wrap {
    height: 240px;
  }

  .chart-canvas-wrap.tall {
    height: 280px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .ksp-district-report {
    padding-top: 64px;
  }

  .report-page {
    padding: 16px 10px 32px;
  }

  .report-hero {
    padding: 18px 16px;
    margin-bottom: 20px;
  }

  .report-hero h1 {
    font-size: 1.35rem;
  }

  .report-hero p {
    font-size: 0.95rem;
  }

  .kpi-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .kpi-card {
    padding: 14px;
  }

  .kpi-card .kpi-value {
    font-size: 1.5rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin: 24px 0 12px;
  }

  .section-header h3 {
    font-size: 1.2rem;
  }

  .report-scroll-hint {
    font-size: 0.85rem;
    padding: 6px 10px;
  }

  .report-table-wrap {
    max-height: min(420px, 58vh);
    border-radius: 8px;
    margin-bottom: 20px;
  }

  .report-table {
    font-size: 13px;
  }

  .report-table th,
  .report-table td {
    padding: 8px 9px;
  }

  .report-table thead th {
    font-size: 12px;
  }

  .report-table .sticky-col-1 {
    min-width: 40px;
    width: 40px;
    max-width: 40px;
    left: 0;
  }

  .report-table .sticky-col-2 {
    left: 40px;
    min-width: 120px;
  }

  .report-table thead tr:nth-child(2) th {
    top: 34px;
  }

  .report-table thead tr:nth-child(3) th {
    top: 68px;
  }

  .report-table thead tr:nth-child(2) th.sticky-col-1,
  .report-table thead tr:nth-child(2) th.sticky-col-2 { top: 34px; }

  .report-table thead tr:nth-child(3) th.sticky-col-1,
  .report-table thead tr:nth-child(3) th.sticky-col-2 { top: 68px; }

  .comp-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    padding: 14px;
  }

  .chart-panel h4 {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }
}
