:root {
  --bg: #faf9f7; --card: #ffffff; --ink: #1c1c1a; --soft: #6b6a65;
  --faint: #9a9993; --line: #e6e4df; --accent: #1d9e75; --warn: #854f0b;
  --warn-bg: #faeeda; --danger: #a32d2d; --pad: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a; --card: #1f1f24; --ink: #f0efec; --soft: #a3a29c;
    --faint: #75746f; --line: #2e2e34; --accent: #5dcaa5; --warn: #fac775;
    --warn-bg: #3a2f1a; --danger: #f09595;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* An author `display` rule outranks the UA stylesheet's [hidden] rule, so any
   flex container would ignore hidden entirely and sit permanently on screen. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
}
.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav button {
  background: none; border: 0; color: var(--soft); font-size: 26px;
  padding: 0 10px; cursor: pointer; line-height: 1;
}
.heading { text-align: center; }
h1 { font-size: 17px; font-weight: 600; margin: 0; }
#range { margin: 2px 0 0; font-size: 13px; color: var(--soft); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: none; color: var(--soft);
  border-radius: 14px; padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

main { padding: 4px var(--pad) 90px; }
.day { margin-top: 18px; }
.day h2 {
  font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint); margin: 0 0 6px;
}
.day.today h2 { color: var(--accent); }
.row {
  display: flex; gap: 12px; align-items: baseline; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 11px 2px; color: inherit; font: inherit; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.when { flex: 0 0 54px; font-size: 13px; color: var(--soft); font-variant-numeric: tabular-nums; }
.body { flex: 1; min-width: 0; }
.title { font-size: 15px; display: block; }
.row.cancelled .title { text-decoration: line-through; color: var(--faint); }
.meta {
  font-size: 12px; color: var(--faint); margin-top: 1px; display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.who { flex: 0 0 auto; display: flex; gap: 3px; }
.pip {
  width: 21px; height: 21px; border-radius: 50%; background: var(--line);
  color: var(--soft); font-size: 10px; display: flex; align-items: center;
  justify-content: center; font-weight: 600;
}
.row.advisory .title { color: var(--soft); }
/* An invitation nobody has answered is on the calendar but is not yet a
   commitment, so it reads as a placeholder rather than a plan. */
.row.unconfirmed .title, .row.unconfirmed .meta { color: var(--faint); }
.row.declined .title { text-decoration: line-through; color: var(--faint); }
.row.declined .meta { color: var(--faint); }
.row.critical .title, .row.critical .when { color: var(--danger); }
.clash {
  background: var(--warn-bg); color: var(--warn); border-radius: 8px;
  padding: 8px 11px; font-size: 12px; margin: 6px 0 2px;
}
.empty { color: var(--faint); font-size: 14px; text-align: center; padding: 44px 0; }
.stale { background: var(--warn-bg); color: var(--warn); font-size: 12px;
  padding: 6px 11px; border-radius: 8px; margin-bottom: 8px; text-align: center; }

footer {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; gap: 8px;
  padding: 10px var(--pad) calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg); border-top: 1px solid var(--line);
}
button.ghost, #sheet-save {
  flex: 1; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 9px; padding: 10px; font-size: 14px; cursor: pointer;
}
button.ghost[disabled] { color: var(--faint); }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; }
.sheet-inner {
  background: var(--bg); width: 100%; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head {
  position: sticky; top: 0; background: var(--bg); display: flex; align-items: center;
  justify-content: space-between; gap: 10px; padding: 12px var(--pad);
  border-bottom: 1px solid var(--line);
}
.sheet-head span { font-size: 14px; font-weight: 600; }
.sheet-head button { flex: 0 0 auto; padding: 7px 13px; font-size: 14px; }
#sheet-save { background: var(--ink); color: var(--bg); border-color: var(--ink); }
#sheet-body { padding: var(--pad); }
#sheet-body h3 { font-size: 19px; margin: 0 0 3px; font-weight: 600; }
.sub { color: var(--soft); font-size: 14px; margin: 0 0 3px; }
.provenance {
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font-size: 12px; color: var(--soft); margin: 14px 0;
}
label { display: block; font-size: 12px; color: var(--soft); margin: 16px 0 6px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; font: inherit; font-size: 15px; padding: 10px 12px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
}
textarea { min-height: 72px; resize: vertical; }
.toggle { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 30;
  background: var(--ink); color: var(--bg); font-size: 13px; padding: 9px 16px;
  border-radius: 20px;
}
