/* ============================================
   拼豆图纸生成器 - 样式表
   ============================================ */

:root {
    --primary-color: #FF6B9D;
    --primary-light: #FFB6C1;
    --primary-dark: #E85A8A;
    --secondary-color: #6C5CE7;
    --accent-color: #00CEC9;
    --success-color: #00B894;
    --danger-color: #E17055;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-bg: rgba(255, 255, 255, 0.98);
    --text-primary: #2D3436;
    --text-secondary: #636E72;
    --text-muted: #B2BEC3;
    --border-color: #E8E8E8;
    --border-radius: 16px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', -apple-system, sans-serif;
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 50%, #faf0ff 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============================================
   头部样式
   ============================================ */
.header {
    background: var(--bg-gradient);
    padding: 20px 20px;
    text-align: center;
    color: white;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
}

.header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 4px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.header h1::before {
    content: '';
    width: 30px;
    height: 30px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Ccircle cx='12' cy='12' r='6' fill='%23FF6B9D'/%3E%3C/svg%3E") center/contain no-repeat;
}

.header p {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* ============================================
   主容器和布局 - 三栏布局
   ============================================ */
.main-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    display: grid;
    grid-template-columns: 360px 1fr 340px;
    grid-template-rows: 1fr;
    gap: 20px;
    min-height: calc(100vh - 140px);
}

.left-panel,
.center-panel,
.right-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 16px;
}

@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 320px 1fr;
    }
    .right-panel {
        grid-column: 1 / -1;
    }
}

@media (max-width: 900px) {
    .main-container {
        grid-template-columns: 1fr;
    }
    .center-panel {
        order: 3;
    }
}

/* ============================================
   卡片通用样式
   ============================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 12px;
    flex-shrink: 0;
}

.card-title svg {
    color: var(--primary-color);
}

/* 上传裁剪卡片特殊样式 */
.upload-crop-card {
    gap: 0;
}

.upload-crop-card .card-title {
    margin-bottom: 12px;
}

/* ============================================
   上传区域
   ============================================ */
.upload-area {
    border: 3px dashed var(--primary-light);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(145deg, #fff5f8, #fff);
    height: 248px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: linear-gradient(145deg, #fff0f5, #fff);
}

.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(0, 206, 201, 0.05);
    transform: scale(1.02);
    border-style: solid;
}

.upload-icon {
    color: var(--primary-color);
}

.upload-text {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.upload-input {
    display: none;
}

/* ============================================
   统一预览显示区域
   ============================================ */
.image-display-area {
    display: none;
    flex-direction: column;
}

.image-display-area.active {
    display: flex;
    flex: 1;
    min-height: 0;
}

.preview-wrapper {
    position: relative;
    width: 100%;
    min-height: 180px;
    height: 200px;
    overflow: hidden;
    border-radius: 10px;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    object-fit: contain;
}

/* Cropper.js 容器样式优化 - 确保图片适应容器 */
.cropper-container,
.cropper-container img {
    max-width: 100% !important;
    max-height: 100% !important;
}

.cropper-view-box {
    overflow: hidden;
}

.cropper-canvas {
    max-width: 100% !important;
    max-height: 100% !important;
}

.cropper-wrap-box {
    overflow: hidden;
}

/* ============================================
   按钮组 - 确保一行显示
   ============================================ */
.btn-group {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    margin-top: 12px;
    width: 100%;
}

.btn-group .btn {
    flex: 1;
    min-width: 0;
    padding: 8px 6px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.btn-group .btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ============================================
   按钮样式
   ============================================ */
.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 157, 0.4);
}

.btn-secondary {
    background: #e8e8e8;
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: #d8d8d8;
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color), var(--accent-color));
    color: white;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 184, 148, 0.4);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.btn-lg {
    padding: 12px 20px;
    font-size: 0.95rem;
    width: 100%;
}

.generate-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    margin-top: 6px;
}

.generate-btn:hover:not(:disabled) {
    box-shadow: 0 5px 15px rgba(255, 107, 157, 0.4);
}

/* ============================================
   设置区域 - 高度由内容决定
   ============================================ */
.settings-card {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-height: 0;
}

.settings-card .card-title {
    flex-shrink: 0;
    margin-bottom: 12px;
}

.settings-card .setting-item {
    margin-bottom: 12px;
    flex-shrink: 0;
}

.settings-card .setting-item:last-of-type {
    margin-bottom: 14px;
}

.settings-card .custom-size-inputs,
.settings-card .options-list {
    flex-shrink: 0;
}

.settings-card .generate-btn {
    margin-top: 14px;
    flex-shrink: 0;
}

