/* ==========================================================================
   The modal (components/modal.blade.php)

   Bootstrap still opens and closes it; this file gives it the panel's look and
   its own motion. Colours come from the panel tokens - --ap-* (admin.css) or
   --cp-* (candidate.css) - with fallbacks for a page that has neither. Flat
   colours only, no gradients.

   Motion: the dialog rises 12px and scales from .96 while it fades in; on
   close it runs the same path back, faster. The backdrop fades with it. A
   static modal gives a small nudge when the backdrop is clicked. Reduced-
   motion users get a plain fade.
   ========================================================================== */

.modal.app-modal {
    --am-primary: var(--ap-primary, var(--cp-primary, #198754));
    --am-primary-dark: var(--ap-primary-dark, var(--cp-primary-dark, #146c43));
    --am-primary-soft: var(--ap-primary-soft, var(--cp-primary-soft, #e8f3ee));
    --am-surface: var(--ap-surface, #ffffff);
    --am-surface-muted: var(--ap-surface-muted, #f9fbfa);
    --am-border: var(--ap-border, #e3e9e6);
    --am-text: var(--ap-text, #1b2420);
    --am-text-muted: var(--ap-text-muted, #5f6b66);
    --am-text-faint: var(--ap-text-faint, #8a958f);
    --am-danger: var(--ap-danger, #b42318);
    --am-danger-dark: #912018;
    --am-danger-soft: var(--ap-danger-soft, #fdecec);
    --am-warning: var(--ap-warning, #b45309);
    --am-warning-soft: var(--ap-warning-soft, #fdf3e7);
    --am-info: var(--ap-info, #175cd3);
    --am-info-soft: var(--ap-info-soft, #eaf1fd);
    --am-radius: 16px;
    --am-radius-sm: var(--ap-radius-sm, 8px);

    /* the accent the icon wears; the variants below swap it */
    --am-accent: var(--am-primary);
    --am-accent-soft: var(--am-primary-soft);

    --bs-modal-padding: 22px;
}

.modal.app-modal--danger { --am-accent: var(--am-danger); --am-accent-soft: var(--am-danger-soft); }
.modal.app-modal--warning { --am-accent: var(--am-warning); --am-accent-soft: var(--am-warning-soft); }
.modal.app-modal--info { --am-accent: var(--am-info); --am-accent-soft: var(--am-info-soft); }

/* ---------- motion ---------- */

.modal.app-modal.fade .modal-dialog {
    opacity: 0;
    transform: translateY(12px) scale(.96);
    transition: transform .16s cubic-bezier(.4, 0, 1, 1), opacity .14s ease-in;
}

.modal.app-modal.show .modal-dialog {
    opacity: 1;
    transform: none;
    transition: transform .26s cubic-bezier(.16, 1, .3, 1), opacity .2s ease-out;
}

/* static backdrop clicked: Bootstrap adds .modal-static for a moment */
.modal.app-modal.modal-static .modal-dialog {
    transform: none;
    animation: app-modal-nudge .3s ease;
}

@keyframes app-modal-nudge {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.02); }
}

/* Bootstrap keeps one backdrop for every modal; it only ever belongs to ours now */
.modal-backdrop {
    --bs-backdrop-bg: #0c1a14;
    --bs-backdrop-opacity: .45;
    transition: opacity .2s ease;
}

@media (prefers-reduced-motion: reduce) {
    .modal.app-modal.fade .modal-dialog,
    .modal.app-modal.show .modal-dialog {
        transform: none;
        transition: opacity .15s linear;
    }

    .modal.app-modal.modal-static .modal-dialog {
        animation: none;
    }
}

/* ---------- frame ---------- */

.modal.app-modal .modal-content {
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius);
    background: var(--am-surface);
    color: var(--am-text);
    box-shadow: 0 24px 56px rgba(16, 24, 40, .18), 0 4px 12px rgba(16, 24, 40, .06);
    overflow: hidden;
}

/* a <form> between .modal-content and its parts must not break the scrollable layout */
.modal.app-modal .app-modal__form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
}

.modal.app-modal .modal-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--am-border);
    background: var(--am-surface);
}

.app-modal__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--am-accent-soft);
    color: var(--am-accent);
}

.app-modal__heading {
    flex: 1 1 auto;
    min-width: 0;
    align-self: center;
}

.modal.app-modal .modal-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--am-text);
}

.app-modal__subtitle {
    margin: 3px 0 0;
    font-size: .84rem;
    line-height: 1.45;
    color: var(--am-text-muted);
}

.app-modal__subtitle:empty {
    display: none;
}

.app-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    margin: -4px -6px 0 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--am-text-faint);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.app-modal__close:hover {
    background: var(--am-surface-muted);
    color: var(--am-text);
}

.app-modal__close:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px var(--am-primary-soft);
    color: var(--am-text);
}

.modal.app-modal .modal-body {
    padding: 20px 22px;
    color: var(--am-text);
}

.modal.app-modal .modal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--am-border);
    background: var(--am-surface-muted);
}

.modal.app-modal .modal-footer > * {
    margin: 0;
}

/* ---------- inside the body ---------- */

.modal.app-modal .form-label {
    font-weight: 600;
    font-size: .875rem;
    color: var(--am-text);
}

.modal.app-modal .form-control,
.modal.app-modal .form-select {
    border-radius: 10px;
    border-color: #d5ddd9;
}

.modal.app-modal .form-control:focus,
.modal.app-modal .form-select:focus {
    border-color: var(--am-primary);
    box-shadow: 0 0 0 3px var(--am-primary-soft);
}

.modal.app-modal .form-control[readonly] {
    background: var(--am-surface-muted);
    color: var(--am-text-muted);
}

/* a labelled read-only fact, e.g. who a decision is about */
.app-modal__fact {
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--am-border);
    border-radius: 12px;
    background: var(--am-surface-muted);
}

.app-modal__fact-label {
    display: block;
    margin-bottom: 2px;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--am-text-faint);
}

.app-modal__fact-value {
    font-weight: 600;
    color: var(--am-text);
}

/* ---------- footer buttons ----------
   The look is the shared system (assets/css/buttons.css); the footer only
   keeps its buttons from being narrower than a thumb. */

.modal.app-modal .modal-footer .btn {
    min-width: 96px;
}

/* ---------- small screens ---------- */

@media (max-width: 575.98px) {
    .modal.app-modal .modal-dialog:not(.modal-fullscreen-sm-down) {
        margin: 12px;
    }

    .modal.app-modal .modal-header,
    .modal.app-modal .modal-body,
    .modal.app-modal .modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal.app-modal .modal-footer .btn {
        flex: 1 1 0;
    }
}
