:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --text: #13161b;
  --muted: #5b6471;
  --line: #dfe3e8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d3efea;
  --ok: #15803d;
  --ok-soft: #dcf3e2;
  --warn: #a95a06;
  --warn-soft: #fcebc9;
  --danger: #b91c1c;
  --danger-soft: #fde1e1;
  --alert: #b91c1c;
  --live: #6d28d9;
  --live-soft: #ece3ff;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --radius: 14px;
  --tap: 44px;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1114;
    --surface: #181c21;
    --surface-2: #222830;
    --text: #eef1f4;
    --muted: #9aa4b1;
    --line: #2c333c;
    --accent: #2dd4bf;
    --accent-ink: #052e2b;
    --accent-soft: #123d39;
    --ok: #4ade80;
    --ok-soft: #133a22;
    --warn: #fbbf24;
    --warn-soft: #3d2f0c;
    --danger: #f87171;
    --danger-soft: #451818;
    --live: #c4b5fd;
    --live-soft: #2e2350;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body.station {
  font-size: 22px;
  --tap: 68px;
  --gutter: 28px;
  --radius: 20px;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.4em 0 .5em; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2em 0 .4em; }
p { margin: .5em 0; }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: .15em .4em; border-radius: 6px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.warn { color: var(--warn); }
.pre { white-space: pre-wrap; }
.empty { color: var(--muted); text-align: center; padding: 2em 1em; }
button svg { width: 1.4em; height: 1.4em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- controls ---------- */
button, select, input, textarea {
  font: inherit;
  color: inherit;
}
button {
  min-height: var(--tap);
  padding: 0 1em;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  touch-action: manipulation;
}
button:active { transform: scale(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
button.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
button.lg { min-height: calc(var(--tap) + 8px); font-size: 1.1em; padding: 0 1.4em; }
button.link { min-height: 0; border: 0; background: none; padding: 0 .3em; color: var(--muted); }
button.icon { border: 0; background: none; padding: 0 .4em; color: var(--muted); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9em; margin: 0 0 .9em; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: .35em;
  min-height: var(--tap);
  padding: .5em .75em;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 6px);
  background: var(--surface);
  font-weight: 400;
  font-size: max(16px, 1em); /* no iOS zoom-on-focus */
}
textarea { resize: vertical; }

/* ---------- shell ---------- */
#shell { display: flex; flex-direction: column; height: 100dvh; }
#top {
  display: flex;
  align-items: center;
  gap: .6em;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
#top .ev { flex: 1; min-width: 0; }
#top h1 { font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top .sub { color: var(--muted); font-size: .85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.station #top { padding-top: 22px; padding-bottom: 22px; }
.station #top h1 { font-size: 1.7rem; }
.clock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.on { background: var(--ok); }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; min-height: 0; padding: 0;
  border-radius: 50%; border: 0;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: .85rem;
}
.avatar.sm { width: 2.2em; height: 2.2em; font-size: .8em; }

#offline { background: var(--warn-soft); color: var(--warn); padding: 8px var(--gutter); font-size: .85em; font-weight: 600; }

#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px var(--gutter) 24px;
}

#nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#nav button {
  flex: 1;
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px;
  border: 0; border-radius: 0; background: none;
  color: var(--muted);
  font-size: .72rem; font-weight: 600;
}
#nav button.active { color: var(--accent); }
#nav button.active::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.station #nav button { min-height: 120px; font-size: .8rem; gap: 8px; }
.station #nav svg { width: 1.9em; height: 1.9em; }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--alert); color: #fff; border-radius: 999px; font-size: .7rem; padding: 1px 6px; }

#composer {
  display: flex; gap: 8px;
  padding: 8px var(--gutter);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
#composer input { margin: 0; flex: 1; }
#composer select { margin: 0; width: auto; flex: none; }
body:not(.org) .org-only { display: none; }

