/* ==========================================
   电路模拟器 - 主样式表
   ========================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --secondary-color: #4CAF50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --bg-color: #f5f5f5;
    --panel-bg: #ffffff;
    --border-color: #ddd;
    --text-color: #333;
    --text-light: #666;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ==========================================
   左侧工具箱
   ========================================== */
#toolbox {
    width: 180px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    padding: 15px;
    overflow-y: auto;
    box-shadow: var(--shadow);
    z-index: 10;
}

#toolbox h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}

.tool-category {
    margin-bottom: 20px;
}

.tool-category h3 {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    margin-bottom: 5px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s ease;
    background: #fafafa;
}

.tool-item:hover {
    border-color: var(--primary-color);
    background: #e3f2fd;
    transform: translateX(3px);
}

.tool-item:active {
    cursor: grabbing;
}

.tool-item.dragging {
    opacity: 0.5;
    border-color: var(--primary-color);
    background: #bbdefb;
}

.tool-item svg {
    flex-shrink: 0;
}

.tool-item span {
    font-size: 12px;
    white-space: nowrap;
}

.action-btn {
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    background: var(--primary-color);
    color: white;
}

.action-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.action-btn:active {
    transform: translateY(0);
}

/* ==========================================
   主画布区域
   ========================================== */
#canvas-container {
    flex: 1;
    position: relative;
    background: #fff;
    overflow: hidden;
}

#circuit-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: rgba(255,255,255,0.95);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    font-size: 12px;
    color: var(--text-light);
}

#zoom-level {
    padding: 2px 8px;
    background: var(--bg-light);
    border-radius: 3px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

#zoom-level:hover {
    background: var(--border-color);
}

#simulation-status {
    color: var(--danger-color);
}

#simulation-status.running {
    color: var(--secondary-color);
}

/* ==========================================
   右侧观察/属性面板
   ========================================== */
#side-panel {
    width: 340px;
    min-width: 280px;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.side-panel-header {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.side-panel-header h2 {
    font-size: 16px;
    color: var(--primary-color);
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.side-panel-tabs {
    display: flex;
    gap: 8px;
}

.panel-tab-btn {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    background: #f7f9fc;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    transition: all 0.15s ease;
    user-select: none;
}

.panel-tab-btn:hover {
    border-color: rgba(33, 150, 243, 0.35);
    background: #eef6ff;
    color: var(--primary-dark);
}

.panel-tab-btn.active {
    background: rgba(33, 150, 243, 0.12);
    border-color: rgba(33, 150, 243, 0.35);
    color: var(--primary-dark);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.08);
}

.side-panel-body {
    flex: 1;
    overflow: auto;
    padding: 14px;
}

#side-panel h3 {
    font-size: 12px;
    color: var(--text-light);
    margin: 14px 0 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.panel-page {
    display: none;
}

.panel-page.active {
    display: block;
}

#property-content {
    min-height: 150px;
}

#property-content .hint,
#observation-root .hint {
    color: var(--text-light);
    font-size: 13px;
    font-style: italic;
}

#observation-root h3 {
    margin: 4px 0 10px;
}

.observation-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

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

.observation-actions .control-btn {
    width: auto;
    padding: 10px 12px;
    margin: 0;
    border-radius: 10px;
    font-size: 13px;
    border: 1px solid rgba(33, 150, 243, 0.28);
    background: rgba(33, 150, 243, 0.12);
    color: var(--primary-dark);
}

.observation-actions .control-btn:hover:not(:disabled) {
    border-color: rgba(33, 150, 243, 0.42);
    background: rgba(33, 150, 243, 0.16);
}

.observation-actions .control-btn.stop {
    background: rgba(244, 67, 54, 0.12);
    color: var(--danger-color);
    border: 1px solid rgba(244, 67, 54, 0.25);
}

.observation-actions .control-btn.stop:hover:not(:disabled) {
    background: rgba(244, 67, 54, 0.18);
}

