/* Default styles for standalone form */
#anesthesia-form-container:not(.modal-form) {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: Arial, sans-serif;
}

/* Modal form styles override */
#anesthesia-form-wrapper #anesthesia-form-container {
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: Arial, sans-serif;
    height: auto;
    min-height: 100vh;
}

#anesthesia-form-container h3 {
    color: #333;
    text-align: center;
    margin-bottom: 30px;
    font-size: 24px;
}

.form-section {
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    background-color: #f9f9f9;
}

.form-section legend {
    font-weight: bold;
    font-size: 18px;
    color: #2c3e50;
    padding: 0 10px;
    background-color: white;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
}

.form-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.form-row label {
    font-weight: bold;
    margin-bottom: 5px;
    color: #444;
    font-size: 14px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="date"],
.form-row select,
.form-row textarea {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
}

.form-row input[type="text"]:focus,
.form-row input[type="number"]:focus,
.form-row input[type="date"]:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.form-row select[multiple] {
    height: auto;
    min-height: 80px;
}

.multi-select-container {
    position: relative;
}

.multi-select-container small {
    color: #666;
    font-style: italic;
    margin-top: 5px;
    display: block;
}

/* Two-input rows (age + unit, weight + unit) */
.form-row select + select,
.form-row input + select {
    margin-left: 10px;
    flex: 0 0 auto;
    width: 120px;
}

.form-row:has(input[name="patient_age"]),
.form-row:has(input[name="weight"]) {
    flex-direction: row;
    align-items: flex-end;
}

.form-row:has(input[name="patient_age"]) input,
.form-row:has(input[name="weight"]) input {
    flex: 1;
    margin-right: 10px;
}

.form-row:has(input[name="patient_age"]) label,
.form-row:has(input[name="weight"]) label {
    margin-bottom: 5px;
    flex: 100%;
}

.form-actions {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e1e1e1;
}

#submit-btn {
    background-color: #2980b9;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#submit-btn:hover {
    background-color: #3498db;
}

#submit-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

#form-messages {
    margin-top: 15px;
    padding: 10px;
    border-radius: 4px;
}

#form-messages.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

#form-messages.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

#download-section {
    text-align: center;
    margin-top: 30px;
    padding: 20px;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 6px;
}

#download-section h4 {
    color: #155724;
    margin-bottom: 15px;
}

#download-link {
    display: inline-block;
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

#download-link:hover {
    background-color: #218838;
}

/* Required field indicator */
label:has(+ input[required]),
label:has(+ select[required]),
label:has(+ textarea[required]) {
    position: relative;
}

label:has(+ input[required])::after,
label:has(+ select[required])::after,
label:has(+ textarea[required])::after {
    content: " *";
    color: #e74c3c;
    font-weight: bold;
}

/* Loading state */
.loading #submit-btn {
    position: relative;
    color: transparent;
}

.loading #submit-btn::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Split-screen modal layout */
#anesthesia-form-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    z-index: 1000;
}

.notes-panel {
    width: 50%;
    height: 100vh;
    background: white;
    border-right: 2px solid #333;
    display: flex;
    flex-direction: column;
}

.notes-header {
    padding: 15px 20px;
    background: #f0f0f0;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.notes-header h4 {
    margin: 0;
    color: #333;
}

.toggle-notes {
    background: #2980b9;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.notes-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.notes-content textarea {
    width: 100%;
    height: 100%;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: none;
    outline: none;
}

.notes-content textarea:focus {
    border-color: #3498db;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.form-panel {
    width: 50%;
    height: 100vh;
    background: white;
    overflow-y: auto !important;
    overflow-x: hidden;
    position: relative;
    box-sizing: border-box;
}

/* Ensure proper scrolling behavior */
#anesthesia-form-wrapper .form-panel {
    display: block;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch; /* For iOS smooth scrolling */
}

.notes-panel.minimized {
    width: 10%;
}

.notes-panel.minimized .notes-content {
    display: none;
}

.notes-panel.minimized ~ .form-panel {
    width: 90%;
}

/* Case management section */
.case-management-section {
    margin-bottom: 20px;
    padding: 15px;
    background: #f0f8ff;
    border: 1px solid #c0d9ff;
    border-radius: 5px;
}

/* Fluid additives styling */
.fluids-selection {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fluid-item {
    display: flex;
    flex-direction: column;
}

.fluid-additive {
    margin-left: 20px;
    margin-top: 5px;
}

.additive-input {
    width: 200px;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
}

/* Checkbox grid styling */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-item input[type="checkbox"] {
    margin: 0;
}

.checkbox-item label {
    margin: 0;
    font-weight: normal;
    cursor: pointer;
    font-size: 14px;
}

/* Medication groups */
.medication-group {
    margin-bottom: 25px;
}

.medication-group label {
    font-weight: bold;
    font-size: 16px;
    color: #2c3e50;
    margin-bottom: 10px;
}

/* Dynamic drug/route selection */
.dynamic-medication-container {
    margin-bottom: 15px;
}

.drug-route-pair {
    margin-bottom: 10px;
}

.drug-selection {
    display: flex;
    gap: 10px;
    align-items: center;
}

.drug-select, .route-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
}

.drug-select {
    flex: 2;
    min-width: 200px;
}

.route-select {
    flex: 1;
    min-width: 100px;
}

.add-drug-btn, .remove-drug-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 5px;
}

.add-drug-btn:hover, .remove-drug-btn:hover {
    background: #2980b9;
}

.remove-drug-btn {
    background: #e74c3c;
    padding: 6px 10px;
    font-size: 12px;
}

.remove-drug-btn:hover {
    background: #c0392b;
}

.info-note {
    font-style: italic;
    color: #666;
    font-size: 13px;
    margin-top: 5px;
}

/* Modal close button */
.modal-close {
    position: fixed;
    top: 15px;
    right: 15px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.modal-close:hover {
    background: #c0392b;
    transform: scale(1.1);
    transition: all 0.2s ease;
}

/* Responsive design */
@media (max-width: 768px) {
    #anesthesia-form-wrapper {
        flex-direction: column;
    }

    .notes-panel {
        width: 100%;
        height: 40vh;
        border-right: none;
        border-bottom: 2px solid #333;
    }

    .form-panel {
        width: 100%;
        height: 60vh;
    }

    .notes-panel.minimized {
        height: 10vh;
        width: 100%;
    }

    .notes-panel.minimized ~ .form-panel {
        height: 90vh;
        width: 100%;
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }

    .drug-selection {
        flex-direction: column;
        gap: 8px;
    }

    .drug-select, .route-select {
        flex: none;
        width: 100%;
    }
}

@media (max-width: 600px) {
    #anesthesia-form-container {
        padding: 15px;
    }

    .form-section {
        padding: 15px;
    }

    .form-row:has(input[name="patient_age"]),
    .form-row:has(input[name="weight"]) {
        flex-direction: column;
    }

    .form-row:has(input[name="patient_age"]) input,
    .form-row:has(input[name="weight"]) input {
        margin-right: 0;
        margin-bottom: 5px;
    }

    .form-row select + select,
    .form-row input + select {
        margin-left: 0;
        width: 100%;
    }

    .notes-header {
        padding: 10px 15px;
    }

    .notes-content {
        padding: 15px;
    }

    .add-drug-btn, .remove-drug-btn {
        width: 100%;
        margin-top: 10px;
    }
}