/* ---------- Design tokens ---------- */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --text: #1a2030;
  --muted: #5b6375;
  --border: #d8dce5;
  --accent: #1e3a8a;
  --accent-text: #ffffff;
  --accent-soft: #dfe7fb;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --note: #fff7d6;
  --note-border: #e9cf6a;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .03);
  --tabbar-h: 0px;  /* no bottom bar: the menu opens from the ☰ button */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141b; --surface: #1a1f2a; --surface-2: #242a37; --text: #e6e9f0; --muted: #9aa2b4; --border: #313849;
    --accent: #7ea2f5; --accent-text: #0b1530; --accent-soft: #1f2d52;
    --ok: #4ade80; --ok-soft: #12321f; --warn: #f0b44c; --warn-soft: #3a2a0c; --danger: #f87171;
    --note: #2f2a14; --note-border: #6b5a1c;
  }
}
:root[data-theme="dark"] {
  --bg: #11141b; --surface: #1a1f2a; --surface-2: #242a37; --text: #e6e9f0; --muted: #9aa2b4; --border: #313849;
  --accent: #7ea2f5; --accent-text: #0b1530; --accent-soft: #1f2d52;
  --ok: #4ade80; --ok-soft: #12321f; --warn: #f0b44c; --warn-soft: #3a2a0c; --danger: #f87171;
  --note: #2f2a14; --note-border: #6b5a1c;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.public { padding-bottom: 32px; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack > * + * { margin-top: .6rem; }
.row-gap { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 420px) { .two { grid-template-columns: 1fr; } }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; gap: .75rem; padding: .8rem 16px;
  background: var(--accent); color: var(--accent-text);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; }
main { max-width: 720px; margin: 0 auto; padding: 16px; }
/* The menu: every page, opened with the ☰ button. A panel from the left on a phone;
   on a desktop it stays open as a sidebar, and ☰ hides or shows it. */
.menu-btn { all: unset; cursor: pointer; position: relative; font-size: 1.45rem; line-height: 1; padding: .05rem .35rem; border-radius: 6px; align-self: center; }
.menu-btn:focus-visible { outline: 2px solid var(--accent-text); }
.menu-btn .count { position: absolute; top: -7px; right: -12px; }
.menu-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(10, 15, 30, .4); }
.tabbar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: min(290px, 85vw);
  display: flex; flex-direction: column; gap: 2px; padding: 0 12px 16px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform .2s ease;
}
body.menu-open .tabbar { transform: none; box-shadow: var(--shadow); }
.tabbar::before { content: "AreaConnect"; display: flex; align-items: center; flex: none; height: 52px; margin: 0 -12px 12px; padding: 0 22px; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.tabbar a {
  position: relative; flex: none; display: flex; align-items: center; gap: .75rem; padding: .7rem .85rem; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-size: 1rem;
}
.tabbar a:hover { background: var(--surface-2); color: var(--text); }
.tabbar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tabbar a .ico { width: 1.4rem; text-align: center; font-size: 1.1rem; }
.tabbar .count { margin-left: auto; }
.tabbar a[data-tab="logout"] { margin-top: auto; }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; line-height: 20px; text-align: center;
}

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 36px; padding: .3rem .75rem; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; text-transform: none; letter-spacing: 0; }
input[type="text"], input[type="url"], input[type="search"], input[type="password"], input[type="email"], input[type="tel"],
input[type="date"], input[type="time"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 64px; resize: vertical; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
label.field { display: block; margin-bottom: .75rem; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: .75rem .9rem; font-size: .9rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.warn-text { color: var(--warn); font-weight: 600; }
details > summary { cursor: pointer; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.tile .num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-size: .8rem; color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: .35rem; }
.progress > div { height: 100%; background: var(--accent); }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.list .row {
  display: flex; align-items: center; gap: .75rem; padding: 12px 14px; min-height: 52px;
  color: inherit; text-decoration: none; border-top: 1px solid var(--border);
}
.list .row:first-child { border-top: 0; }
.list .row .grow { flex: 1; min-width: 0; }
.list .row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list .tree { border: 0; border-radius: 0; margin: 0; border-top: 1px solid var(--border); }
button.row.as-link { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; font: inherit; text-align: left; cursor: pointer; }
.list-head { display: flex; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 6px; }

.badge { font-size: .72rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok, .badge.st-closed { background: var(--ok-soft); color: var(--ok); }
.badge.warn, .badge.st-new { background: var(--warn-soft); color: var(--warn); }
.badge.st-open { background: var(--accent-soft); color: var(--accent); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: .6rem 0; }
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
}
.seg.plain button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: .5rem 0 12px; }
.chip {
  min-height: 36px; padding: .3rem .75rem; border: 1px solid var(--border); border-radius: 99px;
  background: var(--surface); color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: .7rem 1rem; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: .9rem; transition: opacity .2s, transform .2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.login { max-width: 380px; margin: 8vh auto 0; }
.pw-box { font-family: ui-monospace, monospace; font-size: 1rem; background: var(--surface); padding: .2rem .5rem; border-radius: 6px; display: inline-block; user-select: all; word-break: break-all; }

/* Events */
.date-chip {
  flex: none; width: 46px; text-align: center; font-size: .72rem; text-transform: uppercase; color: var(--accent);
  border: 1px solid var(--accent-soft); border-radius: 8px; padding: 3px 0; line-height: 1.1;
}
.date-chip b { display: block; font-size: 1.2rem; color: var(--text); }
.task-input { min-height: 34px !important; padding: .25rem .5rem !important; font-size: .85rem !important; margin-top: 4px; }

/* People */
.role-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.role-chip { display: inline-flex; align-items: center; white-space: nowrap; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); }
.role-chip button { background: none; border: 0; color: var(--danger); font-weight: 700; cursor: pointer; padding: 0 0 0 2px; }
dl dt { margin-top: .5rem; }
dl dd { margin: 0; color: var(--muted); }

/* Messages */
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; text-transform: uppercase;
}
.avatar.room { border-radius: 10px; }
.chat-head { position: sticky; top: 46px; z-index: 5; background: var(--bg); padding-bottom: 6px; }
.chat-head h1 { margin: .2rem 0; }
.thread { display: flex; flex-direction: column; gap: 6px; padding: 8px 0 90px; }
.day-sep { align-self: center; font-size: .75rem; color: var(--muted); margin: 10px 0 4px; }
.bubble {
  max-width: 82%; align-self: flex-start; padding: 8px 12px 6px; border-radius: 14px 14px 14px 4px;
  background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere;
}
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-color: var(--accent); border-radius: 14px 14px 4px 14px; }
.bubble.mine a { color: inherit; }
.bubble .who { font-size: .75rem; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.bubble .at { font-size: .68rem; opacity: .7; text-align: right; margin-top: 2px; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; gap: 8px; align-items: flex-end; padding: 8px max(16px, calc((100% - 720px) / 2 + 16px));
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer textarea { min-height: 44px; max-height: 160px; resize: none; }
body.chat-view .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px); }

