:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --green: #15803d;
  --green-bg: #dcfce7;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --grey: #6b7280;
  --grey-bg: #f3f4f6;
  --red: #b91c1c;
  --line: #e5e7eb;
  --text: #111827;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #fff;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--blue); }

h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }

.muted { color: var(--grey); }
.small { font-size: .85rem; }
.error { color: var(--red); background: #fee2e2; padding: .6rem .8rem; border-radius: 8px; }
.notice { color: var(--green); background: var(--green-bg); padding: .6rem .8rem; border-radius: 8px; }

code.block {
  display: block; padding: .6rem; background: var(--grey-bg); border-radius: 8px;
  word-break: break-all; font-size: .9rem;
}

/* ---- simple pages ---- */

.card {
  max-width: 480px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem;
}
.card.wide { max-width: 860px; }

label { display: block; margin: .8rem 0; font-weight: 600; }
label input, label select {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400;
  padding: .7rem .8rem; border: 1px solid #cbd5e1; border-radius: 10px; font-size: 1.05rem;
}

button, .button {
  font: inherit; font-size: 1rem; padding: .6rem 1rem; border-radius: 10px;
  border: 1px solid #cbd5e1; background: #fff; color: var(--text); cursor: pointer;
  text-decoration: none; display: inline-block; line-height: 1.2;
}
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:active { background: var(--blue-dark); }
button.secondary { background: var(--grey-bg); }
button.danger { color: var(--red); border-color: #fca5a5; }
button.big { width: 100%; padding: .9rem; font-size: 1.1rem; margin-top: .5rem; }
button.icon { padding: .5rem .7rem; }

form.inline { display: flex; gap: .5rem; }
form.inline input { flex: 1; font: inherit; padding: .6rem .8rem; border: 1px solid #cbd5e1; border-radius: 10px; }

.event-list { list-style: none; padding: 0; margin: 1rem 0; }
.event-link {
  display: flex; flex-direction: column; gap: .2rem; padding: 1rem;
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: .6rem;
  text-decoration: none; color: var(--text); font-size: 1.1rem;
}
.event-link.state-now { border-color: #86efac; background: var(--green-bg); }
.event-link.state-done { opacity: .6; }
.event-title { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: .15rem .5rem; border-radius: 999px; background: var(--grey-bg); color: var(--grey);
}
.badge.now { background: var(--green); color: #fff; }
.badge.done { background: var(--grey-bg); }
.event-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 .75rem; align-items: end; }
.event-form label { margin: .5rem 0; }
.event-form button { margin: .5rem 0; }
details.edit { margin-top: .4rem; }
details.edit summary { cursor: pointer; }
.event-row { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.event-row .actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; align-items: center; }
.event-row .actions form { margin: 0; }

.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; font-size: .85rem; white-space: nowrap; }
th, td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--grey-bg); position: sticky; top: 0; }

/* ---- check-in app ---- */

body.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 5; background: #fff;
  border-bottom: 1px solid var(--line); padding: .5rem .75rem .5rem;
  padding-top: calc(.5rem + env(safe-area-inset-top));
}
.topbar-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .45rem; }
.topbar-row:last-child { margin-bottom: 0; }
.event-name {
  font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text); text-decoration: none; display: flex; flex-direction: column; line-height: 1.15;
}
.event-name small { font-weight: 400; color: var(--grey); font-size: .75rem; }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; min-width: 0; }
.counts { font-variant-numeric: tabular-nums; color: var(--grey); font-size: .9rem; white-space: nowrap; }
.counts b { color: var(--green); }
.me {
  font-size: .75rem; color: var(--grey); white-space: nowrap;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis;
}

.conn { font-size: .8rem; color: var(--grey); }
.conn.ok { color: var(--green); }
.conn.bad { color: var(--red); }