.observation-plot-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.observation-gauge-section {
    margin-top: 12px;
}

.observation-gauge-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.observation-gauge-card {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 12px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.06);
}

.gauge-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.gauge-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gauge-close-btn {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(244, 67, 54, 0.25);
    background: rgba(244, 67, 54, 0.12);
    color: var(--danger-color);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.gauge-close-btn:hover {
    background: rgba(244, 67, 54, 0.18);
}

.gauge-canvas-wrap {
    width: 100%;
    height: 200px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    overflow: hidden;
    background: #ffffff;
}

.gauge-canvas {
    width: 100%;
    height: 200px;
    display: block;
}

.gauge-footer {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-light);
}

.gauge-meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.observation-plot-card {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 12px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(16, 24, 40, 0.06);
}

.plot-card-header {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.plot-title-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 13px;
}

.plot-title-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.plot-remove-btn,
.plot-clear-btn {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: #f7f9fc;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.plot-remove-btn:hover,
.plot-clear-btn:hover {
    border-color: rgba(33, 150, 243, 0.35);
    background: #eef6ff;
    color: var(--primary-dark);
}

.plot-canvas-wrap {
    width: 100%;
    height: 180px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    overflow: hidden;
    background: #ffffff;
}

.plot-canvas {
    width: 100%;
    height: 180px;
    display: block;
}

.plot-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 10px 0 2px;
}

.plot-latest {
    font-size: 12px;
    color: var(--text-light);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.obs-range-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-light);
}

.obs-range-toggle input[type="checkbox"] {
    width: auto;
}

.obs-range-inputs {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.obs-range-inputs input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 13px;
}

.obs-range-inputs input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

#property-content .prop-group {
    margin-bottom: 12px;
}

#property-content .prop-group label {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

#property-content .prop-group input,
#property-content .prop-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
}

#property-content .prop-group input:focus,
#property-content .prop-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

#property-content .prop-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed #eee;
    font-size: 13px;
}

#property-content .prop-row .label {
    color: var(--text-light);
}

#property-content .prop-row .value {
    font-weight: 500;
    color: var(--primary-dark);
}

#side-panel .form-group {
    margin: 12px 0 14px;
}

#side-panel .form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-light);
}

#side-panel .form-group input,
#side-panel .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    background: #ffffff;
}

#side-panel .form-group input:focus,
#side-panel .form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

#side-panel .form-group .hint {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-light);
}

#side-panel .form-group .input-with-unit {
    display: flex;
    align-items: center;
}

#side-panel .form-group .input-with-unit input {
    border-radius: 10px 0 0 10px;
}

#side-panel .form-group .input-with-unit .unit {
    padding: 10px 12px;
    background: #f5f5f5;
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 10px 10px 0;
    font-size: 13px;
    color: var(--text-light);
    white-space: nowrap;
}

.display-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 6px;
}

.display-chip {
    border: 1px solid var(--border-color);
    background: #f7f9fc;
    color: var(--text-light);
    border-radius: 999px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.display-chip:hover {
    border-color: rgba(33, 150, 243, 0.35);
    background: #eef6ff;
    color: var(--primary-dark);
}

.display-chip.active {
    background: rgba(33, 150, 243, 0.14);
    border-color: rgba(33, 150, 243, 0.35);
    color: var(--primary-dark);
}

#simulation-controls {
    margin-top: 0;
}

.side-panel-footer {
    padding: 12px 14px 14px;
    border-top: 1px solid var(--border-color);
    background: #ffffff;
}

.control-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

.control-btn.run:hover:not(:disabled) {
    background: #43A047;
}

.control-btn.stop {
    background: var(--danger-color);
    color: white;
}

.control-btn.stop:hover:not(:disabled) {
    background: #E53935;
}

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

/* ==========================================
   SVG 元器件样式
   ========================================== */

