/* ============================================================
   Tokens — earthy/natural palette. Light values in :root, dark
   overrides in the prefers-color-scheme block. --color-route is
   deliberately NOT overridden for dark mode — see the Map section
   below for why (OSM tiles never re-theme, so the route line needs
   to stay legible against the same light tiles either way).
   ============================================================ */
:root {
    color-scheme: light dark;

    --color-bg: #f6f2e7;
    --color-surface: #fffdf8;
    --color-surface-sunken: #ece6d5;
    --color-text: #2f2b22;
    --color-text-muted: #6e6656;
    --color-border: #ddd3ba;

    --color-primary: #3f6b4a;
    --color-primary-strong: #2f5138;
    --color-primary-soft: #e3ecdf;
    --color-accent: #b5652f;
    --color-accent-soft: #f3e3d6;

    --color-error: #a3402a;
    --color-error-soft: #f5e3dc;
    --color-success: #3f6b4a;
    --color-focus: #6f9575;

    --color-route: #2f6b3f;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 3px rgba(47, 43, 34, 0.15);
    --shadow-md: 0 4px 12px rgba(47, 43, 34, 0.18);

    --bottom-nav-height: 4rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #1b1e17;
        --color-surface: #262b22;
        --color-surface-sunken: #14160f;
        --color-text: #ece7d8;
        --color-text-muted: #a9a48e;
        --color-border: #3a4033;

        --color-primary: #8fbf8a;
        --color-primary-strong: #a7d1a2;
        --color-primary-soft: #2c3a2a;
        --color-accent: #d08a56;
        --color-accent-soft: #3a2a1c;

        --color-error: #e2836a;
        --color-error-soft: #3a241d;
        --color-success: #8fbf8a;
        --color-focus: #a7d1a2;

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
    }
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-primary-strong);
}

h1, h2, h3 {
    line-height: 1.25;
}

/* ============================================================
   Header (desktop nav)
   ============================================================ */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.site-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 650;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--color-text);
}

.site-mark {
    width: 1.75rem;
    height: 1.75rem;
    color: var(--color-primary);
    flex-shrink: 0;
}

header nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

header nav a {
    text-decoration: none;
    color: var(--color-text);
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
}

header nav a:hover,
header nav a.is-active {
    color: var(--color-primary-strong);
    border-bottom-color: var(--color-primary);
}

header nav .nav-user {
    color: var(--color-text-muted);
}

header nav form {
    margin: 0;
}

/* ============================================================
   Bottom nav (mobile) — hidden by default, shown under the 640px
   breakpoint below. Two nav elements (header nav + .bottom-nav)
   coexist in the DOM at all times; CSS alone toggles which is
   visible, so no JS is needed for navigation.
   ============================================================ */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 3rem;
    padding: 0.5rem 0.25rem;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    list-style: none;
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
}

.bottom-nav-item.is-active {
    color: var(--color-primary-strong);
}

.bottom-nav-item::-webkit-details-marker {
    display: none;
}

.bottom-nav-account {
    position: relative;
}

.bottom-nav-account-panel {
    position: absolute;
    bottom: 100%;
    right: 0.5rem;
    margin-bottom: 0.5rem;
    min-width: 10rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 0.75rem;
    text-align: left;
    font-size: 0.9rem;
}

.bottom-nav-account-panel .nav-user {
    color: var(--color-text-muted);
    margin: 0 0 0.5rem;
}

.bottom-nav-account-panel a {
    display: block;
    padding: 0.35rem 0;
    text-decoration: none;
    color: var(--color-text);
}

.bottom-nav-account-panel form {
    margin: 0;
}

/* ============================================================
   Messages
   ============================================================ */
