/**
 * Forovanta Community Software
 * Copyright (c) 2026 Zovanta Software Co. <sales@zovanta.dev> - https://zovanta.dev
 * Licensed under the Forovanta Free License Agreement. See LICENSE for details.
 *
 * Calendar addon stylesheet.
 *
 * Loaded only while the addon is enabled — by the board's layout on a self-hosted board, and
 * by the React build's own add-on loader — so it is shared by both editions of the calendar
 * and has to stay honest about that. The split below is the whole of the arrangement:
 *
 *  * **`.fv-calendar*`** — the React build's `Calendar.tsx` proves these too. They are the
 *    accent hooks (the week's first and last column, an event chip's colour and hover) and they
 *    are written against the *React* theme's tokens, because those are the ones it has.
 *  * **`.fv-cal-*`** — the PHP page's own layout, for classes the React build never emits. A
 *    board's tokens are `--surface`/`--text`/`--border` where the React theme's are
 *    `--card`/`--foreground`/`--border` (the last one shared), which is exactly why the two
 *    cannot be in the same rule: `.fv-cal-*` names this board's tokens and nothing else reads it.
 *
 * The core sets `--fv-calendar-accent` on the calendar page from the "Accent colour" option, so
 * every rule below follows whatever the administrator picked in the add-on's settings.
 */

.fv-calendar {
  --fv-calendar-accent: #4f46e5;
}

/* Sidebar link dropped in by the addon's `sidenav.after` slot. */
.fv-calendar-nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground, #71717a);
  text-decoration: none;
}

