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

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #111;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Auth pages ── */
.auth-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
  letter-spacing: -0.5px;
}

.auth-card label {
  display: block;
  font-weight: 500;
  margin-top: 1rem;
  margin-bottom: 0.3rem;
}

.auth-card input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

.auth-card input:focus {
  outline: 2px solid #3788d8;
  border-color: transparent;
}

.auth-card button[type="submit"] {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.6rem;
  background: #3788d8;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.auth-card button[type="submit"]:hover { background: #2670bc; }
.auth-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  color: #b91c1c;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 13px;
}

.info-msg {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  color: #1d4ed8;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 13px;
}

/* ── Calendar page ── */
#page-calendar {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  height: 44px;
}

.app-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.3px;
}

.user-email {
  color: #666;
  font-size: 13px;
  flex: 1;
}

.logout-countdown {
  color: #888;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.logout-countdown--warn {
  color: #c0392b;
  font-weight: 600;
}

.btn-outline {
  padding: 0.3rem 0.8rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}

.btn-outline:hover { background: #f5f5f5; }

.calendar-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative; /* anchor for the absolute "+" FAB */
}

#calendar {
  flex: 1;
  padding: 1rem;
  overflow: auto;
  background: #fff;
}

/* ── Agenda view ── */
/* Agenda mode keeps #calendar mounted for its header toolbar (view buttons)
   but collapses the FC view area; the agenda list fills the rest below. */
.calendar-body.agenda-mode {
  flex-direction: column;
}

.calendar-body.agenda-mode #calendar {
  flex: 0 0 auto;
  /* FC's height:'100%' option puts an inline height on #calendar; without this
     override it keeps the full body height and squeezes the agenda to 0px. */
  height: auto !important;
  overflow: visible;
  padding-bottom: 0;
}

.calendar-body.agenda-mode #calendar .fc-view-harness {
  display: none;
}

.agenda {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.agenda-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 4rem;
}

.agenda-day {
  margin-top: 1.25rem;
}

.agenda-day-header {
  position: sticky;
  top: -1px;
  background: #fff;
  z-index: 1;
  font-weight: 600;
  padding: 0.35rem 0;
  border-bottom: 1px solid #eee;
}

.agenda-day-header.is-today {
  color: #1a73e8;
}

.agenda-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid #f3f3f3;
  cursor: pointer;
}

.agenda-row:hover {
  background: #f7f9fc;
}

.agenda-time {
  flex: 0 0 7rem;
  color: #555;
  font-variant-numeric: tabular-nums;
}

.agenda-dot {
  flex: 0 0 0.6rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  align-self: center;
}

.agenda-main {
  flex: 1;
  min-width: 0;
}

.agenda-title {
  font-weight: 500;
}

.agenda-loc {
  color: #777;
  font-size: 0.85em;
}

.agenda-status {
  text-align: center;
  color: #888;
  padding: 1rem;
}

.agenda-spinner {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid #ccc;
  border-top-color: #1a73e8;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.agenda-sentinel {
  height: 1px;
}

/* ── Floating "new event" button (all views) ── */
.fab {
  position: absolute;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 50;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: none;
  background: #1a73e8;
  color: #fff;
  font-size: 1.9rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.fab:hover {
  background: #1666cf;
}

/* ── Settings panel ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 100;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  z-index: 101;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 15px;
  position: sticky;
  top: 0;
  background: #fff;
}

.btn-icon {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  padding: 0.25rem;
  line-height: 1;
}
.btn-icon:hover { color: #111; }

.settings-section {
  padding: 1rem;
  border-bottom: 1px solid #f0f0f0;
}

.settings-section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #888;
  margin-bottom: 0.75rem;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f5f5f5;
}
.account-row:last-child { border-bottom: none; }

.account-url {
  flex: 1;
  font-size: 12px;
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-danger-sm {
  padding: 0.2rem 0.5rem;
  border: 1px solid #fca5a5;
  border-radius: 3px;
  background: #fff;
  color: #b91c1c;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-danger-sm:hover { background: #fee2e2; }

.calendar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
}

.cal-color {
  width: 28px;
  height: 28px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
}

.cal-label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.cal-default-label {
  margin-left: auto;
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  white-space: nowrap;
}

details#add-account-details {
  margin-top: 0.75rem;
}
details#add-account-details summary {
  cursor: pointer;
  font-size: 13px;
  color: #3788d8;
  user-select: none;
  padding: 0.2rem 0;
}

.inner-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.75rem;
}
.inner-form label {
  font-size: 12px;
  font-weight: 500;
  color: #555;
}
.inner-form input,
.inner-form select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}
.inner-form input:focus,
.inner-form select:focus {
  outline: 2px solid #3788d8;
  border-color: transparent;
}
.inner-form button[type="submit"] {
  margin-top: 0.5rem;
  padding: 0.45rem 0.8rem;
  background: #3788d8;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
}
.inner-form button[type="submit"]:hover { background: #2670bc; }
.inner-form button[type="submit"]:disabled { opacity: .6; cursor: not-allowed; }

.loading, .empty-note { font-size: 12px; color: #888; }
.error-note { font-size: 12px; color: #b91c1c; }

/* ── Event detail modal ── */
.fc-event, .fc-event-main { cursor: pointer; }

.event-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 200;
}