/* 禁止SVG元素原生拖放，防止触发drop事件创建重复元器件 */
#circuit-canvas,
#circuit-canvas * {
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.component {
    cursor: move;
    transition: filter 0.2s ease;
}

.component:hover {
    filter: drop-shadow(0 0 4px rgba(33, 150, 243, 0.5));
}

.component.selected {
    filter: drop-shadow(0 0 6px rgba(33, 150, 243, 0.8));
}

.component .body {
    fill: #fff;
    stroke: #333;
    stroke-width: 2;
}

.component .terminal {
    fill: #2196F3;
    stroke: #1565C0;
    stroke-width: 1;
    cursor: crosshair;
    transition: all 0.15s ease;
    pointer-events: all !important;
}

.component .terminal:hover {
    fill: #FF5722;
    r: 7;
}

.component .terminal.connected {
    fill: #4CAF50;
}

/* 端子延长引出线 */
.component .terminal-extension {
    stroke: #333;
    stroke-width: 2;
    pointer-events: none;
}

.component .label {
    font-size: 12px;
    fill: #333;
    font-weight: 500;
    pointer-events: none;
    user-select: none;
}

.component .value-display {
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    user-select: none;
    paint-order: stroke fill;
    stroke: white;
    stroke-width: 3px;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* 电流显示 */
.component .current-display {
    fill: #E91E63;
}

/* 电压显示 */
.component .voltage-display {
    fill: #2196F3;
}

/* 功率显示 */
.component .power-display {
    fill: #4CAF50;
}

/* 数值显示背景 */
.component .value-display-bg {
    fill: rgba(255, 255, 255, 0.85);
    rx: 3;
    ry: 3;
}

/* 灯泡发光效果 */
.component.bulb .glow {
    fill: rgba(255, 235, 59, 0);
    transition: fill 0.3s ease;
}

.component.bulb.on .glow {
    fill: rgba(255, 235, 59, 0.8);
}

/* 导线样式 */
.wire-group {
    cursor: pointer;
}

/* 不可见的点击区域 */
.wire-hit-area {
    fill: none;
    stroke: transparent;
    stroke-width: 12;
    cursor: pointer;
}

.wire {
    fill: none;
    stroke: #333;
    stroke-width: 2;
    cursor: pointer;
    transition: stroke 0.2s ease;
}

.wire-group:hover .wire {
    stroke: #2196F3;
    stroke-width: 3;
}

.wire-group.selected .wire {
    stroke: #FF5722;
    stroke-width: 3;
}

/* 导线控制点 */
.wire-control-point {
    fill: #FF5722;
    stroke: white;
    stroke-width: 2;
    cursor: move;
    opacity: 0.9;
}

.wire-control-point:hover {
    fill: #E64A19;
    r: 8;
}

/* 导线节点点（蓝色，可拖动和连接） */
.wire-node-point {
    fill: #2196F3;
    stroke: white;
    stroke-width: 2;
    cursor: move;
    opacity: 0.9;
    transition: r 0.15s ease;
}

.wire-node-point:hover {
    fill: #1565C0;
    r: 9 !important;
}

/* 添加控制点的按钮（中点） */
.wire-add-point {
    fill: #2196F3;
    stroke: white;
    stroke-width: 1.5;
    cursor: pointer;
    opacity: 0.6;
}

.wire-add-point:hover {
    fill: #1976D2;
    opacity: 1;
    r: 6;
}

/* 对齐辅助线 */
.alignment-guide {
    stroke: #2196F3;
    stroke-width: 1;
    stroke-dasharray: 6, 4;
    pointer-events: none;
    opacity: 0.8;
}

/* 端点高亮（连接预览） */
.terminal-highlight {
    fill: rgba(76, 175, 80, 0.3);
    stroke: #4CAF50;
    stroke-width: 2;
    pointer-events: none;
    animation: terminal-pulse 0.8s ease-in-out infinite;
}

/* 导线节点高亮 */
.wire-node-highlight {
    fill: rgba(33, 150, 243, 0.3);
    stroke: #2196F3;
    stroke-width: 2;
    pointer-events: none;
    animation: terminal-pulse 0.8s ease-in-out infinite;
}

@keyframes terminal-pulse {
    0%, 100% { r: 12; opacity: 0.8; }
    50% { r: 15; opacity: 1; }
}

.wire-temp {
    fill: none;
    stroke: #2196F3;
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    pointer-events: none;
}

/* 电流动画 - 流动效果 */
@keyframes current-flow-forward {
    from { stroke-dashoffset: 24; }
    to { stroke-dashoffset: 0; }
}

@keyframes current-flow-reverse {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: 24; }
}

