:root {
    --bg: #1a1d1a;
    --surface: #232723;
    --surface-2: #2c312c;
    --fg: #e8e6df;
    --accent: #6b8e4e;
    --accent-hover: #7da35a;
    --muted: #8a8a82;
    --error: #d97757;
    --border: #3a3f3a;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top, 1rem) 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--accent);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
}

main.centered, section.centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: max(env(safe-area-inset-top, 1rem), 2rem);
}

section.centered h1 {
    color: var(--accent);
    margin: 0 0 1.5rem;
    font-size: 2rem;
}

.muted { color: var(--muted); }
.error { color: var(--error); margin: 0.5rem 0 0; }

.tabs {
    display: flex;
    width: 100%;
    max-width: 360px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.tabs button {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border: none;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    cursor: pointer;
}

.tabs button.active {
    background: var(--surface);
    color: var(--fg);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 360px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font: inherit;
    width: 100%;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.7rem 1rem;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}

button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.link {
    background: transparent;
    color: var(--muted);
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
    text-decoration: underline;
}
button.link:hover:not(:disabled) { color: var(--fg); background: transparent; }
button.link.danger { color: var(--error); }
button.link.danger:hover:not(:disabled) { color: var(--error); }

/* Home cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem 1rem;
    color: var(--fg);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 90px;
}
.card:hover:not(:disabled) { background: var(--surface-2); }
.card-title { font-weight: 600; font-size: 1.05rem; }
.card-sub   { color: var(--muted); font-size: 0.85rem; }

/* View headers */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.view-header h2 { margin: 0; font-size: 1.4rem; }

/* Stand list */
.stand-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.stand-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}
.stand-main { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.stand-notes { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }
.stand-actions { display: flex; flex-direction: column; gap: 0.25rem; align-self: flex-start; }

/* Forms */
.stand-form { display: flex; flex-direction: column; gap: 1rem; }
.form-row { display: flex; gap: 0.5rem; align-items: center; }
.form-actions { display: flex; gap: 0.5rem; }
.small { font-size: 0.85rem; }

/* Leaflet map container */
.map {
    height: 300px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
}

/* Bottom tab bar */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 50;
}
.tabbar button {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border: none;
    border-radius: 0;
    padding: 0.75rem 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.tabbar button.active { color: var(--accent); }
.tabbar button:disabled { color: var(--border); }

/* Add padding to main so tab bar doesn't overlap content */
main.has-tabbar { padding-bottom: 5rem; }

/* Home CTA */
.home-cta { margin-top: 1.5rem; }

/* Hunt list */
.hunt-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.hunt-item { display: block; }
.hunt-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: var(--fg);
}
.hunt-card:hover { background: var(--surface-2); }
.hunt-card-top, .hunt-card-mid, .hunt-card-weather { display: block; }
.hunt-card-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.hunt-card-weather { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }

/* Hunt detail */
.hunt-detail { display: flex; flex-direction: column; gap: 1rem; }
.hunt-detail-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.hunt-detail-actions { display: flex; gap: 0.5rem; }

.weather-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.weather-card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.weather-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1rem;
    font-size: 0.95rem;
}
.weather-grid > div { display: flex; justify-content: space-between; gap: 0.5rem; }

.subsection {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.subsection .view-header h3 { margin: 0; font-size: 1.05rem; }

.child-list { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; flex-direction: column; gap: 0.4rem; }
.child-item {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
}
.child-item:first-child { border-top: none; }
.child-main { flex: 1; }
.child-actions { display: flex; gap: 0.25rem; align-self: flex-start; }

.inline-form {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.inline-form h4 { margin: 0; font-size: 1rem; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

label.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    color: var(--fg);
}
label.checkbox input { width: auto; }

details summary { cursor: pointer; padding: 0.25rem 0; }

/* Screen-reader-only text */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

/* Pre-cache map indicator */
.precache-progress { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0; }
.precache-progress.done { color: var(--accent); }
.precache-progress.error { color: var(--error); }

/* Hunts list filters */
.filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
}
.filters[open] { padding-bottom: 0.75rem; }
.filters summary { padding: 0; }
.filters .form-grid-2 { margin-top: 0.5rem; }

/* Photos */
.upload-btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
}
.upload-btn:hover { background: var(--accent-hover); }
.upload-btn input[type="file"] {
    /* Visually hidden but still clickable via the label */
    position: absolute;
    width: 1px; height: 1px; opacity: 0;
    pointer-events: none;
}
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.photo { margin: 0; }
.photo img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.photo figcaption {
    display: flex;
    justify-content: center;
    margin-top: 0.15rem;
}

