/* kc-v2 v1.5.7 -- modal dialog */
/* Full class contract and conventions: see README.md and kc-v2-base.css. */

/* ---------------------------------------------------------------------------
 * Modal
 *
 * Reserved as a documented contract in kc-v2.js since KENT-55 and implemented in
 * KENT-59, where the Community home page's nine Bootstrap dialogs move onto it.
 *
 * Measurements come from the Figma frame "return workflow" (54:403) of the Kenton
 * County Updates file -- the only modal the design actually specifies:
 *   dialog   720px wide, 18px radius, #FFFFFF, shadow #0D2438 @30% 0 24px 60px
 *   scrim    #0D2438 @55%
 *   header   69px tall, 22px/28px padding, 1px bottom border
 *   body     28px padding
 *   close    22px glyph, top right
 *
 * The --sm width is NOT from Figma. Seven of the nine dialogs this replaces are a
 * two-field login form, which reads as a mostly-empty 720px box; --sm is a
 * deliberate library addition, flagged in the CHANGELOG for design review.
 *
 * Visibility is the native `hidden` attribute, toggled by kc-v2.js alongside the
 * focus trap / inert / scroll lock -- the same "native attribute, not a bespoke
 * class" approach the accordion panel and tab panels already use.
 * ------------------------------------------------------------------------- */

.kc-v2-modal {
  position: fixed;
  inset: 0;
  z-index: var(--kc-v2-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--kc-v2-space-4);
  background-color: rgba(13, 36, 56, 0.55); /* --kc-v2-ink-900 @ 55%, per Figma.
      Literal rgba rather than color-mix(): this must render identically in the
      older Chromium/WebKit builds these public pages still see. */
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* `display: flex` above is (0,1,0) and would beat the UA's `[hidden] { display: none }`,
   leaving every dialog permanently visible. Any component whose base rule sets
   `display` must restate the hidden case explicitly. */
.kc-v2-modal[hidden] {
  display: none;
}

/* Container component -- ships its own descendant box-sizing reset rather than
   assuming a wrapper class on the host page (README rule #3). */
.kc-v2-modal *,
.kc-v2-modal *::before,
.kc-v2-modal *::after {
  box-sizing: border-box;
}

.kc-v2-modal__dialog {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - var(--kc-v2-space-5)); /* a tall dialog scrolls its body
      rather than growing past the viewport and stranding the actions off-screen */
  margin: auto; /* keeps it centred once it is taller than the scrim's flex box */
  border: 1px solid transparent; /* reserved for forced-colors, where the shadow
                                     and background are both discarded */
  border-radius: var(--kc-v2-radius-xl);
  background-color: var(--kc-v2-white);
  box-shadow: 0 24px 60px rgba(13, 36, 56, 0.3);
  font-family: var(--kc-v2-font-family);
  font-size: var(--kc-v2-body-size);
  line-height: var(--kc-v2-body-line-height);
  color: var(--kc-v2-ink-800);
  text-align: start;
  animation: kc-v2-modal-in 160ms ease-out;
  /* A multi-step dialog may change size between steps -- a narrow sign-in followed by a
     wide results table, for instance. Transitioning max-width makes that read as a
     deliberate step change rather than a layout glitch. Costs nothing for the far more
     common single-size dialog, whose max-width never changes. */
  transition: max-width 200ms ease-out;
}

/* Sizes. A dialog declares one; a multi-step dialog declares the size for the step it is
   showing, by toggling this modifier. That is deliberate rather than sizing to content:
   `width: fit-content` looks tidier but collapses unpredictably, because the form controls
   inside are `width: 100%` and a percentage child under a shrink-to-fit parent resolves
   against a containing block that is itself being sized by its content. */
.kc-v2-modal__dialog--sm {
  max-width: 480px;
}

/* Wide (KENT-44 1.2.0), for the Schedule G / N worksheets: fourteen numbered lines, each a long
   statutory label beside a money field. At the base 720px those labels wrap to three lines each and
   the sheet becomes unreadable.
   960px is the width the previous Bootstrap markup used, via
   `body .modal-schedule { width: 960px; margin-left: 245px }` in Returns.css -- a hardcoded left
   offset that only centred the dialog at one viewport width. Expressed as a size modifier here, the
   centring comes from the scrim's flexbox and works at every width. */
.kc-v2-modal__dialog--lg {
  max-width: 960px;
}

@keyframes kc-v2-modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kc-v2-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--kc-v2-space-3);
  flex-shrink: 0;
  min-height: 69px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--kc-v2-ink-200);
}

.kc-v2-modal__title {
  margin: 0;
  font-family: var(--kc-v2-font-family);
  font-size: var(--kc-v2-h3-size);
  font-weight: var(--kc-v2-h3-weight);
  line-height: var(--kc-v2-h3-line-height);
  letter-spacing: var(--kc-v2-h3-letter-spacing);
  color: var(--kc-v2-ink-900);
}

/* 44x44 target around a 22px glyph -- the same correction the Phase 6 audit made
   to .kc-v2-alert__close, applied here from the start rather than after the fact. */
