/* =====================================================================
   DGA Date Range Picker — NCM news filter
   Values copied from design.dga.gov.sa (Platforms Code v4) live
   component CSS + design tokens, Oct 2026.
   ===================================================================== */

:root {
  /* ---- DGA tokens (names match Platforms Code variables).
     On :root so .dga-label / .dga-input also work outside .dga-drp ---- */
  --dga-text-default: #161616;            /* --text-default */
  --dga-text-muted: #6c737f;              /* weekday labels (Figma artwork) */
  --dga-text-success: #067647;            /* --text-success: selected / today */
  --dga-datecell-hovered: #166a45;        /* --form-datecell-background-hovered */
  --dga-datecell-pressed: #104631;        /* --form-datecell-background-pressed */
  --dga-datecell-100: #dff6e7;            /* --form-datecell-background-100 (range band) */
  --dga-brand-200: #b8eacb;               /* --colors-brand-200 */
  --dga-brand-600: #1b8354;               /* --colors-brand-600 */
  --dga-cell-hover: #e5e7eb;              /* --form-datecell-today-background-hovered */
  --dga-cell-pressed: #d2d6db;            /* --form-datecell-today-background-pressed */
  --dga-field-border: #9da4ae;            /* --form-field-border-default */
  --dga-field-border-hover: #384250;      /* --form-field-border-hovered */
  --dga-field-border-pressed: #161616;    /* focus underline */
  --dga-field-text: #384250;              /* --form-field-text-focused */
  --dga-field-placeholder: #6c727e;       /* --form-field-text-placeholder */
  --dga-field-label: #161616;             /* --form-field-text-label */
  --dga-error: #b42318;                   /* --form-field-border-error */
  --dga-neutral-100: #f3f4f6;
  --dga-divider: #d2d6db;                 /* --border-neutral-primary */
  --dga-white: #ffffff;
  --dga-shadow-2xl: 0 24px 48px -12px rgba(16, 24, 40, 0.18);
  --dga-shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.03);
  --dga-radius-sm: 4px;
  --dga-radius-8: 8px;
  --dga-radius-full: 9999px;
  --dga-font: "IBMPlexSansArabic", "IBM Plex Sans Arabic", system-ui, sans-serif;
}

.dga-drp {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 360px;            /* fits "October 05, 2026 – October 13, 2026" */
  font-family: var(--dga-font);
  color: var(--dga-text-default);
}

.dga-drp *,
.dga-drp *::before,
.dga-drp *::after { box-sizing: border-box; }

.dga-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ */
/* Form control: label + input  (DGA Input, size lg = 40px)            */
/* ------------------------------------------------------------------ */
.dga-form-control { display: flex; flex-direction: column; min-width: 0; }

.dga-label {
  display: flex;
  gap: 4px;
  margin: 0 0 8px;
  font: 400 14px/20px var(--dga-font);
  color: var(--dga-field-label);
}

.dga-input {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--dga-field-border);
  border-radius: var(--dga-radius-sm);
  background: var(--dga-white);
  transition: border-color 0.15s ease;
}
.dga-input:hover { border-color: var(--dga-field-border-hover); }

/* DGA focus/pressed indicator: 2px bar that grows from the centre */
.dga-input::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  transform: translateX(-50%);
  background-color: var(--dga-field-border-pressed);
  transition: width 0.2s ease-in-out;
}
.dga-input:focus-within::after,
.dga-input--open::after { width: 100%; }

.dga-input--error,
.dga-input--error:hover { border-color: var(--dga-error) !important; }
.dga-input--error::after { background-color: var(--dga-error); }

.dga-input__field {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: 400 16px/24px var(--dga-font);
  color: var(--dga-field-text);
  text-overflow: ellipsis;
}
.dga-input__field::placeholder { color: var(--dga-field-placeholder); opacity: 1; }
/* The DGA focus indicator is the 2px bar under the field (.dga-input::after),
   so drop the site-wide input:focus-visible outline inside DGA inputs only. */
.dga-input .dga-input__field:focus,
.dga-input .dga-input__field:focus-visible { outline: none; box-shadow: none; }
.dga-input__field[readonly] { cursor: pointer; }

