﻿/*
 * AIM Form System
 * Created: March 26, 2026
 * Location: AIM.Shared.UI â€” used by all form components
 *
 * Replaces the repeated inline form patterns found across 90+ components:
 *   - Grid layouts (2-col, 3-col, 4-col)
 *   - Labels (standard, small, required)
 *   - Inputs, selects, textareas
 *   - Form sections with headers
 *   - Toolbar rows (search + filters + actions)
 *   - Alert/status banners
 *
 * Usage:
 *   <div class="aim-form-grid aim-form-grid--3col">
 *     <div class="aim-form-group">
 *       <label class="aim-form-label">Name <span class="aim-required">*</span></label>
 *       <input class="aim-form-control" ... />
 *     </div>
 *   </div>
 */

/* ==========================================================================
 * GRID LAYOUTS â€” responsive column grids for form fields
 * ========================================================================== */

.aim-form-grid {
    display: grid;
    gap: 0.75rem;
}

.aim-form-grid--2col { grid-template-columns: 1fr 1fr; }
.aim-form-grid--3col { grid-template-columns: 1fr 1fr 1fr; }
.aim-form-grid--4col { grid-template-columns: repeat(4, 1fr); }
.aim-form-grid--auto { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* Span utilities — a field that needs more than one column of the grid it sits in
   (a notes textarea across a 2-col form, a wide picker in a 4-col row).

   Added 2026-09-17. These class NAMES were already in use in six components; the RULE
   existed in exactly one place — scoped inside ContractsManagerPage.razor.css, whose own
   comment recorded the gap: "aim-forms.css only ships 2/3/4/auto column templates, not a
   span utility." Blazor scoped CSS applies to one component, so everywhere else the class
   was inert and the field silently took a single column. That is what made the Record-PO
   add-line form ragged: six span2 fields, every one of them one column wide.

   A class that is honoured in one component and ignored in five is worse than no class at
   all, because it reads as applied. Promoted here and the scoped copy deleted — one home,
   per feedback_css_drift_two_mechanisms. */
.aim-form-grid--span2 { grid-column: span 2; }
.aim-form-grid--span3 { grid-column: span 3; }
.aim-form-grid--span4 { grid-column: span 4; }

/* The templates collapse below, so the spans must collapse with them or a spanning field
   overflows its own grid. Same two tiers, on the canonical scale (responsive.md §2). */
@media (max-width: 767px) {
    .aim-form-grid--span2,
    .aim-form-grid--span3,
    .aim-form-grid--span4 { grid-column: span 1; }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .aim-form-grid--span3,
    .aim-form-grid--span4 { grid-column: span 2; }
}

/* Canonicalised 2026-09-17 (768 → 767, 769-1024 → 768-1023) so these agree with the span
   utilities above to the pixel. Mismatched, exactly 768px gave a 1-column grid holding a
   2-column span. Same correction ContractsManagerPage.razor.css made for its local copy. */
@media (max-width: 767px) {
    .aim-form-grid--2col,
    .aim-form-grid--3col,
    .aim-form-grid--4col {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .aim-form-grid--3col,
    .aim-form-grid--4col {
        grid-template-columns: 1fr 1fr;
    }
}

/* ==========================================================================
 * FORM GROUP â€” label + input wrapper
 * ========================================================================== */

.aim-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

/* ==========================================================================
 * LABELS
 * ========================================================================== */

.aim-form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--ink);
    display: block;
}

.aim-form-label--sm {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--ink);
    display: block;
}

.aim-form-label--muted {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--ink-muted);
    display: block;
}

.aim-required {
    color: var(--bad);
    margin-left: 0.1rem;
}

/* ==========================================================================
 * INPUTS, SELECTS, TEXTAREAS
 * ========================================================================== */

.aim-form-control {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm, 4px);
    font-size: 0.875rem;
    color: var(--ink);
    background: var(--sunken, var(--raised));
    line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* Halo tier — see aim-consolidated.css § Focus. Was hand-rolling the same
   shape off --color-primary at 18%/2px; now on the shared tokens so one
   change moves every field in the app. */
