/* 主布局 */
.tool-main {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
}

/* 通用面板样式 */
.panel-section,
.preview-panel {
    background: var(--bg-color-50);
    border: 1px solid var(--border-color-10);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.panel-section h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--text-color);
}

/* 通用布局组件 */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h3 {
    margin: 0;
}

/* 开关按钮 */
.switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.switch .label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.switch input[type="checkbox"] {
    position: relative;
    width: 36px;
    height: 20px;
    margin: 0;
    appearance: none;
    background: var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.switch input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s;
}

.switch input[type="checkbox"]:checked {
    background: var(--primary-color);
}

.switch input[type="checkbox"]:checked::before {
    left: 18px;
}

.switch input[type="checkbox"]:hover {
    opacity: 0.8;
}

/* 通用按钮样式 */
.type-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    min-width: 80px;
    height: 40px;
}

/* 形状和方向按钮 */
.shape-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    min-width: 60px;
}

.type-button:hover,
.shape-tab:hover {
    border-color: var(--primary-color);
    background: var(--primary-color-10);
}

.type-button.active,
.shape-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* 网格布局 */
.type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 8px;
}

.shape-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

/* 方向控制 */
.direction-group {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.direction-group .shape-tab {
    padding: 8px;
    font-size: 0.85rem;
    min-width: unset;
    width: 100%;
}

.full-width-tab {
    grid-column: 1 / -1;
    margin-top: 8px;
    padding: 12px 0;
    height: 40px;
}

/* 滑块组件 */
.range-with-value {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-with-value input[type="range"] {
    flex: 1;
}

.value-display {
    min-width: 48px;
    text-align: right;
    color: var(--text-secondary);
}

/* 颜色滑块区域 */
.color-slider {
    position: relative;
    height: 24px;
    background: var(--bg-color);
    border-radius: 12px;
    margin-bottom: 16px;
    user-select: none;
}

.gradient-bar {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    cursor: pointer;
}

#colorStops {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* 颜色节点样式 */
.color-stop {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    pointer-events: auto;
    user-select: none;
    z-index: 1;
}

.color-stop.selected,
.color-stop:hover,
.color-stop.active {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 2;
}

.color-stop:hover::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: inherit;
    border: 2px solid white;
    border-radius: 50%;
    margin-bottom: 8px;
    pointer-events: none;
    z-index: 3;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.color-stop input[type="color"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    border: none;
    cursor: pointer;
    left: 0;
    top: 0;
}

.color-stops-tip {
    font-size: 12px;
}

/* 预览区域 */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.gradient-preview {
    width: 100%;
    height: 480px;
    border-radius: 8px;
    margin-bottom: 16px;
}

/* CSS代码显示 */
.css-code {
    background: var(--bg-color);
    border-radius: 6px;
    overflow: hidden;
}

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

.css-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    background: var(--bg-color-50);
    border-radius: 6px 6px 0 0;
}

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

.css-code-content {
    padding: 16px;
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 24px;
    outline: none;
    background: var(--bg-color);
    border-radius: 0 0 6px 6px;
}

.css-code-content:focus {
    background: var(--bg-color-80);
}

/* 按钮组件 */
.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
}

.btn-group .btn {
    min-width: 0;
    white-space: nowrap;
    font-size: 0.9rem;
}

.btn-group .btn:last-child {
    grid-column: 1 / -1;
}

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

.btn-secondary:hover {
    background: var(--bg-color-50);
    border-color: var(--primary-color);
}

.btn-secondary.disabled,
.btn-secondary:disabled {
    background: var(--bg-color-10);
    color: var(--text-secondary);
    border-color: var(--border-color-10);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary.disabled:hover,
.btn-secondary:disabled:hover {
    background: var(--bg-color-10);
    border-color: var(--border-color-10);
    transform: none;
}

/* 自定义tooltip */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    pointer-events: none;
    z-index: 1000;
    margin-bottom: 8px;
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    pointer-events: none;
    z-index: 1000;
    margin-bottom: 3px;
}

