/* TRFF SecureForms — public form styling */

.trff-mode-wrapper {
    max-width: 720px;
    margin: 0 auto 1.5rem;
}

/* Segmented control: two radios styled as connected buttons */
.trff-mode-toggle {
    display: flex;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 4px;
    background: #f3f4f6;
    margin-bottom: 1.75rem;
    gap: 4px;
}

.trff-mode-toggle legend {
    /* Hidden visually but available to screen readers via class. */
    border: 0; clip: rect(1px, 1px, 1px, 1px); -webkit-clip-path: inset(50%); clip-path: inset(50%);
    height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; word-wrap: normal !important;
}

.trff-mode-option {
    flex: 1;
    margin: 0;
    cursor: pointer;
    position: relative;
}

.trff-mode-option input[type="radio"] {
    /* Hide the actual radio; the label acts as the visual control. */
    position: absolute;
    opacity: 0;
    inset: 0;
    cursor: pointer;
}

.trff-mode-label {
    display: block;
    text-align: center;
    padding: 0.65rem 1rem;
    border-radius: 6px;
    font-weight: 700;
    color: #374151;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    user-select: none;
    text-transform: uppercase;
    font-size: 13px;
}

.trff-mode-option input[type="radio"]:hover + .trff-mode-label {
    color: #111827;
    background: rgba(255, 255, 255, 0.5);
}

.trff-mode-option input[type="radio"]:checked + .trff-mode-label {
    background: #fff;
    color: #1d4ed8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.trff-mode-option input[type="radio"]:focus-visible + .trff-mode-label {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.trff-pane[hidden] {
    display: none;
}

/* Extras: configurable form fields mapped to UDF columns. */

.trff-field-checkbox .trff-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    color: #1f2937;
    text-transform: uppercase;
    font-size: 13px;
}

.trff-field-checkbox .trff-checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
    width: 1.1rem;
    height: 1.1rem;
    accent-color: #2563eb;
    flex-shrink: 0;
}

.trff-field-help {
    font-size: 0.85em;
    color: #666;
    margin-top: 3px;
    line-height: 1.5;
}

.trff-field-checkbox .trff-field-help {
    margin-left: 1.7rem; /* align under the label text, past the checkbox */
}

.trff-required {
    color: #dc2626;
    margin-left: 0.15rem;
}

/* Per-batch extras block on the CSV upload form */

.trff-csv-extras {
    margin: 1.75rem 0 1.5rem;
}

.trff-csv-extras-note {
    margin: 0 0 0.9rem;
    font-size: 0.9rem;
    color: #4b5563;
}

.trff-csv-extras .trff-field {
    margin-bottom: 0.85rem;
}

.trff-csv-extras .trff-field:last-child {
    margin-bottom: 0;
}

.trff-form-container,
.trff-csv-container {
    max-width: 720px;
    margin: 0 auto;
}

.trff-field {
    margin-bottom: 18px;
}

/* Labels: match the values from the /trff/ vc_custom CSS exactly.
   font-weight 700, uppercase, 13px. Letter-spacing default. */
.trff-field label {
    display: block;
    font-weight: 700;
    margin-bottom: 0.4rem;
    color: #1f2937;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0;
}

.trff-field input[type="text"],
.trff-field input[type="email"],
.trff-field input[type="file"],
.trff-field textarea,
.trff-field select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    background: #fff;
}

/* Textarea: monospace + minimum height to match /trff/ #lot_numbers
   styling. The monospace font is intentional — it makes long lot
   numbers easier to read and visually distinguishes the field. */
.trff-field textarea {
    font-family: monospace;
    font-size: 14px;
    line-height: 1.4;
    min-height: 120px;
    resize: vertical;
}

.trff-field input:focus,
.trff-field textarea:focus {
    outline: none;
    border-color: #007bae;
    box-shadow: 0 0 0 3px rgba(0, 123, 174, 0.15);
}

/* Disabled input (e.g. MRN when Discarded is selected) — match /trff/'s
   #patient_number:disabled colors. */