/* 基础流动样式 */
.wire.flowing {
    stroke-dasharray: 6, 6;
}

.wire.flowing-forward {
    animation: current-flow-forward 0.6s linear infinite;
}

.wire.flowing-reverse {
    animation: current-flow-reverse 0.6s linear infinite;
}

/* 电流强度样式 - 影响颜色和速度 */
.wire.current-low {
    stroke: #FFA726;
    stroke-width: 2;
}

.wire.current-low.flowing-forward {
    animation-duration: 1s;
}

.wire.current-low.flowing-reverse {
    animation-duration: 1s;
}

.wire.current-medium {
    stroke: #FF9800;
    stroke-width: 2.5;
}

.wire.current-medium.flowing-forward {
    animation-duration: 0.5s;
}

.wire.current-medium.flowing-reverse {
    animation-duration: 0.5s;
}

.wire.current-high {
    stroke: #FF5722;
    stroke-width: 3;
}

.wire.current-high.flowing-forward {
    animation-duration: 0.3s;
}

.wire.current-high.flowing-reverse {
    animation-duration: 0.3s;
}

/* 短路警告样式 */
.wire.short-circuit {
    stroke: #f44336 !important;
    stroke-width: 3;
    stroke-dasharray: 4, 4;
    animation: short-circuit-pulse 0.5s ease-in-out infinite;
}

@keyframes short-circuit-pulse {
    0%, 100% { 
        stroke-opacity: 1;
        filter: drop-shadow(0 0 3px #f44336);
    }
    50% { 
        stroke-opacity: 0.6;
        filter: drop-shadow(0 0 6px #ff0000);
    }
}

/* 节点样式 */
.node-marker {
    fill: #333;
    stroke: none;
}

/* ==========================================
   对话框样式
   ========================================== */
#dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#dialog-overlay.hidden {
    display: none;
}

#property-dialog {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 24px;
    min-width: 320px;
    max-width: 450px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

#property-dialog h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
    font-size: 18px;
}

#dialog-content .form-group {
    margin-bottom: 16px;
}

#dialog-content .form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-light);
}

#dialog-content .form-group input,
#dialog-content .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

#dialog-content .form-group input:focus,
#dialog-content .form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

#dialog-content .form-group .input-with-unit {
    display: flex;
    align-items: center;
}

#dialog-content .form-group .input-with-unit input {
    border-radius: 6px 0 0 6px;
}

#dialog-content .form-group .input-with-unit .unit {
    padding: 10px 12px;
    background: #f5f5f5;
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 6px 6px 0;
    font-size: 13px;
    color: var(--text-light);
}

#dialog-content .slider-group {
    margin-top: 8px;
}

#dialog-content .slider-group input[type="range"] {
    width: 100%;
    margin-top: 5px;
}

.dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

.dialog-buttons button {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

#dialog-cancel {
    background: #e0e0e0;
    color: var(--text-color);
}

#dialog-cancel:hover {
    background: #d0d0d0;
}

#dialog-ok {
    background: var(--primary-color);
    color: white;
}

#dialog-ok:hover {
    background: var(--primary-dark);
}

/* ==========================================
   滑动变阻器滑块
   ========================================== */
