/* SafeKivi Date Picker — styles for the calendar popover sk-datepicker.js
   renders. Loaded app-wide by layout.html, right after site.css, because the
   accents below resolve through the Design Config tokens site.css declares
   (and theme.js re-writes per tenant): the calendar re-themes with the rest of
   the application instead of carrying its own palette. The one deliberate
   exception is the popover's own surface — see `.sk-dp` below. */

/* The enhanced input keeps type="date" for its value semantics, but the
   browser's own indicator icon would now open a *second*, native calendar
   beside ours — hide it. (WebKit/Blink only; Firefox has no equivalent hook,
   there the script suppresses the native popup via mousedown instead.) */
.sk-dp-input::-webkit-calendar-picker-indicator {
    display: none;
}

/* No `cursor: pointer` here on purpose: the field is still a text control
   whose segments accept typing and click-to-select, and the I-beam is what
   says so. The calendar is an addition to that, not a replacement for it. */

/* `.sk-input-clear` is positioned at `right: 34px` (site.css) to sit clear of
   the browser's own calendar button — which the rule above has just removed.
   On an enhanced field that reservation is an empty 34px gutter with the
   clear button floating in from the edge, so it returns to the inset the
   control's own padding implies. */
.sk-input-icon:has(.sk-dp-input) .sk-input-clear {
    right: 12px;
}

/* ── Row alignment ──────────────────────────────────────────────────────────
   A date input does NOT size like a text input. Its height comes from the
   shadow-DOM segments (dd-mm-yyyy), and Chrome enforces an intrinsic minimum
   on them that exceeds the control's own line box — so the field renders a
   couple of pixels taller than the selects beside it on the same row.

   That minimum cannot be styled away from inside: zeroing the segments'
   padding and line-height helps where padding is the cause, but leaves the
   intrinsic floor intact (measured: still up to ~2.7px over a text input).

   So the height is stated explicitly against the control's own line box,
   taking it off intrinsic sizing altogether.

   Deliberately NOT `box-sizing: content-box`, which resolves the height
   perfectly on its own but is not a per-axis property — it changes what
   `width` means too. Several date fields here carry an inline width
   (`style="width:150px"` on the email-log filters, `max-width:125px` on the
   super-admin log filters), and an inline declaration outranks any class, so
   those would keep their px as a CONTENT width and render ~22px wider than
   the control beside them. A visible width break is a bad trade for a
   sub-pixel height gain.

   The vertical padding is carried in a variable because this app ships two
   control sizes. The only approximation left is the 2px border term: at
   non-100% zoom borders resolve to fractional pixels, leaving up to ~0.5px —
   invisible, and an order of magnitude below the ~2-3px the intrinsic minimum
   contributes.

   `1lh` is the control's real line box, so this holds on any form whose
   controls use a different line-height — unlike a hardcoded `1.5em`, which
   inflates the field wherever that assumption does not hold. Gated on `lh`
   support; without it the field simply keeps its natural height, as before. */
