/* =========================================================================
   Family Calendar
   Layout is mobile first. The desktop layout starts at 900px.
   ========================================================================= */

:root {
  --bg:        #f6f8fc;
  --bg-tint:   #eef2fa;
  --card:      #ffffff;
  --ink:       #0f172a;
  --ink-soft:  #334155;
  --muted:     #64748b;
  --line:      #e4e9f2;
  --line-soft: #eef1f7;
  --brand:     #2563eb;
  --brand-dk:  #1d4ed8;
  --brand-lt:  #eff5ff;
  --danger:    #dc2626;
  --ok:        #15803d;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --sh-1: 0 1px 2px rgba(15,23,42,.06);
  --sh-2: 0 2px 4px rgba(15,23,42,.05), 0 8px 20px rgba(15,23,42,.06);
  --sh-3: 0 8px 24px rgba(15,23,42,.10), 0 24px 60px rgba(15,23,42,.14);

  --bar-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
h3 { font-size: 1.15rem; }

a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.error, .ok { padding: .6rem .8rem; border-radius: var(--r-sm); margin: .5rem 0; font-size: .9rem; }
.error { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; }
.ok    { color: #14532d; background: #f0fdf4; border: 1px solid #bbf7d0; }
code { background: var(--bg-tint); padding: .1rem .35rem; border-radius: 4px; font-size: .9em; }

:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  padding: .45rem .9rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--sh-1);
  transition: background .14s, border-color .14s, box-shadow .14s, transform .06s;
}
.btn:hover { background: #f8fafc; border-color: #cfd8e6; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #3b82f6, var(--brand-dk));
  border-color: var(--brand-dk); color: #fff;
  box-shadow: 0 1px 2px rgba(29,78,216,.35), 0 6px 16px rgba(29,78,216,.25);
}
.btn.primary:hover { filter: brightness(1.05); }

.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }

.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn.tiny  { min-height: 30px; padding: .2rem .6rem; font-size: .78rem; }
.btn.block { display: flex; width: 100%; }

/* --------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--bar-h);
  padding: .5rem clamp(.75rem, 3vw, 1.5rem);
  background: rgba(255,255,255,.88);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: .55rem;
  font-weight: 700; letter-spacing: -.015em; font-size: 1.02rem;
  white-space: nowrap;
}
.brand .mark { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto; box-shadow: var(--sh-1); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.brand-text { display: none; }

.tabs { display: flex; gap: .2rem; margin-left: auto; }
.tabs a {
  display: inline-flex; align-items: center;
  padding: .45rem .75rem;
  border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 550; font-size: .9rem;
  white-space: nowrap;
  transition: background .14s, color .14s;
}
.tabs a:hover { background: var(--bg-tint); color: var(--ink); }
.tabs a.on { background: var(--brand-lt); color: var(--brand-dk); }

.who { display: flex; align-items: center; gap: .5rem; }
.who .name { display: none; font-weight: 600; color: var(--ink-soft); font-size: .9rem; }

/* ------------------------------------------------------------------ layout */
.layout {
  display: block;
  padding: clamp(.6rem, 2.5vw, 1.25rem);
  max-width: 1500px;
  margin: 0 auto;
}

.sidebar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: .8rem .9rem;
  margin-bottom: .8rem;
}
.sidebar h2 { margin-bottom: .55rem; }

/* filters: chips on small screens, a list on desktop */
.filters { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.filters li { margin: 0; }
.filters label {
  position: relative;              /* keeps the hidden checkbox inside the chip */
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .4rem .7rem .4rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: .88rem; font-weight: 550; color: var(--muted);
  transition: background .14s, border-color .14s, color .14s, box-shadow .14s;
  user-select: none;
}
.filters label:hover { border-color: #cfd8e6; }
.filters input { position: absolute; opacity: 0; width: 0; height: 0; }
.filters label:has(input:checked) {
  background: var(--brand-lt); border-color: #bfd4ff; color: var(--brand-dk);
}
.filters label:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.filters label .swatch { opacity: .35; transition: opacity .14s, transform .14s; }
.filters label:has(input:checked) .swatch { opacity: 1; transform: scale(1.1); }

.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

.sidebar-actions { display: flex; gap: .4rem; margin-top: .7rem; }
.legend-note { display: none; }

.sidebar .btn.block { margin-top: .7rem; }

.calendar-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: .6rem .6rem .8rem;
  overflow: hidden;
}

/* ------------------------------------------------------- FullCalendar skin */
.fc {
  --fc-border-color: var(--line-soft);
  --fc-today-bg-color: #fff8e7;
  --fc-neutral-bg-color: var(--bg-tint);
  --fc-page-bg-color: #fff;
  font-size: .92rem;
}

.fc .fc-toolbar.fc-header-toolbar {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin-bottom: .7rem; padding: .1rem .2rem;
}
.fc .fc-toolbar-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }

