:root {
    --ink: #17211d;
    --muted: #66736f;
    --panel: #ffffff;
    --line: #dfe7e3;
    --field: #157347;
    --field-dark: #0f5132;
    --field-soft: #e8f4ee;
    --amber: #f0b429;
    --danger: #b42318;
    --shadow: 0 18px 44px rgba(20, 36, 29, .18);
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background: #eef3f0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #dbe8e0, #f7f8f4 52%, #d7e2e8);
}

.login-panel {
    width: min(430px, 100%);
    background: rgba(255, 255, 255, .95);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--field-dark);
    color: #fff;
    font-weight: 800;
}

.login-brand h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
}

.login-brand p {
    margin: 2px 0 0;
    color: var(--muted);
}

.field-shell {
    height: 100vh;
    display: grid;
    grid-template-rows: 58px minmax(0, 1fr);
}

.topbar {
    display: grid;
    grid-template-columns: 220px minmax(260px, 560px) auto;
    gap: 14px;
    align-items: center;
    padding: 10px 14px;
    background: #18231f;
    color: #fff;
    z-index: 800;
}

.topbar-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
}

.topbar-title span {
    color: #b9c8c2;
    font-size: .9rem;
}

.route-select {
    min-width: 0;
    border: 0;
}

.topbar-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 8px;
    color: #fff;
    background: rgba(255,255,255,.08);
    font-size: 1.1rem;
}

.icon-btn.active {
    background: var(--field);
    border-color: var(--field);
}

.field-main {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 390px;
}

.map-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: #d5ddd8;
}

.work-panel {
    background: var(--panel);
    border-left: 1px solid var(--line);
    padding: 16px;
    overflow-y: auto;
    box-shadow: -10px 0 30px rgba(0,0,0,.08);
    z-index: 600;
}

.panel-handle {
    display: none;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f5f8f6;
}

.segmented button {
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 750;
    padding: 10px 8px;
}

.segmented button.active {
    background: var(--field-dark);
    color: #fff;
}

.tool-form,
.selection-card {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.form-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: start;
    margin-bottom: 10px;
}

.form-head h2 {
    margin: 0;
    font-size: 1.12rem;
    font-weight: 820;
}

.eyebrow,
.panel-title {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.field-note,
.status-box {
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7faf8;
    color: var(--muted);
    font-size: .88rem;
}

.status-box {
    margin-top: 12px;
}

.status-box.error {
    border-color: #f2b8b5;
    color: var(--danger);
    background: #fff6f5;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 800;
    white-space: nowrap;
}

.pill.muted {
    background: #edf2ef;
    color: var(--muted);
}

.pill.active {
    background: var(--field-soft);
    color: var(--field-dark);
}

.soft-label {
    color: var(--muted);
    font-weight: 600;
    font-size: .82rem;
}

.btn-field {
    border: 0;
    background: var(--field);
    color: #fff;
    font-weight: 760;
}

.btn-field:hover,
.btn-field:focus {
    background: var(--field-dark);
    color: #fff;
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.photo-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.photo-thumb {
    position: relative;
    width: 74px;
    height: 74px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #eef3f0;
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-thumb button {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 999px;
    background: rgba(180, 35, 24, .94);
    color: #fff;
    line-height: 1;
    font-weight: 800;
}

.photo-thumb span {
    position: absolute;
    left: 3px;
    bottom: 3px;
    padding: 1px 4px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .58);
    color: #fff;
    font-size: .68rem;
}

.map-chip {
    position: absolute;
    left: 14px;
    z-index: 450;
    max-width: min(560px, calc(100vw - 32px));
    background: rgba(255, 255, 255, .95);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    box-shadow: 0 10px 26px rgba(0,0,0,.12);
}

.route-chip {
    top: 14px;
    font-weight: 820;
}

.gps-chip {
    bottom: 14px;
    display: grid;
    gap: 2px;
    font-size: .9rem;
}

.gps-chip span {
    color: var(--muted);
}

.layers-panel {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 700;
    width: 230px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255,255,255,.97);
    box-shadow: var(--shadow);
}

.layers-panel label {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 5px 0;
    font-size: .93rem;
}

.leaflet-popup-content {
    min-width: 220px;
    font-size: .9rem;
}

.popup-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.popup-actions button {
    flex: 1;
}

.gps-marker {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #1677ff;
    border: 3px solid #fff;
    box-shadow: 0 0 0 8px rgba(22,119,255,.18);
}

@media (max-width: 900px) {
    .field-shell {
        grid-template-rows: 56px minmax(0, 1fr);
    }

    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
    }

    .topbar-title {
        display: none;
    }

    .route-select {
        font-size: .9rem;
    }

    .topbar-actions {
        gap: 6px;
    }

    .topbar-actions .btn {
        display: none;
    }

    .field-main {
        grid-template-columns: 1fr;
    }

    .map-stage {
        height: calc(100vh - 56px);
    }

    .work-panel {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: 8px;
        max-height: 46vh;
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 8px;
        box-shadow: var(--shadow);
    }

    .panel-handle {
        display: block;
        width: 42px;
        height: 4px;
        border-radius: 999px;
        background: #cfd8d4;
        margin: 0 auto 8px;
    }

    .tool-form,
    .selection-card {
        margin-top: 8px;
        padding: 9px;
    }

    .form-head h2 {
        font-size: .96rem;
    }

    .form-head {
        margin-bottom: 6px;
    }

    .eyebrow,
    .panel-title {
        margin-bottom: 3px;
        font-size: .66rem;
    }

    .field-note {
        display: none;
    }

    .status-box {
        margin-top: 8px;
        margin-bottom: 8px;
        padding: 7px 8px;
        font-size: .8rem;
    }

    .segmented button {
        padding: 8px 6px;
        font-size: .88rem;
    }

    .form-label {
        margin-bottom: 3px;
        font-size: .82rem;
    }

    .form-control,
    .form-select {
        min-height: 34px;
        padding-top: 5px;
        padding-bottom: 5px;
        font-size: .86rem;
    }

    textarea.form-control {
        min-height: 64px;
    }

    .button-row {
        margin-top: 8px;
        gap: 6px;
    }

    .button-row .btn {
        padding: 7px 8px;
        font-size: .84rem;
    }

    .map-chip {
        left: 10px;
        right: 10px;
        max-width: none;
        padding: 8px 10px;
    }

    .route-chip {
        top: 10px;
        font-size: .86rem;
    }

    .gps-chip {
        bottom: calc(46vh + 24px);
        font-size: .82rem;
    }

    .layers-panel {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        padding: 9px 10px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 12px;
    }

    .layers-panel .panel-title {
        grid-column: 1 / -1;
    }

    .layers-panel label {
        padding: 3px 0;
        font-size: .84rem;
    }

    .photo-tray {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .photo-thumb {
        flex: 0 0 58px;
        width: 58px;
        height: 58px;
    }
}
