/* ========== 全局样式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #0a101f 0%, #0f1b33 100%);
    color: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
    height: 100%；
}

:root {
    --primary: #0099ff;
    --primary-light: #00ccff;
    --primary-dark: #0066cc;
    --success: #36d370;
    --warning: #ff9c40;
    --danger: #ff4d6d;
    --bg-primary: #0a101f;
    --bg-secondary: #131d35;
    --bg-card: #1a2540;
    --bg-input: #0f1b33;
    --border: rgba(0, 150, 255, 0.2);
    --border-light: rgba(0, 150, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #b0c4e0;
    --text-muted: #667892;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(0, 153, 255, 0.3);
}

/* ========== 顶部导航栏 ========== */
.site-header {
    background: linear-gradient(180deg, rgba(10, 16, 31, 0.98) 0%, rgba(15, 27, 51, 0.95) 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-content {
    max-width: 100%;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.home-btn {
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s;
}

.home-btn:hover {
    color: var(--primary-light);
    background: var(--border-light);
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
}

.site-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.site-title {
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, #ffffff, #b0c4e0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.username {
    color: var(--text-secondary);
    font-size: 14px;
}

.vip-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
}

.vip-badge.vip {
    background: linear-gradient(135deg, #ffd700, #ff9500);
    color: #333;
}

.vip-badge.svip {
    background: linear-gradient(135deg, #ff6b9d, #c44dff);
    color: #fff;
}

/* ========== 主容器 ========== */
.tool-container {
    display: grid;
    grid-template-columns: 260px 1fr 320px;
    gap: 20px;
    padding: 20px;
    max-height: calc(100vh - 60px);
    height: calc(100vh - 60px);
}

/* ========== 侧边栏面板 ========== */
.sidebar-left,
.sidebar-right {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 100px);
    padding-right: 4px;
}

/* 自定义滚动条 */
.sidebar-left::-webkit-scrollbar,
.sidebar-right::-webkit-scrollbar,
.panel-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-left::-webkit-scrollbar-track,
.sidebar-right::-webkit-scrollbar-track,
.panel-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.sidebar-left::-webkit-scrollbar-thumb,
.sidebar-right::-webkit-scrollbar-thumb,
.panel-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
    opacity: 0.5;
}

.sidebar-left::-webkit-scrollbar-thumb:hover,
.sidebar-right::-webkit-scrollbar-thumb:hover,
.panel-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.panel-title {
    font-size: 14px;
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
    color: var(--text-primary);
}

.panel-content {
    padding: 16px;
    max-height: none;
    overflow-y: auto;
}

/* ========== 文件夹管理 ========== */
.upload-area {
    margin-bottom: 12px;
}

.upload-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 24px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.3s;
}

.upload-btn:hover {
    border-color: var(--primary);
    background: var(--border-light);
    box-shadow: var(--shadow-glow);
}

.upload-icon {
    font-size: 28px;
}

.upload-btn span:last-child {
    font-size: 13px;
    color: var(--text-secondary);
}

.folder-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.folder-item:hover {
    border-color: var(--primary);
    background: var(--border-light);
}

.folder-item.active {
    border-color: var(--primary);
    background: rgba(0, 153, 255, 0.1);
}

.folder-item .folder-icon {
    font-size: 20px;
}

.folder-item .folder-name {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-item .folder-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 10px;
}

.image-stats {
    font-size: 12px;
    color: var(--text-muted);
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.image-stats span span {
    color: var(--primary-light);
    font-weight: 600;
}

/* ========== 图片缩略图列表 ========== */
.image-thumbnails {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.thumb-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.thumb-item:hover {
    border-color: var(--primary);
}

.thumb-item.active {
    border-color: var(--primary-light);
    box-shadow: 0 0 8px rgba(0, 204, 255, 0.5);
}

.thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-item .thumb-index {
    position: absolute;
    top: 2px;
    left: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
}

/* ========== 主内容区 ========== */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

.preview-section {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
}

.preview-info {
    font-size: 12px;
    color: var(--text-muted);
}

.preview-info span span {
    color: var(--text-secondary);
}

.canvas-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: var(--bg-secondary);
    gap: 12px;
    padding: 20px;
    text-align: center;
}

.placeholder-icon {
    font-size: 48px;
    opacity: 0.5;
}

.canvas-placeholder p {
    font-size: 14px;
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

#previewCanvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* 裁剪框 */
.crop-box {
    position: absolute;
    border: 2px dashed var(--primary-light);
    background: rgba(0, 153, 255, 0.1);
    pointer-events: auto;
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary-light);
    border: 2px solid #fff;
    border-radius: 50%;
}

.crop-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }

/* ========== 操作按钮栏 ========== */
.action-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    font-size: 18px;
}

