:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #d9dce1;
  --header: #1f2937;
  --accent: #b45309;
  --accent-text: #ffffff;
  --overdue: #b91c1c;
  --overdue-bg: #fee2e2;
  --soon: #92400e;
  --soon-bg: #fef3c7;
  --upcoming: #1e40af;
  --upcoming-bg: #dbeafe;
  --done: #166534;
  --done-bg: #dcfce7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #1a2029;
    --text: #e8eaed;
    --muted: #9aa3af;
    --border: #2e3642;
    --header: #111820;
    --accent: #d97706;
    --overdue: #fca5a5;
    --overdue-bg: #4c1d1d;
    --soon: #fcd34d;
    --soon-bg: #4a3610;
    --upcoming: #93c5fd;
    --upcoming-bg: #1e3050;
    --done: #86efac;
    --done-bg: #173624;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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;
}

h1, h2, h3, p { margin: 0; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--header);
  color: #fff;
}
.top-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
}
.brand { flex: 1; min-width: 0; }
.top h1 { font-size: 1.15rem; }
.top h1 a { color: inherit; text-decoration: none; }
.top h1, .top-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-sub { font-size: 0.85rem; color: #c7ccd4; }
.top-nav { display: flex; gap: 4px; }
.top-nav.off { visibility: hidden; }
.top-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: #c7ccd4;
  font-weight: 600;
  text-decoration: none;
}
.top-nav a[aria-current="page"] { border-bottom-color: var(--accent); color: #fff; background: rgba(255, 255, 255, 0.1); }
/* a sticky header must not hide what the browser scrolls to */
html { scroll-padding-top: 120px; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.offline {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--soon-bg);
  color: var(--soon);
  font-size: 0.9rem;
}

/* view tabs */
.views {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.view strong { font-size: 1.35rem; line-height: 1.1; }
.view span { font-size: 0.75rem; color: var(--muted); text-align: center; }
.view.overdue strong { color: var(--overdue); }
.view.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.view.active span { color: var(--text); font-weight: 600; }

/* filters */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.filters input { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.btn {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.btn.small { min-height: 40px; padding: 7px 12px; font-size: 0.875rem; }
.btn.danger { color: var(--overdue); }
.btn.on-dark { border-color: #4b5563; background: transparent; color: #fff; white-space: nowrap; }

.link {
  padding: 6px 4px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}
.link.danger { color: var(--overdue); }

/* task cards */
.list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.card {
  padding: 14px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.card.overdue { border-left-color: var(--overdue); }
.card.soon { border-left-color: #d97706; }
.card.upcoming { border-left-color: #3b82f6; }
.card.done { border-left-color: #22c55e; }
.card.done h3 { text-decoration: line-through; color: var(--muted); }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.card-head h3 { font-size: 1.05rem; overflow-wrap: anywhere; }

.badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge.overdue { background: var(--overdue-bg); color: var(--overdue); }
.badge.soon { background: var(--soon-bg); color: var(--soon); }
.badge.upcoming { background: var(--upcoming-bg); color: var(--upcoming); }
.badge.done { background: var(--done-bg); color: var(--done); }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 8px 0 0;
  font-size: 0.9rem;
}
.meta div { display: flex; gap: 6px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.status-by { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
select.status { width: auto; min-height: 40px; padding: 7px 10px; font-weight: 600; }
select.status.in_progress { border-color: #3b82f6; }
select.status.done { border-color: #22c55e; }

/* notes */
.notes {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.notes ul {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}
.note-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
}
.note-head span { color: var(--muted); font-size: 0.8rem; }
.notes li p { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.95rem; }
.note-form { display: grid; gap: 8px; }
.note-row { display: flex; gap: 8px; }
.note-row .btn { flex-shrink: 0; }

.hint, .empty { color: var(--muted); font-size: 0.9rem; }
.empty { padding: 32px 0; text-align: center; }
.notes .hint { margin-bottom: 12px; }

/* dialogs */
dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog form, .dialog-body { display: grid; gap: 12px; }
.field-hint { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.field-hint a, .error a { color: inherit; text-decoration: underline; }
.also-teams { padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; }
.also-teams summary { cursor: pointer; padding: 12px 0; font-size: 0.875rem; font-weight: 600; }
.also-teams[open] { padding-bottom: 8px; }
.check-list { display: grid; }
dialog label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 1rem; font-weight: 400; }
input[type="checkbox"] { flex-shrink: 0; width: 20px; height: 20px; padding: 0; accent-color: var(--accent); }

/* coordinator lock screen / invalid team link */
.locked {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 420px;
  margin: 48px auto 0;
  text-align: center;
}
.locked h2 { font-size: 1.2rem; }
.locked p { color: var(--muted); }

/* teams, links & PINs */
.team-list {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.team-list li[data-team] {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.team-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; }
.team-head strong { overflow-wrap: anywhere; }
.team-head span { color: var(--muted); font-size: 0.8rem; }
.team-link { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.team-pin { font-size: 1.1rem; letter-spacing: 0.15em; }
.people-block { margin: 10px 0; padding-top: 8px; border-top: 1px solid var(--border); }
.people-title { margin-bottom: 4px; font-size: 0.85rem; font-weight: 600; }
.people { display: grid; gap: 6px; margin: 0 0 8px; padding: 0; list-style: none; }
.people li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.person { flex: 1 1 140px; overflow-wrap: anywhere; }
.person span { color: var(--muted); font-size: 0.85rem; }
.member-form input { flex: 1 1 120px; min-width: 0; }
.people-tools { display: grid; gap: 8px; margin-top: 8px; }
.people-tools > .btn { justify-self: start; }
.people-paste summary { cursor: pointer; padding: 10px 0; font-size: 0.875rem; font-weight: 600; text-decoration: underline; }
.people-paste textarea { width: 100%; margin-bottom: 4px; }
.people-paste .hint { margin: 0 0 8px; }
.member-edit input { flex: 1 1 120px; min-width: 0; }
#teamsPage h2 { font-size: 1.15rem; margin-bottom: 4px; }
#teamsPage .hint { margin-bottom: 12px; }
dialog h2 { font-size: 1.15rem; }
dialog label { display: grid; gap: 4px; font-size: 0.875rem; font-weight: 600; }
dialog label[hidden] { display: none; }
.optional { color: var(--muted); font-weight: 400; }
.error { color: var(--overdue); font-size: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* photos */
.photos {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-bottom: 2px;
  overflow-x: auto;
}
.photo {
  flex-shrink: 0;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
}
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }

.photo-dialog { width: min(720px, calc(100vw - 16px)); padding: 12px; }
.photo-dialog img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 180px);
  margin: 0 auto;
  border-radius: 8px;
}
input[type="file"] { padding: 8px; font-size: 0.9rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--header);
  color: #fff;
  font-size: 0.9rem;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* narrow phones: every toolbar button gets a full-width row */
@media (max-width: 480px) {
  .toolbar .btn { flex: 1 1 100%; }
  .dialog-actions .btn { flex: 1; }
  .note-row { flex-wrap: wrap; }
  .note-row .btn { flex: 1; }
  .member-form input, .member-edit input { flex-basis: 100%; }
  .top-inner { flex-wrap: wrap; row-gap: 6px; }
  .top-nav { order: 3; flex: 1 1 100%; }
  /* Hidden nav keeps its space on the one-row desktop header; on phones it would be an empty row. */
  .top-nav.off { display: none; }
  .top-nav a { flex: 1; }
  html { scroll-padding-top: 130px; }
  .team-list .actions .btn { flex: 1 1 auto; }
  .people-tools > .btn { justify-self: stretch; }
}