/* Clear (x): shown inside the field once a range is applied */
.dga-input__clear {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--dga-radius-full);
  background: transparent;
  color: var(--dga-field-text);
  cursor: pointer;
}
.dga-input__clear[hidden] { display: none; }
.dga-input__clear:hover { background: var(--dga-cell-hover); color: var(--dga-text-default); }
.dga-input__clear:active { background: var(--dga-cell-pressed); }
.dga-input__clear:focus-visible { outline: 2px solid var(--dga-text-default); outline-offset: 0; }

.dga-input__suffix {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--dga-text-default);
  pointer-events: none;
}

.dga-field-error {
  margin: 4px 0 0;
  font: 400 14px/20px var(--dga-font);
  color: var(--dga-error);
}

/* ------------------------------------------------------------------ */
/* Popup container                                                     */
/* ------------------------------------------------------------------ */
.dga-drp__popup {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-start: 0;
  z-index: 1060;
  display: flex;
  flex-direction: column;
  width: max-content;
  padding: 16px;
  border-radius: var(--dga-radius-8);
  background: var(--dga-white);
  box-shadow: var(--dga-shadow-2xl);
}
.dga-drp__popup[hidden] { display: none; }
.dga-drp__popup--align-end { inset-inline-start: auto; inset-inline-end: 0; }

.dga-drp__inputs {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 16px;
}
.dga-drp__inputs .dga-form-control { flex: 1 1 0%; }

.dga-drp__months { display: flex; gap: 32px; }

/* ------------------------------------------------------------------ */
/* Month (calendar)                                                    */
/* ------------------------------------------------------------------ */
.dga-cal {
  display: inline-flex;
  flex-direction: column;
  width: 392px;               /* 7 × 56px */
}

.dga-cal__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 40px;
}

.dga-cal__label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0%;
  padding-inline-start: 20px;
  font: 500 16px/24px var(--dga-font);
  color: var(--dga-text-default);
}

.dga-cal__nav-btns { display: flex; align-items: center; }

.dga-cal__nav-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--dga-radius-sm);
  background: transparent;
  color: var(--dga-text-default);
  cursor: pointer;
}
.dga-cal__nav-btn:hover { background: var(--dga-neutral-100); }
.dga-cal__nav-btn:active { background: var(--dga-cell-hover); }
.dga-cal__nav-btn:focus-visible { outline: 2px solid var(--dga-text-default); outline-offset: -2px; }
.dga-cal__nav-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
[dir="rtl"] .dga-cal__nav-btn svg { transform: rotate(180deg); }

/* Year dropdown */
.dga-year { position: relative; }
.dga-year__btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--dga-radius-sm);
  background: transparent;
  font: 500 14px/20px var(--dga-font);
  color: var(--dga-text-default);
  cursor: pointer;
}
.dga-year__btn:hover { background: var(--dga-neutral-100); }
.dga-year__btn:focus-visible { outline: 2px solid var(--dga-text-default); outline-offset: 0; }
.dga-year__btn[aria-expanded="true"] svg { transform: rotate(180deg); }

.dga-year__list {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  z-index: 2;
  min-width: 104px;
  max-height: 308px;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--dga-cell-hover);
  border-radius: var(--dga-radius-sm);
  background: var(--dga-white);
  box-shadow: var(--dga-shadow-lg);
}
.dga-year__opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  font: 400 14px/20px var(--dga-font);
  color: var(--dga-text-default);
  cursor: pointer;
}
.dga-year__opt:hover,
.dga-year__opt:focus { background: var(--dga-neutral-100); outline: none; }
.dga-year__opt:focus-visible { box-shadow: inset 0 0 0 2px var(--dga-text-default); }
.dga-year__opt svg { visibility: hidden; color: var(--dga-text-default); }
.dga-year__opt[aria-selected="true"] svg { visibility: visible; }

/* Grid */
.dga-cal__grid {
  width: 392px;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
}
.dga-cal__grid th {
  width: 56px;
  height: 56px;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  font: 400 14px/20px var(--dga-font);
  color: var(--dga-text-muted);
}
.dga-cal__grid td { width: 56px; height: 56px; padding: 0; }

/* ------------------------------------------------------------------ */
/* Day cell — mirrors .date-cell / .date-cell__label / span            */
/* ------------------------------------------------------------------ */
.dga-day {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: 400 16px/24px var(--dga-font);
  color: var(--dga-text-default);
}
.dga-day:focus { outline: none; }

