:root {
    --bg: #f4f6f4;
    --panel: #ffffff;
    --border: #e2e6e1;
    --green: #4b7d3a;
    --green-dark: #355626;
    --green-soft: #eaf2e5;
    --text: #1f2a1b;
    --muted: #6b7464;
    --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 6px 18px rgba(0, 0, 0, .05);
}

* {
    box-sizing: border-box;
}

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

.topbar {
    background: var(--green);
    color: #fff;
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow);
}

.topbar h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
}

.topbar h1 a {
    color: inherit;
    text-decoration: none;
}

.layout {
    display: grid;
    grid-template-columns: 240px minmax(220px, 320px) 1fr;
    gap: 1.25rem;
    padding: 1.25rem;
    align-items: start;
    max-width: 1280px;
    margin: 0 auto;
}

/* --- Filters --- */
.filters {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 1.25rem;
}

.filters h2 {
    margin: 0 0 .75rem;
    font-size: 1rem;
}

.search {
    margin-bottom: .85rem;
}

.search input {
    width: 100%;
    padding: .5rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
    background: #fff;
    color: var(--text);
}

.search input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-soft);
}

.filter-group {
    border-top: 1px solid var(--border);
    margin-top: .85rem;
    padding-top: .85rem;
}

.filter-group:first-of-type {
    border-top: 0;
    margin-top: 0;
    padding-top: 0;
}

.filter-group__title {
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    margin: 0 0 .4rem;
}

.check {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .2rem 0;
    font-size: .9rem;
    cursor: pointer;
}

.check input {
    accent-color: var(--green);
}

.check .count {
    margin-left: auto;
    font-size: .75rem;
    color: var(--muted);
    background: var(--green-soft);
    border-radius: 999px;
    padding: 0 .45rem;
    min-width: 1.4rem;
    text-align: center;
}

/* Options that would yield no results (count 0) stay visible but disabled:
   dimmed and non-clickable, while a currently-checked option stays active so
   it can still be unchecked. */
.check.is-disabled {
    cursor: not-allowed;
    opacity: .45;
}

.check.is-disabled input {
    cursor: not-allowed;
}

/* --- Crop list --- */
.list-panel {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Loading overlay shown while the list-panel is fetching (htmx toggles the
   .htmx-request class on it via hx-indicator). */
.list-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .6);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

.list-overlay.htmx-request {
    opacity: 1;
    pointer-events: auto;
}

.list-overlay::after {
    content: "";
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: list-spin .7s linear infinite;
}

@keyframes list-spin {
    to { transform: rotate(360deg); }
}

.crop-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.crop-row {
    border-bottom: 1px solid var(--border);
}

.crop-row:last-child {
    border-bottom: 0;
}

.crop-row__radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.crop-row__link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .75rem 1rem;
    cursor: pointer;
    transition: background .12s ease;
    color: inherit;
    text-decoration: none;
}

/* Small square preview of the crop's primary image. Sized shorter than the
   three-line text block so it never makes the row taller, and fixed-width so
   it never makes the row wider. */
.crop-thumb {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--green-soft);
}

.crop-thumb--empty {
    border: 1px solid var(--border);
}

.crop-row__text {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    min-width: 0;
}

.crop-row__link:hover,
.crop-row__radio:focus-visible + .crop-row__link {
    background: var(--green-soft);
    outline: none;
}

/* Selected row — driven entirely by the checked radio, so a click highlights
   immediately without re-rendering the list. */
.crop-row:has(.crop-row__radio:checked) .crop-row__link {
    background: var(--green-soft);
    box-shadow: inset 3px 0 0 var(--green);
}

.crop-name {
    font-weight: 600;
}

.crop-sci {
    font-style: italic;
    color: var(--muted);
    font-size: .85rem;
}

.crop-family {
    color: var(--muted);
    font-size: .8rem;
}

.empty {
    padding: 1rem;
    color: var(--muted);
}

/* --- Detail --- */
.detail-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    min-height: 200px;
}

.placeholder {
    color: var(--muted);
    font-style: italic;
}

.crop-detail__header {
    border-bottom: 2px solid var(--green-soft);
    padding-bottom: .5rem;
    margin-bottom: 1rem;
}

.crop-detail__header h2 {
    margin: 0;
    color: var(--green-dark);
}

