/* ============================================================
   CropShield — data-inspectie frontend
   Eenvoudige, functionele stijlen. Geen framework.
   ============================================================ */

/* ── Reset & basis ─────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:            #f5f5f5;
  --color-surface:       #ffffff;
  --color-border:        #d0d0d0;
  --color-border-light:  #e8e8e8;
  --color-text:          #1a1a1a;
  --color-text-muted:    #6b7280;
  --color-text-expired:  #9ca3af;
  --color-primary:       #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-danger:        #dc2626;

  /* Categorie-badges */
  --badge-ppp-bg:       #dcfce7;
  --badge-ppp-text:     #166534;
  --badge-bio-bg:       #dbeafe;
  --badge-bio-text:     #1e40af;
  --badge-adj-bg:       #fef9c3;
  --badge-adj-text:     #713f12;

  --font-size-base: 14px;
  --font-mono: "Consolas", "Menlo", "Monaco", monospace;
  --radius: 4px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--font-size-base);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ── App-schil ─────────────────────────────────────────────── */

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Weergave-containers ───────────────────────────────────── */

/* Beide views bestaan altijd in de DOM; de actieve is zichtbaar */
.view { display: none; }
.view.active { display: block; }

/* ── Paginatitel ───────────────────────────────────────────── */

h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 16px;
}
h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 10px;
}
h3 {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 8px;
}

/* ── Filterbar ─────────────────────────────────────────────── */

#filter-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filter-group input[type="text"],
.filter-group select {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--font-size-base);
  background: var(--color-surface);
  color: var(--color-text);
  min-width: 160px;
}

.filter-group input[type="text"]:focus,
.filter-group select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* De q-zoekbalk mag wat breder zijn */
#input-q { min-width: 220px; }

/* Checkbox-rij zit verticaal gecentreerd */
.filter-group.checkbox-group {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding-bottom: 2px; /* optische uitlijning met andere controls */
}
.filter-group.checkbox-group label {
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--font-size-base);
  color: var(--color-text);
  cursor: pointer;
}
.filter-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ── Knoppen ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }

/* ── Statusberichten ───────────────────────────────────────── */

#search-status {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  min-height: 20px;
}

/* ── Resultaten-tabel ──────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-size: 13px;
}

thead th {
  background: #f0f2f5;
  border-bottom: 1px solid var(--color-border);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f0f7ff; }

td {
  padding: 7px 10px;
  vertical-align: middle;
}

/* Verlopen rijen: gedempte tekst */
tr.expired td {
  color: var(--color-text-expired);
}
tr.expired td .badge {
  opacity: .65;
}

/* ── Categoriebadges ───────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}

.badge-ppp  { background: var(--badge-ppp-bg);  color: var(--badge-ppp-text); }
.badge-bio  { background: var(--badge-bio-bg);  color: var(--badge-bio-text); }
.badge-adj  { background: var(--badge-adj-bg);  color: var(--badge-adj-text); }
.badge-default { background: #f3f4f6; color: #374151; }

/* W-coderings statusindicatoren */
.badge-actual  { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 4px; font-size: .8em; white-space: nowrap; }
.badge-expired { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: .8em; white-space: nowrap; }

/* ── Paginering ────────────────────────────────────────────── */

#pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--color-text-muted);
}

#pagination .btn { height: 30px; padding: 0 10px; }

/* ── Laad-indicator ────────────────────────────────────────── */

.loading-overlay {
  text-align: center;
  padding: 40px;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* Simpele spinner via CSS-animatie */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Foutmelding */
.error-msg {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--color-danger);
  font-size: 13px;
}

/* ── Detail-view ───────────────────────────────────────────── */

#view-detail {
  /* Detail heeft een iets smallere max-breedte voor leesbaarheid */
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.detail-header .btn { margin-left: auto; }

.detail-title-block h1 {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.detail-reg-numbers {
  font-size: 12px;
  color: var(--color-text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-reg-numbers span { white-space: nowrap; }

/* ── Info-kaart ────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  border-bottom: 1px solid var(--color-border-light);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

/* Raster met label-waarde paren voor de core-info kaart */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px 24px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}

.info-value {
  font-size: 14px;
}

/* Datumveld rood als verlopen */
.info-value.expired-date {
  color: var(--color-danger);
  font-weight: 500;
}

/* ── Gegevensloos-melding ──────────────────────────────────── */

.empty-msg {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 13px;
  padding: 8px 0;
}

/* ── Sectie-tabel in detail ────────────────────────────────── */

.section-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.section-table th {
  background: #f0f2f5;
  border: 1px solid var(--color-border);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.section-table td {
  border: 1px solid var(--color-border-light);
  padding: 6px 10px;
  vertical-align: top;
}

.section-table tr:nth-child(even) td { background: #fafafa; }

/* Actieve stof vet weergeven */
.section-table td.active-substance { font-weight: 600; }

/* ── Inklapbare secties (details/summary) ──────────────────── */

details {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--color-surface);
}

details[open] { box-shadow: var(--shadow-sm); }

summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 500;
  list-style: none;  /* verberg standaard driehoekje */
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

/* Eigen chevron-icoon */
summary::before {
  content: "▶";
  font-size: 11px;
  color: var(--color-text-muted);
  transition: transform .15s;
  flex-shrink: 0;
}
details[open] > summary::before { transform: rotate(90deg); }

/* Marker verbergen in WebKit */
summary::-webkit-details-marker { display: none; }

.details-body {
  padding: 12px 14px;
  border-top: 1px solid var(--color-border-light);
}

/* ── Badge-lijst (bijv. outcome types) ────────────────────── */

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── JSONB-blok ────────────────────────────────────────────── */

pre.jsonb {
  background: #f8f8f8;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #374151;
  margin: 4px 0;
}

/* ── Tags/pill-lijsten ─────────────────────────────────────── */

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.pill {
  display: inline-block;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
  color: #374151;
}

/* ── Gebruik-groep (targetcrops) ───────────────────────────── */

.use-group-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 20px;
  margin-bottom: 12px;
  font-size: 13px;
}

.use-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.use-meta-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
}

/* ── Meer-laden knop voor doelgewassen ─────────────────────── */

.load-more-note {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  font-size: 13px;
  color: #92400e;
}

/* ── Responsiefheid ────────────────────────────────────────── */

@media (max-width: 700px) {
  #filter-bar { flex-direction: column; align-items: stretch; }
  .filter-group input[type="text"],
  .filter-group select { min-width: 0; width: 100%; }
  #input-q { min-width: 0; }
  .detail-header { flex-direction: column; }
  .detail-header .btn { margin-left: 0; }
}
