/* ============================================================
   Rate Control — views/BEngine/N/calendar_update.php, on the admin kit.

   The grid is server HTML (BEngine_Api_m::calendar_html_get) laid out with
   Bootstrap float columns. Inside .rc every row becomes a CSS grid with real
   column widths, and the grid scrolls inside its own card with the header and
   the day column held in place. The page used to get its fit from
   body.zoomcss, which zoomed everything to 65% on 1024-1600px screens.

   Behaviour is untouched: every class and name the T.* code reads is kept.
   Scoped under .rc (and .rc-modal for the review dialog, which has to live
   outside .adm). Colours come from tokens.css; nothing here declares a token.
   ============================================================ */

/* ---------- choosing what to edit ---------- */

.rc-search-body { display: grid; gap: 18px; }

.rc-row {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(170px, 1fr) minmax(170px, 1fr);
  gap: 16px;
  max-width: 920px;
}
.rc-row .adm-field { max-width: none; }

@container (max-width: 720px) {
  .rc-row { grid-template-columns: minmax(0, 1fr); }
}

.rc-rates, .rc-days { display: flex; flex-wrap: wrap; gap: 8px; }

.rc .rc-rate,
.rc .rc-day {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 12px;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.rc .rc-rate:hover, .rc .rc-day:hover { border-color: var(--slate-400); }
.rc .rc-rate input, .rc .rc-day input { width: 15px; height: 15px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.rc .rc-rate:has(input:checked),
.rc .rc-day:has(input:checked) { color: var(--blue-600); background: var(--blue-50); border-color: var(--blue); }
.rc .rc-day-all { font-weight: 700; }

/* the date "fields" are the picker's divs; make them read as fields */
.rc .rc-date {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  cursor: pointer;
}
.rc .rc-date::before {
  content: "\f073";                    /* fa-calendar */
  font-family: FontAwesome;
  color: var(--slate-400);
}

.rc-error {
  margin: 0;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--danger);
}

/* ---------- the grid card ---------- */

.rc-grid { overflow: hidden; }

.rc-placeholder {
  margin: 0;
  padding: 40px 20px;
  font-size: var(--fs-13);
  text-align: center;
  color: var(--slate-600);
}

.rc-scroll {
  overflow: auto;
  max-height: calc(100vh - 230px);
}

/* Every grid rule below is scoped under #rc, not .rc. bengine_N.css styles
   this grid with class chains up to six deep (.col-sm-12.col-md-1.td.rate
   sets width: 8%; others force 50-55px heights, borders, a hover colour and a
   35px top margin). An id outranks all of them at once, without !important. */
#rc .calendar-updata { margin: 0; }
.rc:not(.has-grid) .rc-scroll { display: none; }

#rc .calendar-updata .table {
  display: block;
  width: auto;
  min-width: 1258px;                    /* the sum of the column tracks below */
  margin: 0;
  background: var(--paper);
  border: 0;
}

/* Legacy CSS makes .thead AND .tbody display: table-header-group, so the
   browser wraps them in anonymous table boxes sized and placed on their own:
   the header ended up 1280px to the right of its columns. Plain blocks share
   the table's width, so header and days get identical tracks. */
#rc .calendar-updata .thead,
#rc .calendar-updata .tbody { display: block; width: auto; }

/* one grid for the header and every day, so the columns always line up:
   day, booked, allotment, stop sale, price, min nights, occupancy,
   extra adult, extra child, no arrival + no departure, policy */
#rc .calendar-updata .tr {
  display: grid;
  grid-template-columns: 132px 84px 108px 88px 124px 96px 96px 104px 104px 132px minmax(190px, 1fr);
  margin: 0;
}

/* The room type's name above the grid. Its cell is a .th (not a .td), so
   Bootstrap's col-md-12 float survived the cell rules below; the header grid,
   a new formatting context, then sat BESIDE that full-width float with no
   width. Unfloat it here. */
#rc .calendar-updata .thead .tr:first-child { display: block; }
#rc .calendar-updata .thead .tr:first-child > div {
  display: block;
  float: none;
  width: auto;
  padding: 11px 16px;
  background: var(--paper);
  border: 0;
  border-bottom: 1px solid var(--slate-200);
}
#rc .calendar-updata label.name_rmt {
  margin: 0;
  font-family: var(--serif);
  font-size: var(--fs-15);
  font-weight: 700;
  color: var(--navy);
}

