/* WestCal styles. Mobile first; works on a desktop browser too. */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1a202c;
  --muted: #5a6577;
  --line: #e2e6ea;
  --accent: #1e3a5f;
  --accent-text: #ffffff;
  --danger: #c53030;
  --focus: #3182ce;
  --sheet-radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* FullCalendar hooks */
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: #f1f3f6;
  --fc-today-bg-color: #fff7e0;
  --fc-now-indicator-color: #e53e3e;
  --fc-list-event-hover-bg-color: #f1f3f6;
  --fc-event-text-color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d26;
    --text: #e6e9ee;
    --muted: #9aa5b5;
    --line: #2a3340;
    --accent: #2f5f94;
    --fc-neutral-bg-color: #1e2631;
    --fc-today-bg-color: #2a2a1c;
    --fc-list-event-hover-bg-color: #1e2631;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 20rem; display: flex; flex-direction: column; gap: .75rem; text-align: center; }
.login-card h1 { margin: 0 0 .5rem; font-size: 1.6rem; }
.login-logo { margin: 0 auto; border-radius: 16px; }

/* ---------- Layout ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .25rem;
  padding: calc(.4rem + var(--safe-top)) .5rem .4rem;
  background: var(--accent); color: var(--accent-text);
}
.topbar-center { flex: 1; display: flex; align-items: center; justify-content: center; gap: .25rem; min-width: 0; }
.cal-title { margin: 0; font-size: 1.05rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: none; border: 0; width: 2.5rem; height: 2.5rem; border-radius: 50%;
  font-size: 1.5rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.text-btn { background: rgba(255,255,255,.15); border: 0; border-radius: 999px; padding: .4rem .8rem; font-size: .9rem; cursor: pointer; }

.subbar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .45rem .6rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.legend { display: flex; gap: .6rem; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.legend-dot { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; }

.calendar { flex: 1; min-height: 0; background: var(--surface); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--bg); }
.segmented button {
  border: 0; background: none; padding: .4rem .8rem; font-size: .85rem; cursor: pointer; color: var(--muted);
}
.segmented button.is-active { background: var(--accent); color: #fff; }
.segmented--views button { padding: .35rem .7rem; }
/* "Who" picker in the form: colored per person */
.form-body .segmented { display: flex; width: 100%; }
.form-body .segmented button { flex: 1; padding: .55rem .4rem; }
.form-body .segmented button.is-active { background: var(--seg-color, var(--accent)); color: #fff; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 1rem; bottom: calc(1rem + var(--safe-bottom));
  width: 3.5rem; height: 3.5rem; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,.25); cursor: pointer; z-index: 20;
}
.fab:active { transform: scale(.96); }

/* ---------- Buttons and inputs ---------- */
.btn {
  border: 0; border-radius: 10px; padding: .7rem 1rem; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: none; color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; }
.btn-small { padding: .4rem .8rem; font-size: .9rem; }
.btn:disabled { opacity: .6; }
.btn-row { display: flex; gap: .6rem; margin-top: 1rem; }
.btn-row .btn { flex: 1; }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 1rem; padding: .5rem; cursor: pointer; }
.link-btn--strong { font-weight: 700; }
@media (prefers-color-scheme: dark) { .link-btn { color: #8ab4f8; } }

.input {
  width: 100%; padding: .6rem .7rem; font-size: 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.input--title { font-size: 1.15rem; font-weight: 600; }
.input--num { width: 4.5rem; text-align: center; }
textarea.input { resize: vertical; }
select.input { appearance: auto; }
.field { margin-top: .9rem; }
.field-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
.field-error { color: var(--danger); font-size: .9rem; margin: .4rem 0 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.pre { white-space: pre-wrap; }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30;
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 88%; overflow-y: auto;
  background: var(--surface); color: var(--text);
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  transform: translateY(105%); transition: transform .22s ease-out; z-index: 31;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -4px 24px rgba(0,0,0,.2);
}
.sheet.is-open { transform: translateY(0); }
.sheet--full { top: 0; max-height: none; border-radius: 0; padding-top: var(--safe-top); }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; width: 32rem; transform: translate(-50%, 105%); }
  .sheet.is-open { transform: translate(-50%, 0); }
  .sheet--full { top: 4vh; bottom: 4vh; border-radius: var(--sheet-radius); }
}
.sheet-body { padding: 1rem 1rem 1.25rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.sheet-title { margin: .25rem 0 .75rem; font-size: 1.1rem; }
.sheet-head .sheet-title { margin: 0; }
.confirm-msg { margin: .5rem 0 0; font-size: 1.05rem; }

.choice-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .75rem; }
.choice {
  text-align: left; padding: .8rem .9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 1rem; cursor: pointer;
}
.choice:active { background: var(--line); }
.choice--danger { color: var(--danger); }

/* Day sheet */
.day-list { display: flex; flex-direction: column; }
.day-item {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--line); padding: .7rem .2rem; cursor: pointer;
}
.day-item:first-child { border-top: 0; }
.day-dot { width: .8rem; height: .8rem; border-radius: 50%; flex: none; }
.day-dot--big { width: 1rem; height: 1rem; }
.day-item-main { display: flex; flex-direction: column; min-width: 0; }
.day-item-title { font-weight: 600; }
.day-item-sub { font-size: .85rem; color: var(--muted); }

