/**
 * ============================================
 * 单片机硬件结构自动生成器 - 样式文件 v2.0
 * ============================================
 * 清新浅色主题
 */

/* ==================== 1. CSS 变量定义 ==================== */
:root {
    /* 背景与文字色 - 浅色主题 */
    --bg-primary: #f5f7fa;
    --bg-secondary: #eef1f5;
    --bg-card: #ffffff;
    --bg-input: #f8f9fc;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-highlight: #1a202c;
    
    /* 主题色 - 清新配色 */
    --color-accent: #3182ce;
    --color-mcu: #2b6cb0;
    --color-left: #38a169;
    --color-right: #dd6b20;
    --color-bottom: #805ad5;
    
    /* 边框与阴影 */
    --border-color: #1a202c;
    --border-radius: 12px;
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
    
    /* 间距 */
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 20px;
    --spacing-lg: 30px;
    
    /* 过渡动画 */
    --transition-fast: 0.2s ease;
}

/* ==================== 2. 基础重置样式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ==================== 3. 整体布局 ==================== */
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--spacing-md);
    gap: var(--spacing-md);
}

/* ==================== 4. 顶部区域样式 ==================== */
.header-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-highlight);
    text-align: center;
    letter-spacing: 1px;
}

.mcu-selector {
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.input-group label {
    font-weight: 600;
    color: var(--color-mcu);
    white-space: nowrap;
}

.input-group select,
.input-group input {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    min-width: 200px;
    transition: var(--transition-fast);
}

.input-group select:focus,
.input-group input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.15);
}

.input-group select:hover,
.input-group input:hover {
    border-color: var(--color-accent);
}

/* 箭头方向说明 */
.direction-tips {
    background: #fef3c7;
    border: 2px solid #f59e0b;
    border-radius: 8px;
    padding: 12px 20px;
    overflow: hidden;
    position: relative;
}

.direction-tips-inner {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-md);
    white-space: nowrap;
    position: relative;
    animation: scrollText 8s ease-in-out infinite alternate;
}

@keyframes scrollText {
    0% {
        left: 0;
        transform: translateX(0);
    }
    100% {
        left: 100%;
        transform: translateX(-100%);
    }
}

.direction-tips span {
    color: #dc2626;
    font-size: 0.95rem;
    font-weight: 500;
}

.direction-tips strong {
    color: #b91c1c;
    font-weight: 700;
}

/* ==================== 5. 中间区域样式 ==================== */
.main-section {
    display: flex;
    gap: var(--spacing-md);
    flex: 1;
    min-height: 500px;
}

.side-panel {
    width: 220px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--border-color);
}

.panel-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.panel-icon {
    font-size: 0.9rem;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: bold;
}

.left-panel {
    border-left: 4px solid var(--color-left);
}

.left-panel .panel-header h3 {
    color: var(--color-left);
}

.left-icon {
    background: rgba(56, 161, 105, 0.1);
    color: var(--color-left);
}

.right-panel {
    border-right: 4px solid var(--color-right);
}

.right-panel .panel-header {
    justify-content: flex-end;
}

.right-panel .panel-header h3 {
    color: var(--color-right);
}

.right-icon {
    background: rgba(221, 107, 32, 0.1);
    color: var(--color-right);
}

.panel-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.side-panel textarea,
.bottom-input-area textarea {
    flex: 1;
    padding: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    transition: var(--transition-fast);
    line-height: 1.5;
}

.side-panel textarea:focus,
.bottom-input-area textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.side-panel textarea::placeholder,
.bottom-input-area textarea::placeholder {
    color: #a0aec0;
    font-style: normal;
}

/* 画布区域样式 */
.canvas-section {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-header {
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.canvas-header h2 {
    font-size: 1.2rem;
    color: var(--text-highlight);
    font-weight: 600;
}

#diagramContainer {
    flex: 1;
    background: #ffffff;
    min-height: 450px;
    overflow: auto;
}

#diagramSvg {
    display: block;
    min-width: 100%;
    min-height: 100%;
}

/* ==================== 6. 底部输入区域样式 ==================== */
.bottom-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    border-bottom: 4px solid var(--color-bottom);
}

.bottom-input-area {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.bottom-input-area .panel-header h3 {
    color: var(--color-bottom);
}

.bottom-icon {
    background: rgba(128, 90, 213, 0.1);
    color: var(--color-bottom);
}

.bottom-input-area textarea {
    min-height: 80px;
}

/* ==================== 7. 按钮区域样式 ==================== */
.action-section {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    padding: var(--spacing-sm) 0;
}

.btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
    box-shadow: var(--shadow-soft);
}

.btn-icon {
    font-size: 1.1rem;
}

.btn-primary {
    background: var(--color-accent);
    color: white;
}

.btn-primary:hover {
    background: #2c5282;
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: var(--color-left);
    color: white;
}

.btn-secondary:hover {
    background: #2f855a;
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-danger {
    background: #e53e3e;
    color: white;
}

.btn-danger:hover {
    background: #c53030;
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-download {
    background: var(--color-bottom);
    color: white;
}

.btn-download:hover {
    background: #6b46c1;
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

/* ==================== 8. 页脚样式 ==================== */
.footer-section {
    text-align: center;
    padding: var(--spacing-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

/* ==================== 9. 响应式设计 ==================== */
@media (max-width: 1024px) {
    .main-section {
        flex-direction: column;
    }
    
    .side-panel {
        width: 100%;
    }
    
    #diagramContainer {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: var(--spacing-sm);
        gap: var(--spacing-sm);
    }
    
    .header-section {
        padding: var(--spacing-md);
    }
    
    .title {
        font-size: 1.2rem;
    }
    
    .mcu-selector {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }
    
    .input-group {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    
    .input-group select,
    .input-group input {
        min-width: 100%;
        padding: 10px;
    }
    
    .main-section {
        min-height: auto;
    }
    
    .side-panel {
        padding: var(--spacing-sm);
    }
    
    .side-panel textarea {
        min-height: 80px;
    }
    
    .canvas-section {
        order: -1;
    }
    
    #diagramContainer {
        min-height: auto;
        width: 100%;
        overflow: hidden;
    }
    
    #diagramSvg {
        width: 100%;
        height: auto;
        max-width: 100%;
    }
    
    .bottom-section {
        padding: var(--spacing-sm);
    }
    
    .bottom-input-area textarea {
        min-height: 60px;
    }
    
    .action-section {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .btn {
        width: 100%;
        justify-content: center;
        padding: 12px var(--spacing-md);
    }
    
    .footer-section {
        padding: var(--spacing-sm);
        font-size: 0.8rem;
    }
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.container > * {
    animation: fadeIn 0.4s ease forwards;
}

.container > *:nth-child(1) { animation-delay: 0.05s; }
.container > *:nth-child(2) { animation-delay: 0.1s; }
.container > *:nth-child(3) { animation-delay: 0.15s; }
.container > *:nth-child(4) { animation-delay: 0.2s; }
.container > *:nth-child(5) { animation-delay: 0.25s; }
