/* Calendar — single stylesheet, no framework, no build step. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --line: #dfe3ea;
  --line-soft: #ebeef3;
  --text: #1c2333;
  --text-dim: #667085;
  --accent: #3b6ef2;
  --accent-fg: #ffffff;
  --danger: #d0342c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 8px;
  --topbar-h: 54px;
  --gutter-w: 56px;
  --hour-h: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1b1e25;
    --surface-2: #23272f;
    --line: #313742;
    --line-soft: #272c35;
    --text: #e6e9ef;
    --text-dim: #99a1b3;
    --accent: #5b8bff;
    --accent-fg: #0d1017;
    --danger: #ff6b61;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

button { font: inherit; color: inherit; }

a { color: var(--accent); }

/* ---------------------------------------------------------------- auth pages */

body.auth {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 24rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.auth-brand { margin: 0 0 .25rem; font-size: 1.35rem; letter-spacing: -.01em; }
.auth-sub { margin: 0 0 1.25rem; color: var(--text-dim); }
.auth-foot { margin: 1.25rem 0 0; color: var(--text-dim); text-align: center; }
.hint { color: var(--text-dim); font-weight: 400; font-size: .85em; }

.auth-card label,
.field label {
  display: block;
  margin: .9rem 0 .3rem;
  font-weight: 600;
  font-size: .82rem;
}

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea { resize: vertical; min-height: 4.5rem; }

.btn, .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover, .btn-primary:hover { filter: brightness(.97); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-fg);
  font-weight: 600;
}

.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 1.4rem; padding: .6rem; }

.btn-quiet { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-quiet:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.full { width: 100%; justify-content: center; }

.alert {
  margin: 0 0 1rem;
  padding: .6rem .75rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: .9rem;
}

/* ------------------------------------------------------------------ app shell */

body.app { overflow: hidden; }

#shell { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  height: var(--topbar-h);
  flex: 0 0 auto;
  padding: 0 .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.spacer { flex: 1; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  color: var(--text-dim);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.nav-group { display: flex; align-items: center; gap: .15rem; }

/* The refresh control spins only while a fetch is in flight. Deliberately
   understated: background polling shouldn't draw the eye, and a refresh that
   finds nothing new should look like nothing happened. */
#refreshBtn.busy svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.period-title {
  margin: 0 .35rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.view-switch {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 2px;
}

.view-switch button {
  border: 0;
  background: transparent;
  padding: .3rem .65rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
}

.view-switch button[aria-selected=true] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
}

.account { position: relative; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  font-size: .78rem;
  cursor: pointer;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + .4rem);
  min-width: 13rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: .3rem;
  z-index: 40;
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: .45rem .6rem;
  border-radius: 6px;
  cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu form { margin: 0; }
.menu-head {
  padding: .5rem .6rem .6rem;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: .3rem;
  display: grid;
}
.menu-head span { color: var(--text-dim); font-size: .82rem; }

.body { display: flex; flex: 1; min-height: 0; }

/* --------------------------------------------------------------------- sidebar */

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: .75rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mini-cal { margin-bottom: .85rem; }

.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .35rem;
  font-weight: 600;
  font-size: .85rem;
}
.mini-head button { border: 0; background: transparent; cursor: pointer; color: var(--text-dim); padding: 2px 5px; border-radius: 5px; }
.mini-head button:hover { background: var(--surface-2); }

.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mini-grid .dow { text-align: center; font-size: .66rem; color: var(--text-dim); padding: 2px 0; }
.mini-grid button {
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  border-radius: 50%;
  font-size: .74rem;
  cursor: pointer;
  color: var(--text);
  padding: 0;
}
.mini-grid button:hover { background: var(--surface-2); }
.mini-grid button.other { color: var(--text-dim); opacity: .55; }
.mini-grid button.today { color: var(--accent); font-weight: 700; }
.mini-grid button.sel { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

.cal-group { margin: .9rem 0 .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }

.cal-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .35rem;
  border-radius: 6px;
  cursor: pointer;
}
.cal-item:hover { background: var(--surface-2); }
.cal-item .swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex: 0 0 14px;
  border: 1px solid rgba(0, 0, 0, .12);
}
.cal-item.off .swatch { background: transparent !important; }
.cal-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item.off .label { color: var(--text-dim); }
.cal-item .cog { opacity: 0; border: 0; background: transparent; cursor: pointer; color: var(--text-dim); padding: 0 2px; }
.cal-item:hover .cog, .cal-item .cog:focus-visible { opacity: 1; }
.cal-item .cog svg { width: 15px; height: 15px; }