#q {
  flex: 1; font: inherit; font-size: 1.25rem; padding: .7rem .9rem;
  border: 2px solid var(--blue); border-radius: 12px; -webkit-appearance: none; appearance: none;
}
#q:focus { outline: none; box-shadow: 0 0 0 3px #bfdbfe; }

.filters { justify-content: space-between; }
.chips { display: flex; gap: .3rem; }
.chip {
  padding: .35rem .7rem; font-size: .85rem; border-radius: 999px; background: var(--grey-bg);
  border-color: transparent; color: var(--grey);
}
.chip.on { background: var(--blue); color: #fff; }
#group { font: inherit; font-size: .9rem; padding: .35rem .5rem; border-radius: 999px; border: 1px solid #cbd5e1; max-width: 45%; }

.list { flex: 1; padding: .25rem .5rem 5rem; }

.kid {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  height: 68px; padding: .5rem .75rem; margin: .3rem 0;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  text-align: left; font: inherit; overflow: hidden;
}
.kid.tappable { cursor: pointer; }
.kid.tappable:active { background: var(--grey-bg); }
.kid .who { flex: 1; min-width: 0; }
.kid .name, .kid .meta { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kid .name { font-size: 1.15rem; font-weight: 600; line-height: 1.25; }
.kid .name .last { font-weight: 800; }
.kid .meta { font-size: .85rem; color: var(--grey); line-height: 1.3; }
.kid .side { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; flex: none; }
.kid .stat { font-size: .75rem; font-weight: 700; line-height: 1.2; white-space: nowrap; min-height: .9rem; }
.kid .btns { display: flex; gap: .3rem; min-height: 1.9rem; }
.kid .btns button { padding: .3rem .55rem; font-size: .85rem; line-height: 1.2; }

.kid.in { background: var(--green-bg); border-color: #86efac; }
.kid.in .stat { color: var(--green); }
.kid.out { background: #fee2e2; border-color: #fca5a5; }
.kid.out .stat { color: var(--red); }

.kid .btns button.more { font-size: 1rem; padding: .2rem .5rem; color: var(--grey); }
.kid .btns button.more.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.card-open { margin: .3rem 0; }
.card-open .kid { margin: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.details {
  border: 1px solid var(--line); border-top: none; border-radius: 0 0 12px 12px;
  padding: .5rem .75rem .7rem; background: #fafafa;
}
.details textarea, label textarea {
  display: block; width: 100%; font: inherit; font-size: 1rem; line-height: 1.35;
  padding: .55rem .7rem; border: 1px solid #cbd5e1; border-radius: 10px; resize: vertical;
}
label textarea { margin-top: .3rem; font-weight: 400; }
.details-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; }
.kid.pending { opacity: .6; }

.hint { text-align: center; color: var(--grey); padding: 2rem 1rem; }
.more { text-align: center; color: var(--grey); padding: .8rem; font-size: .9rem; }

.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem .75rem;
  padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.bottombar .pending { margin: 0 auto; }
.bottombar .switch {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem .9rem; border-radius: 999px; font-weight: 600; font-size: .95rem;
  color: var(--blue); background: #eff6ff; border: 1px solid #bfdbfe; text-decoration: none;
  white-space: nowrap;
}
.bottombar .switch:active { background: #dbeafe; }
.bottombar .switch svg { flex: none; }
.pending { background: var(--amber-bg); color: var(--amber); font-size: .8rem; padding: .2rem .5rem; border-radius: 999px; }

.toast {
  position: fixed; left: 50%; bottom: 4.5rem; transform: translateX(-50%);
  z-index: 10; display: flex; align-items: center; gap: .75rem;
  background: #111827; color: #fff; padding: .7rem 1rem; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92vw;
}
.toast button { background: transparent; color: #93c5fd; border: none; font-weight: 700; padding: .2rem .4rem; }

dialog {
  border: none; border-radius: 16px; padding: 1.25rem; width: min(92vw, 420px);
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
.dialog-buttons { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
