/*------------------------------------------------------------------------------------------
    Form Elements CSS - Replaces jQuery Mobile form styling
    Created: 2026-01-07

    This is the CENTRALIZED form styling for all pages.
    Do NOT add form styling to individual pages.
  -----------------------------------------------------------------------------------------*/

/* ==========================================================================
   Labels
   ========================================================================== */

label {
    display: inline-block;
    font-family: Verdana, Helvetica, sans-serif;
    font-weight: normal;
    font-size: 16px;
    margin-bottom: 5px;
    color: #333;
}

/* Labels that are block-level (common in forms) */
form label,
.form-group label,
fieldset label {
    display: block;
    margin-bottom: 5px;
}

/* ==========================================================================
   Text Inputs, Textareas, Selects

   UNIVERSAL STYLES - These apply to ALL inputs/selects across the site.
   Layout (block vs inline, width) is controlled by parent containers.
   ========================================================================== */

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
textarea,
select {
    display: inline-block;
    vertical-align: middle;
    box-sizing: border-box;
    padding: 6px 8px;
    margin: 4px 10px 4px 0;

    /* Typography */
    font-size: 14px;
    line-height: 1.42857143;
    color: #333;

    /* Appearance */
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}

/* Textarea specific - allow vertical resize, taller default */
textarea {
    height: auto;
    min-height: 80px;
    resize: vertical;
}

/* Date inputs need minimum width to show full date */
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"] {
    min-width: 100px !important;
}

/* Select specific - appearance for dropdown arrow */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