.btn-success {
    background: linear-gradient(135deg, #36d370, #20b954);
    color: #fff;
    box-shadow: 0 4px 15px rgba(54, 211, 112, 0.3);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(54, 211, 112, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ff4d6d, #e63946);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 77, 109, 0.3);
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 77, 109, 0.4);
}

.btn-primary {
    background: linear-gradient(135deg, #0099ff, #00ccff);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 153, 255, 0.3);
}

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

.btn-vip {
    background: linear-gradient(135deg, #ffd700, #ff9500);
    color: #333;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}

.btn-vip:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
}

/* ========== 进度条 ========== */
.progress-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: var(--shadow);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 13px;
}

.progress-info span:first-child {
    color: var(--text-secondary);
}

.progress-info span:last-child {
    color: var(--primary-light);
    font-weight: 600;
}

.progress-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0099ff, #00ccff);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 153, 255, 0.5);
}

/* ========== 状态栏 ========== */
.status-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 20px;
    font-size: 12px;
    color: var(--text-muted);
    box-shadow: var(--shadow);
}

/* ========== 表单组件 ========== */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    transition: all 0.3s;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 153, 255, 0.1);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667892' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-select option {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.form-textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    line-height: 1.5;
}

.form-color {
    width: 36px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    cursor: pointer;
}

.form-range {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 153, 255, 0.5);
}

.range-value {
    text-align: right;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.range-value span {
    color: var(--primary-light);
    font-weight: 600;
}

/* 颜色行 */
.color-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-hex {
    flex: 1;
    font-family: monospace;
    text-transform: uppercase;
}

/* 预设颜色 */
.preset-colors {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.preset-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid transparent;
}

.preset-color:hover {
    transform: scale(1.2);
}

/* 预设尺寸 */
.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.preset-btn,
.ratio-btn {
    padding: 8px;
    font-size: 11px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover,
.ratio-btn:hover {
    border-color: var(--primary);
    color: var(--primary-light);
}

.preset-btn.active,
.ratio-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* 位置网格 */
.position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.pos-btn {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.pos-btn:hover {
    border-color: var(--primary);
    color: var(--primary-light);
}

.pos-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Checkbox 标签 */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin: 0;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* ========== 登录/权限页面 ========== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a101f 0%, #0f1b33 100%);
    padding: 20px;
}

.auth-container {
    max-width: 480px;
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.auth-header {
    padding: 40px 32px;
    text-align: center;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
    border-bottom: 1px solid var(--border);
}

.auth-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #ffffff, #b0c4e0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.auth-tip {
    padding: 32px;
    text-align: center;
}

.auth-tip p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 14px;
}

.auth-tip .btn {
    width: 100%;
    justify-content: center;
}

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

.vip-tip h3 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 20px;
}

/* ========== 响应式 ========== */
@media (max-width: 1200px) {
    .tool-container {
        grid-template-columns: 220px 1fr 280px;
        gap: 12px;
        padding: 12px;
    }
}

@media (max-width: 900px) {
    .tool-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        max-height: none;
        height: auto;
    }

    .sidebar-left,
    .sidebar-right {
        max-height: none;
        overflow: visible;
    }

    .image-thumbnails {
        max-height: 150px;
    }

    .canvas-wrapper {
        min-height: 300px;
    }
}

@media (max-width: 600px) {
    .header-content {
        padding: 10px 16px;
    }

    .site-title {
        display: none;
    }

    .username {
        display: none;
    }

    .tool-container {
        padding: 10px;
        gap: 10px;
    }

    .action-bar {
        padding: 12px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* bare 嵌入模式 */
.bare-mode .site-header {
    display: none !important;
}
.bare-mode {
    padding-top: 0 !important;
}