/* ---------- cards & lists ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1em; margin: 1em 0 .4em; }
.toolbar h2 { margin: 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1em;
  margin: 1em 0;
  box-shadow: var(--shadow);
}
.card-label, .hero-label { font-size: .75em; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.big { font-size: 1.35em; font-weight: 700; }
.row-actions, .sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card .row-actions { margin-top: .8em; }

.checkin { display: flex; align-items: center; justify-content: space-between; gap: 1em; }
.checkin.here { background: var(--ok-soft); border-color: transparent; }
.checkin.here .big { color: var(--ok); }

.heroes { display: grid; gap: 12px; margin-top: 1em; }
.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1em 1.1em;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.hero.is-now { background: var(--live-soft); border-color: transparent; }
.hero.is-now .hero-label { color: var(--live); }
.hero-title { font-size: 1.45em; font-weight: 750; margin: .15em 0; }
.hero-meta, .hero-rel { color: var(--muted); }
.hero-rel { font-weight: 600; margin-top: .3em; }
.station .hero-title { font-size: 2.1em; }
.station .hero { padding: 1.1em 1.3em; }
.empty-hero { cursor: default; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 0; padding: .7em .8em; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 400; white-space: normal; box-shadow: var(--shadow);
}
.stat b { font-size: 1.6em; line-height: 1.1; }
.stat span { font-size: .78em; color: var(--muted); }
.station .stat b { font-size: 2.2em; }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.alert-strip {
  margin-top: 1em; padding: .8em 1em;
  border-radius: var(--radius);
  background: var(--alert); color: #fff; cursor: pointer;
}
.alert-strip .muted { color: rgb(255 255 255 / .8); }

.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; gap: .8em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .65em .8em;
  box-shadow: var(--shadow);
}
.row-main { flex: 1; min-width: 0; cursor: pointer; }
.row-title { font-weight: 650; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: .35em .7em; align-items: center; color: var(--muted); font-size: .85em; margin-top: .2em; }
.row .row-actions { flex: none; }
.row.task.high { border-left: 5px solid var(--danger); }
.row.task.done .row-title, .row.sched.done .row-title, .row.sched.cancelled .row-title { text-decoration: line-through; color: var(--muted); }
.row.sched.current { background: var(--live-soft); border-color: transparent; }
.row .time { width: 4.6em; flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.row .time small { display: block; font-weight: 400; color: var(--muted); }
.row.person.here .avatar { background: var(--ok-soft); color: var(--ok); }
.flag { display: inline-grid; place-items: center; width: 1.2em; height: 1.2em; margin-right: .35em; border-radius: 50%; background: var(--alert); color: #fff; font-size: .8em; }
@media (max-width: 520px) {
  body.app .row.task, body.app .row.sched { flex-wrap: wrap; }
  body.app .row.task .row-actions, body.app .row.sched .row-actions { width: 100%; justify-content: flex-end; }
}

.chip { display: inline-block; padding: .1em .55em; border-radius: 999px; font-size: .8em; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.s-live, .s-doing { background: var(--live-soft); color: var(--live); }
.s-done, .s-in { background: var(--ok-soft); color: var(--ok); }
.s-delayed { background: var(--warn-soft); color: var(--warn); }
.s-cancelled { background: var(--danger-soft); color: var(--danger); }
.s-open { background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; gap: 8px; margin: .3em 0 1em; overflow-x: auto; }
.chips button { min-height: calc(var(--tap) - 6px); border-radius: 999px; font-weight: 600; }
.chips button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- chat ---------- */
.chat { list-style: none; padding: 1em 0 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 85%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .55em .8em;
  align-self: flex-start;
}
.msg.mine { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg.announcement { max-width: 100%; align-self: stretch; background: var(--warn-soft); border-color: transparent; }
.msg.alert { max-width: 100%; align-self: stretch; background: var(--alert); border-color: transparent; color: #fff; }
.msg.alert .muted, .msg.alert button.link { color: rgb(255 255 255 / .8); }
.msg-head { display: flex; gap: .5em; align-items: baseline; font-size: .8em; }
.msg-head .muted { margin-right: auto; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: .15em; }
.tag { font-size: .85em; letter-spacing: .06em; }
.list .msg { max-width: none; }

/* ---------- join panel / settings ---------- */
.join-panel { display: flex; gap: 1.2em; align-items: center; }
.join-panel .qr { flex: none; width: 168px; background: #fff; padding: 8px; border-radius: 12px; }
.join-panel .qr svg { width: 100%; height: auto; display: block; }
.station .join-panel .qr { width: 300px; }
@media (max-width: 480px) { .join-panel { flex-direction: column; align-items: flex-start; } }
.pin { font-size: 2.4em; font-weight: 800; letter-spacing: .25em; font-variant-numeric: tabular-nums; }

/* ---------- join screen ---------- */
#join { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.join-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.join-card label { text-align: left; margin-top: 1.2em; }
.join-card details { text-align: left; margin: 0 0 1em; }
.join-card summary { cursor: pointer; color: var(--muted); padding: .5em 0; }
.join-card .primary { width: 100%; }
.join-card img { border-radius: 16px; }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgb(0 0 0 / .45);
}
.sheet {
  width: min(640px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 22px var(--gutter) calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 1em; }
.sheet-actions { margin-top: 1.2em; }
.spacer { flex: 1; }
@media (min-width: 700px) {
  #modal { align-items: center; }
  .sheet { border-radius: 22px; }
}
.station .sheet { width: min(940px, 100%); }

/* ---------- alert overlay ---------- */
#alert {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: var(--gutter);
  background: var(--alert);
  color: #fff;
  animation: pulse 1.2s ease-in-out 3;
}
.alert-box { max-width: 700px; text-align: center; }
.alert-kicker { font-weight: 800; letter-spacing: .08em; opacity: .9; }
.alert-body { font-size: 2em; font-weight: 800; margin: .5em 0 1em; white-space: pre-wrap; overflow-wrap: anywhere; }
.station .alert-body { font-size: 2.8em; }
#alert button { background: #fff; color: var(--alert); border: 0; min-width: 12em; }
@keyframes pulse { 50% { filter: brightness(1.25); } }
@media (prefers-reduced-motion: reduce) { #alert { animation: none; } }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 640px);
  padding: .7em 1.1em;
  border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.station #toast { bottom: 150px; }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }

/* Location sharing note (members) */
.loc-note {
  display: block; width: 100%; min-height: 0; margin: -.3em 0 1em; padding: .65em .9em;
  border: 0; border-radius: 10px; text-align: left; font-size: .9em;
  background: var(--surface-2); color: var(--muted);
}
.loc-note.on-site { background: var(--accent-soft); color: var(--text); }
.loc-note.blocked { background: var(--warn-soft); color: var(--warn); }

/* Map (organizers) */
.map {
  height: min(62vh, 640px); margin-bottom: 1em; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.station .map { height: 58vh; max-height: none; }
.map[hidden] { display: none; }
.map.leaflet-container { background: #1f2937; letter-spacing: normal; }
.map.map-grid {
  background-color: #1f2937;
  background-image: linear-gradient(rgb(255 255 255 / .06) 1px, transparent 1px),
                    linear-gradient(90deg, rgb(255 255 255 / .06) 1px, transparent 1px);
  background-size: 40px 40px;
}
.map .leaflet-control-attribution { font-size: 11px; }
.pin span {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: #0f766e; color: #fff; font: 700 13px/1 -apple-system, system-ui, sans-serif; letter-spacing: 0;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / .45);
}
.pin.stale span { background: #6b7280; }
.station .pin span { width: 44px; height: 44px; font-size: 16px; margin: -4px; }
