:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #13161b;
  --muted: #5a6371;
  --border: #dce0e6;
  --brand: #e0344b;
  --primary: #1f5fd6;
  --primary-text: #ffffff;
  --ok: #0f7a41;
  --ok-bg: #e0f4e8;
  --late: #9a5200;
  --late-bg: #fff0d9;
  --overdue: #b8192a;
  --overdue-bg: #fde4e7;
  --sos: #d10f27;
  --paused: #56606d;
  --paused-bg: #e9ecf0;
  --new: #2552c9;
  --new-bg: #e3ebff;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 6px 20px rgb(16 24 40 / 0.05);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #20242c;
    --text: #eef1f5;
    --muted: #9ba5b3;
    --border: #2b303a;
    --primary: #5b93ff;
    --primary-text: #0b1020;
    --ok: #45d188;
    --ok-bg: #11291c;
    --late: #ffb84d;
    --late-bg: #2f2210;
    --overdue: #ff6e7a;
    --overdue-bg: #361419;
    --sos: #ff3149;
    --paused: #a3acb9;
    --paused-bg: #242830;
    --new: #93b3ff;
    --new-bg: #19233b;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0;
}

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

code {
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.boot {
  padding: 3rem;
  text-align: center;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.stack {
  display: grid;
  gap: 0.75rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: end;
  flex-wrap: wrap;
}

.row > input,
.row > .grow {
  flex: 1 1 10rem;
}

.between {
  justify-content: space-between;
  align-items: center;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 1.1rem 0;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  font-weight: 600;
}

input:not([type='checkbox'], [type='radio']),
select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 400;
}

input[type='checkbox'],
input[type='radio'] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--primary);
  margin: 0;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem 0.8rem;
  margin: 0;
  display: grid;
  gap: 0.6rem;
}

legend {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 0.3rem;
}

/* ---- Buttons ---- */

