:root {
    --bg: #f7f3ea;
    --surface: #fffdf7;
    --surface-strong: #ffffff;
    --ink: #1e2a24;
    --muted: #637066;
    --border: #ded6c5;
    --green: #2f6b4f;
    --green-dark: #214d3a;
    --blue: #2f6f8f;
    --amber: #b7791f;
    --red: #a33a2f;
    --shadow: 0 12px 30px rgba(54, 46, 32, 0.08);
    --radius: 8px;
    --sidebar: 248px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(47, 107, 79, 0.08), transparent 280px),
        var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
    letter-spacing: 0;
}

a {
    color: var(--green-dark);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 2rem;
    line-height: 1.1;
}

h2 {
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    line-height: 1.2;
}

h3 {
    margin-bottom: 0.55rem;
    color: var(--muted);
    font-size: 0.83rem;
    font-weight: 800;
    text-transform: uppercase;
}

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0.8rem;
    color: var(--ink);
    background: var(--surface-strong);
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 0.4rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

label input,
label select,
label textarea {
    color: var(--ink);
    font-weight: 500;
}

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

.auth-shell,
.system-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1.25rem;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    gap: 1rem;
    border-right: 1px solid var(--border);
    padding: 1.25rem;
    background: rgba(255, 253, 247, 0.9);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--ink);
    font-weight: 850;
    text-decoration: none;
}

.brand-mark,
.nav-mark {
    display: grid;
    width: 2.25rem;
    height: 2.25rem;
    place-items: center;
    border: 1px solid rgba(47, 107, 79, 0.24);
    border-radius: var(--radius);
    background: #eaf2ed;
    color: var(--green-dark);
    font-size: 0.78rem;
    font-weight: 850;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: inherit;
}

.brand.compact .brand-mark {
    width: 2rem;
    height: 2rem;
}

.side-nav {
    display: grid;
    gap: 0.35rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 2.75rem;
    border-radius: var(--radius);
    padding: 0.35rem 0.45rem;
    color: var(--ink);
    font-weight: 750;
    text-decoration: none;
}

.nav-link.active,
.nav-link:hover {
    background: #edf3ef;
}

.sidebar-logout {
    margin-top: auto;
}

.mobile-header,
.bottom-nav {
    display: none;
}

.main {
    width: min(100%, 980px);
    margin: 0 auto;
    padding: 2rem;
}

.main-wide {
    width: min(100%, 1240px);
}

.page-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.65rem;
}

.eyebrow {
    margin-bottom: 0.35rem;
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
}

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

.meta {
    margin-bottom: 0;
    font-size: 0.9rem;
}

.card,
.auth-card,
.system-panel,
.empty-state {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 253, 247, 0.94);
    box-shadow: var(--shadow);
}

.card {
    padding: 1.1rem;
}

.auth-card,
.system-panel {
    width: min(100%, 430px);
    padding: 1.4rem;
}

.system-details {
    margin-top: 1rem;
    border-radius: var(--radius);
    padding: 0.8rem;
    background: #f1eadb;
    color: var(--muted);
    font-size: 0.9rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 1rem;
}

.dashboard-span {
    grid-column: 1 / -1;
}

.panel-hero {
    min-height: 260px;
    background:
        linear-gradient(135deg, rgba(47, 107, 79, 0.14), rgba(47, 111, 143, 0.12)),
        var(--surface);
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 0.45fr);
    gap: 1rem;
    align-items: start;
}

.side-panel {
    display: grid;
    gap: 1rem;
}

.list-stack,
.stack,
.mini-list,
.checklist-groups {
    display: grid;
    gap: 0.8rem;
}

.compact-list {
    gap: 0.6rem;
}

.item-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-card {
    display: grid;
    grid-template-columns: minmax(160px, 220px) minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: center;
}

.site-card-body {
    min-width: 0;
}

.site-card-map {
    min-width: 0;
}

.item-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
}

.item-card h2,
.note-card h2 {
    margin-bottom: 0.2rem;
}

.item-title-row,
.section-head,
.note-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
}

.note-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 0.8rem;
}

.note-card p:last-child {
    margin-bottom: 0;
}

.map-hero {
    margin-bottom: 1rem;
}

.map-hero-head {
    align-items: end;
    margin-bottom: 0.75rem;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 800;
}