.kc-v2-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin: 0; /* site.css's bare `button { margin-right: 8px; }` */
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--kc-v2-radius-sm);
  background-color: transparent;
  color: var(--kc-v2-ink-500);
  cursor: pointer;
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.kc-v2-modal__close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  pointer-events: none; /* so event.target is always the button, never the glyph */
}
.kc-v2-modal__close:hover,
.kc-v2-modal__close:focus,
.kc-v2-modal__close:active {
  background-color: var(--kc-v2-ink-100);
  color: var(--kc-v2-ink-900);
}
.kc-v2-modal__close:focus-visible {
  outline: var(--kc-v2-focus-ring-width) solid var(--kc-v2-focus-ring-color);
  outline-offset: calc(var(--kc-v2-focus-ring-offset) * -1); /* inset: the header's
      edge would otherwise clip an outward ring on the top-right corner */
}

/* A gapped flex column, not a plain block.
 *
 * Spacing inside a dialog is the component's job, not something each page has to remember.
 * As a block, adjacent children only had whatever margins they happened to carry -- and
 * kc-v2's form parts deliberately carry none (spacing comes from the .kc-v2-stack/.kc-v2-grid
 * primitives), so a body containing a field followed by a table rendered them touching. That
 * is a layout the markup cannot get wrong by omission any more.
 *
 * `gap` is the right tool rather than child margins: a child with `display: none` -- which is
 * how these dialogs swap a login form for a results view -- contributes no gap, so the
 * spacing stays correct in every state without the page adjusting anything. */
.kc-v2-modal__body {
  display: flex;
  flex-direction: column;
  gap: var(--kc-v2-space-4);
  flex: 1 1 auto;
  padding: 28px;
  overflow-y: auto;
}

/* Direct children must not be squeezed by the column when the body scrolls. */
.kc-v2-modal__body > * {
  flex-shrink: 0;
}

.kc-v2-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--kc-v2-space-2);
  flex-shrink: 0;
  flex-wrap: wrap;
  padding: 0 28px 28px;
}

/* Below the --sm width there is no useful margin left to show the scrim through;
   the dialog takes the viewport and the radius comes off the bottom. */
@media (max-width: 520px) {
  .kc-v2-modal {
    padding: 0;
    align-items: stretch;
  }
  .kc-v2-modal__dialog,
  .kc-v2-modal__dialog--sm,
  .kc-v2-modal__dialog--lg {
    max-width: none;
    min-height: 100%;
    max-height: none;
    border-radius: 0;
  }
  .kc-v2-modal__header,
  .kc-v2-modal__body {
    padding-inline: var(--kc-v2-space-3);
  }
  .kc-v2-modal__footer {
    padding: 0 var(--kc-v2-space-3) var(--kc-v2-space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kc-v2-modal__dialog {
    animation-duration: 0.01ms;
    transition-duration: 0.01ms;
  }
  .kc-v2-modal__close {
    transition-duration: 0.01ms;
  }
}

@media (forced-colors: active) {
  /* The scrim colour and the dialog shadow are both discarded in forced-colors, so
     without a real border the dialog and the page behind it merge into one surface. */
  .kc-v2-modal__dialog {
    border-color: CanvasText;
  }
  .kc-v2-modal__header {
    border-bottom-color: CanvasText;
  }
  .kc-v2-modal__close {
    border-color: ButtonText;
    color: ButtonText;
  }
}

@media print {
  /* A dialog is transient UI; if one happens to be open when the user prints, the
     page underneath is what they meant to print. */
  .kc-v2-modal {
    display: none;
  }
}

/* ---------------------------------------------------------------------------
 * Pass-through pane wrapper (KENT-44 1.3.0)
 *
 * .kc-v2-modal__dialog is a height-capped flex column and .kc-v2-modal__body is the flex child
 * that scrolls. Any plain <div> BETWEEN those two breaks the chain: it is a flex item whose height
 * is content-driven and, as a flex item, defaults to min-height: auto -- so it refuses to shrink,
 * __body never gets a constrained height, overflow-y: auto never engages, and the footer is pushed
 * past the bottom of the viewport. Precisely what the max-height comment above says must not
 * happen. Measured on Schedule Y before this rule: the Ok button sat at y=1028 in an 804px window,
 * unreachable.
 *
 * The three-pane schedule dialogs cannot drop those wrappers -- their ids are what ScheduleG.js and
 * ScheduleN.js swap between -- so the wrappers carry this instead.
 *
 * THE PANES ARE SWAPPED, NOT ANIMATED. They used to slide, and a height animation on a flex item
 * whose height comes from flex distribution rather than from the height property is a fight the
 * animation cannot win: with both panes mid-slide inside a max-height capped, margin:auto centred
 * dialog, it collapsed to nothing and grew back. Firefox showed it plainly; Chrome mostly absorbed
 * it. The dialog keeps its own entrance animation and its max-width transition, which is where a
 * step change inside one dialog should read from.
 * ------------------------------------------------------------------------- */
.kc-v2-modal__pane {
  /* Plain display, no !important. jQuery .show()/.hide() writes inline display while a pane is
     hidden and clears it on reveal, so nothing inline survives to outrank this. */
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