/* Focus states */
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="month"]:focus,
input[type="week"]:focus,
textarea:focus,
select:focus {
    border-color: #66afe9;
    outline: 0;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled {
    background-color: #eee;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Read-only state */
input:read-only,
textarea:read-only {
    background-color: #f5f5f5;
}

/* ==========================================================================
   Buttons

   UNIVERSAL STYLES - These apply to ALL buttons across the site.
   ========================================================================== */

button,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn {
    display: inline-block;
    padding: 4px 14px 2px 14px;
    margin: 4px;
    font-size: 16px;
    font-weight: normal;
    line-height: 1.42857143;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
    user-select: none;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

/* Default button style */
button,
input[type="button"],
.btn {
    color: #333;
    background-color: #fff;
    border-color: #ccc;
}

button:hover,
input[type="button"]:hover,
.btn:hover {
    color: #333;
    background-color: #e6e6e6;
    border-color: #adadad;
}

/* Submit/Primary button style */
input[type="submit"],
.btn-primary {
    color: #fff;
    background-color: #337ab7;
    border-color: #2e6da4;
}

input[type="submit"]:hover,
.btn-primary:hover {
    color: #fff;
    background-color: #286090;
    border-color: #204d74;
}

/* Button disabled state */
button:disabled,
input[type="button"]:disabled,
input[type="submit"]:disabled,
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

/* Small buttons - use .sm utility class */
.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

/* Large buttons - use .lg utility class */
.btn-lg {
    padding: 14px 20px;
    font-size: 18px;
}

/* ==========================================================================
   Checkboxes and Radio Buttons
   ========================================================================== */

input[type="checkbox"],
input[type="radio"] {
    margin: 4px 8px 0 0;
    line-height: normal;
    vertical-align: middle;
    width: auto;
    height: auto;
}

/* Label next to checkbox/radio */
input[type="checkbox"] + label,
input[type="radio"] + label,
label.checkbox-label,
label.radio-label {
    display: inline;
    font-weight: normal;
    margin-bottom: 0;
    vertical-align: middle;
    cursor: pointer;
}

/* ==========================================================================
   Form Groups (label + input pairs)
   ========================================================================== */

.form-group {
    margin-bottom: 15px;
}

.form-group::after {
    content: "";
    display: table;
    clear: both;
}

/* ==========================================================================
   Form Layout Helpers
   ========================================================================== */

/* Inline form - makes all children inline */
.form-inline > * {
    display: inline-block;
    width: auto;
    vertical-align: middle;
    margin-bottom: 0;
    margin-right: 10px;
}

/* Horizontal form (labels on left) */
.form-horizontal > label {
    text-align: right;
    padding-right: 10px;
}

/* ==========================================================================
   Validation States
   ========================================================================== */

/* Error state */
input.input-validation-error,
textarea.input-validation-error,
select.input-validation-error,
.has-error input,
.has-error textarea,
.has-error select {
    border-color: red;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
}

input.input-validation-error:focus,
textarea.input-validation-error:focus,
select.input-validation-error:focus,
.has-error input:focus,
.has-error textarea:focus,
.has-error select:focus {
    border-color: red;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px red;
}

/* Validation message */
.field-validation-error,
.validation-summary-errors {
    color: red;
    font-size: 14px;
    margin-top: 5px;
}

/* Success state */
.has-success input,
.has-success textarea,
.has-success select {
    border-color: #3c763d;
}

/* ==========================================================================
   Validation Error Banners on Gray Backgrounds

   On gray-background sections (.BoxWrapperWithRails, .BoxWrapper), validation
   error text uses red (#f00) which only achieves a 2.9:1 contrast ratio
   against the #aaaaaa gray — failing WCAG AA (requires 4.5:1).

   These rules override with a contained pink banner using dark red text:
   #721c24 on #f8d7da = 7.8:1 contrast ratio (passes WCAG AA and AAA).

   Affected pages: Login, Register, Reset Password.
   Note: Red input borders (.input-validation-error) are NOT changed here.
   ========================================================================== */

/* Field-level validation errors (rendered by Html.ValidationMessageFor).
   These spans only get .field-validation-error when an error exists,
   so the banner only appears when there's actually an error to show. */
.BoxWrapperWithRails .field-validation-error,
.BoxWrapper .field-validation-error {
    display: block;
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 6px;
    position: relative;
    font-weight: bold;
    font-size: 14px;
}

/* Validation summary errors (rendered by Html.ValidationSummary).
   The [data-valmsg-summary] selector ensures we only target the auto-generated
   element, not hardcoded wrapper divs that always carry .validation-summary-errors
   (e.g., the Login page wraps ValidationMessageFor in such divs). */
.BoxWrapperWithRails .validation-summary-errors[data-valmsg-summary="true"],
.BoxWrapper .validation-summary-errors[data-valmsg-summary="true"] {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 6px;
    position: relative;
    font-weight: bold;
    font-size: 14px;
}

/* Reusable banner class for JS-generated error messages on gray backgrounds.
   Apply this class to error container elements instead of using inline styles.
   Used by: Register page (displayRegistrationErrors, showUsernameError). */
.validation-error-banner {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 6px 0 10px;
    position: relative;
    font-weight: bold;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}


/* --- Grouped error messages (multiple ValidationMessageFor in one banner) ---
   When a container has class .validation-messages-group, all field errors
   inside render in ONE shared pink banner instead of individual banners.
   CSS :has() ensures the banner only appears when actual errors exist.
   Used on: Login (_LoginForm), Reset Password (ResetPasswordView). */
.BoxWrapperWithRails .validation-messages-group:has(.field-validation-error),
.BoxWrapper .validation-messages-group:has(.field-validation-error) {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 6px;
    margin-left: 30px;
    margin-right: 10px;
    position: relative;
    font-weight: bold;
    font-size: 14px;
    /* Override width:100% from .flexbox-with-wrap so margins work */
    width: auto;
}

/* Inside a group: individual error spans should NOT have their own banner —
   they inherit styling from the group container instead. */
.BoxWrapperWithRails .validation-messages-group .field-validation-error,
.BoxWrapper .validation-messages-group .field-validation-error {
    background-color: transparent;
    border: none;
    padding: 2px 0 2px 16px;
    margin-top: 0;
    position: relative;
    color: inherit;
}

/* Bullet prefix for each error message inside a group */
.BoxWrapperWithRails .validation-messages-group .field-validation-error::before,
.BoxWrapper .validation-messages-group .field-validation-error::before {
    content: "\2022";  /* bullet • */
    position: absolute;
    left: 4px;
}

/* Inside a group: reset wrapper div spacing so errors stack tightly.
   The Login/Reset Password pages wrap each ValidationMessageFor in a
   div.validation-summary-errors — override its red color and margins. */
.BoxWrapperWithRails .validation-messages-group .validation-summary-errors,
.BoxWrapper .validation-messages-group .validation-summary-errors {
    color: inherit;
    font-weight: inherit;
    margin-top: 0;
}

/* List formatting inside error banners.
   Html.ValidationSummary renders errors as <ul>/<li>. The site-wide
   reset (FormatContent.css) removes list-style, so we restore it here. */
.BoxWrapperWithRails .validation-summary-errors[data-valmsg-summary="true"] ul,
.BoxWrapper .validation-summary-errors[data-valmsg-summary="true"] ul,
.validation-error-banner ul {
    margin: 0;
    padding-left: 20px;
    list-style-type: disc;
}

.BoxWrapperWithRails .validation-summary-errors[data-valmsg-summary="true"] li,
.BoxWrapper .validation-summary-errors[data-valmsg-summary="true"] li,
.validation-error-banner li {
    margin-bottom: 2px;
}

/* --- Register page error layout (#ProfileErrorSummaryDiv) ---
   Aligns error box with form inputs (labels are ~125px wide) and
   displays errors two per row on desktop for a compact layout. */
#ProfileErrorSummaryDiv {
    text-align: left;
    margin-left: 125px;
    margin-right: 10px;
}

/* Two-column error list: use flexbox so items flow left-to-right in pairs.
   Bullets are added via ::before since flexbox strips native list markers. */
#ProfileErrorSummaryDiv .validation-summary-errors[data-valmsg-summary="true"] ul,
#ProfileErrorSummaryDiv .validation-error-banner ul {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding-left: 0;
}

#ProfileErrorSummaryDiv .validation-summary-errors[data-valmsg-summary="true"] li,
#ProfileErrorSummaryDiv .validation-error-banner li {
    width: 50%;
    box-sizing: border-box;
    padding-left: 16px;
    position: relative;
}