.map-legend span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.legend-dot {
    display: inline-block;
    width: 0.78rem;
    height: 0.78rem;
    border-radius: 999px;
}

.osm-map,
.map-placeholder {
    position: relative;
    display: block;
    overflow: hidden;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #eaf2ed;
}

.osm-map {
    min-height: 260px;
    touch-action: none;
}

.map-placeholder {
    display: grid;
    min-height: 180px;
    place-items: center;
    padding: 1rem;
    color: var(--muted);
    font-weight: 800;
    text-align: center;
}

.dashboard-map {
    min-height: 390px;
}

.map-preview {
    min-height: 138px;
}

.site-hero-map {
    height: 100%;
    min-height: 330px;
    border: 0;
    border-radius: 0;
}

.osm-map.is-dragging {
    cursor: grabbing;
}

.osm-tile-layer,
.osm-marker-layer {
    position: absolute;
    inset: 0;
}

.osm-tile-layer img {
    position: absolute;
    width: 256px;
    height: 256px;
    max-width: none;
    user-select: none;
}

.map-pin {
    position: absolute;
    z-index: 2;
    display: grid;
    min-width: 1.05rem;
    min-height: 1.05rem;
    place-items: center;
    border: 2px solid #ffffff;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(30, 42, 36, 0.32);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 850;
    text-decoration: none;
    transform: translate(-50%, -50%);
}

.map-pin-label {
    min-width: auto;
    max-width: 11rem;
    min-height: 1.75rem;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pin-planned {
    background: var(--blue);
}

.pin-visited {
    background: var(--green);
}

.pin-saved {
    background: var(--amber);
}

.osm-attribution {
    position: absolute;
    right: 0.35rem;
    bottom: 0.3rem;
    z-index: 3;
    border-radius: 4px;
    padding: 0.12rem 0.3rem;
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink);
    font-size: 0.68rem;
    text-decoration: none;
}

.map-controls {
    position: absolute;
    top: 0.55rem;
    left: 0.55rem;
    z-index: 4;
    display: grid;
    gap: 0.3rem;
}

.map-controls button {
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.94);
    color: var(--ink);
    font-weight: 900;
    cursor: pointer;
}

.site-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
    overflow: hidden;
    min-height: 330px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: #eaf2ed;
    box-shadow: var(--shadow);
}

.site-hero-map-only {
    grid-template-columns: 1fr;
}

.site-hero-main,
.site-hero-side {
    position: relative;
    overflow: hidden;
    min-height: 330px;
}

.site-hero-main img {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 330px;
    object-fit: cover;
}

.site-hero-overlay {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    left: 1rem;
    z-index: 5;
    width: min(100% - 2rem, 520px);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    background: rgba(30, 42, 36, 0.78);
    color: #ffffff;
}

.site-hero-overlay h2,
.site-hero-overlay p {
    margin-bottom: 0.2rem;
}

.site-hero-overlay .eyebrow {
    color: #dceddf;
}

.site-hero-side {
    border-left: 1px solid var(--border);
}

.mini-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    border-radius: var(--radius);
    padding: 0.72rem 0;
    color: var(--ink);
    text-decoration: none;
}

.mini-row small {
    text-align: right;
    overflow-wrap: anywhere;
}

.mini-row + .mini-row {
    border-top: 1px solid var(--border);
}

.mini-row small {
    flex: 0 0 auto;
    color: var(--muted);
}

.toolbar,
.inline-add {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.7rem;
    align-items: end;
    margin-bottom: 1rem;
}

.inline-add {
    grid-template-columns: 140px minmax(0, 1fr) auto;
    margin-top: 0.9rem;
    margin-bottom: 0;
}

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

.span-2 {
    grid-column: 1 / -1;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink);
}

.check-field input {
    width: auto;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    border-top: 1px solid var(--border);
    margin: 0 -1.1rem -1.1rem;
    padding: 0.85rem 1.1rem;
    background: rgba(255, 253, 247, 0.96);
}

