/* ==========================================================================
   Modal / Popup Styles
   ========================================================================== */

/* --- Modal Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    padding: 1rem;
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* --- Modal Box --- */
.modal {
    background-color: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    transform: translateY(-10px) scale(0.98);
    transition: transform 0.2s ease;
    overflow: hidden;
}

.modal-overlay.open .modal {
    transform: translateY(0) scale(1);
}

/* Size variants */
.modal-sm {
    max-width: 400px;
}

.modal-lg {
    max-width: 720px;
}

.modal-xl {
    max-width: 960px;
}

.modal-full {
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 2rem);
}

/* --- Modal Header --- */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-light);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all var(--transition);
    line-height: 1;
}

.modal-close:hover {
    background-color: var(--bg);
    color: var(--text);
}

/* --- Modal Body --- */
.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

/* --- Modal Footer --- */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background-color: #f8fafc;
    flex-shrink: 0;
}

/* --- Confirm Dialog variant --- */
.modal-confirm .modal-body {
    text-align: center;
    padding: 2rem 1.5rem;
}

.modal-confirm .modal-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin-bottom: 1rem;
    font-size: 1.75rem;
}

.modal-confirm .modal-icon.icon-warning {
    background-color: #fffbeb;
    color: var(--warning);
}

.modal-confirm .modal-icon.icon-danger {
    background-color: #fef2f2;
    color: var(--danger);
}

.modal-confirm .modal-icon.icon-success {
    background-color: #f0fdf4;
    color: var(--success);
}

.modal-confirm .modal-icon.icon-info {
    background-color: #ecfeff;
    color: var(--info);
}

.modal-confirm .modal-message {
    font-size: 0.9375rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.modal-confirm .modal-sub-message {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.modal-confirm .modal-footer {
    justify-content: center;
}

/* --- Toast / Notification (mini popup) --- */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + 0.75rem);
    right: 1rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    color: var(--text);
    min-width: 280px;
    max-width: 420px;
    pointer-events: auto;
    transform: translateX(120%);
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(0);
}

.toast-success {
    border-left: 3px solid var(--success);
}

.toast-danger {
    border-left: 3px solid var(--danger);
}

.toast-warning {
    border-left: 3px solid var(--warning);
}

.toast-info {
    border-left: 3px solid var(--info);
}

.toast-close {
    margin-left: auto;
    border: none;
    background: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text);
}

/* --- Resizable Modal --- */
.modal-resizable {
    position: relative;
    resize: none;
}

.modal-resizable.modal-positioned {
    position: fixed;
}

.modal-resizable .modal-body {
    min-height: 120px;
}

.modal-resize-edge {
    position: absolute;
    z-index: 1;
}

.modal-resize-edge[data-resize="n"]  { top: -4px; left: 8px; right: 8px; height: 8px; cursor: n-resize; }
.modal-resize-edge[data-resize="s"]  { bottom: -4px; left: 8px; right: 8px; height: 8px; cursor: s-resize; }
.modal-resize-edge[data-resize="w"]  { left: -4px; top: 8px; bottom: 8px; width: 8px; cursor: w-resize; }
.modal-resize-edge[data-resize="e"]  { right: -4px; top: 8px; bottom: 8px; width: 8px; cursor: e-resize; }
.modal-resize-edge[data-resize="nw"] { top: -4px; left: -4px; width: 12px; height: 12px; cursor: nw-resize; }
.modal-resize-edge[data-resize="ne"] { top: -4px; right: -4px; width: 12px; height: 12px; cursor: ne-resize; }
.modal-resize-edge[data-resize="sw"] { bottom: -4px; left: -4px; width: 12px; height: 12px; cursor: sw-resize; }
.modal-resize-edge[data-resize="se"] { bottom: -4px; right: -4px; width: 12px; height: 12px; cursor: se-resize; }

.modal-resizable.modal-dragging {
    user-select: none;
    transition: none;
}

.modal-resizable .modal-header {
    cursor: move;
}

/* --- Responsive --- */
@media (max-width: 576px) {
    .modal-overlay {
        padding: 0.5rem;
        align-items: flex-end;
    }

    .modal {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .modal-sm,
    .modal-lg,
    .modal-xl {
        max-width: 100%;
    }

    .toast-container {
        right: 0.5rem;
        left: 0.5rem;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }
}