.trff-field input[type="text"]:disabled,
.trff-field input[type="email"]:disabled,
.trff-field textarea:disabled {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.trff-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.trff-row > * {
    flex: 1;
    min-width: 0;
}

.trff-field-half {
    flex: 1;
}

.trff-radio-group {
    display: flex;
    gap: 1.5rem;
}

/* Radio labels render the same as field labels in /trff/ because the
   `.form-group label` rule wins specificity over `.radio-label`. So
   "SURGERY"/"DISCARDED" appear as bold uppercase 13px on /trff/, and
   we mirror that exactly. */
.trff-radio {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    cursor: pointer;
    color: #1f2937;
    text-transform: uppercase;
    font-size: 13px;
}

.trff-hint {
    display: block;
    font-size: 0.85em;
    color: #666;
    margin-top: 3px;
}

.trff-conditional {
    font-weight: normal;
    font-size: 0.85rem;
    color: #6b7280;
}

.trff-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.trff-submit {
    background: #007bae;
    color: #fff;
    border: none;
    padding: 0.7rem 1.5rem;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.trff-submit:hover { background: #000000; }
.trff-submit:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.8;
}

.trff-csv-link {
    font-size: 0.95rem;
    color: #2563eb;
    text-decoration: underline;
}

.trff-status-banner {
    padding: 1rem 1.25rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    border-left: 4px solid #6b7280;
    background: #f9fafb;
    color: #374151;
}

.trff-status-banner.trff-status-processing {
    background: #eff6ff;
    border-left-color: #2563eb;
    color: #1e40af;
}

.trff-status-banner.trff-status-complete {
    background: #ecfdf5;
    border-left-color: #10b981;
    color: #065f46;
}

.trff-status-banner.trff-status-failed {
    background: #fef2f2;
    border-left-color: #ef4444;
    color: #991b1b;
}

.trff-status-banner.trff-status-partial {
    background: #fffbeb;
    border-left-color: #f59e0b;
    color: #92400e;
}

.trff-status-text {
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.trff-status-detail {
    font-size: 0.95rem;
    margin: 0.4rem 0;
}

.trff-trace-id {
    font-size: 0.85rem;
    margin-top: 0.6rem;
    opacity: 0.85;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.trff-trace-id code {
    background: rgba(0,0,0,0.06);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}

.trff-error {
    padding: 1rem;
    background: #fef2f2;
    border-left: 4px solid #ef4444;
    color: #991b1b;
    border-radius: 4px;
    margin-bottom: 1rem;
}

/* CSV-specific */
.trff-csv-instructions {
    color: #4b5563;
    line-height: 1.6;
    margin-bottom: 1.75rem;
}

.trff-csv-instructions p:last-child {
    margin-bottom: 0;
}

/* Template-download block: button on its own line, hint as a small
   secondary line underneath. Cleaner than the inline "[button] with the
   expected column headers..." phrasing which wrapped awkwardly. */
.trff-csv-template-block {
    margin: 0 0 2rem;
}

.trff-csv-template-hint {
    display: block;
    margin-top: 0.5rem;
    color: #6b7280;
    font-size: 0.9rem;
}

.trff-template-link {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    text-decoration: none;
    color: #1f2937;
    font-weight: 500;
}

.trff-template-link:hover { background: #e5e7eb; }

/* Give the CSV form a touch more breathing room than the manual form.
   The file picker is a single tall focus point so the surrounding
   fields/buttons need more separation, not less. */
.trff-csv-container .trff-field {
    margin-bottom: 1.5rem;
}

/* Responsive */
@media (max-width: 600px) {
    .trff-row { flex-direction: column; }
    .trff-radio-group { flex-direction: column; gap: 0.5rem; }
}

/*
 * Submit button styling — preserved from the v1 plugin so the visual
 * experience matches what users are accustomed to.
 *
 * The button has BOTH classes: `submit-button` (so the host theme's
 * existing button styling applies — v1 inherited from the theme) and
 * `trff-submit` (our own namespace for any v2-specific overrides).
 *
 * The spinner shown on submit is the v1 implementation verbatim.
 */
.trff-form-container .submit-group,
.trff-csv-container .submit-group {
    text-align: center;
    margin-top: 1.5rem;
}

.trff-csv-container .submit-group {
    margin-top: 2rem;
}

.trff-submit.submit-button {
    position: relative;
    transition: all 0.3s ease;
}

.trff-submit.submit-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Spinner — appears inside the button while a submission is in flight.
   Inline-block so it sits next to the "Processing" text. */
.trff-submit .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: trff-spin 1s ease-in-out infinite;
    vertical-align: middle;
}

@keyframes trff-spin {
    to { transform: rotate(360deg); }
}