/* Sync banner */
.sync-banner {
    background: var(--surface-2);
    color: var(--muted);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}
.sync-banner.offline { background: #3a2a1a; color: #d97757; }

/* Privacy fieldset */
.privacy {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    background: var(--surface);
}
.privacy legend {
    padding: 0 0.4rem;
    color: var(--muted);
    font-size: 0.85rem;
}
label.radio {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    color: var(--fg);
    margin-bottom: 0.3rem;
}
label.radio input { width: auto; }

.shared-tag { color: var(--accent); }

/* Hour range filter */
.hour-range-wrap { display: flex; flex-direction: column; gap: 0.35rem; }
.hour-range-label { font-size: 0.9rem; color: var(--muted); }
.hour-range-inputs { display: flex; gap: 0.25rem; align-items: center; }
.hour-range-inputs input { flex: 1; }

/* Tall map for overview */
.map.map-tall { height: 60vh; }

/* Map pin glyphs (Leaflet divIcon contents) */
.map-pin-wrap { background: transparent !important; border: 0; }
.map-pin {
    width: 28px; height: 28px; line-height: 28px;
    border-radius: 50%;
    color: #fff;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    border: 2px solid #fff;
}

/* Floating help / feedback button */
.fab-help {
    position: fixed;
    right: 1rem;
    bottom: calc(5rem + env(safe-area-inset-bottom, 0));  /* clear the tabbar */
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--accent);
    border: 1px solid var(--border);
    font-size: 1.3rem;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 60;
    cursor: pointer;
    line-height: 1;
}
.fab-help:hover { background: var(--surface); }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Header dropdown menu */
.header-menu {
    position: absolute;
    top: 100%;
    right: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 80;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.header-menu .link {
    text-align: left;
    text-decoration: none;
    padding: 0.5rem 1rem;
    color: var(--fg);
    border-radius: 0;
}
.header-menu .link:hover { background: var(--surface-2); }
.header-menu-name {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

/* Compass rose for picking facing direction */
.compass-rose {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
    max-width: 220px;
    margin: 0.5rem 0;
}
.compass-cell {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    aspect-ratio: 1 / 1;
}
.compass-cell:hover { background: var(--surface-2); }
.compass-cell.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.compass-center { color: var(--muted); }

/* Chip row for angle / time presets */
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.chip {
    background: var(--surface);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Reports */
.totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.total-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.total-n { font-size: 1.6rem; font-weight: 700; color: var(--accent); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }

.bar-chart { list-style: none; padding: 0; margin: 0; }
.bar-chart li {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0;
}
.bar-label { color: var(--muted); font-size: 0.8rem; text-align: right; }
.bar { background: var(--surface); height: 14px; border-radius: 3px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-value { color: var(--muted); font-size: 0.8rem; text-align: right; }

/* Feedback inbox list */
.feedback-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.feedback-item.severity-blocker { border-left: 3px solid var(--error); }
.feedback-item.severity-high    { border-left: 3px solid #d97757; }
.feedback-meta { color: var(--muted); font-size: 0.85rem; }
.feedback-msg  { white-space: pre-wrap; }
.feedback-log  {
    background: #111;
    color: #aab;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    padding: 0.5rem;
    border-radius: 4px;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
}
