/* CSS 变量定义 */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --text-primary: #1e293b;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-light: #475569;
    --background-light: #f8fafc;
    --background-gray: #f1f5f9;
    --border-color: #e2e8f0;
    --border-light: #cbd5e1;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --border-radius-lg: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background-light);
    color: var(--text-secondary);
    line-height: 1.6;
    overflow: auto;
}

/* 主应用容器 */
.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部工具栏 */
.toolbar {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.title-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.title-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.title-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.title-text h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1;
}

.title-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1;
}

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

.export-options {
    display: flex;
    align-items: center;
    gap: 16px;
}

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    text-decoration: none;
    transition: color 0.2s ease;
    font-size: 18px;
}

.github-link:hover {
    color: var(--primary-color);
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--background-gray);
    color: var(--text-light);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

/* 主内容区域 */
.main-content {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

/* 面板通用样式 */
.border-panel,
.image-panel {
    display: flex;
    flex-direction: column;
    background: white;
    min-height: 0;
}

.border-panel {
    width: 300px;
    border-right: 1px solid #e2e8f0;
    flex-shrink: 0;
    overflow-y: auto;
}

.image-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 16px 28px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    height: 60px;
    box-sizing: border-box;
    gap: 16px;
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    flex: 1;
}

.panel-header .btn {
    flex-shrink: 0;
    height: 32px;
    font-size: 12px;
    padding: 6px 12px;
}

/* 边框选择区 */
.border-thumbnails {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 边框控制区域 */
.border-controls {
    padding: 0 20px 20px 20px;
}

/* 页脚样式 */
.border-footer {
    margin-top: auto;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--background-light);
}

.border-footer p {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.4;
    margin: 0;
}

.border-footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.border-footer a:hover {
    color: var(--text-secondary);
    text-decoration: underline;
}

/* 圆角选项 */
.rounded-options {
    padding: 0 20px 20px 20px;
}

.option-item {
    margin-bottom: 12px;
}

.option-item .checkbox-container {
    background: var(--background-gray);
    padding: 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
    justify-content: center;
    text-align: center;
}

.option-item .checkbox-container:hover {
    background: #e2e8f0;
}

/* 自定义复选框 */
.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    user-select: none;
    gap: 8px;
}

.checkbox-container input {
    position: relative;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    height: 20px;
    width: 20px;
    background-color: #eee;
    border-radius: 4px;
    transition: all 0.2s ease;
    position: relative;
    flex-shrink: 0;
}

.checkbox-container:hover input ~ .checkmark {
    background-color: #ccc;
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 7px;
    top: 3px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.border-width-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--background-gray);
    padding: 12px;
    border-radius: 8px;
}


.border-width-control label {
    font-weight: 500;
    color: var(--text-light);
    font-size: 14px;
}

.border-width-control input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    cursor: pointer;
}

.border-width-control input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.border-width-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#borderWidthValue {
    font-weight: 500;
    color: var(--primary-color);
    text-align: center;
    font-size: 14px;
}

.border-item {
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
}

.border-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.border-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.border-preview-canvas {
    width: 100%;
    height: 50px;
    display: block;
    border-radius: 10px;
}

/* 画布容器圆角 */
.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--background-gray);
    padding: 20px;
    min-height: 200px;
}

#previewCanvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-md);
}

/* 图片内容区域 */
.image-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

/* 上传区域 */
.upload-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    background: var(--background-gray);
    min-height: 300px;
}

.upload-icon {
    font-size: 48px;
    color: var(--primary-color);
}

.upload-area p {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* 单张图片预览区域 */
.single-preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 300px;
    overflow: hidden;
}


/* 多张图片预览区域 */
.batch-preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 300px;
    overflow: hidden;
}

.image-count {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

#imageCount {
    color: var(--primary-color);
    font-weight: 600;
}

/* 图片网格 */
.image-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-auto-rows: auto; /* 自动高度 */
    gap: 20px;
    padding: 20px 0;
    overflow-y: auto;
    align-content: start; /* 顶部对齐 */
}

/* 图片项目 */
.image-item {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.image-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-color: var(--primary-color);
}

.image-item-header {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.image-name {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.btn-small {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.btn-small.btn-danger {
    background: #fee2e2;
    color: #dc2626;
}

.btn-small.btn-danger:hover {
    background: #fecaca;
}

.btn-small.btn-success {
    background: #dcfce7;
    color: #16a34a;
}

.btn-small.btn-success:hover {
    background: #bbf7d0;
}

.image-preview {
    position: relative;
    background: var(--background-gray);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.image-preview:hover {
    background: #f1f5f9;
}

.image-preview canvas {
    max-width: 100%;
    max-height: 200px;
    width: auto;
    height: auto;
    border-radius: 8px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .border-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .toolbar {
        padding: 8px 16px;
        flex-direction: column;
        gap: 12px;
    }

    .toolbar-left h1 {
        font-size: 18px;
    }

    .export-options {
        width: 100%;
        justify-content: space-between;
    }

    .border-thumbnails {
        flex-direction: row;
        overflow-x: auto;
    }

    .border-item {
        min-width: 120px;
    }
}

/* 全屏预览弹窗 */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    cursor: pointer;
}

.modal-content {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 1001;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    padding: 24px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    min-height: 400px;
    max-height: calc(90vh - 180px);
    overflow: auto;
    background: var(--background-gray);
}

.modal-body canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
}