/* every cell: drop the Bootstrap float widths and legacy borders */
#rc .calendar-updata .td {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  float: none;
  width: auto;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 6px 8px;
  font-size: var(--fs-13);
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-right: 1px solid var(--slate-100);
  border-bottom: 1px solid var(--slate-100);
  height: auto;
}

#rc .calendar-updata .tbody .tr:hover > .td { background: var(--blue-50); }
#rc .calendar-updata .tbody .tr.color_status { background: transparent; }

/* header row: held at the top while the grid scrolls */
#rc .calendar-updata .thead { position: sticky; top: 0; z-index: 3; }
#rc .calendar-updata .thead .tr + .tr .td {
  justify-content: center;
  padding: 8px 6px;
  font-size: var(--fs-11);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: .04em;
  text-align: center;
  text-transform: uppercase;
  color: var(--slate-600);
  background: var(--slate-50);
  border-bottom-color: var(--slate-200);
}

/* "Extra charge" sits over adult + child */
#rc .calendar-updata .thead .td.extra.sizeextra {
  display: grid;
  grid-column: span 2;
  grid-template-columns: 1fr 1fr;
  padding: 0;
}
#rc .calendar-updata .thead .td.extra.sizeextra > .td:first-child { grid-column: 1 / -1; }

/* no arrival + no departure share one column in both header and rows */
#rc .calendar-updata .tr > .td:has(> .no_check_out),
#rc .calendar-updata .tr > .td:has(> .no_arraival) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0 !important;                /* the markup sets padding inline */
}
#rc .calendar-updata .tr > .td:has(> .no_check_out) > .td,
#rc .calendar-updata .tr > .td:has(> .no_arraival) > .td {
  justify-content: center;
  padding: 6px 4px !important;
  border: 0 !important;
  border-right: 1px solid var(--slate-100) !important;
}
#rc .calendar-updata .tr > .td:has(> .no_check_out) > .td:last-child { border-right: 0 !important; }

/* the pair's inner cells take the row's colour (weekend, stop sale, hover) */
#rc .calendar-updata .tr > .td > .td { background: transparent; }
#rc .calendar-updata .tbody .td > .td.color_status { background: var(--warn-50); }

/* the day column stays in view while scrolling sideways. :first-of-type,
   not :first-child: every day row starts with hidden <input>s */
#rc .calendar-updata .tr > .td:first-of-type {
  position: sticky;
  left: 0;
  z-index: 2;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  border-right-color: var(--slate-200);
}
#rc .calendar-updata small.day {
  position: static;                     /* bengine_N.css: .rate .day { position: absolute } */
  font-size: var(--fs-11);
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--slate-600);
}

/* the read-only day and booked count read as text, not fields */
#rc .calendar-updata .td input.dis-day {
  width: 100%;
  height: auto;
  margin: 0;
  padding: 0;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 0;
  box-shadow: none;
  cursor: default;
}
#rc .calendar-updata .tr > .td:first-of-type input.dis-day { text-align: left; }
#rc .calendar-updata .td.allot input.dis-day { text-align: center; font-weight: 400; color: var(--slate-600); }

/* editable values */
#rc .calendar-updata .td input[type=text]:not(.dis-day),
#rc .calendar-updata .td select {
  flex: 1 1 auto;
  float: none;
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 4px 8px;
  font-size: var(--fs-13);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--slate-300);
  border-radius: var(--r-sm);
  box-shadow: none;
}
#rc .calendar-updata .td input[type=text]:not(.dis-day) { text-align: right; font-variant-numeric: tabular-nums; }
#rc .calendar-updata .td input[type=text]:focus,
#rc .calendar-updata .td select:focus { outline: 0; border-color: var(--blue); box-shadow: var(--focus-ring); }

/* checkboxes: the markup floats them with inline margins */
#rc .calendar-updata .td label {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin: 0;
  font-weight: 400;
}
#rc .calendar-updata .td input[type=checkbox] {
  float: none !important;
  margin: 0 !important;
  accent-color: var(--blue);
}

/* fill down: the first day's value copied to every day below.
   bengine_T.css shows it on the first row only; that stays. */