@supports (height: 1lh) {
    .sk-dp-input {
        height: calc(1lh + (var(--sk-dp-pad-y, 8px) * 2) + 2px);
    }

    /* The app's small control (site.css: `padding: 6px 10px`) — the incident
       report, email-log and super-admin date filters all use it. */
    .form-control-sm.sk-dp-input {
        --sk-dp-pad-y: 6px;
    }

    /* Every one of these sits in a form row (or filter toolbar) beside a plain
       <select> that shared.js's global sweep turns into Select2 - and
       select2-bootstrap-5-theme sizes its own box off a DIFFERENT vertical
       padding assumption (`.75rem` total) than this app's real 8px-per-side
       control padding, settling those Select2 boxes 4px shorter than a date
       field on the same line. First found on New Assignment's Due Date
       (training/assignments.html, next to Priority/Assignment Type); the rest
       were found by auditing every `type="date"` field in the app for a
       <select> sharing its row (2026-08-21) - each one hand-confirmed against
       its template, not inferred from the pattern alone. Dropping to the same
       6px this component already uses for the small control (above) closes
       the gap. The real `padding` is lowered alongside `--sk-dp-pad-y`, not
       just the variable - the calc above sizes the box from that variable, so
       moving one without the other would leave the digits sitting on a
       border 4px too close for the room the box actually reserves them.

       #aDueDate            training/assignments.html - Priority, Assignment Type
       #actDetailDue        partials/_remediation_detail_modal.html - Assignee, Severity
       #actCreateDue        partials/_remediation_create_modal.html - Assignee, Severity
       #inputDob            profile/index.html - Gender
       #dCapaDue            incidents/detail.html - Assign To
       #logFormPerformedDate assets/detail.html - Type
       #planStartDate       control_center/audit_plans.html - Recurrence, End date
       #planEndDate         control_center/audit_plans.html - Recurrence, Start date
       #findingDueDate      partials/_audit_finding_modal.html - Classification, Severity */
    #aDueDate.sk-dp-input,
    #actDetailDue.sk-dp-input,
    #actCreateDue.sk-dp-input,
    #inputDob.sk-dp-input,
    #dCapaDue.sk-dp-input,
    #logFormPerformedDate.sk-dp-input,
    #planStartDate.sk-dp-input,
    #planEndDate.sk-dp-input,
    #findingDueDate.sk-dp-input {
        padding-top: 6px !important;
        padding-bottom: 6px !important;
        --sk-dp-pad-y: 6px;
    }

    /* Same mismatch as the group above, but on fields that were already
       `.form-control-sm` (the small-control rule immediately above this one) -
       three log/report filter toolbars pairing a small date field with a small
       Select2 <select> (logStatus / csvTypeId / logAccessTypeSelect). The
       small Select2 box follows a *different* internal formula again
       (`.5rem` total padding, off the theme's OWN small-variant CSS - this app
       never overrides it), landing near 31.6px against the ~33.8px a small
       date field's own 6px padding above produces - a smaller gap than the
       default-size fields, but the same fix in miniature: shrink both the real
       padding and the calc variable together so the box and its content agree.

       #logDateFrom / #logDateTo   control_center/email_setup.html - logStatus
       #csvFrom / #csvTo           incidents/reports.html - csvTypeId
       #logStartDate / #logEndDate super_admin/dashboard.html - logAccessTypeSelect */
    #logDateFrom.sk-dp-input,
    #logDateTo.sk-dp-input,
    #csvFrom.sk-dp-input,
    #csvTo.sk-dp-input,
    #logStartDate.sk-dp-input,
    #logEndDate.sk-dp-input {
        padding-top: 5px !important;
        padding-bottom: 5px !important;
        --sk-dp-pad-y: 5px;
    }
}

.sk-dp-input::-webkit-datetime-edit,
.sk-dp-input::-webkit-datetime-edit-fields-wrapper {
    padding-top: 0;
    padding-bottom: 0;
    line-height: inherit;
}

/* ── Popover shell ──────────────────────────────────────────────────────────
   position:fixed against the viewport; the script keeps it anchored to its
   input on scroll/resize. z-index above Bootstrap modals (1055) and the
   select2-in-modal dropdowns this app pins at 1060, below the SafeKiviDialog
   overlays (10500+) — a confirm dialog must still paint over an open
   calendar. */
.sk-dp {
    position: fixed;
    z-index: 9000;
    width: 302px;
    padding: 12px;
    /* Explicitly white for the same reason as .filter-card / .safekivi-card /
       .ra-card in site.css: --card-bg is Design Config's "Card/panel
       background" token, and a tenant still holding its old grey value
       (#f2f4f7) rendered the calendar grey. A popover that floats above the
       page needs to read as a sheet of paper over it, so this is the one
       surface in the component that does not follow the token. The border
       token stays — it is an edge, not a fill, and was never the grey. */
    background: #ffffff;
    border: 1px solid var(--card-border, #eef1f4);
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16), 0 2px 8px rgba(16, 24, 40, 0.08);
    font-family: var(--font-sans, "Inter", Arial, sans-serif);
    user-select: none;
    /* Hidden state doubles as the "from" keyframe of the entrance.
       visibility (delayed until the fade-out ends) is what actually removes
       the closed popover's ~47 buttons from the tab order and accessibility
       tree — opacity:0 alone left them focusable and announced. */
    opacity: 0;
    transform: translateY(6px) scale(0.98);
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.14s ease-out, transform 0.14s ease-out, visibility 0s linear 0.14s;
}

.sk-dp.sk-dp-open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    visibility: visible;
    /* No visibility delay on the way in. */
    transition: opacity 0.14s ease-out, transform 0.14s ease-out;
}

/* When flipped above the input, enter from the opposite direction. */
.sk-dp.sk-dp-above:not(.sk-dp-open) {
    transform: translateY(-6px) scale(0.98);
}

@media (prefers-reduced-motion: reduce) {
    .sk-dp {
        transition: none;
    }
}

/* ── Header: ‹ Month Year › ────────────────────────────────────────────── */
.sk-dp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin-bottom: 8px;
}

