/* CrewCampfire - warm dark theme, campfire accent */
:root {
  --bg: #14100d;
  --bg2: #1e1813;
  --panel: #241c15;
  --panel2: #2d231a;
  --border: #3a2d20;
  --text: #f0e7dc;
  --muted: #a89a88;
  --accent: #ff8a3d;
  --accent2: #ffb347;
  --danger: #e05d5d;
  --ok: #6fbf73;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent2); text-decoration: none; }
.hidden { display: none !important; }

/* Topbar */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 18px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 500;
}
#topbar .brand { font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: .2px; white-space: nowrap; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; }
#topbar nav { display: flex; gap: 18px; align-items: center; flex-shrink: 0; }
#topbar nav a { color: var(--muted); font-weight: 600; position: relative; white-space: nowrap; padding: 6px 0; }
#topbar nav a.active, #topbar nav a:hover { color: var(--text); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); position: absolute; top: -2px; right: -10px; }

#view { max-width: 1080px; margin: 0 auto; padding: 20px 16px calc(60px + env(safe-area-inset-bottom, 0px)); }
.loading { color: var(--muted); text-align: center; padding: 60px 0; }

/* Cards, buttons, forms */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  background: var(--accent); color: #1d1005; border: none; border-radius: 9px;
  padding: 9px 16px; font-size: 14px; font-weight: 700;
  min-height: 38px; touch-action: manipulation;
}
.btn:hover { background: var(--accent2); }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--muted); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px; font-family: inherit;
  font-size: 16px; /* >=16px stops iOS Safari auto-zooming on focus */
  min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 0 5px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
h1 { font-size: 24px; margin: 6px 0 4px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* Auth */
.auth-wrap { max-width: 400px; margin: 8vh auto 0; }
.auth-logo { text-align: center; font-size: 42px; margin-bottom: 6px; }
.auth-title { text-align: center; font-size: 24px; font-weight: 800; margin-bottom: 2px; }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }

