body {
    margin: 0;
    padding: 0;
    display: flex;
    height: 100vh;
    font-family: 'Microsoft YaHei', sans-serif;
    overflow: hidden;
    background-color: #f5f5f5;
}

.toolbar {
    width: 260px;
    background: #fff;
    border-right: 1px solid #ccc;
    padding: 15px;
    box-sizing: border-box;
    overflow-y: auto;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    z-index: 10;
}

.toolbar h3 {
    margin-top: 0;
    font-size: 16px;
    color: #333;
    border-bottom: 2px solid #0078d7;
    padding-bottom: 5px;
}

.help-text {
    font-size: 12px;
    color: #666;
    margin-top: 20px;
    line-height: 1.6;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
    border-left: 3px solid #0078d7;
}

.toolbar-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
}

.toolbar-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
    border-bottom: 2px solid #0078d7;
    padding-bottom: 5px;
    flex: 1;
}

#undo-btn, #open-params-btn, #export-btn, #import-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
    color: #555;
    margin-left: 4px;
    transition: background 0.15s;
}
#undo-btn { font-size: 18px; }
#open-params-btn { font-size: 18px; }
#undo-btn:hover, #open-params-btn:hover, #export-btn:hover, #import-btn:hover { background: #e8e8e8; }
#undo-btn:disabled { color: #bbb; cursor: default; border-color: #e0e0e0; }
#undo-btn:disabled:hover { background: none; }
#export-btn { color: #0078d7; border-color: #0078d7; }
#import-btn { color: #107c10; border-color: #107c10; }
#export-btn:hover { background: #e5f1fb; }
#import-btn:hover { background: #dff0df; }

.symbol-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 15px;
}

/* 参数弹窗 */
.params-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.params-overlay.hidden { display: none; }

.params-modal {
    background: #fff;
    border-radius: 8px;
    width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.params-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #eee;
}
.params-modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: #222;
}
#close-params-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #888;
    padding: 2px 6px;
    border-radius: 4px;
}
#close-params-btn:hover { background: #f0f0f0; color: #333; }

.params-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}
.params-modal-body h4 {
    margin: 0 0 10px;
    font-size: 14px;
    color: #0078d7;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 4px;
}

.param-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
}
.param-row label {
    flex: 1;
    font-size: 13px;
    color: #444;
}
.param-row input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    text-align: right;
}
.param-row span {
    font-size: 12px;
    color: #888;
    width: 30px;
}

.params-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
#params-reset-btn {
    padding: 7px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    color: #555;
}
#params-reset-btn:hover { background: #f5f5f5; }
#params-apply-btn {
    padding: 7px 20px;
    background: #0078d7;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
#params-apply-btn:hover { background: #005fa3; }

