:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef2ff, #f5f6f8);
}
.login-card {
  background: var(--panel);
  padding: 2.5rem;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  text-align: center;
  max-width: 22rem;
  width: 90%;
}
.login-logo { font-size: 2.5rem; }
.login-card h1 { font-size: 1.35rem; margin: 0.5rem 0 0.25rem; }
.login-foot { font-size: 0.8rem; margin-top: 1.25rem; }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.5rem;
  padding: 0.7rem 1.3rem;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}
.btn-google .g {
  background: #fff;
  color: var(--accent);
  width: 1.4rem; height: 1.4rem;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800;
}
.btn-google:hover { filter: brightness(1.05); }

/* ---------- App ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 0.85rem; font-size: 0.85rem; }
.btn-ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.85rem;
}
.btn-ghost:hover { background: #f0f1f4; }

/* ---------- Filter bar ---------- */
.filterbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem;
  padding: 0.55rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.filter-group { display: flex; align-items: center; gap: 0.4rem; }
.filter-btn, .search-box, .filterbar input[type="date"] {
  border: 1px solid var(--line); border-radius: 8px; padding: 0.4rem 0.6rem;
  background: var(--panel); font-size: 0.85rem; color: var(--ink);
}
.filter-btn { cursor: pointer; white-space: nowrap; }
.search-box { min-width: 16rem; flex: 1 1 16rem; max-width: 28rem; }
.date-filter label { display: flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
.presets { display: flex; gap: 0.25rem; }
.preset { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 0.25rem 0.6rem; font-size: 0.78rem; cursor: pointer; }
.preset:hover { background: #eef2ff; border-color: var(--accent); }
.filter-spacer { flex: 1 1 auto; }

.users-filter { position: relative; }
.dropdown-panel {
  position: absolute; top: 110%; inset-inline-start: 0; z-index: 30; width: 18rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.12); padding: 0.5rem;
}
.dropdown-search { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.5rem; margin-bottom: 0.4rem; }
.dropdown-actions { display: flex; gap: 0.75rem; padding: 0 0.25rem 0.4rem; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 0.8rem; padding: 0; }
.dropdown-list { max-height: 16rem; overflow: auto; }
.u-item { display: flex; align-items: center; gap: 0.45rem; padding: 0.28rem 0.25rem; font-size: 0.85rem; cursor: pointer; border-radius: 6px; }
.u-item:hover { background: #f0f1f4; }

/* ---------- Tabs ---------- */
.tabs { display: flex; align-items: center; gap: 0.25rem; padding: 0.5rem 1rem 0; }
.tab {
  border: 1px solid var(--line); border-bottom: none; background: #eef0f3;
  border-radius: 8px 8px 0 0; padding: 0.45rem 1rem; cursor: pointer; font-size: 0.9rem; color: var(--muted);
}
.tab.active { background: var(--panel); color: var(--ink); font-weight: 600; }
.tabs .stats { margin-left: auto; }

.colorby { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.3rem; }
.colorby select { border: 1px solid var(--line); border-radius: 8px; padding: 0.3rem 0.4rem; font-size: 0.8rem; }

/* ---------- Presence + stats info bar ---------- */
.infobar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.45rem 1rem; background: #fbfcfe; border-bottom: 1px solid var(--line); font-size: 0.84rem;
}
.presence { flex: 1 1 26rem; }
.statsbar { margin-left: auto; white-space: nowrap; }
.pill { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; background: #eef2ff; color: var(--ink); font-weight: 600; font-size: 0.78rem; }
.pill.green { background: #e7f7ee; }

/* ---------- Print ---------- */
.print-only { display: none; }

.layout {
  display: grid;
  grid-template-columns: 1fr 22rem;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}
.cal-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  position: relative;
  min-height: 70vh;
}
#calendar { --fc-border-color: var(--line); }
.loading {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: grid; place-items: center;
  font-weight: 600; color: var(--muted);
  z-index: 5; border-radius: 12px;
}

.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  position: sticky; top: 4.2rem;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
}
.detail-head { display: flex; align-items: center; justify-content: space-between; }
.detail-head h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.detail-body { font-size: 0.9rem; }

.person-group { margin-bottom: 0.9rem; }
.person-name {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 700; margin-bottom: 0.3rem;
}
.swatch { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; }
.evt {
  border-inline-start: 3px solid var(--line);
  padding-inline-start: 0.6rem;
  padding-block: 0.3rem;
  margin: 0.35rem 0;
}
.evt-title { font-weight: 600; }
.evt-meta { color: var(--muted); font-size: 0.82rem; }
.evt-loc { color: var(--ink); }

.empty { color: var(--muted); padding: 1rem 0; }
.evt-desc { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; white-space: pre-wrap; }

/* ---------- List view ---------- */
.listwrap { padding: 1rem; position: relative; min-height: 50vh; }
.list { max-width: 60rem; margin: 0 auto; }
.list-date {
  position: sticky; top: 0; background: var(--bg); z-index: 2;
  font-size: 0.95rem; margin: 1rem 0 0.4rem; padding: 0.3rem 0; border-bottom: 2px solid var(--line);
}
.lcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin: 0.5rem 0; overflow: hidden; }
.lcard-head { display: grid; grid-template-columns: 9rem 1fr; gap: 0.2rem 1rem; padding: 0.7rem 0.9rem; cursor: pointer; align-items: baseline; }
.lcard-head:hover { background: #f7f8fa; }
.lcard-when { grid-row: 1 / span 3; color: var(--muted); font-size: 0.82rem; align-self: center; }
.lcard-title { font-weight: 600; }
.lcard-loc { color: var(--ink); font-size: 0.85rem; }
.lcard-people { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 0.2rem; border: 1px solid var(--line); border-inline-start-width: 4px; border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.78rem; background: #fafbfc; }
.chip .st { color: var(--muted); }
.lcard-body { padding: 0.2rem 0.9rem 0.8rem; border-top: 1px dashed var(--line); font-size: 0.85rem; }
.kv { margin: 0.5rem 0; }
.kv .desc { white-space: pre-wrap; color: var(--ink); margin-top: 0.2rem; }
.att { margin-top: 0.3rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.15rem 1rem; }
.att-row { color: var(--ink); }
.att-row .st { display: inline-block; width: 1rem; color: var(--muted); }

/* FullCalendar tweaks */
.fc .fc-toolbar-title { font-size: 1.15rem; }
.fc-event { cursor: pointer; border: none; }
.fc-daygrid-event { white-space: normal; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .detail { position: static; max-height: none; }
}

@media print {
  .topbar, .filterbar, .infobar, .tabs, #calendarView, .btn-ghost, #listLoading { display: none !important; }
  body { background: #fff; }
  .listwrap { padding: 0; }
  .print-only { display: block; margin-bottom: 0.5rem; }
  #printHeader h1 { font-size: 1.2rem; margin: 0; }
  #printHeader div { color: #555; font-size: 0.85rem; }
  .lcard { break-inside: avoid; border-color: #ccc; }
  .lcard-body { display: block !important; }
  .list-date { position: static; }
}