.button,
.text-button {
    cursor: pointer;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.55rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.58rem 0.95rem;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.button-small {
    min-height: 2.2rem;
    padding: 0.42rem 0.7rem;
    font-size: 0.9rem;
}

.button-primary {
    background: var(--green);
    color: #ffffff;
}

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

.button-muted {
    border-color: var(--border);
    background: var(--surface-strong);
    color: var(--ink);
}

.button-danger {
    background: var(--red);
    color: #ffffff;
}

.text-button {
    border: 0;
    padding: 0.25rem;
    background: transparent;
    color: var(--red);
    font-size: 0.85rem;
    font-weight: 800;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 1.65rem;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.76rem;
    font-weight: 850;
}

.pill-amber {
    background: #f7e6c4;
    color: #794a08;
}

.pill-green {
    background: #dceddf;
    color: #234c39;
}

.pill-blue {
    background: #dcecf4;
    color: #214e64;
}

.progress {
    overflow: hidden;
    height: 0.7rem;
    border-radius: 999px;
    background: #e9e1d0;
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--green), var(--blue));
}

.check-group {
    border-top: 1px solid var(--border);
    padding-top: 0.8rem;
}

.check-row-wrap,
.template-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: center;
    min-height: 2.5rem;
}

.check-row label {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 700;
}

.check-row input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    accent-color: var(--green);
}

.danger-zone {
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.delete-inline {
    margin-top: -0.4rem;
    margin-bottom: 0.8rem;
}

.photo-upload-form {
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    padding-bottom: 1rem;
}

.photo-grid {
    display: grid;
    gap: 0.75rem;
}

.photo-tile {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-strong);
}

.photo-tile img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.photo-tile-body {
    display: grid;
    gap: 0.55rem;
    padding: 0.7rem;
}

.photo-tile-body p {
    margin-bottom: 0;
    color: var(--ink);
    font-weight: 750;
    overflow-wrap: anywhere;
}

.photo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.flashes {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.flash,
.form-errors {
    border-radius: var(--radius);
    padding: 0.8rem;
    font-weight: 700;
}

.flash-success {
    background: #dceddf;
    color: #234c39;
}

.flash-error,
.form-errors {
    background: #f8ded9;
    color: #74291f;
}

.flash-info {
    background: #dcecf4;
    color: #214e64;
}

.empty-state {
    padding: 1.3rem;
    text-align: center;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
        padding-bottom: 4.6rem;
    }

    .sidebar {
        display: none;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.8rem;
        margin-bottom: 1rem;
    }

    .bottom-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 10;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        border-top: 1px solid var(--border);
        background: rgba(255, 253, 247, 0.98);
    }

    .bottom-nav .nav-link {
        display: grid;
        min-height: 4rem;
        justify-items: center;
        gap: 0.2rem;
        border-radius: 0;
        padding: 0.45rem 0.2rem;
        font-size: 0.78rem;
    }

    .bottom-nav .nav-mark {
        width: 1.65rem;
        height: 1.65rem;
        font-size: 0.68rem;
    }

    .main {
        width: 100%;
        padding: 1rem;
    }

    .page-header {
        align-items: start;
        flex-direction: column;
    }

    .page-actions {
        justify-content: flex-start;
    }

    .dashboard-grid,
    .detail-grid,
    .form-grid,
    .note-grid {
        grid-template-columns: 1fr;
    }

    .site-card,
    .site-hero {
        grid-template-columns: 1fr;
    }

    .site-card {
        align-items: stretch;
    }

    .site-card-map {
        order: -1;
    }

    .site-hero-side {
        min-height: 240px;
        border-top: 1px solid var(--border);
        border-left: 0;
    }

    .dashboard-map {
        min-height: 320px;
    }

    .span-2 {
        grid-column: auto;
    }

    .item-card,
    .item-actions,
    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .toolbar,
    .inline-add {
        grid-template-columns: 1fr;
    }

    .sticky-actions {
        position: static;
    }
}

@media (max-width: 420px) {
    h1 {
        font-size: 1.65rem;
    }

    .button {
        width: 100%;
    }

    .mobile-header .button {
        width: auto;
    }

    .map-pin-label {
        max-width: 8rem;
        font-size: 0.68rem;
    }

    .site-hero-overlay {
        right: 0.65rem;
        bottom: 0.65rem;
        left: 0.65rem;
        width: auto;
    }

    .check-row-wrap,
    .template-row {
        grid-template-columns: 1fr;
    }
}
