:root {
    --bg: #f3f6f8;
    --card: #ffffff;
    --text: #17232d;
    --muted: #64727f;
    --primary: #17324d;
    --primary-2: #245579;
    --border: #dce4e9;
    --success: #176b43;
    --danger: #a52c2c;
    --warning: #a56400;
    --shadow: 0 8px 30px rgba(20, 45, 65, .07);
}

* { box-sizing: border-box; }

html { font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

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

.wrap {
    width: min(1180px, calc(100% - 32px));
    margin-inline: auto;
}

.narrow { width: min(640px, calc(100% - 32px)); }

.topbar {
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: 0 4px 18px rgba(0,0,0,.1);
}

.topbar-inner {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    color: #fff;
    font-weight: 800;
    letter-spacing: .01em;
}

.brand:hover { text-decoration: none; }

.nav { display: flex; gap: 16px; align-items: center; }
.nav a { color: #fff; opacity: .92; }

.page { padding: 28px 0 48px; }

.footer {
    color: var(--muted);
    font-size: 14px;
    padding: 16px 0 32px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

h1, h2, h3 { line-height: 1.15; margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); margin-bottom: 12px; }
h2 { font-size: 22px; margin-bottom: 18px; }

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

form { display: grid; gap: 16px; }

label {
    display: grid;
    gap: 7px;
    font-weight: 650;
}

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #cbd7de;
    border-radius: 10px;
    padding: 12px 13px;
    color: var(--text);
    background: #fff;
}

input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(36, 85, 121, .14);
    border-color: var(--primary-2);
}

button, .button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 12px 18px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
}

button:hover, .button:hover {
    background: var(--primary-2);
    text-decoration: none;
}

button:disabled { opacity: .65; cursor: wait; }