.aim-form-control:focus {
    outline: none;
    border-color: var(--focus-ring-color);
    box-shadow: 0 0 0 var(--focus-ring-halo-width) var(--focus-ring-halo);
}

.aim-form-control:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: var(--color-surface-alt);
}

/* Compact variant â€” tighter padding for dense forms */
.aim-form-control--sm {
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

/* Select specific */
select.aim-form-control {
    cursor: pointer;
    appearance: auto;
}

/* Textarea specific */
textarea.aim-form-control {
    min-height: 80px;
    resize: vertical;
}

/* ==========================================================================
 * FORM SECTION â€” bordered card with header for grouping fields
 * ========================================================================== */

.aim-form-section {
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 6px);
    overflow: hidden;
    margin-bottom: 1rem;
}

.aim-form-section__header {
    padding: 0.5rem 0.75rem;
    background: var(--ground);
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ink);
}

.aim-form-section__body {
    padding: 0.75rem;
}

/* ==========================================================================
 * TOOLBAR â€” horizontal bar with filters, search, and action buttons
 * ========================================================================== */

.aim-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.aim-toolbar__group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ==========================================================================
 * BUTTONS
 * ========================================================================== */

.aim-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-sm, 4px);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
    white-space: nowrap;
    line-height: 1.5;
}

.aim-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.aim-btn--primary {
    background: var(--brand-fill-on-surface);
    color: var(--color-text-on-primary);
    border-color: var(--brand-border-on-surface);
}

.aim-btn--primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.aim-btn--secondary {
    background: transparent;
    color: var(--ink);
    border-color: var(--line);
}

.aim-btn--secondary:hover:not(:disabled) {
    background: var(--color-surface-alt);
}

.aim-btn--danger {
    background: var(--bad);
    color: var(--color-text-on-primary);
    border-color: var(--bad);
}

.aim-btn--danger:hover:not(:disabled) {
    background: var(--color-danger-dark);
}

.aim-btn--sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.aim-btn--ghost {
    background: none;
    border: none;
    color: var(--ink-muted);
    padding: 0.3rem 0.5rem;
}

.aim-btn--ghost:hover:not(:disabled) {
    color: var(--ink);
    background: var(--color-surface-alt);
}

/* ==========================================================================
 * ALERT BANNERS â€” success, error, warning, info
 * ========================================================================== */

.aim-alert {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm, 4px);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.aim-alert--success {
    background: var(--ok-wash);
    color: var(--color-success-dark);
    border: 1px solid var(--color-success-light);
}

.aim-alert--error {
    background: var(--bad-wash);
    color: var(--color-danger-dark);
    border: 1px solid var(--color-danger-light);
}

.aim-alert--warning {
    background: var(--warn-wash);
    color: var(--color-warning-dark);
    border: 1px solid var(--color-warning-light);
}

.aim-alert--info {
    background: var(--info-wash);
    color: var(--color-info-dark);
    border: 1px solid var(--color-info-light);
}

.aim-alert__close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: inherit;
    opacity: 0.7;
    padding: 0;
}

.aim-alert__close:hover {
    opacity: 1;
}

/* ==========================================================================
 * TAB BAR
 * ========================================================================== */

.aim-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--line);
    margin-bottom: 1.5rem;
}

.aim-tab {
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.aim-tab:hover {
    color: var(--ink);
}

.aim-tab--active {
    color: var(--brand-on-surface);
    border-bottom-color: var(--brand-border-on-surface);
}

/* ==========================================================================
 * HEADER ROW â€” page/section title with action buttons
 * ========================================================================== */

.aim-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.aim-header-row h2,
.aim-header-row h3,
.aim-header-row h4,
.aim-header-row h5,
.aim-header-row h6 {
    margin: 0;
}

/* ==========================================================================
 * PRINT â€” hide form elements in print
 * ========================================================================== */

@media print {
    .aim-toolbar,
    .aim-tab-bar,
    .aim-btn,
    .aim-alert__close {
        display: none !important;
    }
}
