/**
 * 图片编辑器样式 - Fabric.js 版本
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    overflow: hidden;
}

/* ==================== 加载和错误页面 ==================== */

.loading-screen,
.error-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e5e7eb;
    border-top-color: #10B981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.loading-text {
    color: #6b7280;
    font-size: 16px;
    margin: 0;
}

.error-content {
    text-align: center;
    background: white;
    padding: 40px 60px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    max-width: 480px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-title {
    font-size: 20px;
    color: #1f2937;
    margin: 0 0 12px;
    font-weight: 600;
}

.error-message {
    color: #6b7280;
    margin: 0 0 24px;
    font-size: 14px;
    line-height: 1.6;
}

.error-content button {
    margin: 0 8px;
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

.error-content .btn-retry {
    background: #10B981;
    color: white;
}

.error-content .btn-retry:hover {
    background: #059669;
}

.error-content .btn-close {
    background: #e5e7eb;
    color: #374151;
}

.error-content .btn-close:hover {
    background: #d1d5db;
}

/* ==================== 主容器 ==================== */

.editor-container {
    display: flex;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* ==================== 左侧工具栏 ==================== */

.toolbar-left {
    width: 200px;
    background: white;
    border-right: 1px solid #e5e7eb;
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.logo {
    margin-bottom: 24px;
    text-align: center;
    padding: 8px;
}

.logo img {
    max-width: 100%;
    height: auto;
    max-height: 48px;
    object-fit: contain;
}

.tool-group {
    margin-bottom: 24px;
}

.tool-group-title {
    font-size: 12px;
    color: #9CA3AF;
    margin-bottom: 8px;
    padding-left: 8px;
    font-weight: 500;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    transition: all 0.2s;
    text-align: left;
}

.tool-btn .icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.tool-btn .label {
    flex: 1;
}

.tool-btn:hover {
    background: #F3F4F6;
}

.tool-btn.active {
    background: #D1FAE5;
    border-color: #10B981;
    color: #059669;
}

/* ==================== 中间编辑区域 ==================== */

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #E5E7EB;
    overflow: hidden;
    min-width: 0;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.image-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-name {
    font-weight: 500;
    font-size: 14px;
    color: #374151;
}

.image-status {
    font-size: 12px;
    padding: 2px 8px;
    background: #FEF3C7;
    color: #D97706;
    border-radius: 4px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #E5E7EB;
}

.canvas-container canvas {
    display: block;
}

/* Fabric.js 创建的 canvas wrapper 也要铺满 */
.canvas-container > div {
    width: 100% !important;
    height: 100% !important;
}

/* 消除笔覆盖层 */
.eraser-overlay {
    background: transparent !important;
}

/* 工具选项栏 */
.tool-options {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 20;
}

.eraser-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-section label {
    font-size: 14px;
    color: #6B7280;
}

.brush-slider {
    width: 120px;
}

.brush-size-value {
    min-width: 30px;
    text-align: center;
    font-size: 14px;
    color: #374151;
}

/* ==================== 右侧图片列表 ==================== */

.panel-right {
    width: 220px;
    background: white;
    border-left: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    flex-shrink: 0;
}

.image-count {
    color: #9CA3AF;
    font-weight: normal;
}

.thumbnail-list {
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

.thumbnail-item {
    position: relative;
    margin-bottom: 12px;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.thumbnail-item:hover {
    border-color: #D1FAE5;
}

.thumbnail-item.active {
    border-color: #10B981;
}

.thumbnail-item img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
}

.thumbnail-name {
    display: block;
    padding: 4px 8px;
    font-size: 12px;
    color: #6B7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #F9FAFB;
}

.modified-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #F59E0B;
    border-radius: 50%;
    box-shadow: 0 0 0 2px white;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #9CA3AF;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* ==================== 底部操作栏 ==================== */

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
    height: 60px;
}

.footer-right {
    display: flex;
    gap: 12px;
}

/* ==================== 按钮样式 ==================== */

button {
    padding: 8px 16px;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

button:hover {
    background: #F3F4F6;
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:disabled:hover {
    background: white;
}

button.primary {
    background: #10B981;
    color: white;
    border-color: #10B981;
}

button.primary:hover {
    background: #059669;
}

button.primary:disabled:hover {
    background: #10B981;
}

.btn-clear {
    background: #FEE2E2;
    color: #DC2626;
    border-color: #FEE2E2;
}

.btn-clear:hover {
    background: #FECACA;
}

.btn-cancel {
    background: #F3F4F6;
    color: #6B7280;
    border-color: #E5E7EB;
}

.btn-cancel:hover {
    background: #E5E7EB;
}

/* ==================== Loading 覆盖层 ==================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    background: white;
    padding: 24px 40px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #E5E7EB;
    border-top-color: #10B981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: 14px;
    color: #6B7280;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== Toast 通知 ==================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
    min-width: 200px;
}

.toast.success {
    background: #10B981;
}

.toast.error {
    background: #EF4444;
}

.toast.info {
    background: #3B82F6;
}

.toast.warning {
    background: #F59E0B;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==================== 对话框 ==================== */

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.dialog {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    min-width: 320px;
    max-width: 480px;
    animation: slideUp 0.3s ease;
}

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

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #E5E7EB;
}

.dialog-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #374151;
}

.dialog-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 24px;
    color: #9CA3AF;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.dialog-close:hover {
    background: #F3F4F6;
    color: #374151;
}

.dialog-content {
    padding: 20px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.radio-option:hover {
    background: #F9FAFB;
    border-color: #10B981;
}

.radio-option:last-child {
    margin-bottom: 0;
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.radio-option span {
    font-size: 14px;
    color: #374151;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #E5E7EB;
}

/* 确认对话框 */
.confirm-dialog {
    min-width: 380px;
}

.confirm-message {
    font-size: 15px;
    line-height: 1.6;
    color: #374151;
    margin: 0;
    text-align: center;
}

/* ==================== 响应式设计 ==================== */

@media (max-width: 1024px) {
    .toolbar-left {
        width: 180px;
    }

    .panel-right {
        width: 200px;
    }
}

@media (max-width: 768px) {
    .toolbar-left,
    .panel-right {
        display: none;
    }

    .editor-container {
        flex-direction: column;
    }
}

/* ==================== AI 工具样式 ==================== */

/* 放大倍数选择对话框 */
.scale-dialog h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    font-weight: 600;
    color: #374151;
}

.scale-dialog .current-size {
    color: #6B7280;
    margin-bottom: 16px;
    font-size: 14px;
}

.scale-options {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.scale-option {
    flex: 1;
    padding: 20px;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.scale-option:hover {
    border-color: #10B981;
    background: #F0FDF4;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}

.scale-option .scale-label {
    display: block;
    font-size: 28px;
    font-weight: bold;
    color: #10B981;
    margin-bottom: 4px;
}

.scale-option .scale-size {
    display: block;
    font-size: 12px;
    color: #6B7280;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 智能选择工具 */
.smart-select-overlay {
    background: rgba(59, 130, 246, 0.05);
}

.smart-select-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
}

.smart-select-toolbar .hint {
    color: #6B7280;
    font-size: 14px;
}

/* 智能选择操作菜单 */
.action-menu {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    min-width: 160px;
}

.action-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: white;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    color: #374151;
    transition: background 0.2s;
}

.action-btn:hover {
    background: #F3F4F6;
}

.action-btn:active {
    background: #E5E7EB;
}

.action-btn + .action-btn {
    border-top: 1px solid #E5E7EB;
}

/* 消除笔工具栏简化 */
.eraser-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.eraser-toolbar .toolbar-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.eraser-toolbar .toolbar-section:first-child {
    flex: 1;
}

.eraser-toolbar label {
    font-size: 14px;
    color: #374151;
    white-space: nowrap;
}

.eraser-toolbar .brush-slider {
    width: 200px;
}

.eraser-toolbar .brush-size-value {
    font-size: 14px;
    color: #6B7280;
    min-width: 30px;
    text-align: right;
}

/* 裁剪/旋转工具栏 */
.crop-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
}

.crop-toolbar .section-title {
    font-size: 12px;
    color: #6B7280;
    margin-right: 4px;
}

/* 调整尺寸工具栏 */
.resize-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
}

.resize-toolbar input[type="number"] {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    font-size: 14px;
}

.resize-toolbar .lock-btn {
    padding: 6px 8px;
    font-size: 16px;
}

.resize-toolbar .lock-btn.active {
    background: #D1FAE5;
    color: #10B981;
}

/* 标注工具栏 */
.annotate-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
}

.annotate-toolbar .section-title {
    font-size: 12px;
    color: #6B7280;
    margin-right: 4px;
}

.annotate-toolbar .icon-btn {
    width: 32px;
    height: 32px;
    padding: 4px;
    font-size: 18px;
}

.annotate-toolbar .icon-btn.active {
    background: #D1FAE5;
    color: #10B981;
}

.annotate-toolbar .color-picker {
    width: 40px;
    height: 32px;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    cursor: pointer;
}

.annotate-toolbar .width-slider {
    width: 100px;
}

.annotate-toolbar .width-value {
    min-width: 20px;
    text-align: center;
    font-size: 14px;
    color: #374151;
}

.annotate-toolbar .btn-delete {
    background: #FEE2E2;
    color: #DC2626;
    border-color: #FEE2E2;
}

.annotate-toolbar .btn-delete:hover {
    background: #FECACA;
}

/* 微调工具栏 */
.finetune-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
}

.finetune-toolbar label {
    font-size: 14px;
    color: #374151;
    white-space: nowrap;
}

.finetune-toolbar input[type="range"] {
    width: 120px;
}

.finetune-toolbar .brightness-value,
.finetune-toolbar .contrast-value,
.finetune-toolbar .saturation-value {
    min-width: 30px;
    text-align: center;
    font-size: 14px;
    color: #6B7280;
}

.finetune-toolbar .btn-reset {
    background: #F3F4F6;
    color: #6B7280;
}

.finetune-toolbar .btn-reset:hover {
    background: #E5E7EB;
}

/* 滤镜工具栏 */
.filter-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
}

.filter-toolbar .section-title {
    font-size: 12px;
    color: #6B7280;
    margin-right: 8px;
}

.filter-toolbar .filter-btn {
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
}

.filter-toolbar .filter-btn.active {
    background: #D1FAE5;
    color: #10B981;
    border-color: #10B981;
}
