/* Modal Dialog Styles */

/* Prevent background scrolling when any modal is open */
body:has(dialog[open]) {
    overflow: hidden;
}

/* Base dialog styling */
.modal-dialog {
    padding: 0;
    border: none;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 90%;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: modalFadeIn 0.2s ease-out;
}

.modal-dialog.modal-narrow {
    max-width: 420px;
}

.modal-dialog.modal-wide {
    max-width: 560px;
}

/* Backdrop styling for dialog.

   No backdrop-filter. A blur here has to be recomputed over the whole
   viewport while the backdrop and the dialog above it animate, which drops
   frames on a long page — the question builder runs to several thousand
   nodes. Two pixels of blur under a half-black scrim was not visible enough
   to pay for that. */
.modal-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    animation: backdropFadeIn 0.2s ease-out;
}

/* Modal content container */
.modal-content {
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

/* Modal header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

/* Modal close button */
.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-close .label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.modal-close::before {
    content: '';
    display: block;
    width: 1rem;
    height: 1rem;
    background-image: url('/images/icons_sunrise/Exit.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.modal-close:hover::before {
    background-image: url('/images/icons_blaze/Exit.svg');
}

/* Modal body */
.modal-body {
    padding: 1.5rem;
    flex: 1;
    /* Modals are portalled into whatever markup happens to contain them — the
       survey end screen centres its content, which the dialog then inherited and
       rendered as ragged centered prose. State the alignment rather than depend
       on the ancestor. */
    text-align: left;
}

.modal-body p {
    margin: 0;
    line-height: 1.6;
    color: #333;
}

.modal-body p + p {
    margin-top: 0.75rem;
}

/* Modal footer */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid #e0e0e0;
    background-color: #f8f9fa;
}

/* Password input with visibility toggle */
.password-input-wrapper {
    display: flex;
    position: relative;
}

.password-input-wrapper input {
    flex: 1;
    padding-right: 2.75rem;
}

.password-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--color-text-secondary, #666);
    transition: color 0.2s;
}

.password-toggle:hover {
    color: var(--color-text-primary, #333);
}

.password-toggle::before {
    content: "";
    display: block;
    width: 1.25rem;
    height: 1.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z'/%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.password-toggle[aria-label="Hide password"]::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M3.98 8.223A10.477 10.477 0 0 0 1.934 12c1.292 4.338 5.31 7.5 10.066 7.5.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88'/%3E%3C/svg%3E");
}

/* Password validation error (client-side, shown below input) */
.password-error {
    color: var(--color-error, #c33);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Danger zone styling */
.danger-zone {
    margin-top: 3rem;
    padding: 1.5rem;
    border: 2px solid #dc3545;
    border-radius: 8px;
    background-color: #fff5f5;
}

.danger-zone h3 {
    color: #dc3545;
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.danger-zone h3::before {
    content: '';
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    background-image: url('/images/icons_blaze/Delete.svg');
    background-size: contain;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.danger-zone p {
    color: #721c24;
    margin-bottom: 1rem;
}

/* Animations */
/* Opacity only. The dialog's own transform already centers it, and the
   keyframes used to restate it with a scale(1) that changed nothing but
   made this a transform animation, which the compositor cannot always
   hand off. The close animation below does move, and keeps its transform. */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes backdropFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Close animation class (applied via JS when closing) */
.modal-dialog.closing {
    animation: modalFadeOut 0.15s ease-in;
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -52%) scale(0.95);
    }
}

/* Wide modal variant */
.modal-dialog.modal-wide {
    max-width: 700px;
}

/* Dependency warning modal styles */
.dep-warning {
    background-color: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    color: #6d4c00;
    line-height: 1.5;
}

.dep-card {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fafafa;
}

.dep-card:last-of-type {
    margin-bottom: 0;
}

.dep-card-header {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.dep-card-header .dep-qid-badge {
    display: inline-block;
    background: var(--color-brand-navy, #1a3a5c);
    color: white;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.dep-card-header .dep-prompt {
    color: #555;
    font-size: 0.9rem;
    line-height: 1.4;
}

.dep-condition-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.dep-condition-row select,
.dep-condition-row input[type="text"],
.dep-condition-row input[type="number"] {
    padding: 0.35rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.85rem;
}

.dep-condition-row select {
    min-width: 120px;
}

.dep-condition-row .dep-field-select {
    flex: 1;
    min-width: 140px;
}

.dep-condition-row .dep-operator-select {
    min-width: 120px;
}

.dep-condition-row .dep-value-input {
    flex: 1;
    min-width: 100px;
}

.dep-condition-label {
    font-size: 0.8rem;
    color: #888;
    font-weight: 500;
    min-width: 1.5rem;
}

.dep-condition-readonly {
    font-size: 0.85rem;
    color: #888;
    font-style: italic;
    padding: 0.35rem 0;
}

.dep-draft-warning {
    font-style: italic;
    color: #b26a00;
    font-size: 0.85rem;
    margin-top: 1rem;
}

.dep-modal-body {
    max-height: 60vh;
    overflow-y: auto;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .modal-dialog {
        width: 95%;
        max-width: none;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 1rem;
    }
}