.btn {
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
  background: var(--primary);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.danger-btn {
  color: var(--overdue);
  border-color: color-mix(in srgb, var(--overdue) 45%, transparent);
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  justify-self: start;
  font-size: 0.9rem;
}

.icon-btn {
  border: 0;
  background: transparent;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.2rem;
  flex: none;
}

.icon-btn:hover {
  background: var(--surface-2);
}

/* ---- Status palette ---- */

.status-ok {
  --s: var(--ok);
  --s-bg: var(--ok-bg);
}
.status-late {
  --s: var(--late);
  --s-bg: var(--late-bg);
}
.status-overdue {
  --s: var(--overdue);
  --s-bg: var(--overdue-bg);
}
.status-sos {
  --s: #fff;
  --s-bg: var(--sos);
}
.status-paused {
  --s: var(--paused);
  --s-bg: var(--paused-bg);
}
.status-new {
  --s: var(--new);
  --s-bg: var(--new-bg);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 750;
  color: var(--s);
  background: var(--s-bg);
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
}

/* ---- Auth ---- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(28rem, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 1.25rem;
}

.tagline {
  color: var(--muted);
}

.form-error {
  color: var(--overdue);
  font-size: 0.9rem;
  min-height: 1.2em;
}

/* ---- Shell ---- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.brand svg {
  width: 1.9rem;
  height: 1.9rem;
}

.brand.big {
  font-size: 1.6rem;
}

.brand.big svg {
  width: 2.6rem;
  height: 2.6rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: end;
  min-width: 0;
}

@media (max-width: 640px) {
  .hide-narrow {
    display: none;
  }
}

@media (max-width: 360px) {
  .topbar .brand > span {
    display: none;
  }
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.live::before {
  content: '';
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--paused);
}

.live.on::before {
  background: var(--ok);
}

.layout {
  display: grid;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem) 3rem;
  max-width: 88rem;
  margin: 0 auto;
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: minmax(20rem, 24rem) 1fr;
    align-items: start;
  }
}

.col {
  display: grid;
  gap: 1.25rem;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}

.card:empty {
  display: none;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.4rem;
  margin-left: 0.3rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85rem;
  vertical-align: middle;
}

.count.hot {
  background: var(--sos);
  color: #fff;
}

.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.2rem;
}

.tab {
  border: 0;
  background: transparent;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.tab.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.empty {
  padding: 1.25rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* ---- My signal ---- */

.summary {
  display: grid;
  gap: 0.6rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.due {
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

progress.window {
  width: 100%;
  height: 0.5rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  color: var(--s);
}

progress.window::-webkit-progress-bar {
  background: var(--surface-2);
}

progress.window::-webkit-progress-value {
  background: var(--s);
  border-radius: 999px;
}

progress.window::-moz-progress-bar {
  background: var(--s);
  border-radius: 999px;
}

.ok-btn {
  min-height: 4.25rem;
  margin-top: 0.4rem;
  border: 0;
  border-radius: 16px;
  background: var(--ok);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
}

.ok-btn:hover:not(:disabled) {
  background: var(--ok);
  filter: brightness(1.08);
}

@media (prefers-color-scheme: dark) {
  .ok-btn {
    color: #06140c;
  }
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.sos-btn {
  position: relative;
  width: 100%;
  min-height: 4.25rem;
  border: 2px solid var(--sos);
  border-radius: 16px;
  background: var(--surface);
  color: var(--sos);
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  margin-bottom: 0.5rem;
}

.sos-fill {
  position: absolute;
  inset: 0;
  background: var(--sos);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
}

.sos-label {
  position: relative;
}

.sos-btn.holding .sos-label {
  color: #fff;
  mix-blend-mode: difference;
}

.sos-banner {
  background: var(--sos);
  color: #fff;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.sos-banner strong {
  font-size: 1.2rem;
}

.sos-banner ul {
  margin: 0.3rem 0 0;
  padding-left: 1.1rem;
}

.safe-btn {
  background: #fff;
  color: var(--sos);
  border: 0;
  min-height: 3.25rem;
  font-size: 1.1rem;
}

.safe-btn:hover:not(:disabled) {
  background: #fff;
  filter: brightness(0.95);
}

.emoji-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.emoji {
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.3rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.emoji.on {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 16%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--primary);
}

.radio {
  display: flex;
  gap: 0.6rem;
  align-items: start;
  font-weight: 400;
}

.radio input {
  margin-top: 0.2rem;
}

details.danger {
  margin-top: 1rem;
}

details.danger summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

details.danger[open] {
  display: grid;
  gap: 0.6rem;
}

/* ---- Alerts ---- */

.alert-list {
  display: grid;
  gap: 0.75rem;
}

.alert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--k, var(--border));
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.55rem;
  box-shadow: var(--shadow);
}

.alert-card.kind-sos {
  --k: var(--sos);
  background: color-mix(in srgb, var(--sos) 9%, var(--surface));
}
.alert-card.kind-missed_checkin {
  --k: var(--overdue);
}
.alert-card.kind-back_online,
.alert-card.kind-sos_cleared {
  --k: var(--ok);
}

.alert-card.resolved {
  opacity: 0.8;
  background: var(--surface);
}

.alert-head {
  display: flex;
  gap: 0.7rem;
  align-items: center;
}

.alert-icon {
  font-size: 1.5rem;
}

.acks {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.925rem;
}

/* ---- People ---- */

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 0.85rem;
}

.person {
  text-align: left;
  display: grid;
  gap: 0.7rem;
  justify-items: start;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-top: 5px solid var(--s);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.person:hover {
  border-color: color-mix(in srgb, var(--s) 50%, var(--border));
  border-top-color: var(--s);
}

.person.status-sos {
  border-top-color: var(--sos);
  background: color-mix(in srgb, var(--sos) 10%, var(--surface));
  animation: pulse 1.4s ease-in-out infinite;
}

.person.status-sos .pill {
  animation: none;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--sos) 30%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .person.status-sos {
    animation: none;
  }
}

.person-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-width: 0;
}

.person > .facts {
  width: 100%;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  background: var(--s-bg);
  color: var(--s);
  font-weight: 800;
}

.status-sos .avatar {
  color: #fff;
}

.person-name {
  display: grid;
  min-width: 0;
  flex: 1;
}

.person-name > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.facts > span {
  display: grid;
}

.k {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}

.v {
  font-size: 0.92rem;
  font-weight: 600;
}

.low {
  color: var(--overdue);
}

.split {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 1200px) {
  .split {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.invite-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 0.5rem;
}

.code {
  font: 800 1.6rem/1 ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
}

.circle {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.circle-name {
  font-weight: 700 !important;
  flex: 1;
}

.toggles,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip,
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
}

.chip:has(input:checked),
.switch:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

.note {
  font-size: 0.85rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: var(--late-bg);
  color: var(--late);
}

/* ---- Dialog ---- */

dialog {
  width: min(36rem, calc(100% - 2rem));
  max-height: calc(100vh - 4rem);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}

dialog::backdrop {
  background: rgb(10 12 16 / 0.55);
}

.dialog-body {
  display: grid;
  gap: 1rem;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.detail-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.45rem 1rem;
  margin: 0;
}

.detail-list dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-list dd {
  margin: 0;
  font-weight: 550;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  max-height: 16rem;
  overflow: auto;
}

.timeline li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.9rem;
}

/* ---- Toasts ---- */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: grid;
  gap: 0.5rem;
  max-width: min(24rem, calc(100% - 2rem));
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
  font-weight: 550;
  transition: opacity 0.4s, transform 0.4s;
}

.toast.ok {
  background: var(--ok);
  color: #fff;
}

.toast.danger {
  background: var(--sos);
  color: #fff;
}

.toast.out {
  opacity: 0;
  transform: translateY(0.5rem);
}