.messages {
    list-style: none;
    margin: 0;
    padding: 0.5rem 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.messages li {
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    background: var(--color-surface-sunken);
    color: var(--color-text);
}

.messages li.success {
    background: var(--color-primary-soft);
    color: var(--color-primary-strong);
}

.messages li.warning {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.messages li.error {
    background: var(--color-error-soft);
    color: var(--color-error);
}

/* ============================================================
   Forms
   ============================================================ */
main {
    padding: 1rem;
}

.form-field {
    margin: 0.75rem 0;
}

form label,
.form-field label {
    display: block;
    margin: 0.75rem 0 0.35rem;
    font-weight: 600;
}

.form-field label {
    margin-top: 0;
}

form input[type="text"],
form input[type="datetime-local"],
form input[type="email"],
form input[type="password"],
form textarea,
/* Django's default form.as_p rendering on the auth pages (login,
   signup, password reset) — no explicit classes to hook, so these
   are styled by element type within any <form>. */
form p input,
form p textarea {
    display: block;
    width: 100%;
    max-width: 30rem;
    box-sizing: border-box;
    padding: 0.55rem 0.7rem;
    /* >=16px keeps Safari on iOS from auto-zooming the page on focus. */
    font-size: 1rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

form input:focus,
form textarea:focus {
    outline: 2px solid var(--color-focus);
    outline-offset: 1px;
}

form p {
    margin: 0.75rem 0;
}

.errors,
ul.errorlist {
    color: var(--color-error);
    background: var(--color-error-soft);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.85rem;
    list-style: none;
    margin: 0.5rem 0;
}

ul.errorlist li {
    padding: 0.1rem 0;
}

.auth-card {
    max-width: 26rem;
    margin: 1rem auto;
    padding: 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   Buttons
   ============================================================ */
button,
input[type="submit"] {
    min-height: 2.75rem;
    padding: 0.5rem 1.25rem;
    font-size: 1rem;
    font-family: inherit;
    color: #fff;
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
}

button:hover,
input[type="submit"]:hover {
    background: var(--color-primary-strong);
}

button:focus-visible,
input[type="submit"]:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.btn-secondary {
    color: var(--color-text);
    background: var(--color-surface-sunken);
}

.btn-secondary:hover {
    background: var(--color-border);
}

.btn-danger {
    background: var(--color-error);
}

.btn-danger:hover {
    background: var(--color-error);
    opacity: 0.85;
}

/* ============================================================
   Map & map controls
   ============================================================ */
/* Leaflet needs an explicit height or it renders as a blank 0px box. */
.map-canvas {
    height: 60vh;
    min-height: 300px;
    width: 100%;
}

/* The map-wrap div carries the sizing that .map-canvas used to have on its
   own (see the plain .map-canvas rule above — kept for any future bare,
   unwrapped map). Both the map and the search toggle are absolutely
   positioned *within* this div so they occupy the same box and the button
   can overlap the map, rather than the button's position depending on the
   map's in-flow height. Used by the frontpage map and, with the
   .map-wrap-compact size override below, the add-walk page's track/draw
   maps. overflow:hidden lets border-radius actually clip Leaflet's tile
   layer, which doesn't round its own corners. */
.map-wrap {
    position: relative;
    height: 60vh;
    min-height: 300px;
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.map-wrap .map-canvas {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    width: auto;
}

/* Smaller variant used on the add-walk page's track/draw maps, which share
   the page with mode-select and finish/undo controls that also need room. */
.map-wrap-compact {
    height: 50vh;
    min-height: 250px;
}

/* Raster OSM tiles can't be recolored for dark mode without artifacting
   labels, so the map is treated as an intentional light "window" island —
   framed rather than fought. */
@media (prefers-color-scheme: dark) {
    .map-wrap {
        border: 1px solid var(--color-border);
        box-shadow: var(--shadow-md);
    }
}

.leaflet-container {
    background: var(--color-surface-sunken);
}

.leaflet-bar,
.leaflet-control-layers,
.leaflet-control-layers-expanded {
    box-shadow: var(--shadow-md) !important;
    border-radius: var(--radius-sm) !important;
}

.leaflet-bar a {
    background-color: var(--color-surface) !important;
    color: var(--color-text) !important;
    border-bottom-color: var(--color-border) !important;
}

.leaflet-bar a:hover,
.leaflet-bar a:focus {
    background-color: var(--color-primary-soft) !important;
}

.leaflet-control-attribution {
    background: var(--color-surface) !important;
    color: var(--color-text-muted) !important;
}

/* Floating control overlapping the map's bottom-left corner, matching
   Leaflet's own control z-index (1000) so it layers above tiles/routes. 48px
   square meets the ~44-48px minimum touch-target size recommended for mobile.
   Class-based (not #id) since the same style now applies to more than one
   map instance on a page (add.html has both a track-map and a draw-map). */
.location-search-toggle {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    z-index: 1000;
    width: 3rem;
    height: 3rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-md);
    cursor: pointer;
}

.location-search-toggle:hover {
    background: var(--color-surface);
    color: var(--color-primary-strong);
}

.search-panel {
    position: absolute;
    bottom: 4.5rem;
    left: 1rem;
    z-index: 1000;
    width: calc(100% - 2rem);
    max-width: 18rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 0.75rem;
}

.location-hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 0;
}

.location-search input[type="text"] {
    /* >=16px keeps Safari on iOS from auto-zooming the page on focus. */
    font-size: 1rem;
    padding: 0.5rem;
}

.location-search button {
    width: 100%;
}

.location-search-status {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* ============================================================
   Mode-select / add-walk flow
   ============================================================ */
#mode-select {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
}

#mode-select button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 1.05rem;
    font-weight: 600;
}

#mode-select button svg {
    color: var(--color-primary);
}

#mode-select button:hover {
    background: var(--color-primary-soft);
    border-color: var(--color-primary);
}