.fv-calendar-nav-link:hover {
  background: var(--accent, rgb(0 0 0 / 0.04));
  color: var(--foreground, #18181b);
}

.fv-calendar-nav-icon {
  font-size: 0.9em;
  line-height: 1;
}

/* Month / week grids: keep the day cells equal and let them grow on narrow
   screens instead of squashing the event chips. */
.fv-calendar-month .fv-calendar-day,
.fv-calendar-week .fv-calendar-day {
  transition: background-color 120ms ease;
}

.fv-calendar-month .fv-calendar-day:hover,
.fv-calendar-week .fv-calendar-day:hover {
  background: color-mix(in oklab, var(--fv-calendar-accent) 4%, transparent);
}

.fv-calendar-weekdays span:first-child,
.fv-calendar-weekdays span:last-child {
  color: color-mix(in oklab, var(--fv-calendar-accent) 70%, var(--muted-foreground, #71717a));
}

.fv-calendar-event {
  border-left-width: 3px;
  color: var(--foreground, #18181b);
}

.fv-calendar-event:hover {
  background: color-mix(in oklab, var(--fv-calendar-accent) 12%, var(--card, #fff));
}

/* Keep the six-week grid readable on phones: cells stay tappable, chips clamp. */
@media (max-width: 640px) {
  .fv-calendar-month .fv-calendar-day {
    min-height: 4.5rem;
    padding: 0.25rem;
  }

  .fv-calendar-event {
    padding-inline: 0.25rem;
    font-size: 10px;
  }
}

/* ==========================================================================
 * The PHP page's own layout (`addons/forovanta-calendar/pages.php`).
 * ========================================================================== */

.fv-calendar-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

.fv-cal-icon {
  font-size: 0.8rem;
  line-height: 1;
}

.fv-cal-icon--sm {
  font-size: 0.62rem;
}

/* A chevron that points the other way: the icon set has one chevron, not two. */
.fv-cal-flip {
  transform: scaleX(-1);
}

/* ---------- the heading and the controls ---------- */

.fv-cal-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.fv-cal-heading h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.fv-cal-sub {
  margin: 0.125rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.fv-cal-controls {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.fv-cal-segment {
  display: flex;
  align-items: center;
  padding: 0.125rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.fv-cal-seg {
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
}

.fv-cal-seg:hover {
  color: var(--text);
  text-decoration: none;
}

.fv-cal-seg.is-active {
  background: var(--fv-calendar-accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.fv-cal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2.25rem;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.fv-cal-btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.fv-cal-btn--icon {
  width: 2.25rem;
  padding: 0;
}

.fv-cal-btn--primary,
.fv-cal-btn--primary:hover {
  border-color: transparent;
  background: var(--fv-calendar-accent);
  color: #fff;
}

.fv-cal-btn--primary:hover {
  background: color-mix(in srgb, var(--fv-calendar-accent) 85%, #fff);
}

.fv-cal-btn--danger {
  color: var(--danger);
}

.fv-cal-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- the grid, and the rail beside it ---------- */

.fv-cal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 17.5rem;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .fv-cal-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.fv-cal-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.fv-cal-cardhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
}

.fv-cal-period {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.fv-cal-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 40%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
}

.fv-cal-weekdays span {
  padding: 0.5rem 0;
}

.fv-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.fv-cal-day {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  min-height: 6rem;
  padding: 0.375rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.fv-cal-day:nth-child(7n) {
  border-right: none;
}

/* The last row pays for its own bottom edge: the card's corner is the border. */
.fv-cal-grid .fv-cal-day:nth-last-child(-n + 7) {
  border-bottom: none;
}

.fv-cal-grid--week .fv-cal-day {
  min-height: 16rem;
}

/* The days either side of this month: present, so the grid is whole, and set back, so it
   reads as last month and next month rather than as days with nothing on. */
.fv-cal-day.is-outside {
  background: color-mix(in srgb, var(--surface-2) 35%, transparent);
  color: var(--muted);
}

.fv-cal-dayhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}

.fv-cal-daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.fv-cal-daynum.is-today {
  background: var(--fv-calendar-accent);
  color: #fff;
}

.fv-cal-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.35rem;
  color: color-mix(in srgb, var(--muted) 85%, transparent);
}

.fv-cal-add:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.fv-cal-daylist {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

/* One event in a cell. It keeps `.fv-calendar-event` as well, so the chip's accent edge and
   its hover are the same rules the React build's chips use; only the colour and the box are
   named again here, because a board's text is `--text` and the React theme's is `--foreground`. */
.fv-cal-chip {
  display: block;
  width: 100%;
  padding: 0.25rem 0.375rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--fv-calendar-accent);
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.fv-cal-chip:hover {
  color: var(--text);
  text-decoration: none;
}

.fv-cal-chip-time {
  margin-right: 0.25rem;
  color: var(--muted);
}

.fv-cal-chip.is-pending {
  border-style: dashed;
  opacity: 0.7;
}

/* ---------- the rail ---------- */

.fv-cal-rail {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.fv-cal-widget {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.fv-cal-widget--muted {
  background: color-mix(in srgb, var(--surface-2) 50%, transparent);
}

.fv-cal-widget--warn {
  border-color: color-mix(in srgb, #d97706 40%, transparent);
  background: color-mix(in srgb, #d97706 8%, var(--surface));
}

.fv-cal-widget-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.fv-cal-upcoming {
  display: flex;
  flex-direction: column;
  margin-top: 0.6rem;
}

.fv-cal-upcoming-item {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  min-width: 0;
}

.fv-cal-upcoming-item:first-child {
  border-top: none;
  padding-top: 0;
}

.fv-cal-upcoming-title {
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fv-cal-upcoming-when {
  color: var(--muted);
  font-size: 11px;
}

.fv-cal-empty {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-note-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
}

.fv-cal-note-text {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

/* ---------- the dialogs ---------- */

/*
 * A dialog is a fragment (`#event-form`) or a server-rendered panel (`.is-open`), and it is
 * `display: none` until one of those two says otherwise — so nothing inside it is focusable
 * while it is shut, which is the reason this is not done with `visibility`.
 */
.fv-cal-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.fv-cal-modal:target,
.fv-cal-modal.is-open {
  display: flex;
}

.fv-cal-backdrop {
  position: absolute;
  inset: 0;
  background: oklch(0 0 0 / 0.55);
}

.fv-cal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 32rem;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.fv-cal-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.4rem;
  color: var(--muted);
}

.fv-cal-close:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.fv-cal-dialog-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding-right: 2rem;
  font-size: 1.125rem;
}

.fv-cal-dialog-sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.fv-cal-pill {
  padding: 0.1rem 0.55rem;
  border-radius: 99px;
  background: color-mix(in srgb, #d97706 16%, transparent);
  color: #b45309;
  font-size: 0.72rem;
  font-weight: 600;
}

html[data-mode="dark"] .fv-cal-pill {
  color: #fbbf24;
}

.fv-cal-detail {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.9rem;
  font-size: 0.875rem;
}

.fv-cal-fact {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--muted);
}

.fv-cal-description {
  margin: 0;
  white-space: pre-wrap;
}

.fv-cal-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-rsvp {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
}

.fv-cal-rsvp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.fv-cal-rsvp-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fv-cal-rsvp-count {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-rsvp-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.6rem;
}

.fv-cal-rsvp-buttons .fv-cal-btn {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8rem;
}

.fv-cal-attendees {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.75rem;
}

.fv-cal-note {
  margin: 0;
  padding: 0.5rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.fv-cal-inline {
  margin: 0;
}

.fv-cal-actions .fv-cal-btn {
  height: 2.25rem;
}

/* ---------- the form ---------- */

.fv-cal-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.fv-cal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .fv-cal-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

.fv-cal-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  font-weight: 400;
}

.fv-cal-field--narrow {
  max-width: 10rem;
}

.fv-cal-label {
  color: var(--muted);
  font-size: 0.75rem;
}

.fv-cal-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
}

.fv-cal-check input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex: none;
}

.fv-cal-form textarea {
  min-height: 6rem;
}

.fv-cal-center {
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.fv-cal-center h1 {
  margin: 0 0 0.5rem;
}

.fv-cal-center .fv-cal-btn {
  margin-top: 1rem;
}

.fv-cal-muted {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}
