/*
 * DataTables Editor modal — Resultrics restyle
 * (loaded from Views/Shared/_LayoutPartialForDataTables.cshtml, AFTER
 *  editor.dataTables.min.css and datatables-custom.css so it wins on
 *  equal specificity)
 *
 * The Add/Edit forms render inside a real Bootstrap modal — see
 * wwwroot/js/editor-bootstrap-modal.js, which swaps Editor's own lightbox
 * display for one that hosts the form in .modal > .modal-dialog >
 * .modal-content, exactly like the hand-written modals elsewhere in the app.
 * Editor still tags its elements DTE_*, and it adds the Bootstrap classes
 * alongside them: div.DTE is the .modal-content, DTE_Header the .modal-header,
 * DTE_Body the .modal-body, DTE_Footer the .modal-footer.
 *
 * Two goals:
 *  1. Make the Create/Edit modals look like the rest of the app — white card,
 *     1rem radius, navy ink, Poppins, token borders/radii, no gray text, no
 *     gradient chrome buttons.
 *  2. Fit the whole form on one screen on desktop. The stock Editor form is a
 *     single stacked column (label left / input right) which forces the taller
 *     Race Results form to scroll; here DTE_Form_Content becomes an auto-fit
 *     grid (label above input) that packs 3-4 fields per row on desktop and
 *     collapses to 2 then 1 column on smaller viewports.
 */

:root {
    /* Editor's autocomplete/tag dropdowns are driven by these vars. */
    /* Editor attaches a main-form dropdown inside the display controller's node —
       our .modal — so it shares that stacking context with .modal-content, which
       site.css pins at z-index 10001. At Editor's default of 12 the Search Racer
       list renders behind the form. */
    --dte-dropdown-zindex: 10050;
    --dte-dropdown-background: var(--color-white);
    --dte-dropdown-background-hover: var(--surface-tint);
    --dte-dropdown-border: 1px solid var(--border-subtle);
    --dte-dropdown-border-radius: var(--radius-plate);
    --dte-dropdown-font-size: 0.95rem;
    --dte-dropdown-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
    --dte-dropdown-input-border: 1px solid var(--border-subtle);
    --dte-dropdown-input-border-radius: var(--radius-plate);
    --dte-dropdown-input-padding: 0.55rem 0.85rem;
    --dte-tag-background: var(--surface-tint);
    --dte-tag-background-hover: var(--border-subtle);
    --dte-tag-border: 1px solid var(--border-subtle);
    --dte-tag-border-radius: var(--radius-plate);
    --dte-tag-color: var(--color-navy);
    --dte-tag-font-size: 0.9rem;
}

/* ---------------------------------------------------------------- shell -- */

/* Wide enough for the Race Results form (21 fields) to lay out 5 columns and fit
   on one desktop screen; still inside the app's container-xxl width. */
.dte-modal .modal-dialog {
    width: min(1240px, calc(100vw - 2rem));
    max-width: none;
}

/* div.DTE is the .modal-content. The header/footer bars carry matching corner
   radii, so nothing here has to clip to the rounded box — and no overflow:hidden,
   which would clip the Search Racer autocomplete dropping out of the form.
   Stated in terms of DTE_* rather than the Bootstrap classes so the modal holds
   its shape even if Editor's class map is ever reset. */
.dte-modal div.DTE {
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    overflow: visible;
    background: var(--color-white);
    border: 0;
    border-radius: 1rem;
    box-shadow: 0 28px 60px rgba(15, 23, 42, 0.28);
}

/* The body is the scrolling middle; header and footer stay put. */
.dte-modal div.DTE div.DTE_Body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.dte-modal div.DTE div.DTE_Header,
.dte-modal div.DTE div.DTE_Footer {
    flex: 0 0 auto;
}

.dte-modal-backdrop {
    background-color: rgba(24, 28, 50, 0.55);
}

.dte-modal-backdrop.show {
    opacity: 1;
}

div.DTE {
    font-family: Poppins, sans-serif;
    color: var(--color-navy);
}

/* Close button, pinned to the form wrapper's top-right corner (it is a child of
   .modal-content, not of the header — see editor-bootstrap-modal.js). Not Bootstrap's
   .btn-close: Metronic pins that class to position:absolute/top:0/right:0
   globally, so this one is styled from scratch and draws its own glyph. */
.dte-modal .dte-modal-close {
    position: absolute;
    top: 1rem;
    right: 1.15rem;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: transparent;
    color: var(--color-navy);
    font-family: Poppins, sans-serif;
    font-size: 1.5rem;
    font-weight: var(--fw-body);
    line-height: 1;
    opacity: 1;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.dte-modal .dte-modal-close:hover {
    background-color: var(--surface-tint);
    color: var(--color-black);
}

.dte-modal .dte-modal-close:focus {
    outline: 2px solid rgba(0, 105, 180, 0.35);
    outline-offset: 2px;
}

/* ------------------------------------------------------- header / footer -- */

/* Editor's own stylesheet positions the header/footer bars absolutely and pads
   DTE_Body to clear them. Inside a Bootstrap modal they are ordinary flex rows,
   so that layout has to be unwound. */
div.DTE div.DTE_Header,
div.DTE div.DTE_Footer {
    position: static;
    height: auto;
    width: auto;
}

div.DTE div.DTE_Header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Right padding leaves room for the close button that overlays this corner. */
    padding: 1.1rem 3.5rem 1.1rem 1.75rem;
    background-color: var(--color-white);
    border-bottom: 1px solid var(--border-subtle);
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    font-size: 1.25rem;
    font-weight: var(--fw-bold);
    color: var(--color-navy);
}