#rc .calendar-updata .copy-below {
  flex: 0 0 auto;
  float: none !important;
  display: none;
  place-items: center;
  width: 22px;
  height: 22px;
  margin: 0 !important;
  padding: 0 !important;
  font-size: 13px !important;
  color: var(--blue-600);
  text-decoration: none;
  border-radius: var(--r-sm);
}
#rc .calendar-updata .tbody .tr:first-child .copy-below { display: inline-grid; }
#rc .calendar-updata .copy-below:hover { background: var(--blue-50); }

/* weekends */
#rc .calendar-updata .tbody .tr.is-weekend > .td { background: var(--slate-50); }
#rc .calendar-updata .tbody .tr.is-weekend small.day { color: var(--blue-600); }

/* stop sale and no arrival / departure (classes set by the page's own handlers) */
#rc .calendar-updata .tbody .tr.color_status > .td { background: var(--danger-50); }
#rc .calendar-updata .tbody .td.color_status { background: var(--warn-50); }

/* edited, not yet updated */
#rc .calendar-updata .td.is-changed input[type=text]:not(.dis-day),
#rc .calendar-updata .td.is-changed select {
  border-color: var(--warn);
  background: var(--warn-50);
}
#rc .calendar-updata .td.is-changed:has(input[type=checkbox]) { box-shadow: inset 0 0 0 2px var(--warn); }

/* ---------- the action bar, held at the bottom of the screen ---------- */

.rc-bar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--slate-200);
  border-radius: var(--r-lg);
  box-shadow: var(--e-2);
}
.rc-bar .adm-btn { margin-left: auto; }
.rc-changes { font-size: var(--fs-13); font-weight: 700; color: var(--slate-600); }
.rc-bar.is-dirty .rc-changes { color: var(--warn); }
.rc:not(.has-grid) .rc-bar { display: none; }

/* ---------- the review dialog ---------- */

.rc-modal .modal-content { max-width: 1240px; border-radius: var(--r-lg); overflow: hidden; }
.rc-modal .modal-header { display: block; padding: 14px 20px; background: var(--slate-50); border-bottom: 1px solid var(--slate-200); }
.rc-modal-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.rc-modal-title h4 { margin: 0; font-family: var(--serif); font-size: var(--fs-17); font-weight: 700; color: var(--navy); }
.rc-modal .legend { flex-wrap: wrap; gap: 10px 24px; margin-top: 0; padding: 12px 14px; font-size: var(--fs-13); background: var(--slate-50); border-radius: var(--r); }
.rc-modal label.legend-item { margin: 0; font-weight: 400; cursor: pointer; }
.rc-modal .title-section { margin-top: 14px; padding: 10px 14px; background: var(--blue-50); border-radius: var(--r) var(--r) 0 0; }
.rc-modal .title-section h2 { margin: 0; font-family: var(--serif); font-size: var(--fs-15); color: var(--navy); }
.rc-modal table { font-size: var(--fs-13); }
.rc-modal th { padding: 8px 6px; font-size: var(--fs-11); letter-spacing: .04em; text-transform: uppercase; color: var(--slate-600); background: var(--slate-50); border: 1px solid var(--slate-200); }
.rc-modal td { padding: 6px; border: 1px solid var(--slate-100); }
.rc-modal td:first-child { white-space: nowrap; font-weight: 600; }
/* days changed in something other than price; the grid marks the same edits amber */
.rc-modal .highlight-edit { background: var(--warn-50); }
.rc-modal .input-field { width: 100%; min-width: 64px; padding: 4px 6px; border: 1px solid var(--slate-200); border-radius: var(--r-sm); background: transparent; text-align: right; }
.rc-modal .modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; background: var(--slate-50); border-top: 1px solid var(--slate-200); }
/* the shared .btn-confirm is yellow; the kit button rules here win */
.rc-modal .btn-confirm.adm-btn-primary { padding: 7px 18px; font-size: var(--fs-13); color: var(--paper); background: var(--blue); border: 1px solid var(--blue); border-radius: var(--r); }
.rc-modal .btn-confirm.adm-btn-primary:hover { background: var(--blue-600); }

@media (prefers-reduced-motion: reduce) {
  .rc .rc-rate, .rc .rc-day { transition: none; }
}
