/* ===== 圖片編輯器樣式 - Petoko 全螢幕設計風格 ===== */
.image-editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100000; /* 確保在發文表單 (z-index: 9999) 之上 */
    display: none;
    background: var(--white);
}

.image-editor-overlay {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--white);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

.image-editor-container {
    background: var(--white);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

/* ===== 頂部工具欄 - 完全模仿 post-form-page-header 設計 ===== */
.image-editor-header {
    position: sticky;
    top: 0;
    background: var(--white);
    border-bottom: 1px solid var(--bg-secondary);
    z-index: 10001;
    padding: 0.8rem 1rem;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    pointer-events: auto;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0;
}

.btn-close-editor {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: none;
    text-decoration: none;
    transition: all 0.3s ease;
    cursor: pointer;
}

.btn-close-editor:hover {
    background: var(--primary);
    color: var(--white);
}

.header-title {
    flex: 1;
    text-align: center;
}

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

/* 操作提示 - 模仿 post-form 的 action-hint */
.header-subtitle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    margin: 0;
    margin-top: 0.2rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.header-subtitle i {
    font-size: 0.65rem;
    opacity: 0.7;
}

/* 標題列間距元素 - 模仿 post-form 的 header-spacer */
.header-spacer {
    width: 36px;
    flex-shrink: 0;
}

/* 確認按鈕 - 完全模仿 post-form 的 submit-btn */
.btn-confirm-edit {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.6rem 1.2rem;
    background: var(--gradient-primary);
    color: var(--white);
    border: none;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-medium);
}

.btn-confirm-edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--shadow-medium);
}

.btn-confirm-edit:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px var(--shadow-medium);
}

/* ===== 主編輯區域 ===== */
.image-editor-content {
    flex: 1;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    min-height: 0;
    background: var(--bg-primary);
}

/* ===== 圖片預覽區 - 最大化設計 ===== */
.image-preview-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    padding: 10px;
}

.preview-frame {
    position: relative;
    aspect-ratio: 1 / 1; /* 保持正方形比例 */
    width: min(90vw, 80vh); /* 取視窗較小的一邊，避免超出 */
    height: auto; /* 由 aspect-ratio 決定高度 */
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary);
    box-shadow: 0 4px 16px var(--shadow-medium);
    transition: all 0.3s ease;
}

.preview-frame:hover {
    border-color: var(--primary);
    box-shadow: 0 12px 40px rgba(255, 107, 107, 0.15);
}

/* ===== 九宮格線 - 優雅設計 ===== */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none !important; /* 強制確保不影響點擊和拖曳 */
    z-index: 2; /* 確保九宮格在圖片上方顯示 */
    user-select: none; /* 防止選取 */
    touch-action: none; /* 防止觸控干擾 */
}

.grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.9); /* 高透明度讓線條更明顯 */
    z-index: 2;
    transition: all 0.3s ease;
    pointer-events: none !important; /* 強制確保不影響點擊和拖曳 */
    display: block !important; /* 強制顯示 */
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.3); /* 添加陰影讓線條更明顯 */
    animation: gridLinePulse 2s ease-in-out infinite; /* 添加脈衝動畫 */
    user-select: none; /* 防止選取 */
    touch-action: none; /* 防止觸控干擾 */
}

/* 九宮格線脈衝動畫 */
@keyframes gridLinePulse {
    0%, 100% {
        opacity: 0.7;
        box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
    }
    50% {
        opacity: 1;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
    }
}

.grid-vertical-1,
.grid-vertical-2 {
    width: 2px; /* 增加線條寬度 */
    height: 100%;
    top: 0;
    display: block !important; /* 強制顯示 */
    pointer-events: none !important; /* 確保點擊穿透 */
    user-select: none; /* 防止選取 */
    touch-action: none; /* 防止觸控干擾 */
}

.grid-vertical-1 {
    left: 33.33%;
}

.grid-vertical-2 {
    left: 66.66%;
}

.grid-horizontal-1,
.grid-horizontal-2 {
    width: 100%;
    height: 2px; /* 增加線條寬度 */
    left: 0;
    display: block !important; /* 強制顯示 */
    pointer-events: none !important; /* 確保點擊穿透 */
    user-select: none; /* 防止選取 */
    touch-action: none; /* 防止觸控干擾 */
}

.grid-horizontal-1 {
    top: 33.33%;
}

.grid-horizontal-2 {
    top: 66.66%;
}

.grid-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px rgba(255, 107, 107, 0.5);
    pointer-events: none !important; /* 強制確保不影響點擊和拖曳 */
    display: block !important; /* 強制顯示 */
    user-select: none; /* 防止選取 */
    touch-action: none; /* 防止觸控干擾 */
}

/* ===== Canvas 容器 ===== */
.image-canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.image-canvas {
    width: 100%;
    height: 100%;
    cursor: grab;
    display: block;
    transition: all 0.3s ease;
    z-index: 1; /* 確保在九宮格下面，但仍能接收點擊事件 */
    position: relative; /* 確保 z-index 生效 */
}

.image-canvas:active {
    cursor: grabbing;
}

/* ===== 拖拽提示 ===== */
.drag-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(44, 62, 80, 0.8);
    color: var(--white);
    padding: 12px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(10px);
}