.fc .fc-button {
  background: #fff; border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: 999px; padding: .38rem .8rem; min-height: 38px;
  font-weight: 550; font-size: .86rem; text-transform: none;
  box-shadow: var(--sh-1);
  transition: background .14s, border-color .14s, color .14s;
}
.fc .fc-button:hover { background: #f8fafc; border-color: #cfd8e6; color: var(--ink); }
.fc .fc-button:disabled { opacity: .45; }
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: var(--brand-lt); border-color: #bfd4ff; color: var(--brand-dk);
}
.fc .fc-button:focus, .fc .fc-button:focus-visible { box-shadow: 0 0 0 3px rgba(37,99,235,.25); }

/* prev / next as clear round arrow buttons */
.fc .fc-prev-button, .fc .fc-next-button {
  width: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.fc .fc-icon { font-size: 1.15em; line-height: 1; }

.fc .fc-button-group { gap: .3rem; }
.fc .fc-button-group > .fc-button { border-radius: 999px !important; }

.fc .fc-col-header-cell { background: transparent; border-color: transparent; padding: .5rem 0 .45rem; }
.fc .fc-col-header-cell-cushion {
  color: var(--muted); font-weight: 700; font-size: .74rem;
  text-transform: uppercase; letter-spacing: .06em; text-decoration: none;
}

.fc .fc-daygrid-day-frame { padding: 2px; }
.fc .fc-daygrid-day-number {
  color: var(--ink-soft); font-weight: 600; font-size: .84rem;
  padding: .3rem .45rem; text-decoration: none;
}
.fc .fc-day-other .fc-daygrid-day-number { color: #b4bdcc; font-weight: 500; }
.fc .fc-day-sat, .fc .fc-day-sun { background: #fbfcfe; }

.fc .fc-day-today { background: var(--fc-today-bg-color) !important; }
.fc .fc-day-today .fc-daygrid-day-number {
  background: var(--brand); color: #fff; border-radius: 999px;
  min-width: 26px; text-align: center; margin: .2rem .2rem 0 0;
}

.fc .fc-scrollgrid { border-radius: var(--r); overflow: hidden; }
.fc .fc-scrollgrid-section > * { border-color: var(--line-soft); }

.fc .fc-daygrid-event, .fc .fc-timegrid-event {
  border: none; border-radius: 7px;
  padding: 2px 7px; margin: 1.5px 2px;
  font-size: .8rem; font-weight: 550;
  box-shadow: 0 1px 1px rgba(15,23,42,.10);
  cursor: pointer;
}
.fc .fc-daygrid-event:hover, .fc .fc-timegrid-event:hover { filter: brightness(1.06); }
.fc .fc-event-title { font-weight: 600; }
.fc .fc-event-time { opacity: .85; font-weight: 500; }
.fc .fc-daygrid-block-event .fc-event-title { padding: 0; }
.fc .fc-daygrid-more-link {
  font-size: .76rem; font-weight: 650; color: var(--brand-dk);
  padding: 1px 6px; border-radius: 6px; margin: 0 2px;
}
.fc .fc-daygrid-more-link:hover { background: var(--brand-lt); }

.fc .fc-timegrid-slot { height: 2.4em; }
.fc .fc-timegrid-slot-label-cushion, .fc .fc-timegrid-axis-cushion {
  color: var(--muted); font-size: .76rem; font-weight: 600;
}
.fc .fc-timegrid-now-indicator-line { border-color: #ef4444; border-width: 2px 0 0; }
.fc .fc-timegrid-now-indicator-arrow { border-color: #ef4444; }

.fc .fc-list { border: none; }
.fc .fc-list-day-cushion {
  background: var(--bg-tint); padding: .5rem .8rem;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
}
.fc .fc-list-day-text, .fc .fc-list-day-side-text { color: var(--ink-soft); font-weight: 700; text-decoration: none; }
.fc .fc-list-event { cursor: pointer; }
.fc .fc-list-event:hover td { background: var(--brand-lt); }
.fc .fc-list-event-title a { color: var(--ink); font-weight: 600; text-decoration: none; }
.fc .fc-list-event-time { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.fc .fc-list-event-dot { border-width: 6px; }
.fc .fc-list-table td { padding: .7rem .8rem; border-color: var(--line-soft); }
.fc .fc-list-empty { background: transparent; color: var(--muted); padding: 2.5rem 1rem; }

/* ------------------------------------------------------------------ modals */
.modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { transform: translateY(16px); opacity: .6 } to { transform: none; opacity: 1 } }

.modal-card {
  position: relative;
  background: var(--card);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--sh-3);
  padding: 1.4rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
.modal-card::before {
  content: ""; display: block;
  width: 40px; height: 4px; border-radius: 999px;
  background: #d7dee9;
  margin: -.6rem auto 1rem;
}

.modal-close {
  position: absolute; top: .7rem; right: .7rem;
  width: 34px; height: 34px;
  border: none; background: var(--bg-tint); color: var(--muted);
  border-radius: 50%; font-size: 1.25rem; line-height: 1; cursor: pointer;
  transition: background .14s, color .14s;
}
.modal-close:hover { background: #e2e8f0; color: var(--ink); }

.modal-actions {
  display: flex; gap: .5rem; justify-content: flex-end;
  margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.modal-actions .btn { flex: 1 1 auto; }

.view-person {
  display: inline-flex; align-items: center; gap: .45rem;
  font-size: .78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--bg-tint); padding: .3rem .65rem; border-radius: 999px;
  margin-bottom: .6rem;
}
.view-when { font-weight: 600; color: var(--ink-soft); margin: 0 0 .5rem; }
.view-line { margin: .8rem 0 0; padding-top: .8rem; border-top: 1px solid var(--line-soft); }
.view-line strong { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ------------------------------------------------------------------- forms */
label { display: block; margin: .8rem 0 0; font-weight: 600; font-size: .84rem; color: var(--ink-soft); }
label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 550; }
label.inline input { width: auto; margin: 0; }

input[type=text], input[type=password], input[type=email], input[type=date],
input[type=time], input[type=number], select, textarea {
  width: 100%;
  margin-top: .3rem;
  padding: .6rem .7rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  font: inherit;
  font-weight: 500;
  color: var(--ink);
  transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.16);
}
textarea { min-height: 80px; resize: vertical; }
input[type=color] { padding: .2rem; height: 44px; cursor: pointer; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

/* ------------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line-soft); font-size: .9rem; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-2);
  padding: 1.1rem; margin: 0 0 1rem;
}
.wrap { padding: clamp(.6rem, 2.5vw, 1.25rem); max-width: 900px; margin: 0 auto; }

/* --------------------------------------------------------------- sign in */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100svh; padding: 1.2rem;
  background:
    radial-gradient(900px 500px at 15% -10%, #dbe8ff 0%, transparent 60%),
    radial-gradient(800px 500px at 100% 0%, #e6dcff 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  padding: 2rem 1.5rem 1.7rem;
  width: 100%; max-width: 380px;
  text-align: center;
}
.auth-card .auth-mark {
  width: 62px; height: 62px; border-radius: 17px;
  margin: 0 auto .9rem; display: block; box-shadow: var(--sh-2);
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: .2rem; }
.auth-card > .muted { margin-top: 0; margin-bottom: 1.2rem; }
.auth-card label { text-align: left; }
.auth-card .btn { width: 100%; margin-top: 1.2rem; min-height: 46px; }

/* --------------------------------------------- floating add button, mobile */
.fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 50;
  width: 56px; height: 56px; padding: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #3b82f6, var(--brand-dk));
  color: #fff; font-size: 1.7rem; line-height: 1;
  box-shadow: 0 4px 12px rgba(29,78,216,.35), 0 12px 32px rgba(29,78,216,.28);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s, filter .14s;
}
.fab:hover { filter: brightness(1.06); }
.fab:active { transform: scale(.94); }

/* ============================== small screens ============================ */
@media (max-width: 899px) {
  /* top bar becomes two rows: brand and sign out, then a scrollable tab strip */
  .topbar {
    flex-wrap: wrap;
    gap: .5rem .6rem;
    padding: .45rem .7rem .3rem;
    min-height: 0;
  }
  .who { margin-left: auto; }
  .who .name { display: none; }
  .btn { white-space: nowrap; }

  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
    gap: .15rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .3rem;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: 0 0 auto; padding: .35rem .7rem; font-size: .88rem; }

  /* filters become one swipeable row */
  .sidebar { padding: .6rem .55rem; border-radius: var(--r); }
  .sidebar h2 { margin: 0 0 .45rem .2rem; font-size: .66rem; }
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .2rem;
    scroll-snap-type: x proximity;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filters li { flex: 0 0 auto; scroll-snap-align: start; }
  /* fade the right edge so it is clear the row keeps going */
  .sidebar { position: relative; }
  .sidebar::after {
    content: ""; position: absolute; top: 0; right: 0; bottom: 0;
    width: 28px; pointer-events: none; border-radius: 0 var(--r) var(--r) 0;
    background: linear-gradient(to right, rgba(255,255,255,0), #fff 78%);
  }
  .filters label { padding: .32rem .6rem .32rem .5rem; font-size: .82rem; gap: .35rem; }
  .filters label .swatch { width: 10px; height: 10px; }
  .sidebar-actions { margin-top: .5rem; }
  .sidebar-actions .btn { min-height: 28px; font-size: .74rem; padding: .15rem .55rem; }
  .sidebar .btn.block { display: none; }
  .legend-note { display: none; }

  /* calendar toolbar: month title on its own line, controls beneath */
  .calendar-wrap { padding: .5rem .35rem .6rem; }
  .fc .fc-toolbar.fc-header-toolbar {
    flex-wrap: wrap; gap: .4rem; justify-content: space-between; margin-bottom: .55rem;
  }
  .fc .fc-toolbar-chunk { display: flex; align-items: center; gap: .3rem; }
  .fc .fc-toolbar-chunk:nth-child(2) {
    order: -1; width: 100%; justify-content: center; margin-bottom: .1rem;
  }
  .fc .fc-toolbar-title { font-size: 1.05rem; }
  .fc .fc-button { padding: .35rem .65rem; font-size: .8rem; min-height: 36px; }
  .fc .fc-prev-button, .fc .fc-next-button { width: 36px; }

  .fc .fc-list-table td { padding: .75rem .6rem; }
  .fc .fc-list-event-time { font-size: .8rem; }
  .fc .fc-daygrid-day-number { font-size: .78rem; padding: .2rem .3rem; }
  .fc .fc-daygrid-event { font-size: .72rem; padding: 1px 5px; }
  .fc .fc-col-header-cell-cushion { font-size: .66rem; }
}

@media (max-width: 420px) {
  .tabs a { padding: .32rem .6rem; font-size: .84rem; }
  .brand .mark { width: 28px; height: 28px; }
  .btn.small { padding: .25rem .6rem; font-size: .8rem; min-height: 32px; }
}

/* ============================== large screens ============================ */
@media (min-width: 900px) {
  .brand-text { display: inline; }
  .who .name { display: inline; }

  .layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.1rem;
    align-items: start;
  }

  .sidebar {
    position: sticky;
    top: calc(var(--bar-h) + 1.1rem);
    margin-bottom: 0;
    padding: 1.1rem;
  }
  .filters { flex-direction: column; flex-wrap: nowrap; gap: .25rem; }
  .filters li { width: 100%; }
  .filters label { width: 100%; border-color: transparent; box-shadow: none; padding: .5rem .6rem; }
  .filters label:hover { background: var(--bg-tint); border-color: transparent; }
  .filters label:has(input:checked) { background: var(--brand-lt); border-color: transparent; }
  .legend-note { display: block; margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--line-soft); font-size: .8rem; }

  .calendar-wrap { padding: 1rem 1.1rem 1.2rem; }
  .fc { font-size: .95rem; }
  .fc .fc-toolbar-title { font-size: 1.3rem; }
  .fc .fc-daygrid-day-frame { min-height: 108px; }

  .fab { display: none; }

  .modal { align-items: center; padding: 1.5rem; }
  .modal-card {
    max-width: 520px;
    border-radius: var(--r-xl);
    padding: 1.6rem 1.6rem 1.3rem;
    max-height: 86vh;
  }
  .modal-card::before { display: none; }
  .modal-actions .btn { flex: 0 0 auto; }
}

@media (min-width: 1280px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); }
  .fc .fc-daygrid-day-frame { min-height: 124px; }
}

/* ------------------------------------------------------------ preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

@media print {
  .topbar, .sidebar, .fab, .fc .fc-header-toolbar { display: none !important; }
  body { background: #fff; }
  .calendar-wrap { box-shadow: none; border: none; }
}