.sk-dp-nav {
    flex: none;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--icon-color, #78829d);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sk-dp-nav:hover {
    background: var(--grid-row-hover-bg, #f2f4f7);
    color: var(--nav-side-text, #344054);
}

/* The title is a button — clicking it zooms out to month, then year view. */
.sk-dp-title {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--header-text, #1e2129);
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.sk-dp-title:hover {
    background: var(--grid-row-hover-bg, #f2f4f7);
}

/* ── Weekday labels ────────────────────────────────────────────────────── */
.sk-dp-week {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 2px;
}

.sk-dp-week span {
    text-align: center;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--grid-header-text-color, #98a2b3);
    padding: 4px 0;
}

/* ── Day grid ──────────────────────────────────────────────────────────── */
.sk-dp-grid {
    display: grid;
    gap: 2px;
}

.sk-dp-grid-days {
    grid-template-columns: repeat(7, 1fr);
}

.sk-dp-day {
    position: relative;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-size: 0.83rem;
    font-weight: 500;
    color: var(--nav-side-text, #344054);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sk-dp-day:hover:not(:disabled) {
    background: var(--grid-row-hover-bg, #f2f4f7);
}

.sk-dp-day:disabled {
    opacity: 0.25;
    cursor: default;
}

/* Days that pad the grid out to full weeks belong to adjacent months.
   These are enabled, clickable text, so they must hold WCAG AA (4.5:1) on the
   white card — the lighter #98a2b3 header token measures only 2.58:1. */
.sk-dp-outside {
    color: var(--text-muted, #667085);
    font-weight: 400;
}

/* Today: accent text plus a dot marker, so it stays visible even when
   another day is selected. */
.sk-dp-today {
    color: var(--form-focus-color, #1b838b);
    font-weight: 700;
}

.sk-dp-today::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 4px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    transform: translateX(-50%);
    background: currentColor;
}

/* Selected: the one filled cell on the sheet. */
.sk-dp-day.sk-dp-selected {
    background: var(--btn-primary-bg, #1b838b);
    color: var(--btn-primary-text, #ffffff);
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(16, 24, 40, 0.18);
}

.sk-dp-day.sk-dp-selected:hover {
    background: var(--btn-primary-hover-bg, #146267);
}

/* ── Month / year grids (3 × 4) ────────────────────────────────────────── */
.sk-dp-grid-months {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.sk-dp-cell {
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--nav-side-text, #344054);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sk-dp-cell:hover {
    background: var(--grid-row-hover-bg, #f2f4f7);
}

.sk-dp-cell.sk-dp-selected {
    background: var(--btn-primary-bg, #1b838b);
    color: var(--btn-primary-text, #ffffff);
    font-weight: 600;
}

/* ── Footer: Clear · Today ─────────────────────────────────────────────── */
.sk-dp-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--card-border, #eef1f4);
}

.sk-dp-action {
    border: 0;
    background: transparent;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    /* Interactive text at 12.8px needs 4.5:1 on the white card; #667085
       passes where the lighter grid-header grey (2.58:1) did not. */
    color: var(--text-muted, #667085);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sk-dp-action:hover {
    background: var(--grid-row-hover-bg, #f2f4f7);
    color: var(--nav-side-text, #344054);
}

.sk-dp-action-primary {
    /* The hover-bg token as TEXT: #1b838b on the tinted chip is 3.78:1,
       under AA; the darker #146267 measures 5.93:1 on the same chip. */
    color: var(--btn-primary-hover-bg, #146267);
    background: var(--grid-row-selected-bg, #dcefef);
}

.sk-dp-action-primary:hover {
    background: var(--btn-primary-bg, #1b838b);
    color: var(--btn-primary-text, #ffffff);
}

/* ── App-format display (see showAppFormat in sk-datepicker.js) ─────────────
   The native segments are hidden, not removed, so the value, validation and
   keyboard entry are untouched; the formatted text is drawn over them. */
.sk-dp-display {
    position: absolute;
    display: none;
    pointer-events: none;
    z-index: 2;
    white-space: nowrap;
    overflow: hidden;
    box-sizing: border-box;
}
.sk-dp-display.sk-dp-display-empty {
    color: var(--bs-secondary-color, #6c757d);
    opacity: .75;
}
.sk-dp-input.sk-dp-masked,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-fields-wrapper,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-text,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-month-field,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-day-field,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-year-field,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-month-field:focus,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-day-field:focus,
.sk-dp-input.sk-dp-masked::-webkit-datetime-edit-year-field:focus {
    /* text-fill, not `color`: the real colour stays readable through
       getComputedStyle (and survives any colour transition on the field),
       which the overlay copies. */
    -webkit-text-fill-color: transparent !important;
    background: transparent;
}