.rheostat-slider {
    cursor: ew-resize;
    /* 滑块不应该阻挡对端子的点击 */
    pointer-events: auto;
}

.rheostat-slider:hover {
    fill: #FF5722;
}

/* ==========================================
   响应式调整
   ========================================== */
@media (max-width: 900px) {
    #toolbox {
        width: 150px;
        padding: 10px;
    }
    
    #property-panel {
        width: 180px;
        padding: 10px;
    }
    
    .tool-item span {
        display: none;
    }
}

/* ==========================================
   上下文菜单
   ========================================== */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    padding: 4px 0;
    min-width: 160px;
    z-index: 10000;
    animation: contextMenuFadeIn 0.15s ease-out;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-color);
    transition: background 0.15s ease;
}

.context-menu-item:hover {
    background: var(--bg-color);
}

.context-menu-item.danger {
    color: var(--danger-color);
}

.context-menu-item.danger:hover {
    background: rgba(244, 67, 54, 0.1);
}

/* ==========================================
   滚动条美化
   ========================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ==========================================
   开关切换按钮样式
   ========================================== */
.switch-toggle {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.switch-toggle button {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: #f5f5f5;
    color: var(--text-color);
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.switch-toggle button:first-child {
    border-radius: 4px 0 0 4px;
}

.switch-toggle button:last-child {
    border-radius: 0 4px 4px 0;
}

.switch-toggle button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.switch-toggle button:hover:not(.active) {
    background: #e0e0e0;
}

/* ==========================================
   仪表样式
   ========================================== */
.ammeter-body {
    fill: #fff;
    stroke: #c00;
}

.voltmeter-body {
    fill: #fff;
    stroke: #00c;
}

.meter-label {
    font-weight: bold;
}

.ammeter-reading {
    color: #c00;
    font-weight: bold;
}

.voltmeter-reading {
    color: #00c;
    font-weight: bold;
}

.prop-row.reading {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    margin: 8px -10px;
    padding: 12px 10px;
    border-radius: 6px;
    border: 1px solid #ddd;
}

.prop-row.reading .label {
    font-weight: 600;
}

.prop-row.reading .value {
    font-size: 18px;
    font-weight: 700;
}

/* 仪表 SVG 读数显示 */
.component .meter-reading {
    font-size: 15px;
    font-weight: 700;
    paint-order: stroke fill;
    stroke: white;
    stroke-width: 4px;
}

/* ==========================================
   开关元器件样式
   ========================================== */
.switch-blade {
    cursor: pointer;
    transition: transform 0.15s ease;
}

.switch-touch {
    cursor: pointer;
}

/* ==========================================
   电容器样式
   ========================================== */
.capacitor-plate {
    stroke: #333;
    transition: stroke 0.3s ease, stroke-width 0.3s ease;
}

/* 充电状态 - 高亮显示 */
.capacitor-plate.charged {
    stroke: #2196F3;
    stroke-width: 3;
}

/* 平行板电容可动极板提示 */
.plate-movable {
    transition: stroke 0.15s ease, fill 0.15s ease, opacity 0.15s ease;
}

.plate-movable:hover {
    stroke: #FF5722;
}

.component.switch:hover .switch-blade {
    stroke: var(--primary-color);
}

/* 黑箱 */
.component.blackbox .blackbox-body.transparent {
    fill: rgba(33, 150, 243, 0.06);
    stroke: rgba(33, 150, 243, 0.55);
    stroke-width: 2;
    stroke-dasharray: 6 4;
}

.component.blackbox .blackbox-body.opaque {
    fill: rgba(15, 23, 42, 0.88);
    stroke: rgba(15, 23, 42, 0.95);
    stroke-width: 2;
}

.component.blackbox .blackbox-title {
    fill: rgba(248, 250, 252, 0.95);
    font-weight: 700;
    letter-spacing: 0.2px;
    pointer-events: none;
    user-select: none;
}

.component.blackbox .blackbox-body.transparent + .blackbox-title {
    fill: rgba(15, 23, 42, 0.85);
}

.component.blackbox .blackbox-port {
    fill: rgba(148, 163, 184, 0.95);
    font-size: 10px;
    pointer-events: none;
    user-select: none;
}

/* ==========================================
   AI助手面板 - ChatGPT 简约风格
   ========================================== */
#ai-assistant-panel {
    position: fixed;
    bottom: 16px;
    right: 20px;
    width: 420px;
    height: 420px;
    min-width: 320px;
    min-height: 260px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#ai-assistant-panel.collapsed {
    transform: translateY(calc(100% - 46px));
}

#ai-assistant-panel.resizing,
#ai-assistant-panel.dragging {
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

#ai-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--panel-bg);
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    border-radius: 10px 10px 0 0;
    transition: background 0.2s;
    user-select: none;
    cursor: move;
}