/* Group grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.group-card { cursor: pointer; transition: border-color .15s; }
/* hover-capable devices only: touch taps otherwise leave a stuck highlight */
@media (hover: hover) { .group-card:hover { border-color: var(--accent); } }
.group-card .gname { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.group-card .gmeta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.group-card .gblurb {
  font-size: 13px; margin-top: 8px; color: var(--text); opacity: .85;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.pill { display: inline-block; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); border-radius: 20px; padding: 1px 9px; font-size: 11.5px; font-weight: 600; }
.pill.club { color: var(--accent2); border-color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.toolbar input, .toolbar select { width: auto; flex: 1; min-width: 140px; }

/* Group page */
.group-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.group-head > div { min-width: 0; }
/* Anything that starts a list right after a header row (button included) gets
   breathing room; cards otherwise only carry bottom margins. */
.group-head + .grid, .group-head + .card, .group-head + #cu-list { margin-top: 16px; }
#my-membership { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; line-height: 20px; }
.tabs {
  display: flex; gap: 4px; margin: 16px 0 14px; border-bottom: 1px solid var(--border);
  flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: none; color: var(--muted); font-weight: 700; font-size: 14px;
  padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; position: relative;
  white-space: nowrap; flex-shrink: 0; touch-action: manipulation;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs button .dot { top: 8px; right: 2px; }

/* Map */
#map { height: 62vh; min-height: 380px; border-radius: var(--radius); border: 1px solid var(--border); }
.pin-marker { display: flex; flex-direction: column; align-items: center; transform: translateY(-4px); }
.pin-emoji {
  background: var(--panel); border: 2px solid var(--accent); border-radius: 50%;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.pin-label {
  margin-top: 2px; background: rgba(20,16,13,.85); border-radius: 6px; padding: 1px 6px;
  font-size: 11px; font-weight: 700; color: var(--text); white-space: nowrap;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}
.pin-marker.catchup .pin-emoji { border-color: var(--ok); border-radius: 10px; }
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--panel); }
.map-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Member card */
.member-card { display: flex; gap: 12px; }
.member-card .avatar { font-size: 34px; line-height: 1; }
.member-card .mname { font-weight: 700; font-size: 15px; }
.member-card .mrole { color: var(--accent2); font-size: 13px; font-weight: 600; }
.member-card .msub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.member-card .mbio { font-size: 13px; margin-top: 6px; opacity: .9; }
.member-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }

/* Chat */
.chat-wrap { display: flex; gap: 14px; height: 62vh; min-height: 380px; }
.chan-list { width: 190px; flex-shrink: 0; overflow-y: auto; }
.chan-list button {
  display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  background: none; border: none; color: var(--muted); padding: 8px 10px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.chan-list button.active { background: var(--panel2); color: var(--text); }
.chan-list button .dot { position: static; }
.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px; }
.msg { display: flex; gap: 10px; padding: 5px 0; }
.msg .avatar { font-size: 22px; line-height: 1.3; }
.msg .mhead { font-size: 13px; }
.msg .mhead b { color: var(--accent2); }
.msg .mhead time { color: var(--muted); font-size: 11.5px; margin-left: 6px; }
.msg .mbody { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg .mbody.deleted { color: var(--muted); font-style: italic; }
.msg .msg-del { visibility: hidden; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 4px 6px; }
.msg:hover .msg-del { visibility: visible; }
@media (hover: none) { .msg .msg-del { visibility: visible; opacity: .55; } }
.msg .mention { color: var(--accent); font-weight: 700; }
.chat-send { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-send textarea { resize: none; height: 44px; }
.chat-empty { color: var(--muted); text-align: center; margin-top: 40px; font-size: 14px; }

/* Catch-ups */
.catchup-card { margin-bottom: 12px; }
.catchup-card .ctitle { font-weight: 700; font-size: 16px; }
.catchup-card .cwhen { color: var(--accent2); font-weight: 600; font-size: 13.5px; margin-top: 2px; }
.catchup-card .cvenue { color: var(--muted); font-size: 13.5px; }
.catchup-card .cdetails { font-size: 13.5px; margin-top: 8px; opacity: .9; white-space: pre-wrap; }
.rsvp-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.rsvp-row .btn.on { outline: 2px solid var(--accent2); }
.attendees { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* DMs */
.dm-wrap { display: flex; gap: 14px; height: 68vh; min-height: 400px; }
.dm-list { width: 260px; flex-shrink: 0; overflow-y: auto; }
.dm-item { display: flex; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; align-items: center; flex-shrink: 0; }
.dm-item:hover, .dm-item.active { background: var(--panel2); }
.dm-item .avatar { font-size: 24px; }
.dm-item .dname { font-weight: 700; font-size: 14px; }
.dm-item .dlast { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.request-banner { background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin: 10px; font-size: 13.5px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* Modal + toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 900; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 6vh 14px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 480px; padding: 22px; position: relative; }
.modal .close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--text); border-radius: 10px;
  padding: 10px 18px; z-index: 1000; font-size: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.4);
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.err { border-color: var(--danger); }

/* Emoji picker */
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 6px; }
.emoji-grid button { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; font-size: 20px; padding: 5px 0; cursor: pointer; }
.emoji-grid button.on { border-color: var(--accent); background: var(--panel2); }

/* Suburb picker */
.suggest { position: relative; }
.suggest-list { position: absolute; top: 100%; left: 0; right: 0; background: var(--panel2); border: 1px solid var(--border); border-radius: 9px; z-index: 200; max-height: 220px; overflow-y: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 9px 12px; cursor: pointer; font-size: 14px; }
.suggest-list button:hover { background: var(--panel); }
.suggest-list .sregion { color: var(--muted); font-size: 12px; }

/* Invite landing */
.invite-hero { text-align: center; max-width: 460px; margin: 6vh auto 0; }
.invite-hero .big { font-size: 46px; }
.invite-hero h1 { margin: 8px 0 4px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.mt { margin-top: 14px; }

@media (max-width: 720px) {
  .chat-wrap, .dm-wrap { flex-direction: column; height: auto; }
  .chan-list, .dm-list {
    width: 100%; display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .chan-list::-webkit-scrollbar, .dm-list::-webkit-scrollbar { display: none; }
  .chan-list button { width: auto; white-space: nowrap; flex-shrink: 0; }
  .dm-item { padding: 8px 10px; }
  .dm-item .dlast { max-width: 130px; }
  .chat-main { height: 55vh; height: 55dvh; }
  #map { height: 50vh; height: 50dvh; min-height: 320px; }
  .member-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  #view { padding: 14px 12px calc(48px + env(safe-area-inset-bottom, 0px)); }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
  .sub { font-size: 13.5px; }
  /* group header: keep it compact so the content (map/chat) stays above the fold */
  .group-head .sub {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    margin-bottom: 10px;
  }
  #my-membership { width: 100%; }
  .tabs { margin: 10px 0 12px; }
  .tabs button { padding: 9px 11px; }
  /* topbar: brand + 3 links must fit 320px */
  #topbar { padding-left: 12px; padding-right: 12px; }
  #topbar .brand { font-size: 15px; }
  #topbar .brand .brand-flame { font-size: 14px; }
  #topbar nav { gap: 12px; }
  #topbar nav a { font-size: 13.5px; }
  .dot { right: -8px; }
  /* forms and modals */
  .row { flex-direction: column; gap: 0; }
  .modal-backdrop { padding: 3vh 10px 8vh; }
  .modal { padding: 18px 14px; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { min-width: 120px; }
  .auth-wrap { margin-top: 4vh; }
  .grid { grid-template-columns: 1fr; }
  .chat-msgs { padding: 10px; }
  .rsvp-row { gap: 6px; }
  .invite-hero { margin-top: 3vh; }
  .attendees { font-size: 12.5px; }
}