.setting-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    margin-bottom: 6px;
    display: block;
}

.select-wrapper {
    position: relative;
}

.select-wrapper select {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    color: var(--text-primary);
}

.select-wrapper select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.select-wrapper::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-muted);
    pointer-events: none;
}

.custom-size-inputs {
    display: none;
    margin-top: 10px;
}

.custom-size-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-size-row input {
    flex: 1;
    padding: 8px 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
    transition: all 0.3s ease;
}

.custom-size-row input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.size-separator {
    font-weight: 600;
    color: var(--text-muted);
}

.size-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* 选项 */
.options-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.8rem;
    background: #f8f8f8;
}

.checkbox-item:hover {
    background: #f0f0f0;
}

.checkbox-item input {
    display: none;
}

.checkbox-custom {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.checkbox-item input:checked + .checkbox-custom {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-item input:checked + .checkbox-custom::after {
    content: '';
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

/* ============================================
   图纸预览区域
   ============================================ */
.blueprint-card {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

.blueprint-container {
    background: #f8f8f8;
    border-radius: 12px;
    padding: 12px;
    overflow: hidden;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 200px;
}

.blueprint-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
}

.blueprint-canvas {
    display: block;
    box-shadow: var(--shadow-md);
    image-rendering: pixelated;
    border-radius: 4px;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
}

.blueprint-info {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.info-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #f8f9ff, #fff);
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.info-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.info-value {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 0.95rem;
}

.export-btn {
    margin-top: 12px;
    background: linear-gradient(135deg, var(--success-color), var(--accent-color));
    flex-shrink: 0;
}

.export-btn:hover:not(:disabled) {
    box-shadow: 0 5px 15px rgba(0, 184, 148, 0.4);
}

/* ============================================
   统计卡片
   ============================================ */
.stats-card {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.search-filter-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.search-box {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    padding: 8px 10px 8px 34px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.color-type-select {
    width: 120px;
    flex-shrink: 0;
}

.color-type-select select {
    padding: 8px 28px 8px 10px;
    font-size: 0.8rem;
}

/* 下拉选择 */
.color-dropdown {
    margin-bottom: 10px;
}

.dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #f8f8f8;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.dropdown-header:hover {
    background: #f0f0f0;
}

.dropdown-header.active {
    background: #fff;
    border-color: var(--primary-color);
    border-radius: 8px 8px 0 0;
}

.dropdown-header span {
    font-size: 0.85rem;
}

.dropdown-panel {
    display: none;
    background: white;
    border: 2px solid var(--primary-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
}

.dropdown-panel.active {
    display: block;
}

.color-category-list {
    padding: 6px;
}

.color-category-item {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-category-item:hover {
    background: #f8f8f8;
}

.category-preview {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    max-width: 160px;
}

.category-preview-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}

.category-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.category-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* 统计列表 */
.stats-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    min-height: 100px;
    max-height: 300px;
}

.stats-list::-webkit-scrollbar {
    width: 5px;
}

.stats-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.stats-list::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: 3px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 5px;
    background: #f8f8f8;
    transition: all 0.2s ease;
}

.stat-item:hover {
    background: #f0f0f0;
    transform: translateX(3px);
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.color-info {
    flex: 1;
    min-width: 0;
}

.color-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.color-id {
    font-size: 0.7rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.color-count {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 0.95rem;
    min-width: 35px;
    text-align: right;
}

/* 全部颜色列表 */
.all-colors-list {
    padding: 6px;
    max-height: 280px;
    overflow-y: auto;
}

.all-color-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.all-color-item:hover {
    background: #f8f8f8;
}

.all-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 5px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.all-color-id {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
    min-width: 45px;
}

.all-color-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* 总计 */
.total-stats {
    margin-top: auto;
    padding: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 10px;
    color: white;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.total-row:last-child {
    margin-bottom: 0;
}

.total-label {
    font-size: 0.8rem;
    opacity: 0.9;
}

.total-value {
    font-weight: 800;
    font-size: 1.1rem;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-muted);
}

.empty-icon {
    margin-bottom: 10px;
    opacity: 0.5;
}

.empty-text {
    font-size: 0.85rem;
}

/* ============================================
   底部版权
   ============================================ */
.footer {
    text-align: center;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.footer p {
    margin: 0;
}

/* ============================================
   加载状态
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.active {
    display: flex;
}

.loading-content {
    background: white;
    padding: 30px 50px;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 107, 157, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

/* ============================================
   Toast 提示
   ============================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success {
    background: linear-gradient(135deg, #00B894, #00CEC9);
}

.toast-error {
    background: linear-gradient(135deg, #E17055, #D63031);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