.symbol-item {
    width: 65px;
    height: 50px;
    background: white;
    cursor: grab;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.symbol-svg-container {
    width: 60px;
    height: 24px;
    border: 1px solid transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: border-color 0.2s;
}

.symbol-svg-container:hover {
    border-color: #0078d7;
}

.symbol-svg-container svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.symbol-name {
    font-size: 11px;
    margin-top: 4px;
    color: #333;
    text-align: center;
    white-space: nowrap;
}

.chart-container {
    flex: 1;
    overflow: auto;
    position: relative;
    padding: 20px;
    padding-left: 220px;
}

.chart-wrapper {
    position: relative;
    /* 1440 mins * 2px/min = 2880px */
    width: 3080px; /* 2880 + 200px for labels */
    padding-top: 30px; /* For time header */
}

.time-header {
    position: absolute;
    top: 0;
    left: 200px;
    width: 2880px;
    height: 30px;
    display: flex;
}

.time-label {
    width: 120px; /* 60 mins * 2px */
    flex-shrink: 0;
    border-left: 2px solid rgba(0,0,0,0.55);
    box-sizing: border-box;
    position: relative;
    height: 30px;
}

.time-label-hour {
    position: absolute;
    top: 3px;
    left: 4px;
    font-weight: bold;
    font-size: 13px;
    color: #333;
    line-height: 1;
}

/* 15分、45分：短刻度线 */
.time-tick {
    position: absolute;
    bottom: 0;
    display: block;
}

.time-tick-quarter {
    width: 1px;
    height: 6px;
    background: #888;
}

/* 30分：中刻度线 + ":30" 文字 */
.time-tick-half {
    height: 14px;
    border-left: 1px solid #555;
    padding-left: 2px;
    font-size: 9px;
    color: #666;
    line-height: 14px;
    white-space: nowrap;
}

.chart {
    position: relative;
    width: 2880px; 
    margin-left: 200px;
    background-color: #d4eadd; /* Light green */
    /* 网格层级：整点(120px) > 30分(60px) > 10分(20px) */
    background-image: 
        linear-gradient(to right, rgba(0,0,0,0.55) 2px, transparent 2px),
        linear-gradient(to right, rgba(0,0,0,0.28) 1px, transparent 1px),
        linear-gradient(to right, rgba(0,0,0,0.11) 1px, transparent 1px);
    background-size: 120px 100%, 60px 100%, 20px 100%;
    border: 1px solid #333;
    border-top: 2px solid #333;
    min-height: 500px;
}

.rows {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.row {
    height: 40px;
    border-bottom: 1px solid #666;
    display: flex;
    box-sizing: border-box;
    position: relative;
}

.row-header {
    background-color: #d4eadd;
    font-weight: bold;
}

.row-label {
    position: sticky;
    left: 0;
    top: 0;
    width: 200px;
    height: 100%;
    background: #fff;
    border-right: 2px solid #333;
    border-bottom: 1px solid #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: bold;
    color: #333;
    box-sizing: border-box;
    z-index: 50;
    margin-left: -200px;
}

.row-group .row-label > div:first-child {
    border-bottom: none;
}

.row-group-child .row-label > div:first-child {
    border-top: none;
    color: transparent; /* Hide text for child group */
}

.row-content {
    flex: 1;
    position: relative;
    height: 100%;
}

.draggable-symbol {
    position: absolute;
    height: 24px;
    bottom: 0;
    cursor: grab;
    user-select: none;
    display: block;
    z-index: 10;
    overflow: visible;
}

.wait-resize-handle {
    position: absolute;
    top: 0;
    width: 6px;
    height: 24px;
    background: rgba(100,100,200,0.5);
    cursor: ew-resize !important;
    z-index: 50;
    border-radius: 2px;
    transition: background 0.15s;
}
.wait-resize-handle:hover,
.wait-resize-handle:active {
    background: #0078d7;
}

/* ── 邻接区间运转时分表 ────────────────────────────────────────── */
.transit-table {
    border-collapse: collapse;
    font-size: 12px;
    width: 100%;
    margin-top: 6px;
}
.transit-table th {
    background: #e8f4e8;
    border: 1px solid #aaa;
    padding: 4px 8px;
    text-align: center;
    font-weight: bold;
    color: #333;
}
.transit-table td {
    border: 1px solid #ccc;
    padding: 3px 6px;
    text-align: center;
}
.transit-table td.td-label {
    background: #f5f5f5;
    font-weight: bold;
    color: #555;
    white-space: nowrap;
}
.transit-table input[type="number"] {
    width: 44px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
}

/* ── 旅客列车时刻表编辑UI ─────────────────────────────────────── */
.schedule-table {
    border-collapse: collapse;
    font-size: 12px;
    width: 100%;
}
.schedule-table th {
    background: #f0f6ff;
    border: 1px solid #ccc;
    padding: 4px 6px;
    font-weight: bold;
    color: #333;
    white-space: nowrap;
}
.schedule-table td {
    border: 1px solid #ddd;
    padding: 2px 3px;
}
.schedule-table input, .schedule-table select {
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px 3px;
    font-size: 12px;
    background: #fff;
}
.schedule-table tr:nth-child(even) td { background: #fafafa; }
.sch-del {
    background: none;
    border: none;
    color: #e81123;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
}
.sch-del:hover { color: #a00; }
.sch-btn {
    padding: 5px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    color: #444;
    white-space: nowrap;
}
.sch-btn:hover { background: #f0f0f0; }
.sch-btn.primary {
    background: #0078d7;
    color: #fff;
    border-color: #0078d7;
}
.sch-btn.primary:hover { background: #005fa3; }

/* ── 自动生成的旅客列车符号 ─────────────────────────────────────── */
.train-symbol {
    cursor: grab;
    overflow: visible !important;
}
.train-symbol:hover { outline: 1px dashed #c00; }
.train-symbol.selected { outline: 2px solid #c00; }

.ctx-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    z-index: 9998;
    min-width: 160px;
    padding: 4px 0;
    font-size: 13px;
}
.ctx-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ctx-menu-item:hover { background: #f0f6ff; color: #0078d7; }
.ctx-menu-item.active { font-weight: bold; color: #0078d7; }
.ctx-menu-item.active::before { content: '✓'; margin-right: 4px; }
.ctx-menu-item.disabled { color: #aaa; cursor: not-allowed; background: none !important; }

/* 送取结合模式选择菜单 */
.ctx-option {
    padding: 7px 14px;
    cursor: pointer;
    color: #333;
    border-left: 3px solid transparent;
    transition: background 0.1s;
}
.ctx-option:hover { background: #f0f6ff; border-left-color: #0078d7; }
.ctx-option.ctx-selected {
    background: #eef4ff;
    border-left-color: #7b00d4;
    font-weight: bold;
}
.ctx-option.ctx-selected::before {
    content: '✓ ';
    color: #7b00d4;
}

.freight-dest-menu { min-width: 150px; padding: 4px 0; }
.ctx-menu-title {
    padding: 6px 14px 5px;
    font-size: 12px;
    font-weight: bold;
    color: #555;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}
.ctx-menu-dest-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 14px;
    font-size: 13px;
    color: #222;
}
.dest-label { color: #444; }
.dest-count { font-weight: bold; color: #0078d7; margin-left: 16px; }

/* 装车/取车/送车 右键表单菜单 */
.ctx-menu-form { min-width: 200px; padding: 4px 0 8px; }
.ctx-form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 14px;
    gap: 8px;
}
.ctx-form-row label {
    font-size: 12px;
    color: #444;
    min-width: 60px;
    flex-shrink: 0;
}
.ctx-num-input {
    width: 60px;
    padding: 2px 4px;
    font-size: 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
    text-align: right;
}
.ctx-num-input:disabled { background: #f0f0f0; color: #aaa; }
.ctx-form-btn {
    display: block;
    margin: 8px 14px 0;
    padding: 4px 16px;
    background: #0078d7;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    width: calc(100% - 28px);
}
.ctx-form-btn:hover { background: #005ea6; }
.ctx-avail { font-size: 10px; color: #888; font-weight: normal; }

/* 约束锁定符号：位置由联动规则决定，不可自由拖拽 */
.constrained-symbol {
    cursor: default !important;
}

/* 解体/编组 模式颜色区分 */
.draggable-symbol[data-type="disassemble"][data-mode="ZD"] svg rect,
.draggable-symbol[data-type="disassemble"][data-mode="ZD"] svg polygon,
.draggable-symbol[data-type="assemble"][data-mode="ZD"] svg rect,
.draggable-symbol[data-type="assemble"][data-mode="ZD"] svg polygon {
    stroke: #0078d7; /* 蓝色：区段/直通 */
    stroke-width: 2px;
}
.draggable-symbol[data-type="disassemble"][data-mode="MZ"] svg rect,
.draggable-symbol[data-type="disassemble"][data-mode="MZ"] svg polygon,
.draggable-symbol[data-type="assemble"][data-mode="MZ"] svg rect,
.draggable-symbol[data-type="assemble"][data-mode="MZ"] svg polygon {
    stroke: #e81123; /* 红色：摘挂 */
    stroke-width: 2px;
}

.constrained-symbol[data-mode="ZD"] {
    outline: 2px solid rgba(0, 120, 215, 0.4);
}
.constrained-symbol[data-mode="MZ"] {
    outline: 2px solid rgba(232, 17, 35, 0.4);
}
.constrained-symbol:hover {
    outline-width: 3px;
    outline-color: rgba(0, 0, 0, 0.6);
}

/* 送取结合：送车右侧无分隔线，取车左侧无分隔线，整体用紫色轮廓标记配对 */
.draggable-symbol.paired-send {
    outline: 2px solid rgba(128, 0, 200, 0.55);
    outline-offset: 1px;
    border-right: none !important;
    z-index: 8;
}
.draggable-symbol.paired-fetch {
    outline: 2px solid rgba(128, 0, 200, 0.55);
    outline-offset: 1px;
    border-left: none !important;
    z-index: 8;
}
.draggable-symbol.paired-send svg rect,
.draggable-symbol.paired-send svg polygon {
    fill-opacity: 0.92;
}
.draggable-symbol.paired-fetch svg rect,
.draggable-symbol.paired-fetch svg polygon {
    fill-opacity: 0.92;
}

/* 手动模式标记：右上角小圆点 */
.draggable-symbol[data-manual-mode]::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ff6b00;
    box-shadow: 0 0 3px rgba(255, 107, 0, 0.6);
    pointer-events: none;
    z-index: 10;
}

.wait-drag-tip {
    position: fixed;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 13px;
    font-weight: bold;
    padding: 4px 10px;
    border-radius: 5px;
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.draggable-symbol svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.draggable-symbol:active {
    cursor: grabbing;
}

.draggable-symbol:hover {
    outline: 2px solid #ff9800;
    z-index: 100;
}

.draggable-symbol.selected {
    outline: 2px solid #ff0000;
    z-index: 100;
}

.draggable-symbol.invalid-pos {
    outline: 2px solid #e81123 !important;
    background-color: rgba(232, 17, 35, 0.2);
}

.tooltip {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    display: none;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: rgba(0,0,0,0.8) transparent transparent transparent;
}

.draggable-symbol:hover .tooltip,
.draggable-symbol.dragging .tooltip {
    display: block;
}

/* 图标行外标注：装卸车显示在图标上方，取送车显示在图标下方 */
.icon-label {
    position: absolute;
    left: 0;
    width: 100%;
    height: 19px;
    line-height: 19px;
    font-size: 9px;
    font-family: sans-serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    color: #444;
    text-align: center;
    z-index: 2;
}
.icon-label.above {
    bottom: 100%;
    top: auto;
}
.icon-label.below {
    top: 100%;
    bottom: auto;
}

/* ── 循环画布：右溢出的wrap-around幽灵元素 ─────────────────────────── */
.ghost-wrap-symbol {
    position: absolute;
    pointer-events: auto;
    opacity: 0.45;
    box-sizing: border-box;
    outline: 1.5px dashed rgba(0, 100, 200, 0.55);
    outline-offset: -1px;
    z-index: 4;
    cursor: pointer;
}
.ghost-wrap-symbol svg { display: block; width: 100%; height: 100%; pointer-events: none; }

/* ── 到发线闭合检测：列头指示器（左侧内嵌彩条，不影响布局） ─────────── */
.row-label.closure-closed   { box-shadow: inset 4px 0 0 #22b14c; }
.row-label.closure-conflict { box-shadow: inset 4px 0 0 #e04040; }