/* ==========================================================================
   Grindset form & modal standard

   Reference pattern taken from the cleanest forms already in the app:
     Areas/Admin/Pages/Inventory/Suppliers.cshtml   (grid body, explicit
                                                     asterisk, gradient header)
     Areas/Admin/Pages/Procurement/Index.cshtml     (footer button order)
     Areas/Admin/Pages/Invoicing/Index.cshtml       (grid + hint text)

   The standard, in short:
     - modal:    .gs-modal on .modal; gradient header, white title + close,
                 body is a .row.g-3.gs-form-grid, footer is Cancel then action
     - field:    .gs-field cell = .form-label (+ required asterisk) > control
                 > optional .form-text hint > validation message
     - required: <span class="text-danger">*</span> inside the label. Controls
                 carrying only the `required` attribute get the same asterisk
                 generated for them, so the marker is identical either way.

   This file is linked BEFORE material-dashboard.css, so rules that compete
   with a Material Dashboard declaration are given either a descendant
   selector (higher specificity) or !important where Material Dashboard
   itself used !important. Both cases are marked below.
   ========================================================================== */

:root {
    --gs-required: #f44336;
    --gs-focus: var(--gs-brand-primary);
    --gs-border: #c8cdd6;
    --gs-border-hover: #9ca3af;
    /* One control row: line-height + vertical padding + both borders. Keeps
       the required accent the same length next to a taller field. */
    --gs-control-height: calc(1.5rem + 1rem + 2px);
}

/* ==========================================================================
   1. Required-field marker

   One marker, one alignment. The asterisk is authored in the label where the
   page already does that; where a control only carries `required` the same
   asterisk is generated, so both spellings render identically.
   ========================================================================== */

/* Generated asterisk — skipped when the label already spells one out, which
   previously produced a doubled "Name * *". */
.form-label[for]:not(:has(.text-danger)):has(+ :is(input, select, textarea, .form-control, .form-select)[required]),
.form-label[for]:not(:has(.text-danger)):has(+ .input-group input[required]) {
    position: relative;
}

    .form-label[for]:not(:has(.text-danger)):has(+ :is(input, select, textarea, .form-control, .form-select)[required])::after,
    .form-label[for]:not(:has(.text-danger)):has(+ .input-group input[required])::after {
        content: "*";
        color: var(--gs-required);
        margin-left: 0.25rem;
        font-weight: 700;
    }

/* Authored asterisk — same weight and gap as the generated one. */
.form-label > .text-danger {
    margin-left: 0.25rem;
    font-weight: 700;
}

/* Fallback for browsers without :has(). */
.required-field::after {
    content: "*";
    color: var(--gs-required);
    margin-left: 0.25rem;
    font-weight: 700;
}

/* Field-level accent. Inputs and selects are always one row tall, so a left
   border is uniform across them. */
input[required],
select[required],
.form-control[required]:not(textarea),
.form-select[required] {
    border-left: 3px solid var(--gs-required) !important; /* beats .form-control's !important border */
}

/* A textarea is several rows tall, and a full-height border made the accent
   run ragged beside its neighbours. It gets a stripe clipped to one control
   row instead, so every accent in a row starts and ends on the same line
   whatever the field's height. */
textarea[required] {
    border-left-color: transparent !important; /* let the stripe occupy the full 3px */
    background-image: linear-gradient(var(--gs-required), var(--gs-required));
    background-repeat: no-repeat;
    background-origin: border-box;
    background-position: left top;
    background-size: 3px var(--gs-control-height);
}

/* Validation error state. */
input[required].is-invalid,
select[required].is-invalid,
textarea[required].is-invalid,
.form-control[required].is-invalid,
.form-select[required].is-invalid {
    border-color: var(--gs-required);
    box-shadow: 0 0 0 0.2rem rgba(244, 67, 54, 0.25);
}

/* Validation messages sit under their control, not jammed against it. The
   empty (`field-validation-valid`) state stays inline so it takes no space. */
.field-validation-error {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    line-height: 1.2;
}

/* ==========================================================================
   2. Control chrome
   ========================================================================== */

