:root {
    --bg: #f4f6f7;
    --panel: #ffffff;
    --text: #1d2a2e;
    --muted: #69777d;
    --line: #d8e0e3;
    --primary: #12695f;
    --primary-dark: #0e554e;
    --warn: #a85b00;
    --ok: #1f7a45;
    --danger: #a63232;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

.table-scroll {
    overflow-x: auto;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox input {
    width: auto;
}

.map-toggle {
    align-items: center;
    min-height: 39px;
    padding: 0 2px;
}

.shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: #142225;
    color: #e8f0ef;
    padding: 22px;
}

.brand {
    display: block;
    color: #fff;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 28px;
}

.brand span {
    color: #9fc8c1;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar nav a {
    color: #dbe7e5;
    border-radius: 6px;
    padding: 9px 10px;
}

.sidebar nav a:hover {
    background: #203539;
}

.main {
    min-width: 0;
    padding: 22px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
}

.panel,
.login-box,
.metric {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.panel + .panel,
.metric-grid + .panel,
.toolbar + .panel,
.notice + .panel {
    margin-top: 14px;
}

.setup {
    max-width: 880px;
    margin: 40px auto;
    padding: 0 18px;
}

.login-box {
    max-width: 420px;
}

.login-box form,
.inline-form {
    display: grid;
    gap: 14px;
}

.compact-form {
    display: inline-grid;
    gap: 0;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.metric span {
    color: var(--muted);
    display: block;
    margin-bottom: 6px;
}

.metric strong {
    display: block;
    font-size: 28px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.admin-metrics .metric strong {
    font-size: 22px;
}

.two-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.status-list {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 10px 14px;
    margin: 0;
}

.status-list dt {
    color: var(--muted);
    font-weight: 700;
}

.status-list dd {
    margin: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.admin-submenu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.admin-submenu a {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    padding: 8px 11px;
}

.admin-submenu a:hover,
.admin-submenu a.is-active {
    border-color: #9fc8c1;
    background: #e8f2f0;
    color: var(--primary-dark);
}

.search,
.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.search input {
    min-width: 320px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 10px 14px;
}

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

.button:disabled {
    background: #aeb8bb;
    cursor: not-allowed;
}

.button-secondary {
    background: #31545a;
}

.button-danger {
    background: var(--danger);
}

.button-danger:hover {
    background: #842626;
}

.button-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.danger-zone {
    border-color: #e3b8b8;
    background: #fffafa;
}

.danger-zone h2 {
    color: var(--danger);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-fieldset {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin: 0;
    padding: 14px;
}

.form-fieldset legend {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    padding: 0 6px;
}

.full,
.form-actions {
    grid-column: 1 / -1;
}

.detail dl {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 10px 16px;
    margin: 0;
}

.detail dt {
    color: var(--muted);
    font-weight: 700;
}

.detail dd {
    margin: 0;
}

.plant-detail {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) minmax(360px, 0.9fr);
    gap: 22px;
    align-items: stretch;
}

.plant-detail-fields {
    min-width: 0;
}

.plant-detail-map-area {
    display: grid;
    min-width: 0;
    grid-template-rows: minmax(320px, 1fr) auto;
    gap: 10px;
}

.plant-detail-map {
    min-height: 320px;
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #dbe6e8;
}

.plant-detail-map .leaflet-popup-content {
    margin: 9px 12px;
}

.map-actions {
    display: flex;
    justify-content: flex-end;
}

.plant-map-fallback {
    min-height: 320px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fbfb;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: #edf2f3;
    color: #294046;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 700;
}

.badge.ok {
    background: #e5f4eb;
    color: var(--ok);
}

.badge.warn {
    background: #fff0d9;
    color: var(--warn);
}

.notice {
    border-radius: 6px;
    margin-bottom: 14px;
    padding: 10px 12px;
}

.notice.success {
    background: #e5f4eb;
    color: var(--ok);
}

.notice.error {
    background: #fae6e6;
    color: var(--danger);
}

.muted {
    color: var(--muted);
}

.help-text {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
}

details {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
}

summary {
    cursor: pointer;
    font-weight: 700;
}

details label {
    margin-top: 12px;
}

.upload-progress {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    background: #f8fbfb;
}

.upload-progress-bar {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #dbe6e8;
}

.upload-progress-bar span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width 160ms ease;
}

.map-shell {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 0 rgba(20, 34, 37, 0.04);
}

#map {
    min-height: 680px;
    width: 100%;
}

.river-tooltip {
    border: 1px solid #86bdda;
    color: #124e72;
    font-size: 12px;
    font-weight: 700;
}

.map-fallback {
    display: grid;
    min-height: 620px;
    place-items: center;
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

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

    .sidebar {
        position: static;
    }

    .metric-grid,
    .two-column,
    .form-grid,
    .status-list,
    .plant-detail {
        grid-template-columns: 1fr;
    }

    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .search input {
        min-width: 0;
    }
}
