*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a202c;
  --muted: #4a5568;
  --border: #e2e8f0;
  --accent: #4c6ef5;
  --danger: #e53e3e;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  padding: 20px 16px 90px;
}

/* ── TOP BAR ── */
.top-bar {
  max-width: 900px;
  margin: 0 auto 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-size: 22px;
  font-weight: 700;
  cursor: text;
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
  outline: none;
  border-bottom: 1px dashed transparent;
}
.app-title:hover { border-bottom-color: var(--border); }
.app-title:focus { border-bottom-color: var(--accent); background: #f7fafc; }

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #cbd5e0;
  transition: background 0.2s;
}
.sync-dot.connected { background: #38a169; }
.sync-dot.error { background: var(--danger); }

.nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.nav-btn:hover { background: #edf2f7; }

.month-label {
  font-weight: 700;
  font-size: 20px;
  min-width: 170px;
  text-align: center;
}

.today-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.today-btn:hover { background: #edf2f7; }

/* ── LEGEND ── */
.legend {
  max-width: 900px;
  margin: 0 auto 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px 4px 8px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── CALENDAR ── */
.calendar-wrap {
  max-width: 900px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  padding: 12px;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 0 8px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  touch-action: none;
}

.day-cell {
  min-height: 88px;
  border-radius: 8px;
  padding: 6px 4px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.day-cell:hover { background: #f7fafc; }
.day-cell.other-month { opacity: 0.35; }
.day-cell.today { border-color: var(--accent); background: #eef1ff; }

.day-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 0 2px;
}
.day-cell.today .day-num { color: var(--accent); }

.event-chip {
  font-size: 10.5px;
  line-height: 1.3;
  padding: 2px 5px;
  border-radius: 5px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-more {
  font-size: 10px;
  color: var(--muted);
  padding: 0 4px;
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(76,110,245,0.4);
  cursor: pointer;
}
.fab:hover { filter: brightness(1.08); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal.small { max-width: 320px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 { font-size: 17px; }

.icon-btn {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0 4px;
}

input[type="text"], input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Date field + popover ── */
.date-field { position: relative; }

.date-display {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.date-display:hover { background: #f7fafc; }

.date-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 10;
  width: 260px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  padding: 10px;
}
.date-popover.hidden { display: none; }

.dp-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.dp-nav-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
}
.dp-nav-btn:hover { background: #edf2f7; }
.dp-month-label { font-size: 13px; font-weight: 600; }

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 0;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin: 2px 0 8px;
}

.dp-day {
  aspect-ratio: 1;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.dp-day:hover { background: #edf2f7; }
.dp-day.other { color: #cbd5e0; }
.dp-day.in-range { background: #e0e7ff; border-radius: 0; }
.dp-day.range-start { background: var(--accent); color: #fff; border-radius: 6px 0 0 6px; }
.dp-day.range-end { background: var(--accent); color: #fff; border-radius: 0 6px 6px 0; }
.dp-day.range-start.range-end { border-radius: 6px; }

.dp-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-small { padding: 5px 10px; font-size: 12px; }

.added-by-row {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

.muted { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.spacer { flex: 1; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { background: #edf2f7; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid #feb2b2; }
.btn-danger:hover { background: #fff5f5; }

#name-overlay .modal { text-align: left; }

.setup-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fefcbf;
  color: #744210;
  text-align: center;
  font-size: 13px;
  padding: 10px;
  font-weight: 600;
}
.setup-banner.hidden { display: none; }

@media (max-width: 480px) {
  .day-cell { min-height: 68px; }
  .month-label { min-width: 130px; font-size: 17px; }
  .nav-btn { width: 42px; height: 42px; font-size: 21px; }
  .field-row { grid-template-columns: 1fr; }
}