.crop-detail__sci {
    margin: .15rem 0 0;
    font-style: italic;
    color: var(--muted);
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 1.25rem;
}

.badge {
    font-size: .78rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    border: 1px solid transparent;
}

.badge--substance {
    background: #e7f0ff;
    color: #1d4bb8;
    border-color: #c9ddff;
}

.badge--chemical {
    background: #fdeede;
    color: #9a5b14;
    border-color: #f6d7af;
}

.badge--usage {
    background: var(--green-soft);
    color: var(--green-dark);
    border-color: #cfe2c2;
}

.facts {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: .35rem .75rem;
    margin: 0 0 1.25rem;
}

.facts dt {
    font-weight: 600;
    color: var(--muted);
    font-size: .85rem;
}

.facts dd {
    margin: 0;
}

.crop-detail h3 {
    color: var(--green-dark);
    font-size: 1rem;
    margin: 1.25rem 0 .5rem;
}

/* --- Detail tabs (CSS-only, radio-driven) --- */
.tab-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.tab {
    padding: .5rem .9rem;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    margin-bottom: -1px;
    color: var(--muted);
    font-weight: 600;
    font-size: .9rem;
}

.tab:hover {
    color: var(--green-dark);
}

/* Keyboard focus on the (visually hidden) radio highlights its label. */
.tab-radio:focus-visible + .tab-bar .tab,
.tab-radio:focus-visible ~ .tab-bar .tab {
    outline: none;
}

.tab-panel {
    display: none;
}

#crop-tab-gewas:checked ~ .tab-bar label[for="crop-tab-gewas"],
#crop-tab-toepassingen:checked ~ .tab-bar label[for="crop-tab-toepassingen"],
#crop-tab-media:checked ~ .tab-bar label[for="crop-tab-media"],
#crop-tab-contact:checked ~ .tab-bar label[for="crop-tab-contact"] {
    color: var(--green-dark);
    background: var(--panel);
    border-color: var(--border);
    border-bottom-color: var(--panel);
}

#crop-tab-gewas:checked ~ .tab-panels .tab-panel--gewas,
#crop-tab-toepassingen:checked ~ .tab-panels .tab-panel--toepassingen,
#crop-tab-media:checked ~ .tab-panels .tab-panel--media,
#crop-tab-contact:checked ~ .tab-panels .tab-panel--contact {
    display: block;
}

/* Nested sub-tabs (Plantkenmerken / Teeltkenmerken) inside the Gewas panel. */
.subtabs {
    margin-top: 1.25rem;
}

.tab-bar--sub .tab {
    font-size: .82rem;
    padding: .35rem .7rem;
}

#subtab-plant:checked ~ .tab-bar label[for="subtab-plant"],
#subtab-teelt:checked ~ .tab-bar label[for="subtab-teelt"] {
    color: var(--green-dark);
    background: var(--panel);
    border-color: var(--border);
    border-bottom-color: var(--panel);
}

#subtab-plant:checked ~ .tab-panels .tab-panel--plant,
#subtab-teelt:checked ~ .tab-panels .tab-panel--teelt {
    display: block;
}

.media-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
}

.media-item {
    margin: 0;
}

.lightbox-thumb {
    display: block;
    cursor: zoom-in;
}

.lightbox-thumb img {
    display: block;
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: opacity .15s;
}

.lightbox-thumb:hover img {
    opacity: .85;
}

.media-item figcaption {
    margin-top: .3rem;
    font-size: .78rem;
    color: var(--muted);
}

/* CSS-only lightbox overlay, toggled by the per-image checkbox. */
.lightbox-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgba(0, 0, 0, .85);
    cursor: zoom-out;
}

.lightbox-overlay img {
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

.lightbox-toggle:checked ~ .lightbox-overlay {
    display: flex;
}

.media-videos {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.media-video {
    margin: 0;
}

.media-video__frame {
    position: relative;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.media-video__frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.media-video figcaption {
    margin-top: .3rem;
    font-size: .78rem;
    color: var(--muted);
}

.media-docs {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.media-doc {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--green-dark);
    text-decoration: none;
}

.media-doc:hover {
    border-color: var(--green-dark);
    background: var(--green-soft);
}

.media-doc__icon {
    font-size: 1.1rem;
}

@media (max-width: 860px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .filters {
        position: static;
    }
}