#ProfileErrorSummaryDiv .validation-summary-errors[data-valmsg-summary="true"] li::before,
#ProfileErrorSummaryDiv .validation-error-banner li::before {
    content: "\2022";  /* bullet • */
    position: absolute;
    left: 4px;
}

/* ==========================================================================
   Utility Classes

   Simple classes that can be applied to ANY element.
   ========================================================================== */

/* Make any element full-width */
.full-width {
    display: block !important;
    width: 100% !important;
    margin-right: 0 !important;
}

/* Make any element inline */
.inline {
    display: inline-block !important;
    width: auto !important;
}

/* Smaller size for inputs/buttons */
.sm {
    height: 32px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
}

/* Larger size for inputs/buttons */
.lg {
    height: 46px !important;
    padding: 6px 12px !important;
    font-size: 18px !important;
}

/* ==========================================================================
   jQuery UI Overrides (for components we're keeping temporarily)
   ========================================================================== */

/* jQuery UI buttons should match our button style */
.ui-button {
    padding: 6.5px 14px;
    font-size: 14px;
}

/* jQuery UI dialog buttons */
.ui-dialog-buttonpane button {
    padding: 8px 14px;
}

/* ==========================================================================
   Responsive adjustments
   ========================================================================== */

@media (max-width: 768px) {
    /* Prevent iOS zoom on input focus */
    input, textarea, select {
        font-size: 16px;
    }

    /* Buttons on mobile */
    button,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    .btn {
        padding: 6px 10px;
        width: 100%;
        margin-bottom: 4px;
        font-size: 14px;
    }

    /* Grouped validation errors: remove side margins on mobile */
    .BoxWrapperWithRails .validation-messages-group:has(.field-validation-error),
    .BoxWrapper .validation-messages-group:has(.field-validation-error) {
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }

    /* Register page errors: remove margins and stack single-column on mobile */
    #ProfileErrorSummaryDiv {
        margin-left: 0;
        margin-right: 0;
    }

    #ProfileErrorSummaryDiv .validation-summary-errors[data-valmsg-summary="true"] li,
    #ProfileErrorSummaryDiv .validation-error-banner li {
        width: 100%;
    }
}
