:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e2de;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --today-bg: #e8f0fd;
  --dot: #2f6fdb;
  --danger: #c0392b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #212124;
    --text: #ececec;
    --muted: #9a9aa0;
    --border: #34343a;
    --accent: #6d9cf0;
    --accent-text: #0e1420;
    --today-bg: #233250;
    --dot: #7fa8f4;
    --danger: #e5675a;
  }
}

* { box-sizing: border-box; }

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

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---- Buttons & inputs ---- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { border-color: var(--muted); text-decoration: none; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--accent); padding: 0; min-height: 0; }

input, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label { display: block; font-weight: 500; margin-bottom: 12px; }
label input, label textarea { margin-top: 4px; font-weight: 400; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
}

/* ---- Top bar ---- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); margin-right: 4px; }
.jump { display: flex; gap: 6px; }
.jump input { width: auto; }
.logout { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); }

/* ---- Pager (‹ title ›) ---- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.pager h1 { text-align: center; }
.pager .button { font-size: 1.3rem; width: 44px; padding: 0; }
.badge {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
}

/* ---- Month grid ----
   Each week is a 7-column grid. Day cells span every row as backgrounds;
   events sit on top in rows 2..4 ("lanes"), and "+N more" in row 5. */

.weekdays, .week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  column-gap: 4px;
}
.weekdays { margin-bottom: 4px; }
.weekdays span { text-align: center; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.week {
  grid-template-rows: 28px repeat(3, 20px) 18px;
  row-gap: 2px;
  margin-bottom: 4px;
}

.day {
  grid-row: 1 / -1;
  padding: 4px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.day:hover { border-color: var(--accent); text-decoration: none; }
.day.other { background: transparent; color: var(--muted); }
.day.today { background: var(--today-bg); border-color: var(--accent); }
.day.today .num { color: var(--accent); font-weight: 700; }
.num { font-size: 0.95rem; }

.ev {
  position: relative; /* paint above the day cells */
  min-width: 0;
  margin: 0 5px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 0.78rem;
  line-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.ev:hover { text-decoration: none; filter: brightness(1.1); }
.ev.bar { background: var(--accent); color: var(--accent-text); font-weight: 500; }
/* Continues from last week / into next week: run to the cell edge, square corners. */
.ev.l { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.ev.r { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ev.timed { padding-left: 2px; }
.ev.timed::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--dot);
  vertical-align: 1px;
}
.ev .time { color: var(--muted); }
.ev.timed:hover { background: var(--bg); filter: none; }

.more {
  position: relative;
  padding: 0 10px;
  font-size: 0.75rem;
  line-height: 18px;
  color: var(--muted);
}
.more .short { display: none; }

/* ---- Agenda list (month page) ---- */

.agenda { margin-top: 24px; }
.agenda h2 { margin-bottom: 8px; }
.agenda ul { list-style: none; margin: 0; padding: 0; }
.agenda li a {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.agenda li a:hover { background: var(--surface); text-decoration: none; }
.agenda .date { color: var(--muted); font-variant-numeric: tabular-nums; }
.agenda .title { font-weight: 500; }
.agenda .when { font-size: 0.9rem; text-align: right; }

/* ---- Day view ---- */

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.empty { text-align: center; padding: 32px 0; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.event-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.events p { margin: 6px 0 0; }
.events .when { color: var(--muted); }
.notes { white-space: pre-wrap; }

/* ---- Forms ---- */

.form { max-width: 560px; margin: 0 auto; }
.form h1 { margin-bottom: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.delete { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 16px; text-align: center; }
.login button { width: 100%; margin-top: 4px; }

/* ---- Phones ---- */

@media (max-width: 600px) {
  main { padding: 12px; }
  .topbar { padding: 8px 12px; }
  .who { display: none; }
  .jump { order: 3; width: 100%; }
  .jump input { flex: 1; }
  h1 { font-size: 1.15rem; }
  /* Too narrow for titles: events become thin bars and dots, and taps
     fall through to the day cell. */
  .weekdays, .week { column-gap: 2px; }
  .week { grid-template-rows: 24px repeat(3, 6px) 12px; margin-bottom: 2px; }
  .day { padding: 3px; text-align: center; }
  .ev, .more { pointer-events: none; }
  .ev { align-self: center; height: 4px; margin: 0 3px; padding: 0; font-size: 0; line-height: 0; }
  .ev.timed { justify-self: center; width: 6px; height: 6px; margin: 0; border-radius: 50%; background: var(--dot); }
  .ev.timed::before { display: none; }
  .more { padding: 0; text-align: center; font-size: 0.7rem; line-height: 12px; color: var(--dot); }
  .more .long { display: none; }
  .more .short { display: inline; }
  .agenda li a { grid-template-columns: 4.25rem 1fr; }
  .agenda .when { grid-column: 2; text-align: left; margin-top: -10px; }
  .row { grid-template-columns: 1fr; gap: 0; }
}
