/* ============================================================================
   Calendar Designer — UI styles
   ============================================================================ */

html, body { height: 100% !important; }
body {
  background: #f6f7f9;
  display: flex !important;
  flex-direction: column !important;
  margin: 0 !important;
}

/* Navbar takes its natural height; app-shell fills the rest */
body > nav { flex: 0 0 auto; }
.app-shell {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;     /* keep on app-shell to prevent column overflow,
                                       but body itself can still rubber-band */
  display: flex !important;
  flex-direction: column !important;
  width: 100%;
  max-width: 100%;
  padding: 0 !important;            /* override .app-shell .p-3 padding */
}
.app-shell {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100%;
  max-width: 100%;
  padding: 12px !important;        /* visual gutter lives here, outside the constrained row */
}
.app-shell > .row {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  width: 100%;
  max-width: 100%;
  --bs-gutter-y: 0 !important;
  --bs-gutter-x: 12px !important;
}
.app-shell > .row > [class*="col-"] {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Both side and main cards fill their column */
aside > .card,
main  > .card {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100%;
}

/* Side panel's body scrolls internally when content overflows */
aside > .card > .card-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
}

/* Canvas card's body: a NON-scrolling positioned container that holds the
   sticky zoom controls AND the inner scrollable canvas wrapper. */
main > .card > .card-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;        /* let .cd-canvas-scroll fill us fully */
  position: relative;
}

.card-header {
  height: 83px !important;
  flex: 0 0 83px !important;
}

/* Zoom controls float in the top-right of the canvas viewport. They sit
   inside .card-body but OUTSIDE the scrolling wrapper, so they stay pinned
   to the viewport corner when the canvas is zoomed and scrolled. */
.cd-zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  /*background: rgba(255,255,255,0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);*/
}

/* The actual scrolling container for the canvas. It fills the card-body
   so the canvas can pan/scroll within it when zoomed.

   The "center when fits, scroll-naturally when overflows" pattern is tricky
   in both flex and grid because default centering CLIPS overflow on the
   start side. Two layered fixes:
     1. `place-items: safe center` — modern keyword, supported in all current
        browsers; falls back to start-alignment when content overflows.
     2. `margin: auto` on the child — older-browser fallback that works the
        same way in any formatting context (block, flex, grid).
   Either alone would suffice; together they ensure correct behavior even on
   slightly older Safari versions. */
/* The actual scrolling container for the canvas. It fills the card-body
   so the canvas can pan/scroll when zoomed.

   Centering an item that may overflow its scroll container is famously
   tricky — `justify-content: center` / `place-items: center` (in both flex
   and grid) CLIP the overflow start, making the top/left of zoomed content
   unreachable.

   The reliable cross-browser pattern that works in every direction:
     * Container: `display: flex` with start-alignment defaults (no centering).
     * Child: `margin: auto`.

   `margin: auto` distributes leftover space evenly when the child fits, and
   collapses to zero when it overflows — at which point flex's natural
   start-alignment kicks in and the user can scroll freely. */
.cd-canvas-scroll {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
}
.cd-canvas-scroll > #canvasWrap {
  margin: auto;
}

.card-header .nav-tabs .nav-link {
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
}

/* Color picker row */
.color-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
  font-size: 0.875rem;
}
/* The label is the first span — let it shrink/truncate, but never push the
   controls off the row. */
.color-row > span:first-child {
  flex: 1 1 0;
  min-width: 0;
  color: #495057;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Empty filler when a row has no color picker (e.g. day number, events) */
.color-row .cd-spacer { flex: 0 0 28px; }
.pickr .pcr-button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #ced4da;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Advanced font controls (size stepper + weight select) sit between the
   label and the color picker. Compact widths so the row stays narrow. */
.adv-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
}
.adv-controls .adv-size-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid #ced4da;
  border-radius: 4px;
  overflow: hidden;
}
.adv-controls .adv-size-btn {
  background: #f8f9fa;
  border: 0;
  width: 22px;
  height: 24px;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  color: #495057;
}
.adv-controls .adv-size-btn:hover:not(:disabled) { background: #e9ecef; }
.adv-controls .adv-size-btn:disabled { opacity: 0.35; cursor: default; }
.adv-controls .adv-size-value {
  min-width: 28px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border-left: 1px solid #ced4da;
  border-right: 1px solid #ced4da;
  padding: 0 4px;
  color: #212529;
}
.adv-controls .adv-weight {
  height: 24px;
  font-size: 0.78rem;
  padding: 0 1.2rem 0 0.35rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background-color: #fff;
}

/* Hide all advanced controls when the master switch is off. The
   .advanced-fonts class on <body> is set from CD.ADVANCED_FONT_SETTINGS. */
body:not(.advanced-fonts) [data-advanced-fonts] {
  display: none !important;
}

/* Override row: a label-color or nameday-color picker paired with a toggle
   that controls whether the override is active. When inactive, the picker
   is visually dimmed to make the "inherit" state obvious. */
.cd-override-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
}
.cd-override-row > .form-check {
  flex: 1 1 0;
  min-width: 0;
}
.cd-override-row .form-check-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.cd-override-row.cd-override-off .pickr .pcr-button {
  opacity: 0.4;
  pointer-events: none;
}

