/* ============================================================
   CervixDx Platform — forms.css
   All form-specific styles. Loaded after style.css.
   Covers: patients/add, patients/edit, specimens/add,
           specimens/edit, images/upload, and any future forms.
   ============================================================ */

/* ── Design tokens (mirrors style.css — no duplication needed,
      vars are global once style.css is loaded first) ───────── */

/* ════════════════════════════════════════════════════════════
   1. PAGE WRAPPER & HEADER
   ════════════════════════════════════════════════════════════ */

.form-container {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.form-header {
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 2px solid var(--border);
}

.form-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    margin: 0 0 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.form-header h2 i {
    color: var(--brand-start);
    font-size: 1.25rem;
}

.form-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
    line-height: 1.5;
}

/* ════════════════════════════════════════════════════════════
   2. FORM SECTIONS — white card groupings
   ════════════════════════════════════════════════════════════ */

.form-section {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 14px);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(15,23,55,0.08));
}

.form-section:last-of-type {
    margin-bottom: 0;
}

.form-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--brand-start, #4f63d2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Accent bar before section title */
.form-section-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 13px;
    background: linear-gradient(180deg, var(--brand-start, #4f63d2), var(--brand-end, #6c3fc5));
    border-radius: 2px;
    flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════
   3. FORM GROUPS & LABELS
   ════════════════════════════════════════════════════════════ */

.form-group {
    margin-bottom: 1.125rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary, #4a5270);
    margin-bottom: 0.375rem;
    letter-spacing: 0.01em;
}

/* Required asterisk */
.required {
    color: #dc2626;
    font-size: 0.9em;
    margin-left: 2px;
}

/* Optional tag */
.optional-tag {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted, #8892b0);
    margin-left: 0.25rem;
}

/* Hint text below inputs */
.help-text {
    display: block;
    font-size: 0.78125rem;
    color: var(--text-muted, #8892b0);
    margin-top: 0.3rem;
    line-height: 1.45;
}

/* Note about required fields */
.required-fields-note {
    font-size: 0.8125rem;
    color: var(--text-muted, #8892b0);
    margin-bottom: 1.25rem;
}

/* ════════════════════════════════════════════════════════════
   4. FORM CONTROLS — inputs, selects, textareas
   ════════════════════════════════════════════════════════════ */

.form-control {
    width: 100%;
    padding: 0.5625rem 0.875rem;
    font-family: 'IBM Plex Sans', -apple-system, sans-serif;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary, #1a1f36);
    background: #ffffff;
    border: 1.5px solid var(--border-strong, #c8cee0);
    border-radius: 6px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    box-sizing: border-box;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand-start, #4f63d2);
    box-shadow: 0 0 0 3px rgba(79, 99, 210, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted, #8892b0);
    font-size: 0.875rem;
}

/* Select */
select.form-control {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%234a5270' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    background-size: 10px;
    padding-right: 2.5rem;
}

/* Textarea */
textarea.form-control {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

/* Disabled / readonly */
.form-control:disabled,
.form-control[readonly],
.auto-field {
    background: var(--bg-subtle, #f7f8fc) !important;
    color: var(--text-muted, #8892b0) !important;
    cursor: not-allowed !important;
    border-color: var(--border, #e2e6f0) !important;
    box-shadow: none !important;
}

.auto-field-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted, #8892b0);
    font-style: italic;
    margin-top: 0.3rem;
}

/* Sizes */
.form-control-sm { padding: 0.375rem 0.625rem; font-size: 0.8125rem; }
.form-control-lg { padding: 0.75rem 1rem;      font-size: 1rem; }

/* ════════════════════════════════════════════════════════════
   5. VALIDATION STATES
   ════════════════════════════════════════════════════════════ */

.form-control.is-valid   { border-color: #16a34a; }
.form-control.is-valid:focus { box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }

.form-control.is-invalid { border-color: #dc2626; }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }

.valid-feedback {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: #16a34a;
}

.invalid-feedback,
.form-error {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: #dc2626;
}

/* ════════════════════════════════════════════════════════════
   6. SPECIAL INPUT TYPES
   ════════════════════════════════════════════════════════════ */

/* Lab number — highlighted blue monospace */
.lab-number-field {
    font-family: 'IBM Plex Mono', monospace !important;
    font-weight: 600 !important;
    font-size: 0.9375rem !important;
    letter-spacing: 0.03em;
    color: #1d4ed8 !important;
    background: #eff6ff !important;
    border: 2px solid #3b82f6 !important;
}

.lab-number-field:focus {
    border-color: #1d4ed8 !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.18) !important;
}

/* Date / datetime */
input[type="date"].form-control,
input[type="datetime-local"].form-control {
    cursor: pointer;
}

/* Number — show spinners */
input[type="number"].form-control::-webkit-inner-spin-button,
input[type="number"].form-control::-webkit-outer-spin-button {
    opacity: 1;
}

/* File */
input[type="file"].form-control {
    padding: 0.4375rem 0.75rem;
    cursor: pointer;
}

/* ════════════════════════════════════════════════════════════
   7. CHECKBOXES & RADIO
   ════════════════════════════════════════════════════════════ */

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.625rem;
}

.form-check-input,
input[type="checkbox"],
input[type="radio"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--brand-start, #4f63d2);
    cursor: pointer;
    flex-shrink: 0;
}

.form-check-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary, #1a1f36);
    cursor: pointer;
    margin: 0;
}

/* Inline checkbox in a form-group label */
.form-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-primary, #1a1f36);
    font-size: 0.9rem;
}

/* ════════════════════════════════════════════════════════════
   8. GRID LAYOUT — form-row
   ════════════════════════════════════════════════════════════ */

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0;
}

.form-row + .form-row {
    margin-top: 1.125rem;
}

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

.form-row.four-col {
    grid-template-columns: repeat(4, 1fr);
}

.form-col-full {
    grid-column: 1 / -1;
}

/* ════════════════════════════════════════════════════════════
   9. INPUT GROUPS (icon/button attached to input)
   ════════════════════════════════════════════════════════════ */

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    border-radius: 6px 0 0 6px;
    flex: 1;
}

.input-group-append { display: flex; }

.input-group-append .btn {
    border-radius: 0 6px 6px 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0.5625rem 0.875rem;
    background: var(--bg-subtle, #f7f8fc);
    border: 1.5px solid var(--border-strong, #c8cee0);
    border-left: none;
    border-radius: 0 6px 6px 0;
    color: var(--text-muted, #8892b0);
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Password toggle */
.password-toggle { position: relative; }

.password-toggle .toggle-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted, #8892b0);
    padding: 0;
    line-height: 1;
    transition: color 0.18s;
}

.password-toggle .toggle-btn:hover { color: var(--brand-start, #4f63d2); }

/* ════════════════════════════════════════════════════════════
   10. FORM ACTIONS BAR
   ════════════════════════════════════════════════════════════ */

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 1.25rem 0 0.25rem;
    border-top: 1px solid var(--border, #e2e6f0);
    margin-top: 1.25rem;
}

/* ════════════════════════════════════════════════════════════
   11. SEARCH FORM
   ════════════════════════════════════════════════════════════ */

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.search-form .form-control { flex: 1; }

/* ════════════════════════════════════════════════════════════
   12. FILE UPLOAD — drag & drop zone
   ════════════════════════════════════════════════════════════ */

.file-upload-area {
    border: 2.5px dashed #3b82f6;
    border-radius: var(--radius-lg, 14px);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    background: linear-gradient(135deg, var(--bg-subtle, #f7f8fc), #eff6ff);
    position: relative;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-color: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(59,130,246,0.12);
}

.upload-icon {
    font-size: 2.75rem;
    margin-bottom: 0.75rem;
    display: block;
    line-height: 1;
    opacity: 0.85;
}

.upload-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #1a1f36);
    margin: 0 0 0.375rem;
}

.upload-sub {
    font-size: 0.8125rem;
    color: var(--text-muted, #8892b0);
    margin: 0.2rem 0;
}

/* ════════════════════════════════════════════════════════════
   13. IMAGE PREVIEW GRID (upload page)
   ════════════════════════════════════════════════════════════ */

.multiple-previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
    padding: 1.125rem;
    background: var(--bg-subtle, #f7f8fc);
    border-radius: var(--radius-md, 10px);
    border: 2px solid #86efac;
}

.image-preview-item {
    position: relative;
    background: #ffffff;
    border-radius: var(--radius-md, 10px);
    padding: 0.5rem;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(15,23,55,0.08));
    border: 1px solid var(--border, #e2e6f0);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.image-preview-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(15,23,55,0.12);
}

.image-preview-item img {
    width: 100%;
    height: 115px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: block;
}

.preview-info {
    font-size: 0.75rem;
    color: var(--text-secondary, #4a5270);
}

.preview-info strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary, #1a1f36);
    margin-bottom: 0.125rem;
    font-weight: 600;
}

.q-badge {
    position: absolute;
    top: 8px; right: 8px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 700;
    backdrop-filter: blur(4px);
}

.q-high   { background: #16a34a !important; }
.q-medium { background: #d97706 !important; }
.q-low    { background: #dc2626 !important; }

.remove-btn {
    position: absolute;
    top: 8px; left: 8px;
    background: #dc2626;
    color: #fff;
    border: none;
    padding: 2px 7px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.6;
    transition: background 0.15s ease;
}

.remove-btn:hover { background: #b91c1c; }

/* Quality info box (replaces the quality score input in upload) */
.quality-info-box {
    padding: 0.875rem 1rem;
    background: #f0fdf4;
    border-left: 3px solid #16a34a;
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-secondary, #4a5270);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 80px;
}

.quality-info-box p { margin: 0 0 0.25rem; }
.quality-info-box p:last-child { margin: 0; }
.quality-info-box strong { color: var(--text-primary, #1a1f36); }

/* Lab number pill (shown after selecting specimen) */
.lab-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: #eff6ff;
    border: 1px solid #93c5fd;
    border-radius: 6px;
    padding: 0.1875rem 0.625rem;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    color: #1d4ed8;
    font-size: 0.875rem;
    letter-spacing: 0.02em;
}

/* ════════════════════════════════════════════════════════════
   14. RESPONSIVE
   ════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .form-container {
        padding: 0;
    }

    .form-section {
        padding: 1.125rem;
        border-radius: 10px;
    }

    .form-row,
    .form-row.three-col,
    .form-row.four-col {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .file-upload-area {
        padding: 2rem 1rem;
    }

    .multiple-previews {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    .search-form { flex-direction: column; }
}

@media (max-width: 480px) {
    .form-section { padding: 1rem; }
    .form-header h2 { font-size: 1.25rem; }
    .multiple-previews { grid-template-columns: 1fr 1fr; }
}
