:root {
    --bg: #eef3f1;
    --bg-deep: #dce7e4;
    --bg-card: #fffdf9;
    --ink: #1c2a33;
    --muted: #5d6b73;
    --line: #c5d2ce;
    --header: #123347;
    --header-ink: #f4efe6;
    --accent: #1b7a78;
    --accent-hover: #156461;
    --accent-soft: #d7eeec;
    --gold: #c9a227;
    --gold-soft: #f6ead0;
    --danger: #9a3b32;
    --danger-soft: #f8e4e1;
    --ok: #2e7d4f;
    --ok-soft: #dcefe4;
    --shadow: 0 10px 30px rgba(18, 51, 71, 0.12);
    --radius: 16px;
    --font: "Georgia", "Times New Roman", serif;
    --sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--bg);
}
a { color: var(--accent); }
img { max-width: 100%; }
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--header);
    color: var(--header-ink);
    position: sticky;
    top: 0;
    z-index: 40;
    flex-wrap: wrap;
}
.topbar-public { background: transparent; color: var(--ink); }
.topbar-public .brand { color: var(--ink); }
.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--header-ink);
    text-decoration: none;
    letter-spacing: 0.02em;
}
.brand-mark { display: grid; place-items: center; flex: 0 0 auto; }
.brand-logo {
    display: block;
    height: 40px;
    width: auto;
}
.hero-logo {
    display: block;
    width: min(200px, 72%);
    height: auto;
    margin: 8px auto 4px;
}
.circle-switch select {
    background: #1a4258;
    color: var(--header-ink);
    border: 1px solid #3d6a82;
    border-radius: 999px;
    padding: 8px 12px;
    font: inherit;
    max-width: 220px;
}
.topbar-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.topbar-nav a {
    color: #d7e4df;
    text-decoration: none;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 0.92rem;
}
.topbar-nav a.is-active,
.topbar-nav a:hover {
    background: #1a4258;
    color: #fff;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}
.user-chip {
    color: #efe4d0;
    font-size: 0.92rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 220px;
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell {
    color: var(--header-ink);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.badge {
    background: var(--gold);
    color: var(--header);
    border-radius: 999px;
    min-width: 1.2rem;
    padding: 0 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    padding: 9px 18px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    background: #d5e0dc;
    color: var(--ink);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-gold { background: var(--gold); color: var(--header); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid currentColor; }
.topbar:not(.topbar-public) .btn-ghost { color: var(--header-ink); border-color: #8aa8b8; }
.btn-lg { padding: 12px 22px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-small { padding: 6px 12px; font-size: 0.86rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.page-landing, .page-auth {
    min-height: 100vh;
    background:
        radial-gradient(circle at 10% 10%, #f4efe6, transparent 40%),
        radial-gradient(circle at 90% 0%, #d7eeec, transparent 35%),
        var(--bg);
}
.hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 40px;
    max-width: 1100px;
    margin: 40px auto;
    padding: 0 24px 60px;
    align-items: center;
}
.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
}
.hero h1, .auth-card h1, .page-head h1, .panel h2, .empty-state h2 {
    font-family: var(--font);
    margin: 0 0 12px;
}
.hero h1 { font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.15; }
.lead, .muted { color: var(--muted); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 22px 0; }
.hero-points { padding-left: 18px; color: var(--muted); }
.hero-card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 24px;
    min-height: 280px;
    box-shadow: var(--shadow);
    padding: 28px;
}
.mini-map {
    height: 220px;
    border-radius: 16px;
    background:
        radial-gradient(circle at 30% 40%, var(--accent-soft), transparent 28%),
        linear-gradient(160deg, #cfe0dc, #e7efe8);
    position: relative;
    overflow: hidden;
}
.pin {
    position: absolute;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid #fff;
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(18,51,71,.25);
}
.pin-home {
    width: 70px; height: 70px; border-radius: 50%;
    border: 2px dashed var(--accent);
    position: absolute; left: 18%; top: 42%;
}

.wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
.page-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.page-head p { margin: 0; color: var(--muted); }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.card, .panel, .auth-card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 18px; text-decoration: none; color: inherit; display: block; }
.card:hover { border-color: var(--accent); }
.card h2 { font-family: var(--font); font-size: 1.2rem; margin: 0 0 8px; }
.meta { font-size: 0.9rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.role-pill, .status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 0.78rem;
    background: var(--accent-soft);
    color: var(--accent-hover);
    text-transform: capitalize;
}
.role-pill.owner, .role-pill.admin { background: var(--gold-soft); color: #7a6414; }
.role-pill.child { background: #e7eef6; color: #3d6b9a; }

.panel { padding: 18px; }
.panel + .panel { margin-top: 16px; }
.layout-split {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.9fr);
    gap: 16px;
    align-items: start;
}
.map-shell {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    min-height: 520px;
    position: relative;
}
#map { height: 560px; width: 100%; background: #dce7e4; }
.map-toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px;
    background: #f7faf8;
    border-bottom: 1px solid var(--line);
}

.member-row, .place-row, .note-row, .msg-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.member-row:last-child, .place-row:last-child, .note-row:last-child, .msg-row:last-child { border-bottom: 0; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 0.8rem;
    flex: 0 0 auto;
    overflow: hidden;
    background: var(--accent);
    position: relative;
}
.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
    display: block;
    background: #fffdf9;
}
.avatar-xs { width: 28px; height: 28px; font-size: 0.65rem; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.72rem; }
.avatar-md { width: 40px; height: 40px; font-size: 0.8rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 0.95rem; }
.avatar-xl { width: 112px; height: 112px; font-size: 2rem; }
.photo-picker {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 8px 0 16px;
}
.map-shell .avatar-md { width: 36px; height: 36px; }
.grow { flex: 1; min-width: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.place-dot {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid var(--accent); background: var(--accent-soft);
}

.auth-wrap { display: grid; place-items: center; padding: 40px 16px; }
.auth-card {
    width: min(440px, 100%);
    padding: 28px;
}
.auth-card label, .panel label, .form-card label { display: block; margin: 12px 0; font-size: 0.92rem; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
.form-error, .flash-error { background: var(--danger-soft); color: var(--danger); }
.flash {
    max-width: 1180px;
    margin: 12px auto 0;
    padding: 10px 16px;
    border-radius: 10px;
}
.flash-success { background: var(--ok-soft); color: var(--ok); }
.auth-switch { text-align: center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .span-2, .check { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    font-size: 0.92rem;
    vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }

.empty-state {
    padding: 28px;
    text-align: center;
    color: var(--muted);
}
.invite-code {
    font-family: var(--sans);
    font-size: 1.6rem;
    letter-spacing: 0.12em;
    background: var(--gold-soft);
    color: var(--header);
    padding: 12px 16px;
    border-radius: 12px;
    text-align: center;
    font-weight: 700;
}
.sos-banner {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 10px;
    font-weight: 600;
}
.chat-log {
    max-height: 240px;
    overflow: auto;
    background: #f7faf8;
    border-radius: 12px;
    padding: 10px;
}
.msg-row { align-items: flex-start; border: 0; padding: 6px 0; }
.leaflet-div-icon.fc-pin {
    background: transparent !important;
    border: 0 !important;
}
.fc-marker {
    box-sizing: border-box;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(18,51,71,.35);
    overflow: hidden;
    background-color: #fffdf9;
}
.fc-marker-photo {
    background-color: #fffdf9;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

@media (max-width: 860px) {
    .hero, .layout-split, .form-grid { grid-template-columns: 1fr; }
    #map { height: 420px; }
    .avatar-md { width: 34px; height: 34px; }
    .avatar-lg { width: 44px; height: 44px; }
    .avatar-xl { width: 88px; height: 88px; }
    .topbar-nav { width: 100%; order: 3; }
    .circle-switch { width: 100%; }
    .circle-switch select { max-width: none; width: 100%; }
}