#ai-panel-header:hover {
    background: #f8faff;
}

#ai-panel-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text-color);
    letter-spacing: -0.3px;
}

#ai-panel-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

#ai-panel-actions button {
    background: #f7f9ff;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-panel-actions button:hover {
    background: #e8f2ff;
    color: var(--primary-dark);
    border-color: var(--primary-color);
}

#ai-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    min-height: 210px;
}

#ai-tabs {
    display: flex;
    padding: 0 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #f9fbff;
}

.ai-tab {
    padding: 12px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    color: var(--text-light);
    position: relative;
}

.ai-tab:hover {
    color: var(--primary-dark);
    background: rgba(33, 150, 243, 0.06);
}

.ai-tab.active {
    color: var(--primary-dark);
    border-bottom-color: var(--primary-color);
    background: var(--panel-bg);
}

.ai-tab-content {
    display: none;
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.ai-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* 图片上传区域 - 简约风 */
#image-upload-zone {
    flex: 1;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

#image-drop-area {
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: all 0.2s;
    height: 190px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #f9fbff;
}

#image-drop-area.dragover {
    border-color: var(--primary-color);
    background: rgba(33, 150, 243, 0.06);
    border-style: solid;
}

#image-upload-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #666;
}

#image-upload-prompt svg {
    color: #999;
    opacity: 0.6;
}

#image-upload-prompt p {
    font-size: 14px;
    margin: 0;
    color: var(--text-light);
    font-weight: 500;
}

#image-preview-area {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#image-preview-area.hidden {
    display: none;
}

#image-preview {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    object-fit: contain;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#image-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(33,150,243,0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    backdrop-filter: blur(4px);
    transition: all 0.2s;
}

#image-remove-btn:hover {
    background: rgba(25,118,210,0.95);
    transform: scale(1.1);
}

#ai-resize-handle {
    height: 16px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    padding: 0 10px 6px 0;
    cursor: nwse-resize;
}

#ai-resize-handle::after {
    content: '';
    width: 14px;
    height: 14px;
    border-right: 2px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
    border-radius: 2px;
    opacity: 0.8;
}

#ai-assistant-panel.collapsed #ai-resize-handle {
    opacity: 0;
    pointer-events: none;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-color);
    padding: 11px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    width: 100%;
    box-shadow: 0 1px 3px rgba(33, 150, 243, 0.2);
}

.primary-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.25);
}

.primary-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

/* 聊天区域 - ChatGPT 风格 */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 4px;
    margin-bottom: 10px;
    max-height: 190px;
}

#followup-actions {
    display: flex;
    gap: 8px;
    margin: 6px 0 10px;
}

#chat-controls {
    display: flex;
    gap: 8px;
    margin: 6px 0 10px;
    flex-wrap: wrap;
}

#chat-controls button,
#chat-controls select {
    padding: 6px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 10px;
    background: #f9fbff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color);
    transition: all 0.2s;
}