/* ----------------------------------------------------------------- view canvas */

.view { flex: 1; min-width: 0; overflow: auto; overscroll-behavior: contain; position: relative; }

/* Month */

.month {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 30rem;
}

.month-dow, .week-dow {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 3;
}

.month-dow div {
  padding: .35rem .5rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: center;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(5.5rem, 1fr);
}

.day-cell {
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  padding: 2px 3px 4px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  cursor: pointer;
}
.day-cell:nth-child(7n) { border-right: 0; }
.day-cell.other { background: var(--bg); }
.day-cell.weekend:not(.other) { background: color-mix(in srgb, var(--bg) 45%, var(--surface)); }
.day-cell.drop-target { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

.day-num {
  align-self: flex-end;
  font-size: .74rem;
  color: var(--text-dim);
  padding: 1px 4px;
  border-radius: 999px;
  line-height: 1.4;
}
.day-cell.today .day-num { background: var(--accent); color: var(--accent-fg); font-weight: 700; }

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .76rem;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border-left: 3px solid transparent;
}
.chip:hover { background: var(--surface-2); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.chip .t { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.chip .n { overflow: hidden; text-overflow: ellipsis; }
.chip.block { color: #fff; padding-left: 5px; }
.chip.block .t { color: rgba(255, 255, 255, .82); }
.chip.block:hover { filter: brightness(1.08); }
.chip.dragging { opacity: .45; }
.chip.cancelled { text-decoration: line-through; opacity: .6; }

.more-link { font-size: .72rem; color: var(--text-dim); padding: 0 4px; background: none; border: 0; cursor: pointer; text-align: left; }
.more-link:hover { color: var(--accent); }

/* Week / day */

.timegrid { display: grid; grid-template-rows: auto auto 1fr; height: 100%; }

.week-dow {
  grid-template-columns: var(--gutter-w) repeat(var(--cols, 7), minmax(0, 1fr));
}
.week-dow .dow-cell { padding: .35rem .25rem .4rem; text-align: center; border-left: 1px solid var(--line-soft); }
.week-dow .dow-name { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.week-dow .dow-num { font-size: 1.05rem; font-weight: 600; line-height: 1.3; }
.week-dow .dow-cell.today .dow-num {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
  display: inline-block;
  min-width: 1.7rem;
  padding: 0 .3rem;
}

.allday-row {
  display: grid;
  grid-template-columns: var(--gutter-w) repeat(var(--cols, 7), minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 1.6rem;
}
.allday-row .gutter-label { font-size: .66rem; color: var(--text-dim); padding: .3rem .4rem; text-align: right; }
.allday-row .allday-cell { border-left: 1px solid var(--line-soft); padding: 2px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.timegrid-scroll { overflow: auto; position: relative; }

.timegrid-inner {
  display: grid;
  grid-template-columns: var(--gutter-w) repeat(var(--cols, 7), minmax(0, 1fr));
  position: relative;
}

.hour-gutter { position: relative; }
.hour-gutter .hour-label {
  height: var(--hour-h);
  font-size: .68rem;
  color: var(--text-dim);
  text-align: right;
  padding-right: .4rem;
  transform: translateY(-.5em);
  font-variant-numeric: tabular-nums;
}

.day-col {
  position: relative;
  border-left: 1px solid var(--line-soft);
  min-width: 0;
}
.day-col.today { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.hour-line { height: var(--hour-h); border-bottom: 1px solid var(--line-soft); }
.hour-line.half { border-bottom-style: dotted; }

.tevent {
  position: absolute;
  left: 1px;
  right: 1px;
  border-radius: 5px;
  padding: 2px 5px;
  overflow: hidden;
  font-size: .74rem;
  color: #fff;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .25);
  line-height: 1.25;
}
.tevent:hover { filter: brightness(1.08); z-index: 5; }
.tevent .tt { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tevent .th { opacity: .85; font-size: .7rem; }
.tevent.short { padding-top: 0; font-size: .7rem; }
.tevent.short .tt { display: inline; }
.tevent.short .th { display: none; }

.nowline { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--danger); z-index: 6; pointer-events: none; }
.nowline::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* Agenda */

.agenda { padding: .75rem 1rem 3rem; max-width: 46rem; }
.agenda-day { display: grid; grid-template-columns: 5.5rem 1fr; gap: .75rem; padding: .55rem 0; border-top: 1px solid var(--line-soft); }
.agenda-day:first-child { border-top: 0; }
.agenda-date { color: var(--text-dim); font-size: .8rem; padding-top: .2rem; }
.agenda-date strong { display: block; color: var(--text); font-size: 1.2rem; font-weight: 600; }
.agenda-date.today strong { color: var(--accent); }
.agenda-items { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.agenda-item { display: flex; gap: .55rem; align-items: baseline; padding: .3rem .4rem; border-radius: 6px; cursor: pointer; }
.agenda-item:hover { background: var(--surface-2); }
.agenda-item .when { color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .82rem; }
.agenda-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; align-self: center; }
.agenda-item .what { flex: 1; min-width: 0; }
.agenda-item .where { color: var(--text-dim); font-size: .82rem; }

.empty { color: var(--text-dim); padding: 3rem 1rem; text-align: center; }

/* -------------------------------------------------------------------- modals */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 30rem;
  max-height: 90dvh;
  overflow-y: auto;
  border: 1px solid var(--line);
}
.modal.wide { max-width: 44rem; }

.modal header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal header h2 { margin: 0; font-size: 1.02rem; flex: 1; }
.modal .content { padding: 1rem; }
.modal footer {
  display: flex;
  gap: .5rem;
  padding: .85rem 1rem;
  border-top: 1px solid var(--line-soft);
  position: sticky;
  bottom: 0;
  background: var(--surface);
}
.modal footer .grow { flex: 1; }

.field { margin-bottom: .25rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 8rem; }

.check { display: flex; align-items: center; gap: .45rem; margin: .8rem 0 0; font-size: .88rem; }
.check input { width: auto; }

.tabs { display: flex; gap: .25rem; padding: 0 1rem; border-bottom: 1px solid var(--line-soft); }
.tabs button {
  border: 0;
  background: transparent;
  padding: .55rem .7rem;
  cursor: pointer;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button[aria-selected=true] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .1rem;
  border-top: 1px solid var(--line-soft);
}
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow small { display: block; color: var(--text-dim); }
.list-row select { width: auto; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--surface-2);
  border-radius: 999px;
  padding: .1rem .5rem;
  font-size: .78rem;
}
.pill button { border: 0; background: transparent; cursor: pointer; color: var(--text-dim); padding: 0; line-height: 1; }

.swatches { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button[aria-pressed=true] { border-color: var(--text); }

.detail-line { display: flex; gap: .55rem; align-items: flex-start; margin: .55rem 0; color: var(--text-dim); }
.detail-line svg { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; }
.detail-line .v { color: var(--text); white-space: pre-wrap; word-break: break-word; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: .5rem .9rem;
  border-radius: 999px;
  z-index: 80;
  box-shadow: var(--shadow);
  font-size: .88rem;
}
.toast.err { background: var(--danger); color: #fff; }

.copyfield { display: flex; gap: .4rem; margin-top: .5rem; }
.copyfield input { font-size: .8rem; }

/* -------------------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .16s ease-out;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(16, 24, 40, .35);
    z-index: 20;
  }
  .menu-toggle { display: grid; }
  .period-title { font-size: .95rem; }
  .view-switch button { padding: .3rem .45rem; font-size: .8rem; }
  #newEventBtn .plus { display: none; }
}

@media (min-width: 861px) {
  .menu-toggle { display: none; }
}

@media (max-width: 620px) {
  .view-switch [data-view=agenda], .view-switch [data-view=day] { display: none; }
  .period-title { display: none; }
  .agenda-day { grid-template-columns: 4rem 1fr; }

  /* A month cell is only ~50px wide here. There is room for one of the two,
     and "Standup" tells you more than "11am" does. */
  .chip .t { display: none; }
  .chip { font-size: .7rem; }

  /* Everything in the top bar has to fit on the narrowest phone without the
     avatar sliding off the end, so tighten it up rather than let it overflow. */
  .topbar { padding: 0 .4rem; gap: .25rem; }
  .topbar > * { min-width: 0; }
  .btn, .btn-primary { padding: .45rem .5rem; }
  .icon-btn { width: 28px; height: 28px; }
  .icon-btn svg { width: 18px; height: 18px; }
  .view-switch button { padding: .3rem .4rem; font-size: .78rem; }
}

/* Small phones, down to 320px. Today / prev / next / refresh / view switch /
   new-event / avatar all have to fit, so new-event drops back to a bare "+".
   It keeps its aria-label, so nothing is lost to a screen reader. */
@media (max-width: 430px) {
  #newEventBtn .plus { display: inline; font-size: 1.15rem; line-height: 1; }
  #newEventBtn .label { display: none; }
  .topbar { gap: .15rem; }
  #todayBtn { padding: .45rem .4rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
