@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --field-900: #16281c;
  --field-700: #23422e;
  --field-500: #3f7d4c;
  --field-300: #8fbd93;
  --field-100: #e7f0e3;

  --soil-700: #5a4632;
  --soil-300: #c9b89a;

  --paper: #f6f4ec;
  --paper-raised: #ffffff;
  --ink: #1c1f1a;
  --ink-soft: #5b6156;

  --alert-700: #9c3b23;
  --alert-100: #f4e3da;

  --line: #d8d3c2;

  --radius-sm: 3px;
  --radius-md: 6px;

  --shadow-panel: 0 1px 0 rgba(28, 31, 26, 0.06), 0 8px 20px -12px rgba(22, 40, 28, 0.35);

  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: 'IBM Plex Sans', sans-serif;
  margin: 0;
}

code, .mono {
  font-family: 'IBM Plex Mono', monospace;
}

button {
  font-family: inherit;
}

/* HEADER */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--field-900);
  color: var(--field-100);
  border-bottom: 3px solid var(--field-500);
}

.app-header__title h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.app-header__subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--field-300);
  font-family: 'IBM Plex Mono', monospace;
}

/* LAYOUT */

.app-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--paper-raised);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.map-area {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.map-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  margin: 0;
  padding: 6px 12px;
  background: rgba(22, 40, 28, 0.85);
  color: var(--field-100);
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* SIDEBAR PANELS */

.panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.panel:first-child {
  border-top: none;
  padding-top: 0;
}

.panel h2 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: none;
  color: var(--field-700);
  margin-bottom: 8px;
}

.panel-hint {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.checkbox-list--empty {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-style: italic;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.checkbox-list label:hover {
  background: var(--field-100);
}

.checkbox-list input[type="checkbox"] {
  accent-color: var(--field-500);
  width: 16px;
  height: 16px;
}

.pest-crops {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-family: 'IBM Plex Mono', monospace;
}

.primary-button {
  border: none;
  background: var(--field-500);
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 120ms ease;
}

.primary-button:hover {
  background: var(--field-700);
}

.primary-button:disabled {
  background: var(--soil-300);
  cursor: not-allowed;
}

.status-message {
  min-height: 1.1em;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin: 0;
}

.status-message[data-tone="error"] {
  color: var(--alert-700);
}

.icon-button {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

#sidebar-toggle {
  display: none;
}

/* LOCATION PANEL (slide-over) */

.location-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--paper-raised);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
  overflow-y: auto;
  padding: 18px;
  position: relative;
}

.location-panel #close-location-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  color: var(--ink-soft);
}

.location-summary {
  padding-right: 28px;
}

.location-summary h2 {
  font-size: 1rem;
  margin-bottom: 2px;
}

.location-summary .subdistrict {
  font-size: 0.85rem;
  color: var(--field-700);
  font-weight: 600;
}

.location-summary .coordinates {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin: 2px 0 12px;
}

.summary-counts {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.summary-counts .count-chip {
  flex: 1;
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: center;
}

.count-chip .count-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}

.count-chip .count-label {
  display: block;
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.count-chip--present {
  background: var(--alert-100);
}

.count-chip--present .count-value {
  color: var(--alert-700);
}

.count-chip--absent {
  background: var(--field-100);
}

.count-chip--absent .count-value {
  color: var(--field-700);
}

.pest-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--field-300);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.pest-card[data-present="true"] {
  border-left-color: var(--alert-700);
}

.pest-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.pest-card__header h3 {
  font-size: 0.95rem;
}

.pest-card__status {
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.pest-card[data-present="true"] .pest-card__status {
  color: var(--alert-700);
}

.pest-card[data-present="false"] .pest-card__status {
  color: var(--field-700);
}

.pest-card__meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.pest-card__crops {
  font-size: 0.74rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.pest-card details {
  font-size: 0.82rem;
}

.pest-card summary {
  cursor: pointer;
  color: var(--field-700);
  font-weight: 500;
  margin-bottom: 6px;
}

.pest-card p {
  line-height: 1.5;
  margin: 6px 0;
}

.pest-card ul {
  margin: 6px 0;
  padding-left: 18px;
  line-height: 1.5;
}

/* LEAFLET OVERRIDES */

.subdistrict-label {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: var(--subdistrict-label-font-size, 9px);
  font-weight: var(--subdistrict-label-font-weight, 800);
  color: var(--subdistrict-label-text-color, #111111);
  text-shadow:
    0 0 var(--subdistrict-label-halo-size, 3px) var(--subdistrict-label-halo-color, rgba(255, 255, 255, 0.95)),
    0 0 var(--subdistrict-label-halo-size, 3px) var(--subdistrict-label-halo-color, rgba(255, 255, 255, 0.95)),
    0 0 var(--subdistrict-label-halo-size, 3px) var(--subdistrict-label-halo-color, rgba(255, 255, 255, 0.95));
  white-space: nowrap;
  pointer-events: none;
}

/* Applied when SUBDISTRICT_LABEL_BACKGROUND_ENABLED is true: gives each
   label an opaque "pill" background so it reads cleanly on top of the
   base map's own place-name labels instead of visually blending with
   them (this is what actually fixes label-on-label overlap, since a
   raster base map's text can't otherwise be hidden). */
.subdistrict-label--boxed {
  background: var(--subdistrict-label-background-color, rgba(255, 255, 255, 0.88));
  padding: var(--subdistrict-label-padding, 2px) calc(var(--subdistrict-label-padding, 2px) + 3px);
  border-radius: var(--subdistrict-label-border-radius, 3px);
  text-shadow: none;
}

.subdistrict-label--bordered {
  border: 1px solid var(--subdistrict-label-border-color, rgba(0, 0, 0, 0.35));
}

.leaflet-popup-content {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.85rem;
}

/* RESPONSIVE */

@media (max-width: 860px) {
  #sidebar-toggle {
    display: inline-block;
  }

  .app-layout {
    position: relative;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 900;
    width: min(320px, 84vw);
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .location-panel {
    position: absolute;
    inset: 0 0 0 auto;
    z-index: 900;
    width: min(360px, 90vw);
  }
}
