/* cal — light theme + calendar grid styles ported from whenfit (phone-verified
   there). Mobile-first; verify 390px + 360px. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #e9edf1;
  --text: #1a2129;
  --text-dim: #647385;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --danger: #d64550;
  --border: #dfe4ea;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app { height: 100%; }

/* App shell: fixed viewport height, panes scroll internally. Document scroll +
   sticky topbar got the bar pinned under the Android status bar (clipped tabs). */
.view {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* display:flex would otherwise override the hidden attribute */
.view[hidden] { display: none; }
[hidden] { display: none !important; }

.boot-splash {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Login ---------- */
#view-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 360px;
  margin: auto; /* centers, and unlike flex centering doesn't clip when taller than the viewport */
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.logo {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.logo span { color: var(--accent); }
.logo-small { font-size: 1.15rem; }

.tagline {
  color: var(--text-dim);
  margin: 0 0 8px;
  line-height: 1.5;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost {
  background: none;
  color: var(--text-dim);
  padding: 8px 10px;
  min-height: 0;
  font-size: 0.85rem;
}
.btn-gear { font-size: 1.1rem; padding: 6px 10px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--surface-2);
}

.guest-form { display: flex; flex-direction: column; gap: 10px; }

input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 14px;
  font-size: 1rem;
  min-height: 48px;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.note { color: var(--text-dim); font-size: 0.8rem; min-height: 1em; }

/* ---------- Topbar ---------- */
.topbar {
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
}
.topbar .logo {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.tab-bar { display: flex; gap: 2px; }
.tab {
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); }

/* ---------- calendar nav row ---------- */
.mycal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
}
.mycal-label { font-weight: 600; color: var(--text); font-size: 0.95rem; flex: 1; text-align: center; }
.mycal-today { color: var(--accent); font-weight: 600; }
.mycal-nav .btn { font-size: 1.15rem; padding: 4px 14px; }

/* ---------- calendar legend + overlap switcher ---------- */
.mycal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 6px 12px;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  font-size: 0.75rem;
  color: var(--text-dim);
}
.legend-chip { display: inline-flex; align-items: center; gap: 5px; }
.cal-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.overlap-seg {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  font-size: 0.75rem;
  color: var(--text-dim);
}
.seg-label { margin-right: 2px; }
.seg-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.seg-chip.active { background: var(--surface-2); color: var(--text); border-color: var(--text-dim); }
.seg-row { display: flex; gap: 6px; }

/* ---------- Week grid ---------- */
.week-pane {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 8px 24px;
}
.week-grid {
  display: grid;
  /* minmax(0,1fr): a 44px column floor overflowed the pane on 360px-wide phones
     (34+7*44+14 gaps+16 pane padding = 372px) causing a slight sideways pan */
  grid-template-columns: 34px repeat(7, minmax(0, 1fr));
  gap: 2px;
  max-width: 680px;
  margin: 0 auto;
}
.wg-corner { }
/* The container splits into a sticky head grid + body grid (paintWeek) — a
   sticky grid ITEM can only stick within its own row, so the head must be a
   sibling grid, not a grid row. Both inherit .week-grid's column template. */
.week-grid.week-wrap { display: block; }
.week-wrap .wg-headgrid {
  position: sticky;
  /* -10px = .week-pane's padding-top: sticky pins at the pane's CONTENT edge,
     which would leave a 10px strip of scrolling events peeking above the
     header — pull it up flush with the pane's border edge instead. */
  top: -10px;
  z-index: 6; /* above stacked event blocks (lane z-index reaches ~4) */
  background: var(--bg);
  padding-bottom: 2px;
}
.wg-dayhead {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 4px 0;
  background: var(--bg);
}
.wg-dayhead.today { color: var(--accent); font-weight: 700; }
.wg-dayhead.tappable { cursor: pointer; }
.wg-dayhead.tappable:active { color: var(--accent); }
.wg-hours { position: relative; }
.wg-hourlabel {
  position: absolute;
  right: 4px;
  font-size: 0.62rem;
  color: var(--text-dim);
  transform: translateY(-50%);
}
.wg-daycol {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.wg-block {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 5px;
  font-size: 0.6rem;
  overflow: hidden;
  padding: 2px 4px;
  line-height: 1.2;
  box-shadow: 0 0 0 1px var(--bg); /* hairline gap so adjacent events separate */
  cursor: pointer;
}
.wg-blocktime { display: block; font-size: 0.55rem; opacity: 0.7; font-weight: 600; }
.wg-hourline { position: absolute; left: 0; right: 0; height: 1px; background: rgba(0,0,0,0.05); }

.wg-cal {
  background: var(--accent-soft);
  color: var(--text);
  border-left: 3px solid var(--accent);
  font-weight: 500;
}
.wg-allday {
  min-height: 22px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 1px;
  background: var(--bg);
}
.wg-allday-chip {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 4px;
  font-size: 0.58rem;
  padding: 1px 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* extra per-calendar bar on deduped multi-calendar events */
.wg-dupbar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
}
.pop-copies {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.pop-copies .seg-chip { display: inline-flex; align-items: center; gap: 5px; }
.pop-copies .seg-chip.active { border-color: var(--accent); color: var(--text); }

.wg-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--text-dim);
  color: #fff;
  border-radius: 8px;
  padding: 1px 5px;
  font-size: 0.58rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 3;
}

/* ---------- day view ---------- */
.week-grid.day-grid { grid-template-columns: 44px 1fr; }
.wg-dayblock { font-size: 0.78rem; padding: 4px 6px; }
.wg-dayblock .wg-blocktime { font-size: 0.66rem; }

/* ---------- month view ---------- */
.week-grid.month-grid {
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.mg-wd {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-dim);
  padding: 4px 0 2px;
  position: sticky;
  top: 0;
  background: var(--bg);
}
.mg-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 86px;
  padding: 2px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mg-cell:active { border-color: var(--accent); }
.mg-out { opacity: 0.45; }
.mg-num {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}
.mg-today { border-color: var(--accent); }
.mg-today .mg-num {
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  margin: 0 auto;
  line-height: 20px;
}
.mg-chip {
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  color: var(--text);
  border-radius: 3px;
  font-size: 0.55rem;
  line-height: 1.35;
  padding: 1px 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.mg-more { font-size: 0.58rem; color: var(--text-dim); text-align: center; }

/* ---------- day-peek + settings bottom sheets ---------- */
.wg-peek {
  display: block;
  margin: 2px auto 0;
  width: 30px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
}
.wg-peek:active { color: var(--accent); border-color: var(--accent); }

#day-sheet-scrim, #settings-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.35);
  z-index: 24;
}
#day-sheet, #settings-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50vh; /* default; day-sheet drag handle adjusts via style.height */
  min-height: 80px;
  max-height: 92vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  z-index: 25;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#settings-sheet { height: auto; max-height: 80vh; }
.sheet-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 6px 16px;
  cursor: grab;
  touch-action: none; /* head drags resize the sheet; don't let the page scroll */
  flex-shrink: 0;
}
.sheet-grip {
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.sheet-title { flex: 1; font-weight: 700; font-size: 0.95rem; }
.sheet-close {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 1rem;
  padding: 8px 14px;
  cursor: pointer;
}
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 16px;
}

/* ---------- settings sheet content ---------- */
.settings-body { padding: 4px 16px 20px; display: flex; flex-direction: column; gap: 18px; }
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-label { font-weight: 700; font-size: 0.85rem; display: flex; align-items: center; gap: 8px; }
.cal-status { color: var(--text-dim); font-size: 0.8rem; font-weight: 400; }
.cal-list { display: flex; flex-direction: column; gap: 2px; }
.cal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: 8px;
}
.cal-row:active { background: var(--surface-2); }
.cal-row input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.cal-name { font-size: 0.92rem; }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-name { color: var(--text-dim); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; }

/* ---------- connect card (guests / missing scope) ---------- */
.connect-card {
  max-width: 420px;
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  color: var(--text-dim);
}
.connect-card p { margin: 0; line-height: 1.5; }

/* ---------- event details pop (floating card) ---------- */
.cmd-preview {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  max-width: 656px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  padding: 12px 14px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cmd-actions { display: flex; justify-content: flex-end; gap: 8px; }
#event-pop { z-index: 30; } /* must open above the day sheet */
.event-pop .pop-title { font-weight: 700; font-size: 1rem; }
.event-pop .pop-line { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--text); }
