/* the hidden attribute has to win over any display rule below */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 6px 12px 8px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
    overflow: hidden;
    background-color: #f9f9f9;
    color: #333;
}

#topBar {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 2px 12px;
    background: #2bc903;
    border-radius: 8px;
    margin-bottom: 5px;
}

#topBar h2 {
    margin: 0;
    flex-grow: 1;
    font-size: 1.0rem;
    color: #2c3e50;
    text-align: center;
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: white;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 5px;
    flex-shrink: 0;
    /* keeps the dropdowns above the map */
    position: relative;
    z-index: 20;
}

#fieldRow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 24px;
    align-items: flex-start;
}

#buttonRow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-end;
}

#buttonRow button {
    width: 135px;
    text-align: center;
    white-space: nowrap;
    padding-left: 8px;
    padding-right: 8px;
}

.colstack {
    display: flex;
    flex-direction: column;
    gap: 3px;
    justify-content: flex-end;
}

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

.field label {
    font-weight: 600;
    color: #34495e;
    font-size: 0.9rem;
    white-space: nowrap;
}

.fieldnote {
    font-weight: 400;
    font-size: 0.78rem;
    color: #7b8a8b;
}

select,
input[type="text"] {
    padding: 3px 8px;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-size: 0.95rem;
    min-width: 210px;
}

select:focus,
input:focus {
    outline: none;
    border-color: #2980b9;
    box-shadow: 0 0 5px #2980b9;
}

.checkfield {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #34495e;
    cursor: pointer;
}

#legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #34495e;
    padding: 3px 10px;
    border: 1px solid #e2e6ea;
    border-radius: 6px;
    background: #fcfdfe;
    align-self: center;
    margin-left: auto;
    /* legend and Reset sit flush right */
}

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    margin-left: 6px;
}

.swatch:first-child {
    margin-left: 0;
}

.swatch.active {
    background: rgba(245, 124, 0, 0.30);
    border: 2px solid #f57c00;
}

.swatch.other {
    background: rgba(120, 144, 156, 0.20);
    border: 2px solid #78909c;
}

.swatch.picked {
    background: rgba(200, 30, 30, 0.25);
    border: 2px solid #c81e1e;
}

.swatch.buffer {
    background: rgba(41, 128, 185, 0.15);
    border: 2px dashed #2980b9;
}

.swatch.mu {
    background: transparent;
    border: 2px dashed #6a1b9a;
}

button {
    padding: 4px 14px;
    border: none;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, opacity 0.3s ease;
}

#prevBtn,
#nextBtn {
    background-color: #2980b9;
}

#prevBtn:hover:enabled,
#nextBtn:hover:enabled {
    background-color: #1f6391;
}

#zoomTreatmentBtn {
    background-color: #16a085;
}

#zoomTreatmentBtn:hover:enabled {
    background-color: #11806a;
}

#zoomYearBtn {
    background-color: #27ae60;
}

#zoomYearBtn:hover:enabled {
    background-color: #1e874b;
}

/* ---- checkbox dropdowns: county, management unit, treatment type ---- */
.msWrap {
    position: relative;
}

.msBtn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 210px;
    padding: 3px 8px;
    background: #fff;
    color: #2c3e50;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.95rem;
    font-weight: 400;
    text-align: left;
}

.msBtn::after {
    content: "\25BE";
    color: #7b8a8b;
    font-size: 0.8rem;
}

.msBtn:focus {
    outline: none;
    border-color: #2980b9;
    box-shadow: 0 0 5px #2980b9;
}

/* a filter is on: tint the box so it is not forgotten */
.msBtn.filtered {
    border-color: #2980b9;
    background: #eef5fb;
    font-weight: 600;
}

.msMenu {
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    z-index: 50;
    min-width: 100%;
    max-height: 320px;
    overflow: auto;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
}

.msTools {
    display: flex;
    gap: 6px;
    padding: 2px 8px 5px;
    margin-bottom: 3px;
    border-bottom: 1px solid #eceff1;
}

.msTools button {
    padding: 2px 10px;
    font-size: 0.78rem;
    background: #eef1f3;
    color: #34495e;
}

.msTools button:hover {
    background: #dfe4e8;
}

.msList .mitem {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 3px 10px;
    font-size: 0.88rem;
    font-weight: 400;
    color: #2c3e50;
    white-space: nowrap;
    cursor: pointer;
}