.tooltip:hover::after,
.tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

.btn-icon {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: var(--bg-color);
}

.btn-icon .iconify {
    font-size: 14px;
}

.btn-icon:hover {
    background: var(--bg-color-80);
}

/* 颜色选择器弹出层 */
.color-picker-popup {
    position: fixed;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    min-width: 200px;
    overflow: hidden;
}

.color-picker-popup.active {
    display: block;
    animation: popup-fade 0.2s ease-out;
}

.picker-header {
    padding: 8px 12px;
    background: var(--bg-color-50);
    border-bottom: 1px solid var(--border-color-10);
}

.picker-header span {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.picker-content {
    padding: 12px;
}

.color-picker-popup .color-input {
    width: 100%;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 12px;
    cursor: pointer;
    padding: 2px;
}

/* Alpha控制器 */
.alpha-control {
    margin-top: 8px;
}

.alpha-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.alpha-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.alpha-slider input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, var(--header-bg-80), var(--primary-color));
    border-radius: 3px;
}

/* 通用滑块样式 */
.alpha-slider input[type="range"]::-webkit-slider-thumb,
.alpha-slider input[type="range"]::-moz-range-thumb,
.alpha-slider input[type="range"]::-ms-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -webkit-appearance: none;
    appearance: none;
}

.alpha-value {
    min-width: 40px;
    text-align: right;
    font-size: 12px;
    color: var(--text-secondary);
}

/* 动画 */
@keyframes popup-fade {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 位置控制 */
.position-controls {
    margin-top: 10px;
}

.position-row {
    margin-bottom: 12px;
}

.position-row label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    color: #666;
}

/* 链接样式 */
.panel-section a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
    color: var(--text-color);
}

.panel-section a::after {
    content: '→';
    margin-left: 8px;
    transition: transform 0.2s;
}

.panel-section a:hover::after {
    transform: translateX(4px);
}

/* 精选渐变样式面板 */
.preset-gradients-panel {
    background: var(--bg-color-50);
    border: 1px solid var(--border-color-10);
    border-radius: 12px;
    padding: 20px;
    grid-column: 1 / -1;
    --primary-color-rgb: 74, 144, 226;
}

.preset-header {
    margin-bottom: 20px;
}

.preset-header h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--text-color);
}

.preset-categories {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.category-tab {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    white-space: nowrap;
}

.category-tab:hover {
    border-color: var(--primary-color);
    background: var(--primary-color-10);
}

.category-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.preset-item {
    position: relative;
    height: 120px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.preset-item:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.preset-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: inherit;
    border-radius: 12px;
    z-index: 1;
}

.preset-item::after {
    content: attr(data-name);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: none;
    border-radius: 0 0 12px 12px;
    color: white;
    padding: 8px 8px 6px 8px;
    font-size: 11px;
    text-align: center;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    z-index: 2;
    letter-spacing: 0.5px;
}

.preset-item.selected {
    box-shadow:
        inset 0 0 0 3px var(--primary-color),
        0 8px 25px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.preset-item.selected::after {
    background: rgba(var(--primary-color-rgb, 74, 144, 226), 0.3);
    border-color: rgba(var(--primary-color-rgb, 74, 144, 226), 0.4);
    font-weight: 700;
}

/* 滚动条样式 */
.preset-grid::-webkit-scrollbar {
    width: 6px;
}

.preset-grid::-webkit-scrollbar-track {
    background: var(--bg-color-10);
    border-radius: 3px;
}

.preset-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.preset-grid::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* 性能优化 - 减少重绘 */
.color-stop {
    will-change: transform;
}

.gradient-preview {
    will-change: background-image;
}

/* 响应式布局 */
@media (max-width: 768px) {
    .tool-main {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: static;
    }

    .gradient-preview {
        height: 200px;
    }

    .presets-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }

    .preset-item {
        height: 80px;
    }
}