.event-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: auto;
  min-width: 340px;
  min-height: fit-content;
  max-width: min(90vw, 760px);
  max-height: calc(100vh - 2rem);
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  z-index: 201;
  display: flex;
  flex-direction: column;
  overflow: auto;
  resize: both;
}

.event-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 15px;
}

.event-modal-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.event-modal-header { flex: none; }

.ev-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ev-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #888;
}

.event-modal-body input[type="text"],
.event-modal-body .ev-dnum,
.event-modal-body textarea {
  padding: 0.4rem 0.5rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  background: #fafafa;
  color: #222;
}

.event-modal-body textarea { resize: vertical; }

/* Custom date fields: year/month/day numeric inputs + 📅 picker button. The
   hidden native date input only hosts the browser's calendar popup. */
.ev-date-fields {
  display: inline-flex;
  align-items: stretch;
  gap: 0.15rem;
}

.event-modal-body .ev-dnum {
  width: 3.4em;
  text-align: center;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.event-modal-body .ev-year { width: 4.6em; }

.ev-dsep {
  display: flex;
  align-items: center;
  color: #888;
  font-weight: 600;
}

.ev-cal-btn {
  margin-left: 0.25rem;
  padding: 0 0.4rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #fafafa;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.ev-cal-btn:hover { background: #e6e6e6; }
.ev-cal-btn:disabled { cursor: default; opacity: 0.5; }

/* Custom mini date picker popup (replaces the native one so it can honour the
   user's first-day-of-week setting). Appended to <body>, positioned in JS. */
.ev-cal-pop {
  position: fixed;
  z-index: 210;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  padding: 0.5rem;
  width: 15rem;
  font-size: 13px;
}

.ev-cal-pop[hidden] { display: none; }

.ev-cal-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.ev-cal-title { font-weight: 600; border: 0; background: none; cursor: pointer; font-size: inherit; color: inherit; }
.ev-cal-title:hover { text-decoration: underline; }

.ev-cal-nav {
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #fafafa;
  width: 1.8em;
  line-height: 1.4;
  cursor: pointer;
}

.ev-cal-nav:hover { background: #e6e6e6; }

.ev-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.ev-cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #888;
  padding: 0.2rem 0;
}

.ev-cal-day {
  border: 0;
  background: none;
  padding: 0.3rem 0;
  border-radius: 4px;
  cursor: pointer;
  color: #222;
}

.ev-cal-day:hover { background: #e6e6e6; }
.ev-cal-day.other-month { color: #bbb; }
.ev-cal-day.today { outline: 1px solid #93c5fd; }
.ev-cal-day.selected { background: #2563eb; color: #fff; }

.ev-cal-grid.months { grid-template-columns: repeat(3, 1fr); }

.ev-cal-month {
  border: 0;
  background: none;
  padding: 0.5rem 0;
  border-radius: 4px;
  cursor: pointer;
  color: #222;
}

.ev-cal-month:hover { background: #e6e6e6; }
.ev-cal-month.today { outline: 1px solid #93c5fd; }
.ev-cal-month.selected { background: #2563eb; color: #fff; }

/* Header title is a jump-to-date trigger (opens the mini picker). */
.fc-toolbar-title { cursor: pointer; }
.fc-toolbar-title:hover { text-decoration: underline; }

/* HH:MM spinner pair (+ AM/PM toggle in 12h mode). Rebuilt per modal-open to
   match the time_format setting. */
.ev-time-fields {
  display: inline-flex;
  align-items: stretch;
  gap: 0.15rem;
}

.ev-ampm {
  margin-left: 0.25rem;
  padding: 0 0.5rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #fafafa;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ev-ampm:hover { background: #e6e6e6; }
.ev-ampm:disabled { cursor: default; opacity: 0.6; }

.event-modal-body .ev-hh,
.event-modal-body .ev-mm {
  width: 3.4em;
  text-align: center;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

/* Custom ▲▼ stepper buttons (cross-browser, always visible). The column
   stretches to the input height and the two buttons split it 50/50, so each
   arrow gets a full-size, non-overlapping hit target. */
.ev-spin {
  display: inline-flex;
  flex-direction: column;
  margin-left: 0.1rem;
}

.ev-spin button {
  flex: 1 1 0;
  box-sizing: border-box;
  width: 1.6em;
  min-height: 0;
  padding: 0;
  border: 1px solid #d0d0d0;
  background: #f3f3f3;
  color: #555;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ev-spin button:hover { background: #e6e6e6; }
.ev-spin-up { border-radius: 4px 4px 0 0; }
.ev-spin-down { border-radius: 0 0 4px 4px; border-top: none; }

.ev-colon { display: flex; align-items: center; color: #888; font-weight: 600; }

.event-modal-body input[readonly],
.event-modal-body textarea[readonly],
.event-modal-body input[disabled],
.ev-check input[disabled] { cursor: default; }

.event-modal-body input[disabled],
.event-modal-body textarea[disabled] {
  background: #f0f0f0;
  color: #777;
}

.event-modal-footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e0e0e0;
}

.btn-primary {
  padding: 0.3rem 0.9rem;
  border: 1px solid #2563eb;
  border-radius: 4px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { opacity: .6; cursor: default; }

.ev-group {
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ev-group legend {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #888;
  padding: 0 0.25rem;
}

.ev-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 13px;
}

.ev-dt-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ev-dt-row .ev-label {
  width: 3rem;
  flex: none;
}

.ev-recur-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.ev-recur-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.ev-recur-interval, .ev-recur-count { width: 4rem; }
.ev-recur-row select { flex: none; }
.ev-recur-row .ev-radio {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 13px;
}
.ev-recur-unit { font-size: 13px; color: #555; }
.ev-recur-summary {
  font-size: 13px;
  color: #555;
  font-style: italic;
  margin-bottom: 0.25rem;
}
.ev-recur-preview {
  font-size: 13px;
  color: #2563eb;
  min-height: 1.2em;
}

.ev-reminders-box {
  display: flex;
  flex-direction: column;
}

.ev-reminders {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ev-reminder {
  font-size: 13px;
  color: #333;
  padding: 0.3rem 0.5rem;
  background: #f5f5f5;
  border-radius: 4px;
}
.ev-reminder.empty-note { background: none; padding: 0; }
.ev-reminder-locked { color: #999; }

.ev-reminder-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.ev-reminder-row .ev-reminder { flex: 1; }
.ev-reminder-row .ev-reminder-word {
  font-size: 13px;
  color: #333;
}
.ev-reminder-value {
  width: 4.5rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
}
.ev-reminder-unit {
  padding: 0.3rem 0.4rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
}
.ev-reminder-row .ev-hh,
.ev-reminder-row .ev-mm {
  width: 2.6em;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
}
.ev-reminder-del { font-size: 14px; }
.ev-reminder-add {
  align-self: flex-start;
  margin-top: 0.25rem;
  font-size: 18px;
}

.event-modal-body select {
  padding: 0.4rem 0.5rem;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  background: #fafafa;
  color: #222;
}

/* Footer Delete sits on the left; Cancel/Save stay right. */
#btn-event-delete { margin-right: auto; }

.btn-danger {
  padding: 0.3rem 0.9rem;
  border: 1px solid #dc2626;
  border-radius: 4px;
  background: #fff;
  color: #b91c1c;
  font-size: 13px;
  cursor: pointer;
}
.btn-danger:hover { background: #fee2e2; }
.btn-danger:disabled { opacity: .6; cursor: default; }

/* Right-click context menu on events. */
.ev-context-menu {
  position: fixed;
  z-index: 250;
  min-width: 120px;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
}
.ev-context-menu button {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: #222;
  border-radius: 3px;
  cursor: pointer;
}
.ev-context-menu button:hover { background: #f0f0f0; }
.ev-context-menu #ctx-delete { color: #b91c1c; }
.ev-context-menu #ctx-delete:hover { background: #fee2e2; }

/* Confirm (yes/no) dialog — above the event modal. */
#confirm-overlay { z-index: 300; }
.confirm-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  max-width: 90vw;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  z-index: 301;
  padding: 1.25rem;
}
.confirm-modal p {
  margin: 0 0 1rem;
  font-size: 14px;
  color: #222;
}
.confirm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.scope-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.scope-options button {
  text-align: left;
  width: 100%;
}
