/* ==========================================================================
   OrNsoft theme — Calendar (admin/utilities/calendar, planning.html pattern)
   Complements the FullCalendar rules already in ornsoft-perfex.css:
   here the page layout, the toolbar, the day cells and the event tones.
   Tokens only.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page layout — calendar card + filters card
   -------------------------------------------------------------------------- */

body.admin.utilities.calendar .ons-split {
  align-items: start;
  /* The filters panel is opened from the calendar toolbar; until then the
     calendar takes the full width. */
  grid-template-columns: minmax(0, 1fr);
}

body.admin.utilities.calendar .ons-cal-filters {
  display: none;
  max-height: calc(100vh - var(--topbar-h) - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The platform slide-toggles #calendar_filters; the panel follows it. */
body.admin.utilities.calendar
  .ons-split:has(#calendar_filters:not([style*="display:none"]):not([style*="display: none"])) {
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
}

body.admin.utilities.calendar
  .ons-split:has(#calendar_filters:not([style*="display:none"]):not([style*="display: none"]))
  .ons-cal-filters {
  display: block;
}

/* The filter partial is laid out on the 12-column grid; inside a 360px panel
   every column takes the full width. */
body.admin.utilities.calendar .ons-cal-filters .row {
  margin-left: 0;
  margin-right: 0;
}

body.admin.utilities.calendar .ons-cal-filters [class*="col-md-"],
body.admin.utilities.calendar .ons-cal-filters [class*="col-sm-"] {
  width: 100%;
  float: none;
  padding-left: 0;
  padding-right: 0;
}

body.admin.utilities.calendar .ons-cal-filters .col-md-3.text-right {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

body.admin.utilities.calendar .ons-cal-filters hr {
  border-color: var(--border);
  margin: 12px 0;
}

body.admin.utilities.calendar .ons-cal-filters .checkbox,
body.admin.utilities.calendar .ons-cal-filters .form-group {
  margin-bottom: 10px;
}

body.admin.utilities.calendar .ons-cal-filters label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--fg-secondary);
}

body.admin.utilities.calendar .dt-loader {
  color: var(--fg-muted);
}

/* --------------------------------------------------------------------------
   2. Toolbar — buttons read as .ons-btn, title as .ons-h3
   -------------------------------------------------------------------------- */

body.admin .fc .fc-toolbar {
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

body.admin .fc .fc-toolbar-chunk {
  display: flex;
  align-items: center;
  gap: 8px;
}

body.admin .fc .fc-toolbar-title {
  font-size: var(--fs-lg);
  letter-spacing: var(--ls-h3);
}

/* Grouped prev / today / next keep one hairline between them. */
body.admin .fc .fc-button-group {
  display: inline-flex;
}

body.admin .fc .fc-button-group > .fc-button {
  border-radius: 0;
  margin-left: -1px;
}

body.admin .fc .fc-button-group > .fc-button:first-child {
  border-radius: var(--r-md) 0 0 var(--r-md);
  margin-left: 0;
}

body.admin .fc .fc-button-group > .fc-button:last-child {
  border-radius: 0 var(--r-md) var(--r-md) 0;
}

body.admin .fc .fc-button-primary:focus {
  outline: none;
  box-shadow: var(--ring) !important;
}

body.admin .fc .fc-icon {
  font-size: 15px;
  vertical-align: middle;
}

/* --------------------------------------------------------------------------
   3. Month grid — .ons-cal tokens
   -------------------------------------------------------------------------- */

body.admin .fc .fc-col-header-cell {
  background: var(--bg-subtle);
  height: auto;
  padding: 6px 0;
}

body.admin .fc .fc-daygrid-day-top {
  flex-direction: row;
  padding: 2px 2px 0;
}

body.admin .fc .fc-daygrid-day-events {
  padding: 0 4px 4px;
}

body.admin .fc .fc-daygrid-day.fc-day-today {
  background: transparent !important;
}

body.admin .fc .fc-day.fc-day-today .fc-daygrid-day-number,
body.admin .fc .fc-day.fc-day-today .fc-daygrid-day-top a {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-weight: var(--fw-bold);
}

body.admin .fc .fc-daygrid-day:hover {
  background: var(--bg-hover);
}

body.admin .fc .fc-daygrid-more-link {
  font-size: var(--fs-2xs);
  color: var(--fg-muted);
  font-weight: var(--fw-medium);
}

body.admin .fc .fc-popover {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}

body.admin .fc .fc-popover-header {
  background: var(--bg-subtle);
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

/* --------------------------------------------------------------------------
   4. Events — .ons-ev tones
   Event background colours come from the data (category / source), so only
   shape, density and the neutral default are set here.
   -------------------------------------------------------------------------- */

body.admin .fc .fc-daygrid-event,
body.admin .fc a.fc-daygrid-event,
body.admin .fc .fc-event.fc-daygrid-event {
  padding: 3px 6px;
  margin-top: 2px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: var(--fw-semibold);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.admin .fc .fc-event:not([style*="background"]) {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
}

body.admin .fc .fc-event-main,
body.admin .fc .fc-event-title {
  color: inherit;
  font-weight: inherit;
}

body.admin .fc .fc-daygrid-dot-event .fc-event-title {
  font-weight: var(--fw-semibold);
}

body.admin .fc .fc-daygrid-event-dot {
  border-width: 4px;
}

body.admin .fc .fc-event:focus {
  outline: none;
  box-shadow: var(--ring);
}

/* Time-grid views. */
body.admin .fc .fc-timegrid-slot-label-cushion,
body.admin .fc .fc-timegrid-axis-cushion {
  font-family: var(--ons-font-mono);
  font-size: var(--fs-2xs);
  color: var(--fg-muted);
}

body.admin .fc .fc-timegrid-now-indicator-line {
  border-color: var(--danger);
}

body.admin .fc .fc-timegrid-now-indicator-arrow {
  border-top-color: var(--danger);
  border-bottom-color: var(--danger);
}

/* List view. */
body.admin .fc .fc-list-day-cushion {
  background: var(--bg-subtle);
  font-family: var(--ons-font-mono);
  font-size: var(--fs-2xs);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--fg-muted);
}

body.admin .fc .fc-list-event:hover td {
  background: var(--bg-hover);
}

body.admin .fc .fc-list-event-time {
  font-family: var(--ons-font-mono);
  font-size: var(--fs-xs);
  color: var(--fg-muted);
}

/* --------------------------------------------------------------------------
   5. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 980px) {
  body.admin.utilities.calendar .ons-cal-filters {
    position: static;
    max-height: none;
    overflow: visible;
  }

  body.admin .fc .fc-daygrid-day-frame {
    min-height: 76px;
  }
}

/* ==========================================================================
   6. Event tones (planning.html)
   The platform paints every event with one configurable colour per type,
   written inline on the element, so the tones are restated at the same weight.
   The type is read from what the event links to, which is the only stable,
   language independent signal the calendar emits: records keep their own link,
   tasks, leads and custom events are opened by their handler.
   ========================================================================== */

/* Default tone — anything the map below does not name. */
body.admin .fc .fc-event,
body.admin .fc .fc-daygrid-event,
body.admin .fc .fc-list-event .fc-list-event-dot {
  background-color: var(--accent-soft) !important;
  border-color: transparent !important;
  color: var(--accent-soft-fg) !important;
}

/* Tasks and leads. */
body.admin .fc .fc-event[onclick*="init_task_modal"],
body.admin .fc .fc-event[onclick*="init_lead"] {
  background-color: var(--accent-soft) !important;
  color: var(--accent-soft-fg) !important;
}

/* Sales documents. */
body.admin .fc .fc-event[href*="/invoices/"],
body.admin .fc .fc-event[href*="/estimates/"],
body.admin .fc .fc-event[href*="/proposals/"],
body.admin .fc .fc-event[href*="/credit_notes/"],
body.admin .fc .fc-event[href*="/expenses/"] {
  background-color: var(--info-soft) !important;
  color: var(--info) !important;
}

/* Delivery work. */
body.admin .fc .fc-event[href*="/projects/"],
body.admin .fc .fc-event[href*="/contracts/"] {
  background-color: var(--neutral-soft) !important;
  color: var(--neutral) !important;
}

/* Follow-ups: the reminder types that carry their own link. */
body.admin .fc .fc-event[href*="/tickets/"],
body.admin .fc .fc-event[href*="/clients/client/"] {
  background-color: var(--warning-soft) !important;
  color: var(--warning) !important;
}

/* Calendar entries created by hand. */
body.admin .fc .fc-event[onclick*="view_event"] {
  background-color: var(--success-soft) !important;
  color: var(--success) !important;
}

/* Shape and type, once, for every tone. */
body.admin .fc .fc-event,
body.admin .fc .fc-daygrid-event {
  border-width: 0 !important;
  border-radius: 5px !important;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: var(--fw-semibold);
  line-height: 1.25;
}

body.admin .fc .fc-event .fc-event-main,
body.admin .fc .fc-event .fc-event-title,
body.admin .fc .fc-event .fc-event-time,
body.admin .fc .fc-event .fc-daygrid-event-dot {
  color: inherit !important;
  border-color: currentColor !important;
  font-weight: inherit;
}

body.admin .fc .fc-event:hover {
  filter: brightness(0.97);
  text-decoration: none;
}

[data-theme="dark"] body.admin .fc .fc-event:hover {
  filter: brightness(1.15);
}

/* --------------------------------------------------------------------------
   7. Filter legend — the same tones as the events
   -------------------------------------------------------------------------- */

body.admin.utilities.calendar .ons-cal-filters .checkbox label::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: 1px;
  background: var(--ons-cal-tone, var(--accent));
}

body.admin.utilities.calendar .ons-cal-filters label[for="cf_events"] {
  --ons-cal-tone: var(--success);
}

body.admin.utilities.calendar .ons-cal-filters label[for="cf_tasks"] {
  --ons-cal-tone: var(--accent);
}

body.admin.utilities.calendar .ons-cal-filters label[for="cf_invoices"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_estimates"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_proposals"] {
  --ons-cal-tone: var(--info);
}

body.admin.utilities.calendar .ons-cal-filters label[for="cf_projects"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_contracts"] {
  --ons-cal-tone: var(--neutral);
}

body.admin.utilities.calendar .ons-cal-filters label[for="cf_customers_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_expenses_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_leads_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_estimates_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_invoices_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_credit_note_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_proposal_reminders"],
body.admin.utilities.calendar .ons-cal-filters label[for="cf_ticket_reminders"] {
  --ons-cal-tone: var(--warning);
}