#chat-controls button:hover,
#chat-controls select:hover {
    background: #f0f6ff;
    border-color: var(--primary-color);
    color: var(--primary-dark);
}

.followup-btn {
    flex: 1;
    background: #f9fbff;
    border: 1px solid #d0d0d0;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color);
    transition: all 0.2s;
}

.followup-btn:hover {
    background: #f0f6ff;
    border-color: var(--primary-color);
    color: var(--primary-dark);
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

.chat-message {
    margin-bottom: 12px;
    animation: fadeInUp 0.3s ease;
    padding: 0 4px;
}

@keyframes fadeInUp {
    from { 
        opacity: 0; 
        transform: translateY(8px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

.chat-message.user {
    text-align: right;
}

.chat-message-content {
    display: inline-block;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    text-align: left;
}

.chat-message.user .chat-message-content {
    background: #f0f6ff;
    border: 1px solid #d8e7ff;
    color: var(--text-color);
}

.chat-message.assistant .chat-message-content {
    background: #fff;
    border: 1px solid #e5e5e5;
    color: var(--text-color);
}

.chat-message.system .chat-message-content {
    background: #f8faff;
    border: 1px dashed var(--border-color);
    color: var(--text-light);
    font-size: 12px;
    text-align: center;
    max-width: 100%;
}

.loading-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.loading-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-indicator span:nth-child(1) { animation-delay: -0.32s; }
.loading-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { 
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% { 
        transform: scale(1);
        opacity: 1;
    }
}

#quick-questions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.quick-question-btn {
    background: #fff;
    border: 1px solid #d0d0d0;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    color: #2c2c2c;
}

.quick-question-btn:hover {
    background: #f0f6ff;
    border-color: var(--primary-color);
    color: var(--primary-dark);
}

#chat-input-area {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #f9fbff;
    border: 1.5px solid #d0d0d0;
    border-radius: 18px;
    padding: 6px 8px 6px 14px;
    transition: all 0.2s;
}

#chat-input-area:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

#chat-input {
    flex: 1;
    padding: 10px 0;
    border: none;
    font-size: 14px;
    outline: none;
    background: transparent;
    color: #2c2c2c;
}

#chat-input::placeholder {
    color: #999;
}

#chat-send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0;
    width: 34px;
    height: 34px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

#chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* AI设置对话框 - 简约风 */
#ai-settings-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

#ai-settings-dialog.hidden {
    display: none;
}

#ai-settings-dialog .dialog-content {
    background: white;
    padding: 32px;
    border-radius: 16px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#ai-settings-dialog h3 {
    margin: 0 0 24px 0;
    color: #2c2c2c;
    font-size: 18px;
    font-weight: 600;
}

#ai-settings-dialog .form-group {
    margin-bottom: 20px;
}

#ai-settings-dialog .hint-text {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-light);
}

#ai-settings-dialog label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 13px;
    color: #555;
}

#ai-settings-dialog input,
#ai-settings-dialog select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid #d0d0d0;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
    background: #fafafa;
}

#ai-settings-dialog input:focus,
#ai-settings-dialog select:focus {
    outline: none;
    border-color: #10a37f;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.model-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.model-input-row select {
    flex: 0 0 42%;
}

.model-input-row input {
    flex: 1 1 auto;
}

#ai-settings-dialog .dialog-buttons {
    display: flex;
    gap: 12px;
    margin-top: 28px;
    flex-wrap: wrap;
}

#ai-settings-dialog .dialog-buttons button {
    flex: 1;
    padding: 11px 20px;
    border: 1.5px solid #d0d0d0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    background: #fff;
    color: #2c2c2c;
}

#ai-settings-dialog .dialog-buttons button:hover {
    background: #f4f4f4;
    border-color: #b0b0b0;
}

#ai-settings-dialog .dialog-buttons .primary-btn {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

#ai-settings-dialog .dialog-buttons .primary-btn:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