.dga-day__label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
  background-color: transparent;
}
.dga-day__label > span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 100%;
  border-radius: var(--dga-radius-full);
  transition: background-color 0.12s ease;
}

/* default */
.dga-day:hover .dga-day__label > span { background: var(--dga-cell-hover); }
.dga-day:active .dga-day__label > span { background: var(--dga-cell-pressed); }
.dga-day:focus-visible .dga-day__label > span { box-shadow: 0 0 0 2px var(--dga-white), 0 0 0 4px var(--dga-text-default); }

/* today */
.dga-day--today .dga-day__label > span {
  border: 2px solid var(--dga-brand-600);
  color: var(--dga-brand-600);
  font-weight: 700;
}
.dga-day--today:hover .dga-day__label > span { background: var(--dga-datecell-100); }
.dga-day--today:active .dga-day__label > span { background: var(--dga-brand-200); }

/* selected (single date, range start, range end) */
.dga-day--selected .dga-day__label > span {
  background-color: var(--dga-text-success);
  color: var(--dga-white) !important;
}
.dga-day--selected:hover .dga-day__label > span { background: var(--dga-datecell-hovered); }
.dga-day--selected:active .dga-day__label > span { background: var(--dga-datecell-pressed); }

/* range band */
.dga-day--in-range .dga-day__label,
.dga-day--preview-mid .dga-day__label { background-color: var(--dga-datecell-100); }

.dga-day--range-start .dga-day__label::before,
.dga-day--range-end .dga-day__label::before,
.dga-day--preview-start .dga-day__label::before,
.dga-day--preview-end .dga-day__label::before {
  content: "";
  position: absolute;
  top: 0;
  z-index: -1;
  width: 52px;
  height: 48px;
  background-color: var(--dga-datecell-100);
}
/* LTR */
.dga-day--range-start .dga-day__label::before,
.dga-day--preview-start .dga-day__label::before { right: 0; border-radius: 50% 0 0 50%; }
.dga-day--range-end .dga-day__label::before,
.dga-day--preview-end .dga-day__label::before { left: 0; border-radius: 0 50% 50% 0; }
/* RTL (same as DGA [dir="rtl"] rules) */
[dir="rtl"] .dga-day--range-start .dga-day__label::before,
[dir="rtl"] .dga-day--preview-start .dga-day__label::before { left: 0; right: auto; border-radius: 0 50% 50% 0; }
[dir="rtl"] .dga-day--range-end .dga-day__label::before,
[dir="rtl"] .dga-day--preview-end .dga-day__label::before { right: 0; left: auto; border-radius: 50% 0 0 50%; }

/* Range preview (not in DGA; added on request): while the end date is being
   chosen, the band follows the pointer/keyboard focus. The day under the
   pointer keeps the DGA hover circle on top of the band. */
.dga-day--preview-start .dga-day__label > span,
.dga-day--preview-end .dga-day__label > span { position: relative; }

/* disabled (future dates) */
.dga-day[disabled] { opacity: 0.3; cursor: default; }
/* days of the previous/next month: muted grey, as in the DGA artwork (EN + AR) */
.dga-day--outside[disabled] { opacity: 1; color: var(--dga-text-muted); }
.dga-day[disabled]:hover .dga-day__label > span,
.dga-day[disabled]:active .dga-day__label > span { background: transparent; }

/* ------------------------------------------------------------------ */
/* Small screens: single month, cells shrink to fit                    */
/* ------------------------------------------------------------------ */
@media (max-width: 767.98px) {
  .dga-drp { max-width: none; }
  .dga-drp__popup {
    position: fixed;
    top: auto !important;
    left: 16px !important;
    right: 16px !important;
    bottom: 16px;
    width: auto;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
  .dga-drp__inputs { gap: 16px; }
  .dga-cal,
  .dga-cal__grid { width: 100%; }
  .dga-cal__grid th,
  .dga-cal__grid td { width: auto; height: 44px; }
  .dga-day { width: 100%; height: 44px; }
  .dga-day__label { height: 40px; }
  .dga-day__label > span { width: 40px; }
  .dga-day--range-start .dga-day__label::before,
  .dga-day--range-end .dga-day__label::before,
  .dga-day--preview-start .dga-day__label::before,
  .dga-day--preview-end .dga-day__label::before { width: 50%; height: 40px; border-radius: 0; }
}