.drag-hint.show {
    opacity: 1;
}

.drag-hint i {
    color: var(--primary);
}

/* ===== 編輯工具欄 - 緊湊 row 設計 ===== */
.image-editor-toolbar {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: transparent;
    border: none;
    box-shadow: none;
}

.tool-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-width: auto;
    flex: none;
}

.tool-header {
    display: none; /* 隱藏圈圈，只顯示 icon */
}

.tool-label {
    display: none; /* 隱藏圈圈文字 */
}

/* ===== 縮放控制組 - 緊湊設計 ===== */
.zoom-group {
    min-width: auto;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.zoom-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px var(--shadow-light);
    backdrop-filter: blur(10px);
}

.zoom-btn:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-slider-container {
    flex: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.zoom-slider {
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gradient-primary);
    cursor: pointer;
    border: 3px solid var(--white);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
    transition: all 0.3s ease;
}

.zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(255, 107, 107, 0.5);
}

.zoom-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gradient-primary);
    cursor: pointer;
    border: 3px solid var(--white);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.zoom-value {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    min-width: 50px;
    text-align: center;
    background: var(--white);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
}

/* ===== 變換控制組 ===== */
.transform-group {
    min-width: 180px;
}

.transform-controls {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.control-row {
    display: flex;
    gap: 8px;
}

.image-editor-modal .control-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 12px;
    font-weight: 500;
    flex: none;
    box-shadow: 0 2px 8px var(--shadow-light);
    backdrop-filter: blur(10px);
}

.image-editor-modal .control-btn:hover {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
}

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

.image-editor-modal .control-btn i {
    font-size: 16px;
}

.image-editor-modal .control-btn span {
    display: none; /* 隱藏按鈕文字，只顯示 icon */
}

/* ===== 重置控制組 ===== */
.reset-group {
    min-width: 120px;
}

.reset-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--shadow-light);
    width: auto;
    backdrop-filter: blur(10px);
}

.reset-btn:hover {
    background: var(--error);
    color: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
}

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

.reset-btn span {
    display: none; /* 隱藏按鈕文字，只顯示 icon */
}

/* ===== 底部操作區 - 透明設計 ===== */
.image-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: transparent;
    border: none;
    position: relative;
    box-shadow: none;
}

.image-editor-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

.footer-info {
    flex: 1;
}

.image-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.image-info i {
    color: var(--primary);
    font-size: 14px;
}

.footer-actions {
    display: flex;
    gap: 16px;
}

.footer-actions .btn {
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    box-shadow: 0 4px 16px var(--shadow-light);
}

.footer-actions .btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.footer-actions .btn-secondary:hover {
    background: var(--text-secondary);
    color: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--shadow-medium);
}

.footer-actions .btn-primary {
    background: var(--gradient-primary);
    color: var(--white);
}

.footer-actions .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

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

/* ===== 載入遮罩 - 優雅設計 ===== */
.image-editor-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100001; /* 確保在圖片編輯器 (z-index: 100000) 之上 */
    display: none;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    background: var(--white);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(44, 62, 80, 0.3);
    max-width: 320px;
    width: 90%;
}

.spinner-ring {
    width: 60px;
    height: 60px;
    border: 4px solid var(--bg-secondary);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.spinner-text {
    text-align: center;
}

.spinner-text i {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 12px;
    display: block;
}

.spinner-text p {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

.loading-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
}

/* ===== 動畫 ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

/* ===== 響應式設計 - 全螢幕風格 ===== */
@media (max-width: 768px) {
    .image-editor-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    
    .image-editor-header {
        padding: 16px 20px;
    }
    
    .image-editor-content {
        padding: 16px;
        gap: 20px;
    }
    
    .preview-frame {
        aspect-ratio: 1 / 1;
        width: min(95vw, 70vh);
        height: auto;
    }
    
    .image-preview-container {
        padding: 8px;
    }
    
    .image-editor-toolbar {
        flex-direction: row;
        gap: 12px;
        padding: 12px 20px;
    }
    
    .tool-group {
        min-width: auto;
    }
    
    .zoom-controls {
        flex-wrap: nowrap;
        justify-content: center;
    }
    
    .transform-controls {
        gap: 8px;
    }
    
    .control-row {
        flex-direction: row;
        gap: 8px;
    }
    
    .image-editor-footer {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
        padding: 16px 20px;
    }
    
    .footer-actions {
        justify-content: stretch;
    }
    
    .footer-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .preview-frame {
        aspect-ratio: 1 / 1;
        width: min(98vw, 65vh);
        height: auto;
    }
    
    .image-editor-content {
        padding: 12px;
    }
    
    .image-editor-header,
    .image-editor-footer {
        padding: 12px 16px;
    }
    
    .image-preview-container {
        padding: 6px;
    }
    
    .image-editor-toolbar {
        padding: 8px 16px;
        gap: 8px;
    }
    
    .header-title h3 {
        font-size: 18px;
    }
    
    .header-subtitle {
        font-size: 13px;
    }
    
    .tool-label {
        font-size: 12px;
    }
    
    .image-editor-modal .control-btn {
        padding: 10px 12px;
        font-size: 11px;
    }
    
    .zoom-btn {
        width: 36px;
        height: 36px;
    }
}

