/* ============================================================
   forms.css — Form Elements, Ticket Creation, Payload Inputs
   ============================================================ */

/* ---- Form groups ---- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.required {
    color: var(--critical);
}

.form-input,
.form-select {
    width: 100%;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

/* Custom dropdown chevron, comfortably inset from the right border (the native arrow sat jammed
   against the edge). appearance:none removes the native arrow; padding-right keeps the value clear
   of the chevron. */
.form-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
}

.form-textarea {
    width: 100%;
    height: auto;
    min-height: 80px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    resize: vertical;
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.form-hint {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ---- Form layout rows ---- */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

/* ---- Form header (back button) ---- */
.form-header-row {
    margin-bottom: 8px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    margin-left: -8px;
}

.btn-back:hover {
    color: var(--text);
    background: var(--bg);
}

.btn-back .material-symbols-outlined {
    font-size: 18px;
}

/* ---- Form actions (bottom buttons) ---- */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.form-actions-split {
    justify-content: space-between;
}

/* ---- Form errors ---- */
.form-errors {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    animation: fadeSlideIn 200ms ease;
}

.form-errors .material-symbols-outlined {
    color: var(--critical);
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}

.form-errors ul {
    list-style: disc;
    padding-left: 16px;
    margin: 0;
}

.form-errors li {
    font-size: 13px;
    color: var(--critical);
    line-height: 1.5;
}

/* ---- Inline per-field error ----
   Themed message rendered by app.js into the empty <p class="field-error" data-field-error="…">
   directly under the field that failed validation. Hidden until it has text (:empty). */
.field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.45;
    color: var(--critical);
    margin-top: 6px;
    animation: fadeSlideIn 160ms ease;
}

.field-error:empty {
    display: none;
}

.field-error::before {
    content: "";
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    margin-top: 1px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23DC2626' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") no-repeat center / 15px;
}

/* Field whose value failed validation: red border + red focus ring (cleared on edit by app.js). */
.form-input.has-error,
.form-select.has-error,
.form-textarea.has-error {
    border-color: var(--critical);
}

.form-input.has-error:focus,
.form-select.has-error:focus,
.form-textarea.has-error:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Label row (login form) ---- */
.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.forgot-link {
    font-size: 13px;
    font-weight: 500;
    color: #6C63FF;
    white-space: nowrap;
    text-decoration: none;
    flex-shrink: 0;           /* never compress — force the label to shrink instead */
    transition: color 150ms ease;
}

.forgot-link:hover {
    color: #5a52e0;
    text-decoration: underline;
}

/* ---- File upload zone ---- */
.file-upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
}

.file-upload-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.file-upload-zone .material-symbols-outlined {
    font-size: 24px;
    margin-bottom: 8px;
}

/* ---- Modal sizing ---- */
.modal-lg {
    width: 720px;
    max-height: 90vh;
    overflow-y: auto;
}

/* ---- Payload form inputs (Data Correction form) ---- */
.payload-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.payload-input {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 13px;
    line-height: 1.6;
    min-height: 120px;
}

.payload-input-current {
    background: #FFF5F5;
    border-color: #FECACA;
}

.payload-input-current:focus {
    border-color: var(--critical);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.payload-input-corrected {
    background: #F0FFF4;
    border-color: #BBF7D0;
}

.payload-input-corrected:focus {
    border-color: var(--success);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

/* ---- Payload label dot indicators ---- */
.payload-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 2px;
}

.payload-dot-current {
    background: var(--critical);
}

.payload-dot-corrected {
    background: var(--success);
}

/* ---- Data correction section ---- */
.data-correction-fields {
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px solid var(--border);
}

/* ---- Payload diff display (read-only view in ticket detail) ---- */
.payload-diff-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.payload-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.payload-label.current {
    color: var(--critical);
}

.payload-label.corrected {
    color: var(--success);
}

/* ---- Data Defect form: optional tag, field hints, JSON/CSV mode toggle, locked field ---- */
.form-optional {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-secondary);
}

.field-hint {
    /* Positive top margin so the hint has breathing room from the field above (the "e.g." line under
       Title, the category/priority descriptions under their selects) — a negative top margin jammed it
       against the field border. */
    margin: 7px 0 8px;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-secondary);
}

.field-hint code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    background: rgba(127, 127, 127, 0.14);
    padding: 1px 5px;
    border-radius: 4px;
}

.input-mode-toggle {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: rgba(127, 127, 127, 0.10);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.input-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.input-mode-btn .material-symbols-outlined {
    font-size: 18px;
}

.input-mode-btn:hover {
    color: var(--text);
}

.input-mode-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Locked Category field on the Data Defect form (disabled but kept readable). */
.input-locked[disabled] {
    background: rgba(127, 127, 127, 0.10);
    color: var(--text);
    -webkit-text-fill-color: var(--text);
    cursor: not-allowed;
    opacity: 1;
}

/* File inputs (Data Defect CSV upload): the native control needs vertical room so the "Choose file"
   button doesn't crowd the border; the picker button is restyled to match the portal's buttons. */
input[type="file"].form-input {
    height: auto;
    padding: 9px 12px;
    line-height: 1.4;
    cursor: pointer;
}

input[type="file"].form-input::file-selector-button {
    margin-right: 12px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

input[type="file"].form-input::file-selector-button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Data Defect file mode: the worked JSONL example block (long lines scroll horizontally). */
.corrections-example {
    margin: 0 0 12px;
    padding: 12px 14px;
    background: rgba(127, 127, 127, 0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
    overflow-x: auto;
    white-space: pre;
}

.corrections-example code {
    font-family: inherit;
    background: none;
    padding: 0;
}

.payload-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    padding: 16px;
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 120px;
    border: 1px solid;
}

.payload-code.current {
    background: #FFF5F5;
    border-color: #FECACA;
}

.payload-code.corrected {
    background: #F0FFF4;
    border-color: #BBF7D0;
}

.payload-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 24px;
    font-size: 14px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.payload-meta dt {
    color: var(--text-secondary);
    font-weight: 500;
}

.payload-meta dd {
    color: var(--text);
    font-family: monospace;
}

/* ---- Password field eye toggle + strength meter (shared across login/reset/profile) ---- */
.password-field-wrapper {
    position: relative;
    width: 100%;
}

.password-field-wrapper .form-input {
    padding-right: 40px;
}

.pw-eye-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary, #6b5d99);
    padding: 4px;
    line-height: 1;
    transition: color 150ms ease;
}

.pw-eye-toggle:hover {
    color: var(--primary, #6C63FF);
}

.pw-eye-toggle .material-symbols-outlined {
    font-size: 20px;
}

.pw-strength-container {
    margin-top: 8px;
    margin-bottom: 8px;
}

.pw-meter {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.pw-meter-bar {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border, #E5E7EB);
    transition: background 200ms ease;
}

.pw-meter-label {
    font-size: 12px;
    font-weight: 600;
    transition: color 200ms ease;
}

.pw-checklist {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.pw-checklist li {
    font-size: 12px;
    color: var(--text-secondary); /* #6B7280 — passes WCAG AA on white; #9CA3AF (~2.5:1) did not */
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 200ms ease;
}

.pw-checklist li .material-symbols-outlined {
    font-size: 14px;
}

.pw-checklist li.pw-check-pass {
    color: var(--success, #16A34A);
}

.pw-checklist li.pw-check-fail {
    color: var(--text-secondary); /* #6B7280 — passes WCAG AA on white; #9CA3AF (~2.5:1) did not */
}

/* ---- Alpine.js cloak ---- */
[x-cloak] {
    display: none !important;
}
