:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --text: #1a1d21;
  --muted: #5f6672;
  --line: #e3e6ea;
  --accent: #1f6feb;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1e2126;
    --text: #e6e8eb;
    --muted: #9aa1ad;
    --line: #2c3037;
    --accent: #5b9bff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px 64px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar, .toolbar, main { max-width: 720px; margin: 0 auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
  color: inherit;
  text-decoration: none;
}

.brand-name { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
.brand-sub { font-size: .75rem; color: var(--muted); }

.account { position: relative; flex: none; }

.account .ghost {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .12);
}

.menu[hidden] { display: none; }

.menu-who {
  margin: 0;
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}

.menu a, .menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: .9rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu a:hover, .menu button:hover { background: var(--bg); }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 0; }

.pagename { flex: 1; margin: 0; font-size: 1.1rem; }

#tabs {
  display: flex;
  flex: 1;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

#tabs::-webkit-scrollbar { display: none; }

#tabs button {
  flex: none;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: .9rem;
}

#tabs button:hover:not(.active) {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

#tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.event {
  display: flex;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.when { flex: 0 0 96px; font-size: .85rem; color: var(--muted); }
.when strong { display: block; color: var(--text); font-size: .9rem; }

.body h2 { margin: 0 0 2px; font-size: 1rem; line-height: 1.35; }
.meta, .notes { margin: 0; font-size: .85rem; color: var(--muted); }

.needs { margin: 4px 0 0; font-size: .8rem; color: var(--muted); }
.needs .label { text-transform: uppercase; font-size: .7rem; letter-spacing: .04em; }

.duty { margin: 6px 0 0; font-size: .85rem; }
.duty .label { color: var(--muted); }
.duty.none { color: var(--muted); font-style: italic; }

.tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: .72rem;
  color: var(--muted);
  vertical-align: 1px;
}

.clash { display: block; color: #c0392b; font-size: .78rem; }

dialog input[type="search"] { margin-bottom: 10px; }

.assignlist {
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
}

.assignlist .group {
  margin: 10px 0 4px;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.assignlist .member {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 5px 0;
  color: var(--text);
  font-size: .92rem;
  cursor: pointer;
}

.assignlist .member input { display: inline-block; width: auto; margin: 0; }
.assignlist .member .clash { flex-basis: 100%; margin-left: 22px; }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.empty.error { color: #c0392b; }

button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.actions { display: flex; gap: 6px; margin-top: 8px; }

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop { background: rgb(0 0 0 / .45); }

dialog h2 { margin: 0 0 14px; font-size: 1.1rem; }

dialog label { display: block; margin-bottom: 10px; font-size: .8rem; color: var(--muted); }

dialog input, dialog textarea, dialog select {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .95rem;
}

dialog .pair { display: flex; gap: 10px; }
dialog .pair > label { flex: 1; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog .err { margin: 0; min-height: 1.2em; color: #c0392b; font-size: .85rem; }
dialog .check { display: flex; align-items: center; gap: 8px; }
dialog .check input { width: auto; margin: 0; }

dialog fieldset {
  margin: 0 0 10px;
  padding: 6px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

dialog fieldset legend { padding: 0 4px; color: var(--muted); font-size: .8rem; }

dialog fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 14px 0 0;
  color: var(--text);
  font-size: .9rem;
}

dialog fieldset input { width: auto; margin: 0; }

.tablewrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }

th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tbody tr.inactive td { color: var(--muted); }
table .actions { display: flex; gap: 6px; margin: 0; }

@media (max-width: 480px) {
  .event { flex-direction: column; gap: 4px; }
  .when { flex: none; display: flex; gap: 10px; }
}