/* Enquiries */
.case-thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.cmsg { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); overflow-wrap: anywhere; }
.cmsg .who { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.cmsg.resident { border-left: 4px solid var(--warn); }
.cmsg.team { border-left: 4px solid var(--accent); }
.cmsg.internal { background: var(--note); border-color: var(--note-border); }

/* QR codes */
.register-help { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.register-help .qr, .qr-lg { width: 160px; flex: none; background: #fff; border-radius: 6px; }
.qr-lg { width: 200px; margin: 8px 0; }
.register-help .qr svg, .qr-lg svg { display: block; width: 100%; height: auto; }
.register-help .stack { flex: 1 1 180px; }

/* Public contact page */
.choice { display: flex; gap: .6rem; align-items: flex-start; margin-bottom: .75rem; font-size: .9rem; }
.hp { position: absolute; left: -9999px; }

/* Ward profiles */
h3 { font-size: .9rem; margin: 1rem 0 .4rem; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: minmax(7rem, 38%) 1fr 3rem; gap: .5rem; align-items: center; margin: .3rem 0; font-size: .88rem; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--accent); }
.bar-fill.lost { background: var(--muted); opacity: .55; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar-row.vote { margin: .5rem 0; }
.points { border-left: 4px solid var(--accent); }
.points ul { margin: 0; padding-left: 1.2rem; }
.points li { margin: .35rem 0; }
.source { margin-top: .75rem; }
.spark { display: flex; gap: 3px; align-items: flex-end; height: 70px; margin: 8px 0 4px; }
.spark > div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.spark i { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.spark span { font-size: .65rem; color: var(--muted); }
.decile { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; font-size: .8rem; font-weight: 700; color: #fff; }
.decile.d1, .decile.d2 { background: #b91c1c; }
.decile.d3, .decile.d4 { background: #ea580c; }
.decile.d5, .decile.d6 { background: #a16207; }
.decile.d7, .decile.d8 { background: #4d7c0f; }
.decile.d9, .decile.d10 { background: #15803d; }
table.sortable th button { font-weight: 700; color: var(--text); padding: 0; text-align: left; }
td.hi, td .hi { color: var(--danger); font-weight: 700; }
td[class="hi"] { color: var(--danger); font-weight: 700; }
code { font-size: .85em; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }

/* Maps */
.map-box { height: 260px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); margin: 8px 0; background: var(--surface-2); }
.map-box.tall { height: 60vh; min-height: 320px; }
.field-label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.pin span { display: block; width: 22px; height: 22px; margin: 2px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .78rem; color: var(--muted); margin: 0 2px 12px; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.leaflet-popup-content a.btn { color: var(--accent-text); margin-top: 6px; }

/* Enquiry sorting */
.badge.urgent { background: var(--danger); color: #fff; }
.cmsg.auto { background: var(--surface-2); border-style: dashed; font-size: .9rem; }
.inline-select { width: auto; min-height: 0; padding: .1rem .3rem; font-size: .85rem; display: inline-block; }

/* Flyer landing page */
.landing { text-align: center; }
.landing .btn { margin: .4rem 0; font-size: 1.05rem; min-height: 56px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #063d1f; }

/* Ward news */
.check-line { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem 0; border-top: 1px solid var(--border); font-size: .92rem; }
.check-line:first-of-type { border-top: 0; }
.check-line input { margin-top: 2px; }
#news-post { font-family: inherit; font-size: .9rem; min-height: 260px; }

/* Join page */
fieldset.field { border: 0; padding: 0; margin: 0 0 .75rem; min-width: 0; }
fieldset.field legend { font-size: .85rem; font-weight: 600; margin-bottom: .5rem; padding: 0; }
.join-req .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.join-req .actions select { width: auto; min-width: 0; max-width: 100%; flex: 1 1 140px; }

/* ---------- Desktop: the tabs become a sidebar and the page widens ---------- */
@media (min-width: 960px) {
  :root { --side-w: 220px; --page-w: 1060px; }
  body:has(#tabbar:not([hidden])):not(.menu-collapsed) { padding-left: var(--side-w); }
  .topbar { padding: .9rem 24px; }
  .tabbar { width: var(--side-w); z-index: 11; transform: none; transition: none; }
  body.menu-collapsed .tabbar { transform: translateX(-102%); }
  body.menu-open .tabbar { box-shadow: none; }
  .menu-backdrop { display: none !important; }
  body:has(#tabbar:not([hidden])):not(.menu-collapsed) .topbar .brand { visibility: hidden; }
  main { max-width: var(--page-w); padding: 24px 32px; }
  h1 { font-size: 1.6rem; }
  body:not(.menu-collapsed) .composer { left: var(--side-w); }
  .composer { bottom: 0; padding: 10px max(32px, calc((100% - var(--page-w)) / 2 + 32px)); }
  body.chat-view .toast { bottom: 84px; }
  .toast { bottom: 24px; left: calc(50% + var(--side-w) / 2); }
  .bubble { max-width: 70%; }
  .home-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 28px; align-items: start; }
  .home-cols.single { grid-template-columns: minmax(0, 1fr); }
  .home-cols .list { max-height: 420px; overflow-y: auto; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .login { margin-top: 12vh; }
}

/* Area channels: tick list of a branch's wards */
.channel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .35rem .9rem; }

/* Checking a pasted list of people before adding them */
table.simple { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.simple th, table.simple td { text-align: left; padding: .35rem .3rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.simple th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.simple input, table.simple select { min-width: 130px; padding: .4rem .5rem; font-size: .9rem; }

/* Wards page: a candidate's name with a small remove button */
.link-x { all: unset; cursor: pointer; margin-left: .25rem; font-size: .8rem; opacity: .7; }
.link-x:hover, .link-x:focus-visible { opacity: 1; outline: 2px solid currentColor; border-radius: 4px; }
.ward-row { margin-bottom: 10px; }
@media (min-width: 960px) { .ward-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; } }

/* WhatsApp channel set-up: numbered steps with text to copy */
.setup-steps { padding-left: 1.3rem; display: grid; gap: .9rem; margin: 1rem 0; }
.setup-steps li { font-size: .95rem; }
.copy-box { margin-top: .4rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; display: grid; gap: .3rem; }
.copy-text { font-size: .9rem; overflow-wrap: anywhere; }
.copy-box .btn { justify-self: start; }