.msList .mitem:hover {
    background: #f4f7fa;
}

.msList .mitem input {
    margin: 0;
    min-width: 0;
    cursor: pointer;
}

.mname {
    flex: 1;
}

/* long names get cut, not stretched */
.msText {
    max-width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* the "All ..." row */
.msList .mitem.mall {
    font-weight: 600;
    border-bottom: 1px solid #eceff1;
    margin-bottom: 2px;
}

.msFindWrap {
    position: relative;
    margin: 2px 8px 5px;
}

.msFind {
    display: block;
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0;
    padding: 3px 24px 3px 8px !important;
    font-size: 0.85rem !important;
}

/* x buttons: on a picker to clear its selection, in the find box to clear the text */
.msWrap .msX,
.msFindWrap .msFindX {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    padding: 0;
    background: transparent;
    color: #95a5a6;
    font-size: 1.05rem;
    font-weight: 400;
    line-height: 1;
    border-radius: 50%;
}

.msWrap .msX {
    right: 22px;
    top: 13px;
}

.msFindWrap .msFindX {
    right: 4px;
}

.msWrap .msX:hover,
.msFindWrap .msFindX:hover {
    color: #c0392b;
    background: #f4f6f7;
}

/* room between the label and the caret for the x */
.msBtn.filtered .msText {
    margin-right: 20px;
}

/* a county with nothing left after the other filters */
.msList .mitem.zero .mname,
.msList .mitem.zero .mcount {
    color: #b0bec5;
}

.mcount {
    color: #95a5a6;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

/* ---- FCKey filter ---- */
#searchOuter {
    position: relative;
}

/* year list under the compartment box */
#yearSugg {
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    z-index: 50;
    min-width: 100%;
    box-sizing: border-box;
    padding: 3px 0;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.yshead {
    padding: 3px 10px 5px;
    margin-bottom: 2px;
    border-bottom: 1px solid #eceff1;
    font-size: 0.75rem;
    color: #7b8a8b;
    white-space: nowrap;
}

.ysug {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 4px 10px;
    font-size: 0.88rem;
    color: #2c3e50;
    cursor: pointer;
    white-space: nowrap;
}

.ysug.on,
.ysug:hover {
    background: #eef4fa;
}

.ysug.all {
    font-weight: 600;
}

.ysug .yn {
    color: #7b8a8b;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.ysempty {
    padding: 5px 10px;
    font-size: 0.82rem;
    font-style: italic;
    color: #95a5a6;
    white-space: nowrap;
}

/* input, clear and search sit inside one box that looks like a single field */
#searchWrap {
    position: relative;
    display: flex;
    align-items: stretch;
    height: 27px;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    overflow: hidden;
}

#searchWrap:focus-within {
    border-color: #2980b9;
    box-shadow: 0 0 5px #2980b9;
}

#searchWrap.filtered {
    border-color: #2980b9;
    background: #eef5fb;
}

#searchWrap:has(#searchBox:disabled) {
    opacity: 0.55;
}

#searchBox {
    width: 175px;
    min-width: 0;
    padding: 0 4px 0 8px;
    font-size: 0.9rem;
    background: transparent;
    border: none;
    border-radius: 0;
}

#searchBox:focus {
    box-shadow: none;
}

/* a compartment filter is on */
#searchBox.filtered {
    font-weight: 600;
}

#searchBox:disabled {
    cursor: not-allowed;
}

/* search runs only on Enter or this button, never while typing */
#buttonRow #searchGo,
#buttonRow #searchClear {
    height: auto;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 0;
}

#buttonRow #searchGo {
    width: 30px;
    color: #2c3e50;
    border-left: 1px solid #e2e6ea;
}

#buttonRow #searchGo:hover:enabled {
    background: #e4eef8;
    color: #2980b9;
}

#buttonRow #searchClear {
    width: 22px;
    color: #95a5a6;
    font-size: 1.15rem;
    font-weight: 400;
    line-height: 1;
}

#buttonRow #searchClear:hover {
    color: #c0392b;
}

#resetBtn {
    background-color: #7f8c8d;
    width: 100px !important;
}

#resetBtn:hover:enabled {
    background-color: #616a6b;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#middle {
    flex-grow: 1;
    display: flex;
    gap: 0;
    min-height: 0;
}

/* drag handle between the map and the panel */
#splitter {
    flex: 0 0 15px;
    align-self: stretch;
    cursor: col-resize;
    position: relative;
}

