:root {
  --brand: #4f63a8;
  --brand-dark: #3c4d88;
  --weekday: #879ad4;      /* old calendar header colour */
  --page: #e7e9f5;         /* old "emptyday" */
  --cell: #f6f7fc;
  --busy: #d9dfef;         /* old "busyday" */
  --fill: #d5d7df;         /* old "fillday", softened */
  --ink: #1b2240;
  --muted: #5d6585;
  --line: #c9cee3;
  --danger: #c62828;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); }
body { overscroll-behavior-y: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand); color: #fff;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  display: flex; align-items: center; gap: 4px;
}
.top .title {
  position: relative; flex: 1; text-align: center;
  font-size: 18px; font-weight: 650; letter-spacing: .2px;
  background: none; border: 0; color: #fff; padding: 8px 4px; border-radius: 8px;
}
.top .title small { font-weight: 400; opacity: .8; margin-left: 4px; }
.top .title input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.iconbtn {
  background: none; border: 0; color: inherit; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 10px; flex: none;
}
.iconbtn:hover, .top .title:hover { background: rgba(255,255,255,.12); }
.iconbtn svg { width: 22px; height: 22px; }
.todaybtn {
  background: rgba(255,255,255,.16); border: 0; color: #fff; border-radius: 8px;
  padding: 7px 10px; font-size: 14px; font-weight: 600; flex: none;
}

.legend {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); padding: 5px 8px;
}
.legend { gap: 6px; padding: 3px 8px; }
.who {
  background: none; border: 0; border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
  display: inline-flex; align-items: center;
}
.who:hover { background: rgba(79,99,168,.1); }
.who b { font-weight: 650; }
.who.off .swatch { background: transparent !important; outline: 2px solid #b4b9cc; outline-offset: -2px; }
.who.off b { color: #9aa0b8 !important; text-decoration: line-through; }

/* ---------- Month grid ---------- */
.grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px;
  padding: 0 2px calc(var(--safe-bottom) + 2px);
  touch-action: pan-y;
}
.dow {
  background: var(--weekday); color: var(--ink); text-align: center;
  font-size: 12px; font-weight: 650; padding: 5px 0; text-transform: uppercase; letter-spacing: .5px;
}
.day {
  position: relative; background: var(--cell); border: 0; padding: 0; text-align: left;
  min-height: var(--rowh, 88px); display: flex; flex-direction: column; overflow: hidden;
  border-radius: 3px;
}
.day.busy { background: var(--busy); }
.day.out { background: var(--fill); }
.day.out > * { opacity: .55; }
.day:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.day .band { position: absolute; top: 0; height: 22px; width: 38%; }
.day .band.left { left: 0; }
.day .band.right { right: 0; width: 62%; }
.day .num {
  position: relative; font-size: 13px; font-weight: 650; padding: 3px 5px 2px; line-height: 16px;
}
.day.full .num { color: #fff; }
/* Text straight on red/orange: a soft white glow keeps the blue/green readable. */
.day.full .chip { text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff, 0 0 4px #fff; }

/* Today: white, keeping a coloured frame if it's a kids/Emily day. */
.day.today { background: #fff !important; box-shadow: inset 0 0 0 3px var(--rule, var(--brand)); }
.day.today.full .num { color: var(--ink); }
.day.today.full .chip { text-shadow: none; }
.day.today.full .more { color: var(--muted); }
.day.today .num span {
  background: var(--ink); color: #fff; border-radius: 999px; padding: 1px 6px; margin-left: -2px;
}
.chips { position: relative; display: flex; flex-direction: column; gap: 1px; padding: 2px 3px 3px; }
.chip {
  font-size: 10.5px; line-height: 1.3; font-weight: 650;
  background: none; padding: 0 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.more { font-size: 10px; color: var(--muted); padding: 0 3px; font-weight: 600; }
.day.full .more { color: #fff; }

@media (min-width: 720px) {
  .grid { gap: 3px; padding: 0 10px 12px; }
  .chip { font-size: 13px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .day .num { font-size: 15px; padding: 4px 7px; }
  .day .band { height: 25px; }
  .top { padding-left: 16px; padding-right: 16px; }
  .top .title { font-size: 20px; }
}

/* ---------- Sheets (bottom on phone, centred on desktop) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 20; background: rgba(20,24,45,.38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(var(--safe-bottom) + 18px);
  animation: up .2s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
}
@media (min-width: 720px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 16px; padding-bottom: 18px; }
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #d4d7e3; margin: 2px auto 8px; }
.sheet h2 { font-size: 19px; margin: 4px 0 2px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.sheet-head { display: flex; align-items: flex-start; gap: 8px; }
.sheet-head > div { flex: 1; }
.sheet-head .iconbtn { color: var(--muted); }

.daycolour { height: 6px; border-radius: 3px; margin: 0 0 12px; }

.evlist { list-style: none; margin: 0 0 14px; padding: 0; }
.ev {
  display: block; width: 100%; text-align: left; background: #f6f7fc; border: 1px solid #e6e8f2;
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
}
.ev:hover { border-color: var(--line); }
.evrow { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.evrow .ev { flex: 1; min-width: 0; margin-bottom: 0; }
.bin {
  flex: none; min-width: 48px; border: 1px solid #e6e8f2; background: #f6f7fc; color: var(--muted);
  border-radius: var(--radius); display: grid; place-items: center; padding: 0 10px;
  font-size: 14px; font-weight: 650; transition: background .15s, color .15s;
}
.bin svg { width: 20px; height: 20px; }
.bin:hover { color: var(--danger); border-color: #f3c4c4; }
.bin.armed { background: var(--danger); border-color: var(--danger); color: #fff; max-width: 110px; line-height: 1.2; }
.ev .t { font-size: 16px; font-weight: 600; white-space: pre-line; overflow-wrap: anywhere; }
.ev .m { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ev .m svg { width: 13px; height: 13px; vertical-align: -2px; }
.ev .date { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 14px 0 18px; }

.btn {
  border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 650; font-size: 16px;
  background: var(--brand); color: #fff; width: 100%;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #eceef7; color: var(--ink); }
.btn.danger { background: none; color: var(--danger); }
.btn:disabled { opacity: .6; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

label.f { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 12px 0 6px; }
textarea, input[type=text], input[type=password], input[type=date], input[type=search] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font-size: 16px; background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
textarea:focus, input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }

.seg { display: flex; background: #eceef7; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: 8px; padding: 9px 4px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed=true] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.formfoot { margin-top: 18px; display: grid; gap: 8px; }

.menu { display: grid; gap: 8px; }
.card { background: #f6f7fc; border-radius: var(--radius); padding: 12px 14px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.card .btn { font-size: 15px; padding: 10px 14px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.rules { list-style: none; padding: 0; margin: 0; font-size: 14px; display: grid; gap: 6px; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(180deg, var(--brand) 0 38%, var(--page) 38%);
}
.login form { background: #fff; border-radius: 18px; padding: 24px 20px; width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(30,40,80,.18); }
.login img { width: 64px; height: 64px; border-radius: 14px; display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 6px; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; text-align: center; }
.login .btn { margin-top: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 50;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.loading { opacity: .65; transition: opacity .15s; }