div.DTE div.DTE_Header div.DTE_Header_Content {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

div.DTE div.DTE_Body {
    padding: 0;
}

/* .modal-body already scrolls (the dialog is .modal-dialog-scrollable); a second
   scroller in here would clip the autocomplete dropdown. */
div.DTE div.DTE_Body div.DTE_Body_Content {
    max-height: none;
    overflow: visible;
}

div.DTE div.DTE_Footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.1rem 1.75rem;
    background-color: var(--color-white);
    border-top: 1px solid var(--border-subtle);
    border-bottom-left-radius: 1rem;
    border-bottom-right-radius: 1rem;
}

/* Bootstrap spaces .modal-footer children with margins; the gap above already
   does that, and the button rules below carry their own margin. */
div.DTE div.DTE_Footer > * {
    margin: 0;
}

div.DTE div.DTE_Form_Error {
    float: none;
    padding: 0;
    margin-right: auto;
    font-size: 0.9rem;
    font-weight: var(--fw-medium);
    color: #b11f1f;
    white-space: normal;
}

/* --------------------------------------------------------- form buttons -- */

div.DTE button.btn,
div.DTE div.DTE_Form_Buttons button {
    display: inline-block;
    margin-left: 0.75rem;
    padding: 0.65rem 1.6rem;
    border: 1px solid var(--color-navy);
    border-radius: var(--radius-plate);
    background: var(--color-navy);
    background-image: none;
    filter: none;
    box-shadow: none;
    color: var(--color-white);
    font-family: Poppins, sans-serif;
    font-size: 0.95rem;
    font-weight: var(--fw-medium);
    line-height: 1.2;
    text-shadow: none;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

div.DTE button.btn:hover,
div.DTE div.DTE_Form_Buttons button:hover {
    background: var(--color-black);
    background-image: none;
    filter: none;
    border-color: var(--color-black);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
    transform: translateY(-2px);
    color: var(--color-white);
}

div.DTE button.btn:active,
div.DTE div.DTE_Form_Buttons button:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Kill the stock blue gradient + pulsing overlay on focus. */
div.DTE button.btn:focus,
div.DTE div.DTE_Form_Buttons button:focus {
    background: var(--color-black);
    background-image: none;
    filter: none;
    border-color: var(--color-black);
    color: var(--color-white);
    text-shadow: none;
    outline: 2px solid rgba(0, 105, 180, 0.35);
    outline-offset: 2px;
}

div.DTE button.btn:focus:after,
div.DTE div.DTE_Form_Buttons button:focus:after {
    display: none;
    content: none;
    animation: none;
}

/* ---------------------------------------------------------- form layout -- */

div.DTE div.DTE_Body div.DTE_Body_Content {
    background: var(--color-white);
}

.dte-modal div.DTE div.DTE_Body_Content {
    background: var(--color-white);
}

/* Scoped to the modal so inline (click-to-edit) forms keep their own layout.
   auto-fit + a 13rem floor packs 4 columns at the 1040px dialog and 5 on a wide
   desktop, which is what keeps the 21-field Race Results form on one screen. */
.dte-modal div.DTE div.DTE_Form_Content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    align-items: start;
    align-content: start;
    gap: 0.5rem 1.25rem;
    padding: 1.1rem 1.75rem 1.35rem;
}

