:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --ink: #15202b;
    --muted: #5b6b7c;
    --line: #e3e8ee;
    --line-strong: #c9d3de;
    --brand: #0f6e56;
    --brand-soft: #e6f4ef;
    --brand-hover: #0b5844;
    --accent: #1a6bb5;
    --accent-soft: #e8f2fb;
    --ok: #1b7a3d;
    --ok-soft: #e8f7ee;
    --warn: #9a6700;
    --warn-soft: #fff6dd;
    --bad: #b42318;
    --bad-soft: #fef3f2;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(21, 32, 43, 0.04), 0 8px 24px rgba(21, 32, 43, 0.04);
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    min-height: 100%;
}

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

.app {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1rem 0.85rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 700;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
    padding: 0.35rem 0.5rem 1rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.75rem;
}
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}
.brand-sub {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
}
.nav .nav-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0.75rem 0.7rem 0.35rem;
}
.nav a {
    color: var(--muted);
    text-decoration: none;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }

.app-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mobile-topbar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.mobile-topbar .sidebar-toggle {
    border: 1px solid var(--line-strong);
    background: #fff;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 16px;
}

.main {
    width: min(1280px, calc(100% - 2rem));
    margin: 1.25rem auto 2.5rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(21, 32, 43, 0.35);
    z-index: 30;
}
body.sidebar-open .sidebar-backdrop { display: block; }
body.sidebar-open .sidebar { transform: translateX(0); }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.page-head h1 {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}
.page-head p {
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 12.5px;
}
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.alert {
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}
.alert-success { background: var(--ok-soft); border-color: #abefc6; color: var(--ok); }
.alert-error { background: var(--bad-soft); border-color: #fecdca; color: var(--bad); }
.alert-close {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: inherit;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.55rem 0.75rem;
    box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 11px; font-weight: 600; }
.stat .value { font-size: 1.15rem; font-weight: 750; margin-top: 0.1rem; letter-spacing: -0.02em; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--bad); }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 0.75rem;
}
.card-head {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.card-head h2 {
    margin: 0;
    font-size: 0.92rem;
}
.card-head .sub { color: var(--muted); font-size: 11.5px; margin-top: 0.1rem; }
.card-body { padding: 0.75rem 0.85rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.5rem 0.9rem;
    font: inherit;
    font-weight: 650;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    background: var(--surface-2);
    color: var(--ink);
}
.btn:hover { text-decoration: none; filter: brightness(0.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); border-color: #c5dff5; }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: #fecdca; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--muted); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 12px; }

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 140px; }
.field label { font-size: 12px; font-weight: 650; color: var(--muted); }
.field input, .field select, .field textarea {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    font: inherit;
    background: #fff;
    color: var(--ink);
    min-height: 38px;
}
.field input[type="file"] { padding: 0.35rem; }
.checks { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.3rem 0.7rem;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    background: #fff;
}
table.data th, table.data td {
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
    vertical-align: top;
}
table.data th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
}
table.data tbody tr:hover { background: #f7fbf9; }
table.data td.wrap { white-space: normal; max-width: 280px; }
table.data th.num,
table.data td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
table.data th.num .sort-link { justify-content: flex-end; width: 100%; }
.cell-sub {
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    margin-top: 0.1rem;
    white-space: normal;
    max-width: 160px;
}

.report-table { border-collapse: collapse; width: 100%; font-size: 12.5px; background: #fff; }
.report-table th, .report-table td {
    border: 1px solid var(--line-strong);
    padding: 0.4rem 0.55rem;
    vertical-align: middle;
}
.report-table thead th {
    background: var(--surface-2);
    text-align: center;
    font-weight: 700;
    color: var(--muted);
}
.report-table .plant-group { border-bottom: 0; }
.report-table td.num, .report-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table tr.report-total {
    background: #fff6dd;
    font-weight: 700;
}
.report-table tr.report-special td.txn { background: #f3f6fb; }
.report-table tr.report-diff { background: #fff0f0; }
.report-table td.txn { font-weight: 650; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.section-title { font-size: 1rem; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 11px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--accent-soft); color: var(--accent); }

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}
.folder-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.85rem;
    background: var(--surface-2);
}
.folder-card strong { display: block; margin-bottom: 0.25rem; }
.folder-card .meta { color: var(--muted); font-size: 12px; }
.progress {
    margin-top: 0.55rem;
    height: 6px;
    background: #e8eef3;
    border-radius: 999px;
    overflow: hidden;
}
.progress > span {
    display: block;
    height: 100%;
    background: var(--brand);
}

.page-nav { margin-top: 1rem; }
.page-list {
    display: flex;
    gap: 0.35rem;
    list-style: none;
    padding: 0;
    margin: 0;
    flex-wrap: wrap;
}
.page-item a, .page-item span {
    display: inline-flex;
    min-width: 34px;
    justify-content: center;
    padding: 0.35rem 0.55rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
    font-weight: 650;
}
.page-item.active span { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-item.disabled span { opacity: 0.45; }

.test-box {
    margin-top: 0.85rem;
    padding: 0.85rem 1rem;
    background: var(--brand-soft);
    border: 1px solid #b7e0d0;
    border-radius: 8px;
    font-size: 13px;
}

.empty {
    color: var(--muted);
    padding: 1.25rem 0.25rem;
    text-align: center;
}

.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.65rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    color: var(--muted);
    font-weight: 650;
    font-size: 12.5px;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}
.tab-count {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
    font-size: 11px;
    font-weight: 700;
}
.tab.is-active .tab-count {
    background: var(--brand-soft);
    border-color: #b7e0d0;
    color: var(--brand);
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.65rem;
    padding: 0.55rem 0.65rem;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
}
.filters .filter-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: end;
    align-self: end;
    padding-bottom: 1px;
}
.filters .field { min-width: 0; gap: 0.2rem; }
.filters .field label { font-size: 11px; }
.filters .field input,
.filters .field select {
    min-height: 32px;
    padding: 0.3rem 0.5rem;
    font-size: 12.5px;
}

.is-ajax-loading [data-ajax-results] {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

.summary-strip {
    margin-bottom: 1rem;
}
.summary-strip > strong {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 0.45rem;
}
.summary-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.chip {
    display: inline-flex;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 12px;
    font-weight: 650;
    text-decoration: none;
}
.chip:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.chip span { color: var(--muted); font-weight: 600; }
.chip-warn { background: var(--warn-soft); border-color: #f5e4a8; }
.chip-bad { background: var(--bad-soft); border-color: #fecdca; }

.table-meta {
    margin: 0 0 0.55rem;
    font-size: 12px;
    color: var(--muted);
}

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
}
.sort-link:hover { color: var(--brand); text-decoration: none; }
.sort-link.is-active { color: var(--brand); }
.sort-ind { font-size: 11px; }

.clear-card .clear-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.clear-points {
    display: grid;
    gap: 0.35rem;
    font-size: 13px;
    color: var(--muted);
}
.clear-points strong { color: var(--ink); }

.month-bars {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.45rem;
}
.month-bar {
    display: block;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    text-decoration: none;
    color: inherit;
}
.month-bar:hover {
    border-color: var(--brand);
    text-decoration: none;
    color: inherit;
}
.month-bar-top {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 13px;
    margin-bottom: 0.45rem;
}
.month-bar-top span { color: var(--muted); font-weight: 650; }
.month-bar .meta { margin-top: 0.35rem; font-size: 11px; color: var(--muted); }

.dup-panel {
    margin-top: 0.85rem;
    padding: 0.85rem 1rem;
    background: var(--warn-soft);
    border: 1px solid #f5e4a8;
    border-radius: 8px;
    font-size: 13px;
}

.delete-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
}
.delete-title {
    margin: 0 0 0.55rem;
    font-size: 13px;
    font-weight: 700;
}
.delete-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    max-height: 280px;
    overflow: auto;
}
.delete-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}
.delete-row .meta { color: var(--muted); font-size: 12px; margin-top: 0.1rem; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 40;
        transform: translateX(-105%);
        transition: transform 0.18s ease;
        box-shadow: var(--shadow);
    }
    .mobile-topbar { display: flex; }
    .page-head { flex-direction: column; }
    .main { width: calc(100% - 1.25rem); }
}