.button-secondary { background: #315f47; }
.button-light { background: #e9eff3; color: var(--text); }
.button-small { padding: 8px 12px; font-size: 14px; }
.button-large { padding: 15px 22px; font-size: 18px; }
.full-width { width: 100%; }

.alert {
    padding: 13px 15px;
    border-radius: 10px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-success { background: #e7f6ee; border-color: #b9dfcb; color: var(--success); }
.alert-error { background: #fbeaea; border-color: #efc0c0; color: var(--danger); }

.login-card { max-width: 480px; margin: 50px auto; }

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.record-list { display: grid; }
.record-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 16px;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.record-row:last-child { border-bottom: 0; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    background: #e9eff3;
    font-size: 13px;
    font-weight: 800;
}
.status-new { background: #fff1c7; color: #755000; }
.status-processed { background: #e5eff8; color: #244e73; }
.status-checked { background: #dff4e8; color: #176b43; }
.status-disputed { background: #fde5e5; color: #942828; }
.status-cancelled { background: #eceff1; color: #59636b; }

.form-section {
    padding: 6px 0 20px;
    border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: 0; }

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

.check-card, .upload-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: #fafcfd;
}

.check-card {
    grid-template-columns: auto 1fr;
    align-items: center;
    cursor: pointer;
}
.check-card input { width: 20px; height: 20px; }

.upload-card input { margin-top: 6px; }

.switch-line {
    grid-template-columns: auto 1fr;
    align-items: center;
}
.switch-line input { width: 22px; height: 22px; }

.geo-status {
    padding: 12px;
    border-radius: 10px;
    background: #eef3f6;
    color: var(--muted);
}
.geo-status.ok { background: #e7f6ee; color: var(--success); }

.page-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.filters {
    grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(140px, 1fr)) auto auto;
    align-items: end;
}

.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f7f9fa; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.two-columns {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(320px, .9fr);
    gap: 20px;
    align-items: start;
}

.sticky-card { position: sticky; top: 84px; }

.details {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 10px 18px;
    margin: 0;
}
.details dt { color: var(--muted); }
.details dd { margin: 0; font-weight: 650; }

.gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.gallery figure {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}
.gallery img {
    display: block;
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
}
.gallery figcaption {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
}
.gallery small { color: var(--muted); word-break: break-all; }

.audit-list { display: grid; }
.audit-list > div {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 14px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}
.audit-list > div:last-child { border-bottom: 0; }

@media (max-width: 860px) {
    .topbar-inner { align-items: flex-start; padding: 14px 0; }
    .nav { flex-wrap: wrap; justify-content: flex-end; font-size: 14px; }
    .hero, .page-title { align-items: stretch; flex-direction: column; }
    .filters { grid-template-columns: 1fr 1fr; }
    .two-columns { grid-template-columns: 1fr; }
    .sticky-card { position: static; }
}

@media (max-width: 600px) {
    .wrap { width: min(100% - 20px, 1180px); }
    .page { padding-top: 16px; }
    .card { padding: 17px; border-radius: 13px; }
    .topbar { position: static; }
    .topbar-inner { display: grid; }
    .nav { justify-content: flex-start; }
    .hero .button { width: 100%; }
    .check-grid, .photo-grid, .gallery { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr; }
    .details { grid-template-columns: 1fr; gap: 2px; }
    .details dd { margin-bottom: 10px; }
    .record-row { grid-template-columns: 1fr auto; }
    .record-row > :last-child { grid-column: 1 / -1; }
    .audit-list > div { grid-template-columns: 1fr; gap: 3px; }
}

/* Version 2 additions */
.optional { font-size: 13px; font-weight: 500; color: var(--muted); }
.button-danger { background: #a52c2c; }
.button-danger:hover { background: #842323; }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.credentials { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.credentials code { padding: 13px; border-radius: 10px; background: #eef3f6; font-size: 16px; word-break: break-all; }
.credential-card { border: 2px solid #315f47; }
.user-row { display: grid; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.inline-form { display: grid; grid-template-columns: minmax(180px,1fr) auto; gap: 10px; align-items: end; }
.user-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.user-actions form { display: inline-flex; }
.group-grid, .tree-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.group-card, .tree-card { color: var(--text); margin-bottom: 0; }
.group-card:hover, .tree-card:hover { text-decoration: none; border-color: #9fb3c1; transform: translateY(-1px); }
.group-card-head, .tree-card-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.group-card h2, .tree-card h2 { margin-bottom: 8px; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; }
.stats span { background: #f0f4f6; border-radius: 10px; padding: 10px 13px; }
.tree-status-planned { background: #fff1c7; color: #755000; }
.tree-status-cut { background: #dff4e8; color: #176b43; }
.tree-status-cancelled { background: #eceff1; color: #59636b; }
.narrow-card { max-width: 720px; margin-inline: auto; }
.filters.compact { grid-template-columns: minmax(240px,2fr) minmax(170px,1fr) auto auto; }
.map-card { padding: 14px; }
#trees-map { height: min(72vh,720px); min-height: 460px; border-radius: 12px; }
.map-legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 4px 2px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; }
.dot.planned { background: #d98200; }.dot.cut { background: #198754; }.dot.cancelled { background: #6c757d; }
@media (max-width: 700px) {
  .group-grid,.tree-grid,.credentials { grid-template-columns: 1fr; }
  .inline-form,.filters.compact { grid-template-columns: 1fr; }
  #trees-map { min-height: 420px; }
}

/* Version 2.1 — corrected interactive map */
.map-filter-card {
    position: relative;
    z-index: 2;
}

.map-filters {
    display: grid;
    grid-template-columns: minmax(240px, 1.4fr) minmax(190px, .8fr) auto auto;
    gap: 14px;
    align-items: end;
}

.map-card {
    position: relative;
    padding: 14px;
    overflow: hidden;
    isolation: isolate;
}

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

.map-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.map-summary {
    display: flex;
    align-items: baseline;
    gap: 7px;
    color: var(--muted);
}

.map-summary strong {
    color: var(--text);
    font-size: 22px;
}

#trees-map {
    display: block;
    position: relative;
    z-index: 1;
    width: 100%;
    height: clamp(480px, 68vh, 760px);
    min-height: 480px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #dce7ec;
    touch-action: none;
}

#trees-map.leaflet-container {
    width: 100%;
    max-width: 100%;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
}

#trees-map .leaflet-tile-pane,
#trees-map .leaflet-map-pane,
#trees-map .leaflet-pane,
#trees-map .leaflet-control-container {
    max-width: none;
}

#trees-map img.leaflet-tile {
    max-width: none !important;
    max-height: none !important;
}

#trees-map .leaflet-control-zoom a {
    font-size: 22px;
    font-weight: 700;
    line-height: 30px;
}

#trees-map .leaflet-control-attribution {
    max-width: min(80vw, 540px);
    white-space: normal;
}

#trees-map .leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(20, 45, 65, .22);
}

#trees-map .leaflet-popup-content {
    margin: 15px 17px;
}

.tree-map-popup {
    display: grid;
    gap: 8px;
}

.tree-map-popup > strong {
    font-size: 17px;
}

.tree-map-status {
    display: inline-flex;
    width: max-content;
    align-items: center;
    gap: 7px;
    padding: 4px 9px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--marker-color) 14%, white);
    color: var(--text);
    font-size: 12px;
    font-weight: 800;
}

.tree-map-status::before {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--marker-color);
}

.tree-map-link {
    display: inline-flex;
    justify-content: center;
    margin-top: 3px;
    padding: 9px 12px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff !important;
    font-weight: 800;
    text-decoration: none !important;
}

.map-legend {
    position: relative;
    z-index: 2;
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    padding: 13px 4px 1px;
}

.map-empty,
.map-load-error {
    position: absolute;
    z-index: 800;
    left: 50%;
    top: 50%;
    width: min(420px, calc(100% - 40px));
    transform: translate(-50%, -50%);
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow);
    text-align: center;
    color: var(--muted);
    pointer-events: none;
}

body.map-fullscreen-open {
    overflow: hidden;
}

.map-card.map-card-fullscreen {
    position: fixed;
    z-index: 5000;
    inset: 10px;
    width: auto;
    height: auto;
    margin: 0;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    background: var(--card);
}

.map-card.map-card-fullscreen #trees-map {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}

.map-card.map-card-fullscreen .map-legend {
    flex: 0 0 auto;
}

@media (max-width: 800px) {
    .map-filters {
        grid-template-columns: 1fr 1fr;
    }

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

    .map-toolbar-actions,
    .map-toolbar-actions .button {
        width: 100%;
    }

    #trees-map {
        height: 64vh;
        min-height: 430px;
    }
}

@media (max-width: 560px) {
    .map-filters {
        grid-template-columns: 1fr;
    }

    .map-card {
        padding: 9px;
    }

    #trees-map {
        min-height: 400px;
        border-radius: 10px;
    }

    .map-card.map-card-fullscreen {
        inset: 0;
        border: 0;
        border-radius: 0;
    }
}


/* Stage 56: keep object/map content below the sticky site header.
   Leaflet creates internal panes with their own z-index values, so the
   map wrapper gets an isolated stacking context below the header. */
.topbar{
    position:sticky !important;
    top:0 !important;
    z-index:10000 !important;
    isolation:isolate;
}
.map-card,
#trees-map{
    isolation:isolate;
}
.map-card{
    z-index:0 !important;
}
#trees-map{
    z-index:0 !important;
}