/* Detail sheet */
.detail-head { display: flex; align-items: center; gap: .6rem; }
.detail-title { margin: 0; font-size: 1.25rem; }
.detail-when { margin: .4rem 0 .9rem; color: var(--muted); }
.detail-list { margin: 0; }
.detail-list > div { display: grid; grid-template-columns: 5rem 1fr; gap: .5rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.detail-list dt { color: var(--muted); font-size: .85rem; padding-top: .1rem; }
.detail-list dd { margin: 0; }

/* ---------- Event form ---------- */
.form-header {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: .3rem .5rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.form-header h2 { margin: 0; font-size: 1.05rem; }
.form-body { padding: 1rem; }
.form-note { margin: 0 0 .8rem; padding: .6rem .8rem; background: var(--fc-neutral-bg-color); border-radius: 10px; font-size: .9rem; color: var(--muted); }
.form-spacer { height: 3rem; }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin: .9rem 0 .5rem; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { width: 2.8rem; height: 1.6rem; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: .15rem; left: .15rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(1.2rem); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--focus); }
.dt-row { display: grid; grid-template-columns: 3.4rem 1fr auto; gap: .5rem; align-items: center; margin-top: .5rem; }
.dt-label { font-size: .9rem; color: var(--muted); }
.dt-time { width: auto; min-width: 8.6rem; }
.inline-row { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.inline-row select.input { width: auto; }
.inline-row input[type=date].input { width: auto; }
.count-wrap { display: inline-flex; align-items: center; gap: .4rem; }
.repeat-opts { margin-top: .5rem; padding: .6rem .8rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.day-chips { display: flex; gap: .35rem; margin-top: .6rem; }
.chip {
  flex: 1; height: 2.3rem; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
}
.chip.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.radio-col { display: flex; flex-direction: column; gap: .4rem; margin-top: .6rem; }
.repeat-summary { margin: .7rem 0 0; font-size: .9rem; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(4.6rem + var(--safe-top)); transform: translate(-50%, -20px);
  background: #2d3748; color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: 90%; text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); }

/* ---------- FullCalendar tweaks ---------- */
.fc { --fc-small-font-size: .78rem; }
.fc .fc-daygrid-day-number { padding: .2rem .35rem; font-size: .85rem; }
.fc .fc-day-today .fc-daygrid-day-number { background: var(--accent); color: #fff; border-radius: 50%; min-width: 1.5rem; text-align: center; margin: .15rem; }
.fc .fc-col-header-cell-cushion { padding: .35rem 0; font-size: .8rem; color: var(--muted); font-weight: 600; }
.fc .fc-daygrid-event { border-radius: 4px; padding: 0 .25rem; margin: 1px 2px 0; font-size: .74rem; line-height: 1.35; }
.fc .fc-daygrid-event-harness { margin-top: 0; }
.fc .fc-daygrid-more-link { font-size: .72rem; color: var(--muted); }
.fc .fc-timegrid-event { border-radius: 4px; }
.fc .fc-timegrid-slot-label-cushion { font-size: .72rem; color: var(--muted); }
.fc .fc-timegrid-axis-cushion { font-size: .7rem; }
.fc .fc-list { border: 0; }
.fc .fc-list-day-cushion { background: var(--fc-neutral-bg-color); font-size: .85rem; }
.fc .fc-list-event-time { display: none; }
.fc .fc-list-event td { padding: .55rem .6rem; }
.fc .fc-list-event-dot { border-width: 6px; }
.fc .fc-list-empty { background: var(--surface); color: var(--muted); }
.fc a { color: inherit; text-decoration: none; }
.fc .fc-event { cursor: pointer; }
.wc-ev { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wc-ev--week { white-space: normal; font-size: .74rem; line-height: 1.2; padding: .1rem .2rem; }
.wc-ev--week .wc-ev-title { font-weight: 600; }
.wc-ev-time { opacity: .9; font-size: .68rem; }
.fc .fc-daygrid-block-event .fc-event-main { padding: 0; }
.wc-repeat { font-size: .8em; opacity: .8; }
.wc-li-time { font-size: .85rem; color: var(--muted); }
.wc-li-title { font-weight: 600; }
.wc-li-meta { font-size: .85rem; color: var(--muted); }
.fc-daygrid-dot-event .fc-event-title { display: none; } /* we render our own */