.form-control,
.form-select {
    border: 1.5px solid var(--gs-border);
    border-radius: 6px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:hover,
.form-select:hover {
    border-color: var(--gs-border-hover);
}

/* Material Dashboard sets `box-shadow: none` and a transparent border on
   focus, which left focus with no visible affordance. !important is needed
   to restore one in the app's own accent colour. */
.form-control:focus,
.form-select:focus,
textarea:focus {
    border-color: var(--gs-focus) !important;
    box-shadow: 0 0 0 3px rgba(145, 136, 105, 0.15) !important;
    outline: none;
}

/* The accent stays put while the field is focused. */
input[required]:focus,
select[required]:focus,
.form-control[required]:not(textarea):focus,
.form-select[required]:focus {
    border-left-color: var(--gs-required) !important;
}

textarea[required]:focus {
    border-left-color: transparent !important;
}

/* ==========================================================================
   3. Vertical rhythm

   A grid gutter already spaces the rows. A leftover .mb-3 on a cell inside a
   gutter row doubles that gap and is the main reason rows drift out of step.
   ========================================================================== */

.row.g-2 > [class*="col-"].mb-3,
.row.g-3 > [class*="col-"].mb-3,
.row.g-4 > [class*="col-"].mb-3 {
    margin-bottom: 0 !important; /* .mb-3 is itself !important */
}

/* ==========================================================================
   4. Modal shell — .gs-modal
   ========================================================================== */

.gs-modal .modal-content {
    border: 0;
    border-radius: 0.75rem;
    overflow: hidden;
}

.gs-modal .modal-header {
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 0;
}

.gs-modal .modal-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.gs-modal .modal-body {
    padding: 1.5rem;
}

.gs-modal .modal-footer {
    padding: 1rem 1.5rem;
    gap: 0.5rem;
    justify-content: flex-end;
    border-top: 1px solid #e9ecef;
    background-color: #fbfbfc;
}

/* Bootstrap spaces footer children with margins; the gap above does it now,
   so they are reset. .me-auto keeps working — it is !important. */
.gs-modal .modal-footer > * {
    margin: 0;
}

/* Cancel first, primary action last, both the same height. */
.gs-modal .modal-footer .btn {
    min-width: 6.5rem;
    margin-bottom: 0;
}

/* Every label in a modal sits the same distance above its control, whether
   the body is a grid or a stack of .mb-3 blocks. */
.gs-modal .modal-body .form-label {
    margin-bottom: 0.5rem;
    line-height: 1.25rem;
}

/* Stacked fields: .mb-2 and .mb-3 both mean "next field", so they resolve to
   one gap. .mb-4 is left alone — pages use it as a deliberate section break. */
.gs-modal .modal-body > .mb-2,
.gs-modal .modal-body > .mb-3,
.gs-modal .modal-body > form > .mb-2,
.gs-modal .modal-body > form > .mb-3 {
    margin-bottom: 1rem !important; /* .mb-* is itself !important */
}

/* ==========================================================================
   5. Form body grid — .gs-form-grid / .gs-field
   ========================================================================== */

/* Every cell of a .gs-form-grid is a field cell, so marking up the row is
   enough. .gs-field is the same treatment for a cell that stands on its own
   outside a grid. */
.gs-field,
.gs-form-grid > [class*="col-"] {
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

/* A reserved line for the label keeps controls across a row starting on the
   same baseline. */
.gs-field > .form-label,
.gs-form-grid > [class*="col-"] > .form-label {
    margin-bottom: 0.5rem;
    line-height: 1.25rem;
    min-height: 1.25rem;
}

.gs-field > .form-text,
.gs-form-grid > [class*="col-"] > .form-text {
    margin-top: 0.375rem;
    margin-bottom: 0;
    font-size: 0.75rem;
    line-height: 1.2;
}

/* Checkbox / radio cells line up with the controls beside them rather than
   floating against the label row. */
.gs-field > .form-check,
.gs-form-grid > [class*="col-"] > .form-check {
    margin-bottom: 0;
    min-height: var(--gs-control-height);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.gs-field > .form-check > .form-check-input,
.gs-form-grid > [class*="col-"] > .form-check > .form-check-input {
    margin: 0;
    flex: 0 0 auto;
}

.gs-field > .form-check > .form-check-label,
.gs-form-grid > [class*="col-"] > .form-check > .form-check-label {
    margin: 0;
}

/* Material Dashboard pushes checkbox inputs to the right with an important
   auto margin. Keep purchase order and requisition options beside their labels. */
.gs-po-create .gs-field > .form-check,
.gs-pr-create .gs-field > .form-check {
    padding-left: 0;
}

.gs-po-create .gs-field > .form-check > .form-check-input,
.gs-pr-create .gs-field > .form-check > .form-check-input {
    margin-left: 0 !important;
}

/* One spelling for the optional tag. */
.gs-optional {
    margin-left: 0.25rem;
    font-size: 0.75rem;
    font-weight: 400;
    color: #8392ab;
}

/* A full-width divider between groups of fields inside a grid body. */
.gs-form-section {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #8392ab;
}

/* ==========================================================================
   6. Inline (non-modal) form actions — same alignment as a modal footer
   ========================================================================== */

.gs-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
}

    .gs-form-actions .btn {
        min-width: 6.5rem;
        margin-bottom: 0;
    }