/* Canvas wrapper */
#canvasWrap {
  background: linear-gradient(45deg, #d6d6d6 25%, transparent 25%),
              linear-gradient(-45deg, #d6d6d6 25%, transparent 25%),
              linear-gradient(45deg, transparent 75%, #d6d6d6 75%),
              linear-gradient(-45deg, transparent 75%, #d6d6d6 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, 10px 0;
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
#previewCanvas {
  display: block;
  background: transparent;
}

/* Nameday editor */
.nameday-row {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid #eee;
}
.nameday-row .nd-date { font-weight: 600; color: #495057; font-size: 0.85rem; }
.nameday-row .nd-input { font-size: 0.85rem; }

/* Holiday editor */
.holiday-row {
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid #eee;
}
.holiday-row .hd-top {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}
.holiday-row .hd-bot {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
}
.holiday-row .hd-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}
.holiday-row .hd-tag.fixed  { background: #cfe2ff; color: #0a58ca; }
.holiday-row .hd-tag.easter { background: #fff3cd; color: #997404; }
.holiday-row .hd-day {
  width: 60px;
  text-align: center;
  flex: 0 0 60px;
}
.holiday-row .hd-month {
  flex: 1 1 auto;     /* take remaining row space for the month name */
  min-width: 0;
}
.holiday-row .hd-offset {
  width: 75px;
  text-align: center;
}
.holiday-row .hd-name { font-size: 0.85rem; }
.holiday-row .hd-type { font-size: 0.85rem; max-width: 150px; }

/* Event list */
#eventList .list-group-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.5rem;
}
.evt-color-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid #ced4da;
  cursor: pointer;
  flex: 0 0 auto;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.evt-color-swatch:hover {
  border-color: #495057;
}

/* Loader for fonts */
.font-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Pickr's color popup defaults to z-index 10000, which sits OVER Bootstrap
   modals (z-index 1050-1055) and intercepts clicks on modal buttons. Lower it
   so modals work correctly even when a color popup is left open. */
.pcr-app {
  z-index: 1040 !important;
}

/* SweetAlert2 popups: keep the visual language close to the rest of the app.
   The .cd-swal-popup class is added via swal()'s customClass.popup config. */
.cd-swal-popup {
  border-radius: 8px;
  font-family: var(--ar-font-sans-serif, inherit);
}
.cd-swal-popup .swal2-actions {
  gap: 0.25rem;
}
.cd-swal-popup .swal2-input {
  margin: 0.75rem auto;
  max-width: 22rem;
}

/* Font dropdown: render each option in its own font (works in Chrome/Firefox/Edge;
   Safari ignores per-option font styling and shows the system font instead). */
#ctlFont {
  font-size: 0.95rem;
}
#ctlFont option {
  font-size: 1rem;
  padding: 4px 6px;
}

/* Help icon next to form labels (Bootstrap tooltip trigger) */
.cd-help {
  cursor: help;
  opacity: 0.65;
  font-size: 0.85em;
}
.cd-help:hover { opacity: 1; }

/* Style accordion: tighten spacing so it doesn't dwarf the rest of the panel */
#styleAccordion {
  margin-bottom: 1rem;
}
#styleAccordion .accordion-button {
  padding: 0.6rem 0.9rem;
  font-weight: 600;
  font-size: 0.95rem;
}
#styleAccordion .accordion-body {
  padding: 0.75rem 0.9rem;
}

/* Custom font dropdown — works in every browser including Safari.
   The native #ctlFont <select> is hidden but kept for value/form semantics. */