#splitter::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    transform: translateX(-50%);
    border-radius: 2px;
    background: #dfe4e8;
    transition: background 0.15s ease;
}

#splitter:hover::before,
body.resizing #splitter::before {
    background: #2980b9;
}

body.resizing {
    cursor: col-resize;
    user-select: none;
}

/* wrapper exists only to anchor the loading overlay */
#mapWrap {
    flex: 1;
    display: flex;
    position: relative;
    min-width: 0;
}

#viewDiv {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
    background-color: white;
}

/* loading wheel over the map while a query is running */
#mapLoading {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.45);
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    z-index: 10;
    pointer-events: none;
}

#mapLoading.on {
    display: flex;
}

/* stream name / valley segment tooltip that follows the cursor */
#streamTip {
    position: absolute;
    z-index: 15;
    pointer-events: none;
    max-width: 280px;
    padding: 5px 9px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid #cfd8dc;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    font-size: 0.8rem;
    line-height: 1.4;
    color: #2c3e50;
}

#streamTip .tipname {
    display: block;
    font-weight: 700;
    font-size: 0.86rem;
}

#streamTip .tipk {
    color: #7b8a8b;
}

#streamTip .tipwait {
    color: #95a5a6;
    font-style: italic;
}

#mapLoadingText {
    padding: 5px 14px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 14px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 5px solid rgba(41, 128, 185, 0.25);
    border-top-color: #2980b9;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 2.4s;
    }
}

#rightPanel {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-height: 0;
}

#treatmentInfo {
    flex-shrink: 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 4px 10px;
    background: white;
    font-size: 14px;
    color: #444;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}

#treatmentInfo strong {
    color: #2c3e50;
}

#treatmentInfo .sep {
    color: #ccc;
    margin: 0 8px;
}

/* ---- summary card ---- */
#summaryPanel {
    flex-shrink: 0;
    max-height: 40vh;
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 5px 10px;
    background: white;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}

/* no content means nothing is selected, so hide the box entirely */
#summaryPanel:empty {
    display: none;
}

.sumhint {
    font-size: 0.85rem;
    color: #7b8a8b;
}

.sumhead {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #34495e;
    margin-bottom: 3px;
}

.rulebadge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    background: #7f8c8d;
}

.rulebadge.river {
    background: #faf6e3;
    color: #4a3a00;
    border: 1px solid #f0cf5a;
}

.rulebadge.trout {
    background: #2980b9;
}

.rulebadge.aspen {
    background: #f3eefa;
    color: #4a2a6b;
    border: 1px solid #b39ddb;
}

.rulebadge.clear {
    background: #95a5a6;
}

.sumgrid {
    display: grid;
    grid-template-columns: minmax(120px, auto) 1fr;
    gap: 1px 10px;
    font-size: 0.85rem;
    line-height: 1.35;
}

.sumlabel {
    font-weight: 600;
    color: #5d6d7e;
}

.sumval {
    color: #2c3e50;
    word-break: break-word;
}

.sumval.none {
    color: #95a5a6;
    font-style: italic;
}

.chip {
    display: inline-block;
    padding: 0 6px;
    margin: 0 4px 1px 0;
    border-radius: 4px;
    border: 1px solid #cfd8dc;
    background: #f7f9fa;
    font-size: 0.78rem;
    font-weight: 600;
    color: #37474f;
}

.chip.inside {
    border-color: #2980b9;
    background: #2980b9;
    color: #fff;
}

.chip.outer {
    border-style: dashed;
    border-color: #90a4ae;
    background: transparent;
    color: #546e7a;
}

.chip.aspen {
    border-color: #b39ddb;
    background: #f3eefa;
    color: #4a2a6b;
}

/* trout stream type chips, colored by type number */
.chip.tt1 {
    border-color: #81c784;
    background: #e8f5e9;
    color: #1b5e20;
}

.chip.tt2 {
    border-color: #f0cf5a;
    background: #faf6e3;
    color: #4a3a00;
}

.chip.tt3 {
    border-color: #f5a35c;
    background: #fff0e0;
    color: #7a3d00;
}

.chip.tt4 {
    border-color: #7fb0dc;
    background: #e8f1fa;
    color: #154a7a;
}

.sumnote {
    margin-top: 6px;
    font-size: 0.75rem;
    color: #7b8a8b;
}

#tableWrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 3px;
}

#tableTools {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    flex-shrink: 0;
}

#listCount {
    margin-left: auto;
    font-size: 0.8rem;
    font-weight: 600;
    color: #7b8a8b;
}

#tablePreview {
    flex: 1;
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0;
    background: white;
    font-size: 14px;
    color: #444;
    box-sizing: border-box;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
}

#tablePreview .empty {
    padding: 10px;
}

/* separate borders, not collapsed: collapsed borders let rows paint over a
   sticky header in some browsers */
#tablePreview table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

#tablePreview th,
#tablePreview td {
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    padding: 2px 6px;
    text-align: center;
}

#tablePreview th:last-child,
#tablePreview td:last-child {
    border-right: none;
}

#tablePreview thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background-color: #f0f3f7;
    font-weight: 600;
    color: #2c3e50;
}

#tablePreview thead th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

#tablePreview thead th.sortable:hover {
    background-color: #e4eaf2;
}

#tablePreview thead th.sorted {
    color: #2980b9;
}

.sortarrow {
    display: inline-block;
    width: 0.9em;
    font-size: 0.7rem;
}

/* rows sit in their own stacking context below the header */
#tablePreview tbody tr {
    position: relative;
    z-index: 0;
    cursor: pointer;
}

#tablePreview tbody tr:hover {
    background-color: #f9fbfd;
}

#tablePreview tbody tr.picked {
    outline: 2px solid #c0392b;
    outline-offset: -2px;
    font-weight: 600;
}

#tablePreview tbody tr.r-river td {
    background-color: #faf6e3;
}

#tablePreview tbody tr.r-trout td {
    background-color: #eaf2fa;
}

#tablePreview tbody tr.r-aspen td {
    background-color: #f3eefa;
}

#tablePreview tbody tr.r-none td {
    background-color: #f7f9fa;
    color: #8a9499;
}

#status {
    font-size: 0.9rem;
    color: #555;
    margin: 0 0 4px 0;
    min-height: 1.1em;
}

#status.bad {
    color: #c0392b;
    font-weight: 600;
}

/* on-map widgets */
.map-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    font-size: 0.85rem;
    font-weight: 600;
    color: #34495e;
    white-space: nowrap;
    cursor: pointer;
}

.map-toggle input {
    min-width: 0;
    margin: 0;
    cursor: pointer;
}

.map-toggle label {
    cursor: pointer;
}

.map-toggle+.map-toggle {
    margin-top: 4px;
}

/* ---- header help button ---- */
#helpBtn {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    background: #2980b9;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1;
    flex-shrink: 0;
}

#helpBtn:hover {
    background: #1f6391;
}

/* ---- first-run walkthrough ---- */
#tour {
    position: fixed;
    inset: 0;
    z-index: 1000;
}

#tour[hidden] {
    display: none;
}

/* the ring plus a huge shadow makes everything else dim */
#tourSpot {
    position: absolute;
    border-radius: 8px;
    border: 2px solid #2980b9;
    box-shadow: 0 0 0 9999px rgba(18, 26, 35, 0.55);
    transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
    pointer-events: none;
}

#tourBox {
    position: absolute;
    width: 330px;
    max-width: calc(100vw - 24px);
    background: #fff;
    border-radius: 10px;
    padding: 14px 16px 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    transition: left 0.2s ease, top 0.2s ease;
}

#tourClose {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    color: #8a9499;
    font-size: 1.2rem;
    line-height: 1;
}

#tourClose:hover {
    color: #2c3e50;
    background: #eef1f3;
}

#tourCount {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #2980b9;
    margin-bottom: 3px;
}

#tourTitle {
    font-size: 0.98rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 5px;
}

#tourText {
    font-size: 0.85rem;
    line-height: 1.45;
    color: #4d5b66;
}

#tourFoot {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #eceff1;
}

#tourFoot .checkfield {
    font-size: 0.78rem;
    font-weight: 500;
    color: #5d6d7e;
}

#tourFoot .checkfield input {
    min-width: 0;
}

#tourBtns {
    margin-left: auto;
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

#tourBtns button {
    padding: 6px 14px;
    font-size: 0.82rem;
    background: #2980b9;
}

#tourBtns button:hover:enabled {
    background: #1f6391;
}

#tourBack {
    background: #b0bec5;
}

#tourBack:hover:enabled {
    background: #90a4ae;
}