#mode-select button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#mode-select button:disabled:hover {
    background: var(--color-surface);
    border-color: var(--color-border);
}

.mode-unavailable-hint,
.mode-track-hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0.25rem 0 0.5rem;
}

#tracking-panel > button,
#drawing-panel > button {
    margin-top: 0.75rem;
    margin-right: 0.5rem;
}

#pause-tracking.is-paused {
    background: var(--color-accent);
}

#pause-tracking.is-paused:hover {
    background: var(--color-accent);
    opacity: 0.85;
}

/* ============================================================
   Capability/status banners (tracking panel)
   ============================================================ */
.banner {
    position: relative;
    margin: 0 0 0.75rem;
    padding: 0.65rem 2.25rem 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
}

.banner p {
    margin: 0;
}

.banner-warning {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.banner-error {
    background: var(--color-error-soft);
    color: var(--color-error);
}

.banner-dismiss {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    min-height: auto;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    line-height: 1;
    background: transparent;
    color: inherit;
    box-shadow: none;
}

.banner-dismiss:hover {
    background: rgba(0, 0, 0, 0.06);
}

.tracking-status {
    font-size: 0.85rem;
    color: var(--color-accent);
    margin: 0.5rem 0 0;
}

/* ============================================================
   Screen-lock overlay — engages while live-tracking to prevent
   accidental taps while the phone (screen kept awake by the Wake
   Lock) is in a pocket. z-index above both Leaflet's own controls
   and .bottom-nav (both 1000) so it truly covers everything.
   ============================================================ */
.tracking-lock-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 2rem;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    touch-action: none;
}

.tracking-lock-unlock {
    min-height: 4rem;
    padding: 1rem 2rem;
    font-size: 1.05rem;
}

/* ============================================================
   Cards & lists
   ============================================================ */
.walk-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.walk-list li {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.walk-list li a {
    font-weight: 600;
    text-decoration: none;
}

.recent-walks h2 {
    margin-top: 1.5rem;
}

.walk-photo {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    margin: 1rem 0;
}

.walk-note {
    background: var(--color-surface-sunken);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
}

/* ============================================================
   Responsive — single breakpoint for the whole site. Below this,
   the top header nav hides in favor of the fixed bottom tab bar.
   ============================================================ */
@media (max-width: 640px) {
    header nav a,
    header nav .nav-user,
    header nav form {
        display: none;
    }

    .bottom-nav {
        display: flex;
    }

    main {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    }

    .map-wrap {
        height: 50vh;
    }

    .map-wrap-compact {
        height: 42vh;
        min-height: 220px;
    }

    #mode-select {
        flex-direction: column;
    }

    #finalize-form input[type="text"],
    #finalize-form input[type="datetime-local"],
    #finalize-form textarea {
        max-width: none;
    }

    .walk-list li {
        padding: 0.85rem 1rem;
    }
}