/* Hidden fields must not occupy a grid cell. */
div.DTE div.DTE_Form_Content div.DTE_Field_Type_hidden {
    display: none !important;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.full,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.block {
    display: flex;
    flex-direction: column;
    clear: none;
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field:hover {
    background-color: transparent;
    border: 0;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field:after {
    content: none;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field > label,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.full > label,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.block > label {
    float: none;
    width: 100%;
    padding-top: 0;
    margin-bottom: 0.25rem;
    font-size: var(--text-label-caps);
    font-weight: var(--fw-bold);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-navy);
    line-height: 1.3;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field > div.DTE_Field_Input,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.full > div.DTE_Field_Input,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.block > div.DTE_Field_Input {
    float: none;
    width: 100%;
    margin: 0;
}

div.DTE_Field label div.DTE_Label_Info {
    font-size: 0.9rem;
    font-weight: var(--fw-body);
    letter-spacing: normal;
    text-transform: none;
    color: var(--color-navy);
}

/* Racer search sits on its own row above the data fields — full-width row so
   it reads as a lookup, but the control itself stays a sane search-box width. */
.dte-modal div.DTE div.DTE_Form_Content div.DTE_Field_Name_SearchRacer {
    grid-column: 1 / -1;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--border-subtle);
}

.dte-modal div.DTE div.DTE_Form_Content div.DTE_Field_Name_SearchRacer > div.DTE_Field_Input {
    max-width: 30rem;
}

/* ---------------------------------------------------------------- inputs -- */

div.DTE_Field input[type=color],
div.DTE_Field input[type=date],
div.DTE_Field input[type=datetime],
div.DTE_Field input[type=datetime-local],
div.DTE_Field input[type=email],
div.DTE_Field input[type=month],
div.DTE_Field input[type=number],
div.DTE_Field input[type=password],
div.DTE_Field input[type=search],
div.DTE_Field input[type=tel],
div.DTE_Field input[type=text],
div.DTE_Field input[type=time],
div.DTE_Field input[type=url],
div.DTE_Field input[type=week],
div.DTE_Field select,
div.DTE_Field textarea {
    width: 100% !important;
    max-width: 100%;
    padding: 0.45rem 0.85rem;
    min-height: 40px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-plate);
    background-color: var(--surface-tint);
    color: var(--color-navy);
    font-family: Poppins, sans-serif;
    font-size: 0.95rem;
    font-weight: var(--fw-body);
    line-height: 1.4;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

div.DTE_Field textarea {
    min-height: 84px;
}

div.DTE_Field input:focus,
div.DTE_Field select:focus,
div.DTE_Field textarea:focus {
    background-color: var(--color-white);
    border-color: var(--color-blue);
    box-shadow: 0 0 0 0.2rem rgba(0, 105, 180, 0.12);
    outline: none;
}

/* Navy tint rather than Metronic's gray — placeholders still read as hints. */
div.DTE_Field input::placeholder,
div.DTE_Field textarea::placeholder {
    color: rgba(24, 28, 50, 0.45);
    font-weight: var(--fw-body);
}

div.DTE_Field input[readonly],
div.DTE_Field input:disabled,
div.DTE_Field select:disabled {
    background-color: var(--border-subtle);
    color: var(--color-navy);
    cursor: not-allowed;
}

div.DTE_Field select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23181c32' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 14px 14px;
}

/* Checkbox / radio rows read as a compact bordered control. */
div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_checkbox,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_radio {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    align-self: end;
    gap: 0.75rem;
    padding: 0.4rem 0.85rem;
    min-height: 40px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-plate);
    background-color: var(--surface-tint);
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_checkbox > label,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_radio > label {
    width: auto;
    margin-bottom: 0;
}

div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_checkbox > div.DTE_Field_Input,
div.DTE_Body div.DTE_Body_Content div.DTE_Field.DTE_Field_Type_radio > div.DTE_Field_Input {
    width: auto;
    padding-top: 0;
}

div.DTE_Field input[type=checkbox],
div.DTE_Field input[type=radio] {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--color-blue);
    cursor: pointer;
}

/* -------------------------------------------------------------- dropdown -- */

div.dte-dropdown {
    font-family: Poppins, sans-serif;
    color: var(--color-navy);
}

/* The list has no height of its own, so a long Search Racer result set runs past
   the bottom of the modal. Cap it and let it scroll instead. */
div.dte-dropdown div.dte-dropdown-list {
    max-height: 16rem;
    overflow-y: auto;
}

/* --------------------------------------------- messages, errors, multi -- */

div.DTE_Field div.DTE_Field_Info,
div.DTE_Field div.DTE_Field_Message,
div.DTE_Field div.DTE_Field_Error {
    margin-top: 0.35rem;
    font-size: 0.9rem;
    font-weight: var(--fw-body);
    line-height: 1.35;
    color: var(--color-navy);
}

div.DTE_Field div.DTE_Field_Error {
    color: #b11f1f;
    font-weight: var(--fw-medium);
}

div.DTE_Field div.multi-value {
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-plate);
    padding: 0.5rem 0.85rem;
    background-color: var(--surface-tint);
}

div.DTE_Field div.multi-value:hover {
    background-color: var(--border-subtle);
}

div.DTE_Field div.multi-value span {
    font-size: 0.9rem;
    line-height: 1.35;
    color: var(--color-navy);
}

div.DTE_Field div.multi-restore {
    font-size: 0.9rem;
    color: var(--color-blue);
}

/* Delete/confirm form keeps its centred single-column message. */
div.DTE.DTE_Action_Remove div.DTE_Form_Content {
    display: block;
    padding: 1.75rem;
}

div.DTE.DTE_Action_Remove div.DTE_Body_Content {
    padding: 0;
    font-size: 1rem;
    font-weight: var(--fw-body);
    color: var(--color-navy);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 767.98px) {
    .dte-modal .modal-dialog {
        width: auto;
    }

    div.DTE div.DTE_Header {
        padding: 1rem 3.25rem 1rem 1.25rem;
        font-size: 1.15rem;
    }

    div.DTE div.DTE_Footer {
        padding: 1rem 1.25rem;
    }

    .dte-modal div.DTE div.DTE_Form_Content {
        grid-template-columns: minmax(0, 1fr);
        padding: 1.25rem;
    }
}
