@import "../patients/address-lookup-dialog.css";

/* ========================================
   Clinical Form
   ======================================== */

.clinical-form {
    width: 100% !important;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    overflow: visible;
}

/* Form Header */
.clinical-form-header {
    background: linear-gradient(135deg, #186FB5 0%, #1a7cc4 60%, #2089d6 100%);
    padding: 1.75rem 2rem;
    text-align: center;
    border-bottom: 3px solid #155a8f;
}

.clinical-form-title {
    color: #ffffff;
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.01em;
}

.clinical-form-subtitle {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    margin: 0.4rem 0 0;
    font-weight: 400;
}

/* Section */
.question-section {
    width: 100%;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
}

.question-section:last-of-type {
    border-bottom: none;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(90deg, #186FB5 0%, #1a7cc4 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.section-header h3 {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    white-space: nowrap;
}

/* Question rows */
.question-section flex-row[data-question-id] {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease;
}

.question-section flex-row[data-question-id]:last-of-type {
    border-bottom: 1px solid var(--border-color-light, rgba(0, 0, 0, 0.05));
}

.question-section label-field {
    width: 25%;
    min-width: 160px;
    text-align: left;
    justify-content: flex-start !important;
}

.question-section label-field label {
    display: inline;
    line-height: 1.4;
}

.clinical-form-label-text {
    display: inline;
}

.question-section input-field {
    width: 75%;
    display: flex !important;
    gap: .4em !important;
}

flex-row[data-field-type="Table"] input-field {
    flex-direction: column;
    align-items: flex-start;
}

/* Patient Data Fields */
.patient-data-value {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--info-bg, #eff6ff);
    border: 1px solid rgba(24, 111, 181, 0.2);
    border-left: 3px solid var(--blueteq-blue);
    border-radius: 0.25rem;
    min-height: 2.143em;
    width: 100%;
    box-sizing: border-box;
}

.patient-data-value.patient-data-loaded {
    font-weight: 500;
}

.patient-data-value .patient-data-loading {
    color: var(--text-secondary, #6c757d);
    font-style: italic;
    font-weight: 400;
}

/* Form Footer */
.clinical-form-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-tertiary, #f8f9fa);
    border-top: 1px solid var(--border-color);
}

.clinical-form-footer-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* ========================================
   Dark Mode
   ======================================== */
[data-theme="dark"] .clinical-form {
    border-color: var(--border-color);
}

[data-theme="dark"] .clinical-form-header {
    background: linear-gradient(135deg, #0d4f80 0%, #186FB5 100%);
    border-bottom-color: #0b3d63;
}

[data-theme="dark"] .section-header {
    background: linear-gradient(90deg, #0d4f80 0%, #155a8f 100%);
}

[data-theme="dark"] .patient-data-value {
    background-color: rgba(24, 111, 181, 0.1);
    border-color: rgba(24, 111, 181, 0.3);
}

[data-theme="dark"] .clinical-form-footer {
    background: var(--bg-tertiary);
}

/* ========================================
   High Contrast
   ======================================== */
[data-theme="high-contrast"] .clinical-form {
    border: 3px solid #ffffff;
}

[data-theme="high-contrast"] .clinical-form-header {
    background: #000000;
    border-bottom: 3px solid #ffffff;
}

[data-theme="high-contrast"] .clinical-form-title,
[data-theme="high-contrast"] .clinical-form-subtitle {
    color: #ffffff;
}

[data-theme="high-contrast"] .section-header {
    background: #000000;
    border-top: 3px solid #ffffff;
}

[data-theme="high-contrast"] .section-header h3,
[data-theme="high-contrast"] .section-number {
    color: #ffffff;
}

[data-theme="high-contrast"] .section-number {
    background: #ffffff;
    color: #000000;
}

[data-theme="high-contrast"] .patient-data-value {
    background: #000000;
    border: 3px solid #ffffff;
    color: #ffffff;
}

[data-theme="high-contrast"] .clinical-form-footer {
    background: #000000;
    border-top: 3px solid #ffffff;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
    .clinical-form-header {
        padding: 1.25rem 1rem;
    }

    .clinical-form-title {
        font-size: 1.1rem;
    }

    .question-section label-field {
        width: 100%;
        min-width: unset;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color) !important;
        text-align: left;
    }

    .question-section input-field {
        width: 100%;
    }

    .question-section flex-row[data-question-id] {
        flex-direction: column;
    }

    .clinical-form-footer {
        flex-direction: column;
        gap: 0.75rem;
    }

    .clinical-form-footer-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }
}

/* Required indicator */
.required-indicator {
    display: inline;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--danger-color, #dc3545);
    margin-left: 0.35rem;
    white-space: nowrap;
}

/* Validation */
flex-row.validation-error label-field label {
    color: var(--danger-color, #dc3545);
}

flex-row.validation-error input-field input,
flex-row.validation-error input-field textarea,
flex-row.validation-error input-field select {
    border-color: var(--danger-color, #dc3545) !important;
    box-shadow: 0 0 0 1px var(--danger-color, #dc3545);
}

.field-validation-message {
    display: block;
    color: var(--danger-color, #dc3545);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* File upload status indicators */
.file-upload-existing,
.file-upload-none {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.file-upload-existing {
    background: color-mix(in srgb, var(--success-color, #28a745) 10%, transparent);
    color: var(--success-color, #28a745);
    border: 1px solid color-mix(in srgb, var(--success-color, #28a745) 30%, transparent);
}

.file-upload-none {
    background: color-mix(in srgb, var(--text-muted, #6c757d) 10%, transparent);
    color: var(--text-muted, #6c757d);
    border: 1px solid color-mix(in srgb, var(--text-muted, #6c757d) 30%, transparent);
}

/* .form-file-preview lives in elements/sirona-file-upload.css — it's shared by every
   page that renders an upload with .Preview(), not just the clinical form. */

[data-field-type="Text"] {
    padding: 1em;
    background: var(--bg-tertiary);
}

/* ── Checkbox Group ──────────────────────────────────────── */

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-group-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group-item input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--blueteq-blue);
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-group-item label {
    margin: 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* ── Table Field ─────────────────────────────────────────── */

.form-table-empty,
.form-table-no-data {
    color: var(--text-muted, #6c757d);
    font-size: 0.875rem;
    font-style: italic;
}

.form-table-scroll {
    overflow-x: auto;
    width: 100%;
}

.form-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.form-table th {
    background: linear-gradient(90deg, #186FB5 0%, #1a7cc4 100%);
    color: #ffffff;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    text-align: left;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.form-table td {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border-color);
    vertical-align: middle;
    background: var(--bg-secondary);
}

.form-table-action-col {
    width: 2.5rem;
    text-align: center;
}

.form-table-input {
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-table-input:focus {
    outline: none;
    border-color: var(--blueteq-blue);
    box-shadow: 0 0 0 2px rgba(24, 111, 181, 0.15);
}

.form-table-add-row {
    margin-top: 0.5rem;
}

.form-table-static {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
}

.form-table-checkbox {
    width: 1rem;
    height: 1rem;
    accent-color: var(--blueteq-blue);
    cursor: pointer;
    display: block;
    margin: 0 auto;
}

[data-theme="dark"] .form-table th {
    background: linear-gradient(90deg, #0d4f80 0%, #155a8f 100%);
}

[data-theme="dark"] .form-table td {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .form-table-input {
    background: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="high-contrast"] .form-table th {
    background: #000000;
    border: 2px solid #ffffff;
}

[data-theme="high-contrast"] .form-table td {
    background: #000000;
    border: 2px solid #ffffff;
    color: #ffffff;
}

[data-theme="high-contrast"] .form-table-input {
    background: #000000;
    border: 2px solid #ffffff;
    color: #ffffff;
}

/* ========================================
   Address Lookup (standalone)
   ======================================== */

.address-lookup-field--standalone {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.address-lookup-field__item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.address-lookup-field__label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.address-lookup-field__search {
    display: flex;
    gap: 0.5rem;
}

.address-lookup-field__lines {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

@media (max-width: 640px) {
    .address-lookup-field__lines {
        grid-template-columns: 1fr;
    }
}
