: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;
}

.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;
}

/* Hide filter options that would yield no results (count 0),
   but keep a currently-checked option visible so it can be unchecked. */
.check:has(.count.is-zero):not(:has(:checked)) {
    display: none;
}

/* Hide a whole filter group when it has no selectable option and nothing checked. */
.filter-group:not(:has(.check .count:not(.is-zero))):not(:has(:checked)) {
    display: none;
}

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

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

.crop-row {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s ease;
}

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

.crop-row:hover,
.crop-row:focus {
    background: var(--green-soft);
    outline: none;
}

.crop-row.is-active {
    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;
}

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

    .filters {
        position: static;
    }
}
