/*
 * Custom Modal Component for Django Admin
 * 使用專案 CSS 變數，支援深色/淺色模式
 * 所有變數都有 fallback 值，確保在獨立頁面也能正常顯示
 * renhao 2025-11-21
 */

/* #region Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

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

@media (prefers-color-scheme: dark) {
    .modal-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}

html[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}
/* #endregion */

/* #region Modal Container */
.modal-container {
    background: var(--body-bg, #ffffff);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 420px;
    width: calc(100% - 32px);
    max-height: calc(100vh - 32px);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.modal-overlay.active .modal-container {
    transform: scale(1);
}
/* #endregion */

/* #region Modal Header */
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--hairline-color, #e0e0e0);
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.modal-icon.info {
    color: var(--link-fg, #0066cc);
}

.modal-icon.warning {
    color: var(--warning-color, #ff9800);
}

.modal-icon.error {
    color: var(--error-fg, #dc3545);
}

.modal-icon.success {
    color: var(--button-success-bg, #28a745);
}

.modal-icon.question {
    color: var(--secondary, #6c757d);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--body-loud-color, #333333);
    margin: 0;
    flex-grow: 1;
}
/* #endregion */

/* #region Modal Body */
.modal-body {
    padding: 20px;
    color: var(--body-fg, #333333);
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 300px;
    overflow-y: auto;
}
/* #endregion */

/* #region Modal Footer */
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--hairline-color, #e0e0e0);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.1s ease;
    min-width: 80px;
}

.modal-btn:hover {
    transform: translateY(-1px);
}

.modal-btn:active {
    transform: translateY(0);
}

.modal-btn:focus {
    outline: 2px solid var(--primary, #417690);
    outline-offset: 2px;
}

/* 主要按鈕 - 使用 Django Admin 預設按鈕風格 */
.modal-btn-primary {
    background: var(--default-button-bg, #417690);
    color: var(--button-fg, #ffffff);
}

.modal-btn-primary:hover {
    background: var(--default-button-hover-bg, #205067);
}

/* 次要按鈕 - 取消/關閉 */
.modal-btn-secondary {
    background: var(--close-button-bg, #888888);
    color: var(--button-fg, #ffffff);
}

.modal-btn-secondary:hover {
    background: var(--close-button-hover-bg, #666666);
}

/* 危險按鈕 - 刪除/警告操作 */
.modal-btn-danger {
    background: var(--delete-button-bg, #ba2121);
    color: var(--button-fg, #ffffff);
}

.modal-btn-danger:hover {
    background: var(--delete-button-hover-bg, #a41515);
}

/* 成功按鈕 */
.modal-btn-success {
    background: var(--button-success-bg, #28a745);
    color: var(--button-fg, #ffffff);
}

.modal-btn-success:hover {
    background: var(--button-success-hover-bg, #218838);
}
/* #endregion */

/* #region Responsive Design */
@media (max-width: 480px) {
    .modal-container {
        width: calc(100% - 24px);
        max-width: none;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 14px 16px;
        flex-direction: column-reverse;
    }

    .modal-btn {
        width: 100%;
        padding: 12px 20px;
    }
}
/* #endregion */

/* #region Scrollbar Styling */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--scrollbar-bg, #f1f1f1);
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb, #c1c1c1);
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover, #a8a8a8);
}
/* #endregion */

/* #region Animation */
@keyframes modalShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.modal-container.shake {
    animation: modalShake 0.3s ease;
}
/* #endregion */

/* #region Toast 通知（非阻塞、自動消失）20260707 renhao add */
.modal-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.modal-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 220px;
    max-width: 380px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--body-bg, #ffffff);
    color: var(--body-fg, #333333);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    border-left: 4px solid var(--secondary, #6c757d);
    font-size: 14px;
    line-height: 1.4;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
    cursor: pointer;
}

.modal-toast--show {
    opacity: 1;
    transform: translateX(0);
}

.modal-toast__icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: inline-flex;
}

.modal-toast__icon svg {
    width: 20px;
    height: 20px;
}

.modal-toast__msg {
    flex: 1;
    white-space: pre-line;
    word-break: break-word;
}

.modal-toast--info    { border-left-color: var(--link-fg, #0066cc); }
.modal-toast--info    .modal-toast__icon { color: var(--link-fg, #0066cc); }
.modal-toast--warning { border-left-color: var(--warning-color, #ff9800); }
.modal-toast--warning .modal-toast__icon { color: var(--warning-color, #ff9800); }
.modal-toast--error   { border-left-color: var(--error-fg, #dc3545); }
.modal-toast--error   .modal-toast__icon { color: var(--error-fg, #dc3545); }
.modal-toast--success { border-left-color: var(--button-success-bg, #28a745); }
.modal-toast--success .modal-toast__icon { color: var(--button-success-bg, #28a745); }

@media (prefers-color-scheme: dark) {
    .modal-toast {
        background: var(--body-bg, #2b2b2b);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    }
}

@media (max-width: 767px) {
    .modal-toast-container {
        top: auto;
        bottom: 20px;
        left: 12px;
        right: 12px;
    }
    .modal-toast {
        min-width: 0;
        max-width: none;
    }
}
/* #endregion */