.cd-font-dropdown {
  position: relative;
}
.cd-font-dropdown .cd-font-toggle {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.cd-font-dropdown .cd-font-current {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-font-dropdown .cd-font-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 1030;          /* below modal backdrop (1050) and Pickr (1040) */
  margin-top: 2px;
  padding: 4px 0;
}
.cd-font-dropdown .cd-font-menu[hidden] { display: none; }
.cd-font-dropdown .cd-font-group {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #D7263D;
  padding: 6px 12px 2px;
  letter-spacing: 0.04em;
}
.cd-font-dropdown .cd-font-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font-size: 1.2rem;
  cursor: pointer;
  color: #212529;
}
.cd-font-dropdown .cd-font-item:hover {
  background: #f1f3f5;
}
.cd-font-dropdown .cd-font-item.active {
  background: #e7f1ff;
  color: #0a58ca;
  font-weight: 500;
}

/* Range picker */
#startWeekLabel, #endWeekLabel { font-size: 0.95rem; }

/* ===================== Continue product picker ===================== */
/* Card layout: each product is one column inside a Bootstrap .row. The
   .cd-product-card stretches to fill the column so multiple cards with
   different content heights stay aligned. */
.cd-product-card {
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  height: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cd-product-card:hover {
  border-color: #0d6efd;
  box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.1);
}
.cd-product-card .cd-product-image {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  background: #f8f9fa;
  border-radius: 0.375rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cd-product-card .cd-product-image img,
.cd-product-card .cd-product-image svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.cd-product-card .cd-product-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  color: #212529;
}
.cd-product-card .cd-product-subtitle {
  font-size: 0.875rem;
  color: #6c757d;
  margin: 0 0 1rem 0;
  flex: 1;   /* pushes the Choose button to the bottom for vertical alignment */
}

/* ===================== Event image upload ===================== */
/* 4:3 landscape button matching the on-canvas image ratio. Empty state
   shows a dashed border + plus icon. Filled state shows the uploaded
   thumbnail with a × overlay in the corner. The whole thing is a <label>
   so the (hidden) file input picks it up. */
.cd-image-upload {
  width:  100px;
  aspect-ratio: 4 / 3;
  border: 2px dashed #ced4da;
  border-radius: 6px;
  background: #f8f9fa;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cd-image-upload:hover {
  border-color: #0d6efd;
  background: #eef5ff;
}
.cd-image-upload.is-filled {
  border-style: solid;
  border-color: #ced4da;
  background: #000;          /* in case the image has transparency */
  cursor: default;
}
.cd-image-upload.is-filled:hover {
  border-color: #ced4da;
  background: #000;
}
.cd-image-upload.is-uploading {
  opacity: 0.6;
  pointer-events: none;
}

.cd-image-upload .cd-image-plus {
  color: #6c757d;
  font-size: 1.2rem;
}
.cd-image-upload.is-filled .cd-image-plus { display: none; }

.cd-image-upload .cd-image-thumb {
  width:  100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cd-image-upload .cd-image-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #fff;
  background: #dc3545;
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.cd-image-upload .cd-image-remove:hover { background: #b02a37; }

/* Event list rows: small thumbnail next to the color swatch */
.evt-thumb {
  width:  32px;
  height: 24px;    /* same 4:3 ratio */
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid #ced4da;
  flex: 0 0 auto;
}

/* Event list thumbnails are wrapped in a clickable span so the user can
   click to replace (and so the missing-image state has somewhere to live). */
.evt-thumb-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width:  32px;
  height: 24px;
  flex: 0 0 auto;
  cursor: pointer;
  border-radius: 3px;
  overflow: hidden;
  transition: opacity 0.15s ease;
}
.evt-thumb-wrap:hover { opacity: 0.75; }
.evt-thumb-wrap > .evt-thumb { width: 100%; height: 100%; display: block; }

/* Subtle missing-image state: a muted placeholder with a slash-icon and a
   dashed border. Loud enough to notice when scanning the list, calm enough
   not to look like an error notification. */
.evt-thumb-wrap.evt-thumb-missing {
  background: #f1f3f5;
  border: 1px dashed #adb5bd;
  color: #adb5bd;
  font-size: 0.8rem;
}
.evt-thumb-wrap.evt-thumb-missing:hover {
  border-color: #6c757d;
  color: #6c757d;
  opacity: 1;
}
