/**
 * 寵物信託系統 - 前端元件樣式
 */

/* ==================== 載入動畫 ==================== */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

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

.loading-spinner {
    text-align: center;
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 1rem;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: #333;
    font-size: 1rem;
    margin: 0;
    font-weight: 500;
}

/* ==================== Toast 通知 ==================== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 10000;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    min-width: 300px;
    max-width: 500px;
}

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

.toast-icon {
    font-size: 1.5rem;
    font-weight: bold;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    color: #333;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Toast 類型樣式 */
.toast-success {
    border-left: 4px solid #28a745;
}

.toast-success .toast-icon {
    background: #d4edda;
    color: #28a745;
}

.toast-error {
    border-left: 4px solid #dc3545;
}

.toast-error .toast-icon {
    background: #f8d7da;
    color: #dc3545;
}

.toast-warning {
    border-left: 4px solid #ffc107;
}

.toast-warning .toast-icon {
    background: #fff3cd;
    color: #856404;
}

.toast-info {
    border-left: 4px solid #17a2b8;
}

.toast-info .toast-icon {
    background: #d1ecf1;
    color: #17a2b8;
}

/* ==================== 圖片預覽 ==================== */
.image-preview {
    margin-top: 1rem;
    position: relative;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.image-preview img {
    max-width: 300px;
    max-height: 300px;
    display: block;
    border-radius: 8px;
}

.image-preview .remove-preview {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.image-preview .remove-preview:hover {
    background: #dc3545;
    transform: scale(1.05);
}

/* ==================== 表單驗證樣式 ==================== */
input.is-invalid,
textarea.is-invalid,
select.is-invalid {
    border-color: #dc3545 !important;
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

input.is-valid,
textarea.is-valid,
select.is-valid {
    border-color: #28a745 !important;
}

input.is-valid:focus,
textarea.is-valid:focus,
select.is-valid:focus {
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

input.is-invalid:focus,
textarea.is-invalid:focus,
select.is-invalid:focus {
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* ==================== 返回頂部按鈕 ==================== */
#scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: scale(0);
    transition: all 0.3s;
}

#scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

#scroll-to-top:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
}

#scroll-to-top:active {
    transform: scale(0.95);
}

/* ==================== 按鈕載入狀態 ==================== */
button[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

button.loading {
    position: relative;
    color: transparent !important;
}

button.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ==================== 快閃訊息動畫 ==================== */
.alert {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 卡片懸停效果 ==================== */
.feature-card {
    transition: all 0.3s;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15) !important;
}

/* ==================== 互動元素脈動效果 ==================== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.btn-primary:hover,
.btn-secondary:hover {
    animation: pulse 0.5s ease-in-out;
}

/* ==================== 表格行懸停效果 ==================== */
table tbody tr {
    transition: background-color 0.2s;
}

table tbody tr:hover {
    background-color: #f8f9fa !important;
}

/* ==================== 檔案輸入美化 ==================== */
input[type="file"] {
    padding: 0.5rem;
    border: 2px dashed #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

input[type="file"]:hover {
    border-color: #667eea;
    background-color: #f8f9ff;
}

input[type="file"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* ==================== 響應式設計 ==================== */
@media (max-width: 768px) {
    .toast {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        min-width: 0;
    }

    #scroll-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .loading-spinner {
        padding: 1.5rem;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    .image-preview img {
        max-width: 250px;
        max-height: 250px;
    }
}

/* ==================== 進度條 ==================== */
.progress-bar {
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10001;
    transition: width 0.3s;
}

/* ==================== 骨架屏載入效果 ==================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ==================== 工具提示 ==================== */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background: #333;
    color: white;
    font-size: 0.85rem;
    white-space: nowrap;
    border-radius: 4px;
    margin-bottom: 5px;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 1000;
}


/* ==================== 表單自動儲存 ==================== */
.autosave-indicator {
    position: fixed;
    bottom: 80px;
    right: 30px;
    background: #28a745;
    color: white;
    padding: 0.6rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    z-index: 1001;
}

.autosave-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.autosave-prompt {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10002;
    animation: fadeIn 0.3s;
}

.autosave-prompt-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s;
}

.autosave-prompt-content p {
    color: #333;
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.autosave-prompt-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.autosave-prompt-buttons button {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-restore {
    background: #667eea;
    color: white;
}

.btn-restore:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.btn-discard {
    background: #6c757d;
    color: white;
}

.btn-discard:hover {
    background: #5a6268;
}

.btn-clear-autosave {
    background: #ffc107;
    color: #333;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: all 0.2s;
}

.btn-clear-autosave:hover {
    background: #ffb300;
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .autosave-indicator {
        bottom: 70px;
        right: 20px;
        font-size: 0.8rem;
        padding: 0.5rem 0.9rem;
    }

    .autosave-prompt-content {
        margin: 1rem;
        padding: 1.5rem;
    }

    .autosave-prompt-buttons {
        flex-direction: column;
    }

    .autosave-prompt-buttons button {
        width: 100%;
    }
}


/* ==================== 圖片裁切器 ==================== */
.image-cropper-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10003;
    animation: fadeIn 0.3s;
}

.image-cropper-content {
    background: white;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

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

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

.cropper-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: color 0.2s;
}

.cropper-close:hover {
    color: #333;
}

.image-cropper-body {
    padding: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    flex: 1;
}

#cropperCanvas {
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
}

.image-cropper-footer {
    padding: 1.5rem;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.cropper-options {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.cropper-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: #666;
    font-size: 0.95rem;
}

.cropper-options input[type="checkbox"] {
    cursor: pointer;
}

.cropper-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-cropper-primary,
.btn-cropper-secondary,
.btn-cropper-reset {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-cropper-primary {
    background: #667eea;
    color: white;
}

.btn-cropper-primary:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.btn-cropper-secondary {
    background: #6c757d;
    color: white;
}

.btn-cropper-secondary:hover {
    background: #5a6268;
}

.btn-cropper-reset {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #ddd;
}

.btn-cropper-reset:hover {
    background: #e9ecef;
}

@media (max-width: 768px) {
    .image-cropper-content {
        max-width: 95vw;
        max-height: 95vh;
    }

    .image-cropper-header {
        padding: 1rem;
    }

    .image-cropper-body {
        padding: 1rem;
    }

    .image-cropper-footer {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
    }

    .cropper-actions {
        width: 100%;
    }

    .btn-cropper-primary,
    .btn-cropper-secondary {
        flex: 1;
    }
}

/* 裁切詢問對話框 */
.crop-ask-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10002;
    animation: fadeIn 0.3s;
}

.crop-ask-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s;
}

.crop-ask-content h4 {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 1.25rem;
}

.crop-ask-content p {
    color: #666;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.crop-ask-buttons {
    display: flex;
    gap: 0.75rem;
}

.btn-crop-yes,
.btn-crop-no {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-crop-yes {
    background: #667eea;
    color: white;
}

.btn-crop-yes:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.btn-crop-no {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #ddd;
}

.btn-crop-no:hover {
    background: #e9ecef;
}

/* 裁切標籤 */
.crop-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #28a745;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

@media (max-width: 768px) {
    .crop-ask-content {
        margin: 1rem;
        padding: 1.5rem;
    }

    .crop-ask-buttons {
        flex-direction: column;
    }
}
