:root {
  --navy: #0b2948;
  --navy-2: #123d68;
  --sky: #e8f3fb;
  --paper: #f6f8fa;
  --white: #fff;
  --ink: #17212b;
  --muted: #5c6975;
  --line: #d7dfe6;
  --green: #16834b;
  --green-soft: #def4e7;
  --red: #c9322b;
  --red-soft: #fae4e2;
  --gold: #e7ad28;
  --shadow: 0 16px 50px rgb(11 41 72 / 14%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Roboto, system-ui, sans-serif; }
a { color: var(--navy-2); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.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; }
.content-shell { width: min(1320px, calc(100% - 40px)); margin-inline: auto; }
.eyebrow { margin: 0 0 8px; color: #456276; font-size: .76rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; text-decoration: none; font-weight: 700; }
.button-primary { color: #fff; background: var(--navy-2); }
.button-primary:hover { background: var(--navy); }
.button-quiet { color: var(--navy); background: #fff; border-color: var(--line); }
.button-quiet:hover { background: var(--sky); }

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 10%, #376f9c 0, var(--navy) 40%, #06192c 100%); }
body.booting #gate { visibility: hidden; }
.gate-card { width: min(430px, 100%); padding: 38px; border-radius: 18px; background: #fff; box-shadow: 0 30px 80px rgb(0 0 0 / 30%); }
.gate-card h1 { margin: 0; color: var(--navy); font-size: clamp(2rem, 8vw, 3rem); }
.gate-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.gate-card form { display: grid; gap: 12px; margin-top: 26px; }
.gate-card label, .form-grid label, .table-tools label { display: grid; gap: 6px; color: #34414c; font-size: .82rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #bdc8d1; border-radius: 8px; padding: 10px 12px; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgb(18 61 104 / 15%); border-color: var(--navy-2); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 8px; color: #8a1f1a; background: var(--red-soft); }
.brand-logo { width: 50px; height: 50px; flex: 0 0 auto; border-radius: 50%; object-fit: contain; background: #fff; }
.gate-logo { width: 82px; height: 82px; margin-bottom: 20px; }

.site-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px max(20px, calc((100vw - 1320px) / 2)); color: #fff; background: var(--navy); }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.05rem; }
.brand small { margin-top: 3px; color: #c2d3e1; }
.header-actions { display: flex; gap: 8px; }

.intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 40px; padding-block: 56px 34px; }
.intro h1 { max-width: 820px; margin: 0; color: var(--navy); font-size: clamp(2.1rem, 5vw, 4rem); line-height: 1.02; letter-spacing: -.04em; }
.intro-copy { max-width: 780px; margin: 20px 0 0; color: var(--muted); font-size: 1.08rem; line-height: 1.65; }
.stats { display: flex; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 8px 24px rgb(11 41 72 / 7%); }
.stats > div { min-width: 130px; padding: 18px 20px; border-left: 1px solid var(--line); }
.stats > div:first-child { border-left: 0; }
.stats strong, .stats span { display: block; }
.stats strong { color: var(--navy); font-size: 2rem; line-height: 1; }
.stats span { margin-top: 6px; color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.stats .stat-worked strong { color: var(--green); }
.stats .stat-unworked strong { color: var(--red); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; color: var(--navy); font-size: clamp(1.55rem, 3vw, 2.3rem); }
.section-heading > p { max-width: 520px; margin: 0; color: var(--muted); line-height: 1.5; text-align: right; }
.map-section { padding-bottom: 55px; }
.map-wrap { position: relative; width: min(1480px, calc(100% - 24px)); margin-inline: auto; }
#map { height: min(72vh, 780px); min-height: 540px; border: 1px solid #b9c5cd; border-radius: 16px; background: #dae6ef; box-shadow: var(--shadow); }
.map-legend { position: absolute; z-index: 800; top: 14px; right: 14px; width: min(290px, calc(100% - 28px)); border: 1px solid rgb(11 41 72 / 20%); border-radius: 10px; background: rgb(255 255 255 / 94%); box-shadow: 0 10px 26px rgb(0 0 0 / 18%); backdrop-filter: blur(8px); }
.map-legend summary { padding: 12px 14px; cursor: pointer; color: var(--navy); font-weight: 900; }
.map-legend > div { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.map-legend p { margin: 12px 0; font-size: .88rem; }
.map-legend small { color: var(--muted); line-height: 1.4; }
.legend-dot { display: inline-block; width: 13px; height: 13px; margin-right: 8px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgb(0 0 0 / 25%); vertical-align: -2px; }
.legend-dot.worked { background: var(--green); }
.legend-dot.unworked { background: var(--red); }
.legend-line { display: inline-block; width: 22px; height: 10px; margin-right: 7px; border: 2px solid #7b5a29; border-width: 0 0 2px; transform: rotate(-8deg); }
.village-tooltip { min-width: 220px; }
.village-tooltip strong { color: var(--navy); font-size: 1rem; }
.village-tooltip span { display: block; margin-top: 4px; }
.village-tooltip .status { font-weight: 700; }
.village-tooltip .status.worked { color: var(--green); }
.village-tooltip .status.unworked { color: var(--red); }

.directory { padding: 8px 0 70px; }
.directory-heading { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.table-tools { display: grid; grid-template-columns: minmax(250px, 1.5fr) minmax(170px, .6fr) minmax(200px, .8fr) auto; align-items: end; gap: 12px; margin: 22px 0 10px; }
.result-count { margin: 14px 0; color: var(--muted); font-size: .9rem; }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 8px 28px rgb(11 41 72 / 6%); }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; z-index: 2; top: 0; padding: 0; color: #fff; background: var(--navy); text-align: left; }
th button, th > span { width: 100%; display: block; padding: 13px 14px; border: 0; color: inherit; background: transparent; cursor: pointer; text-align: inherit; font-weight: 700; white-space: nowrap; }
th button:hover { background: var(--navy-2); }
th.number, td.number { text-align: right; }
td { padding: 13px 14px; border-bottom: 1px solid #e5eaee; font-size: .92rem; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr:focus-within { background: #eff6fb; }
tbody tr:last-child td { border-bottom: 0; }
.community-name { font-weight: 700; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: .77rem; font-weight: 700; white-space: nowrap; }
.status-chip.worked { color: #0e6338; background: var(--green-soft); }
.status-chip.unworked { color: #95241e; background: var(--red-soft); }
.row-actions { display: flex; gap: 7px; justify-content: end; }
.row-actions a, .row-actions button { min-height: 34px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--navy); background: #fff; text-decoration: none; font-weight: 700; }

dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100vh - 30px); padding: 0; border: 0; border-radius: 15px; box-shadow: 0 28px 90px rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(5 22 37 / 72%); backdrop-filter: blur(3px); }
#edit-form { padding: 26px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.dialog-heading h2 { margin: 0; color: var(--navy); }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--navy); background: #fff; cursor: pointer; font-size: 1.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid small { color: var(--muted); font-weight: 400; }
.checkbox-label { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px !important; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 24px; }
.dialog-actions #profile-link { margin-right: auto; }

footer { color: #c2d3e1; background: var(--navy); }
footer .content-shell { min-height: 90px; display: flex; align-items: center; justify-content: space-between; gap: 20px; font-size: .86rem; }

.profile-page { min-height: 100vh; }
.profile-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 80px; }
.profile-hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.profile-hero h1 { margin: 0 0 14px; color: var(--navy); font-size: clamp(2.2rem, 6vw, 4.5rem); line-height: 1; }
.status-pill { display: inline-flex; margin: 0; padding: 7px 11px; border-radius: 999px; font-weight: 700; }
.status-pill.worked { color: #0e6338; background: var(--green-soft); }
.status-pill.unworked { color: #95241e; background: var(--red-soft); }
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) 350px; align-items: start; gap: 24px; }
.profile-main { display: grid; gap: 20px; }
.profile-card, .fact-list, #profile-map { border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 8px 30px rgb(11 41 72 / 7%); }
.profile-card { padding: 28px; }
.profile-card h2 { margin: 0 0 18px; color: var(--navy); }
.card-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.card-heading h2 { margin-bottom: 0; }
.import-panel { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.import-panel summary { cursor: pointer; color: var(--navy); font-weight: 700; }
.import-panel p { color: var(--muted); line-height: 1.5; }
.import-example { overflow: auto; padding: 12px; border-radius: 8px; color: #28445d; background: #f2f6f9; font: .78rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
.import-panel textarea { width: 100%; margin: 8px 0 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.visit-record { padding: 16px 0; border-top: 1px solid var(--line); }
.visit-record:first-child { border-top: 0; padding-top: 0; }
.visit-meta { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; }
.visit-meta h3 { margin: 0; color: var(--navy); font-size: 1.05rem; }
.visit-date { color: var(--muted); font-size: .85rem; font-weight: 700; }
.visit-location { margin: 6px 0; color: #34414c; font-weight: 700; }
.visit-notes { white-space: pre-wrap; line-height: 1.55; }
.visit-photo { max-width: 100%; max-height: 280px; margin-top: 10px; border-radius: 9px; object-fit: cover; }
.visit-actions { display: flex; gap: 8px; margin-top: 10px; }
.visit-actions button { min-height: 32px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--navy); background: #fff; cursor: pointer; font-weight: 700; }
.form-status { margin-top: 10px; color: #17683e !important; font-weight: 700; }
.prose { color: #3b4853; font-size: 1.02rem; line-height: 1.7; }
.prose img { max-width: 180px; height: auto; float: right; margin: 0 0 18px 20px; border-radius: 10px; }
#profile-map { height: 310px; margin-bottom: 18px; overflow: hidden; }
.fact-list { margin: 0; overflow: hidden; }
.fact-list div { display: grid; grid-template-columns: 1fr 1.25fr; gap: 15px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.fact-list div:last-child { border-bottom: 0; }
.fact-list dt { color: var(--muted); font-size: .83rem; font-weight: 700; }
.fact-list dd { margin: 0; text-align: right; font-weight: 700; }
.runway-table { width: 100%; margin-top: 14px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.runway-table th { position: static; padding: 9px 10px; }
.runway-table td { padding: 9px 10px; }
.profile-error { max-width: 580px; margin: 100px auto; padding: 30px; text-align: center; }

@media (max-width: 980px) {
  .intro { grid-template-columns: 1fr; }
  .stats { width: 100%; }
  .stats > div { flex: 1; }
  .table-tools { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid aside { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
  #profile-map { margin: 0; }
}

@media (max-width: 680px) {
  .content-shell, .profile-shell { width: min(100% - 24px, 1320px); }
  .site-header { min-height: 68px; padding: 9px 12px; }
  .brand small { display: none; }
  .brand-logo { width: 43px; height: 43px; }
  .header-actions .button { min-height: 38px; padding: 7px 9px; font-size: .8rem; }
  .intro { padding-top: 35px; gap: 24px; }
  .intro h1 { font-size: 2.45rem; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); }
  .stats > div { min-width: 0; padding: 14px 10px; }
  .stats strong { font-size: 1.5rem; }
  .stats span { font-size: .62rem; }
  .section-heading { display: block; }
  .section-heading > p { margin-top: 8px; text-align: left; }
  .map-wrap { width: 100%; }
  #map { min-height: 620px; height: 72vh; border-radius: 0; border-inline: 0; }
  .map-legend { top: 10px; right: 10px; }
  .map-legend:not([open]) { width: auto; }
  .map-legend:not([open]) summary { padding: 10px 12px; }
  .table-tools { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .table-tools .button { width: 100%; }
  .table-scroll { margin-inline: -12px; border-radius: 0; }
  td, th button { padding: 11px 10px; }
  table { min-width: 880px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions #profile-link { width: 100%; margin: 0; }
  .profile-hero { display: block; }
  .profile-hero .button { margin-top: 20px; }
  .profile-grid aside { grid-template-columns: 1fr; }
  .prose img { max-width: 120px; }
  footer .content-shell { display: grid; padding-block: 20px; }
}
