/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 13px; color: #1a1a2e; background: #f0f2f5;
    overflow: hidden; height: 100vh;
}
button, input, textarea, select { font: inherit; outline: none; }
button { cursor: pointer; }
a { text-decoration: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #c1c9d6; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ========== Topbar ========== */
.topbar {
    height: 48px; background: #fff; border-bottom: 1px solid #e4e7ed;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left strong { font-size: 15px; }
.topbar-status { font-size: 11px; color: #67c23a; padding: 2px 8px; background: #f0f9eb; border-radius: 10px; }
.topbar-center { display: flex; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 12px; }
.topbar-user { color: #909399; }
.topbar-logout { color: #e6a23c; }

/* ========== Buttons ========== */
.tb-btn {
    padding: 6px 14px; border: 1px solid #dcdfe6; border-radius: 4px;
    background: #fff; color: #606266; font-size: 12px;
    transition: all .15s;
}
.tb-btn:hover { border-color: #409eff; color: #409eff; }
.tb-btn:disabled { opacity: .5; cursor: not-allowed; }
.tb-btn.primary { background: #409eff; border-color: #409eff; color: #fff; }
.tb-btn.primary:hover { background: #337ecc; }
.tb-btn.danger { color: #f56c6c; border-color: #fab6b6; }
.tb-btn.danger:hover { background: #fef0f0; }
.tb-badge {
    display: inline-block; min-width: 16px; padding: 0 5px; margin-left: 4px;
    height: 16px; line-height: 16px; border-radius: 8px;
    background: #f56c6c; color: #fff; font-size: 11px; text-align: center;
}
.tb-btn.sm { padding: 3px 10px; font-size: 11px; }

/* ========== Layout ========== */
.layout {
    display: grid;
    grid-template-columns: 260px 1fr 360px;
    height: 100vh; padding-top: 48px;
    transition: grid-template-columns .25s;
}
.layout.panel-closed { grid-template-columns: 260px 1fr 0; }
.layout.panel-closed .edit-panel { width: 0; overflow: hidden; }

/* ========== Sidebar ========== */
.sidebar {
    background: #fff; border-right: 1px solid #e4e7ed;
    display: flex; flex-direction: column; overflow: hidden;
}
.side-search { padding: 10px 12px; border-bottom: 1px solid #f0f2f5; }
.side-search input {
    width: 100%; padding: 6px 10px; border: 1px solid #e4e7ed; border-radius: 4px;
    font-size: 12px; background: #fafbfc;
}
.side-search input:focus { border-color: #409eff; background: #fff; }
.side-body { flex: 1; overflow-y: auto; padding: 4px 0; }
.side-body::-webkit-scrollbar { width: 4px; }
.side-footer {
    padding: 8px 12px; border-top: 1px solid #f0f2f5;
}
.side-btn {
    width: 100%; padding: 7px; border: 1px dashed #c0c4cc; border-radius: 4px;
    background: #fafbfc; color: #606266; font-size: 12px;
}
.side-btn:hover { border-color: #409eff; color: #409eff; background: #ecf5ff; }

/* ---- 树节点 ---- */
.tree-node { user-select: none; }
.tree-row {
    display: flex; align-items: center; padding: 5px 12px; cursor: pointer;
    border-left: 3px solid transparent; transition: background .1s;
}
.tree-row:hover { background: #f5f7fa; }
.tree-row.active { background: #ecf5ff; border-left-color: #409eff; color: #409eff; }
.tree-row .tree-toggle {
    width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center;
    font-size: 10px; color: #909399; flex-shrink: 0; cursor: pointer;
}
.tree-row .tree-toggle:hover { color: #409eff; }
.tree-row .tree-toggle.empty { visibility: hidden; }
.tree-row .tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-right: 4px; }
.tree-dot.bound { background: #67c23a; }
.tree-dot.unbound { background: #dcdfe6; }
.tree-row .tree-badge {
    font-size: 10px; padding: 1px 6px; border-radius: 8px;
    background: #f0f2f5; color: #909399; flex-shrink: 0; margin-left: 4px;
}
.tree-children { padding-left: 12px; }
.tree-children.collapsed { display: none; }

/* ========== Main Area ========== */
.main-area {
    background: #fff; display: flex; flex-direction: column;
    overflow: hidden; min-width: 0;
}
.main-tabs {
    display: flex; border-bottom: 1px solid #e4e7ed; padding: 0 16px;
    background: #fafbfc; flex-shrink: 0;
}
.tab-btn {
    padding: 10px 18px; border: none; background: none; color: #909399;
    font-size: 13px; border-bottom: 2px solid transparent; cursor: pointer;
}
.tab-btn:hover { color: #409eff; }
.tab-btn.active { color: #409eff; border-bottom-color: #409eff; font-weight: 600; }

/* ---- 面包屑 ---- */
.breadcrumb {
    padding: 10px 16px; font-size: 12px; color: #909399;
    border-bottom: 1px solid #f0f2f5; flex-shrink: 0;
}
.breadcrumb .bc-home { color: #409eff; cursor: pointer; }
.breadcrumb .bc-home:hover { text-decoration: underline; }
.breadcrumb .bc-current { font-weight: 600; color: #303133; }

/* ---- Empty ---- */
.empty-tip {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: #c0c4cc; font-size: 14px;
}

/* ---- Table ---- */
.view-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.table-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; border-bottom: 1px solid #f0f2f5; flex-shrink: 0;
}
.table-info { font-size: 12px; color: #909399; }
.table-wrap { flex: 1; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table thead { position: sticky; top: 0; z-index: 2; }
.data-table th {
    background: #fafbfc; color: #909399; font-weight: 500;
    padding: 8px 12px; text-align: left; border-bottom: 2px solid #e4e7ed; white-space: nowrap;
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid #ebeef5; }
.data-table tbody tr:hover { background: #f5f7fa; }
.data-table tbody tr:hover td { cursor: pointer; }
.data-table .col-code { width: 100px; font-family: monospace; font-size: 11px; color: #909399; }
.data-table .col-num { width: 60px; text-align: center; }
.data-table .col-date { width: 130px; font-size: 11px; color: #909399; }
.data-table .col-act { width: 100px; text-align: center; }
.data-table .act-link { color: #409eff; cursor: pointer; margin: 0 4px; font-size: 11px; }
.data-table .act-link.danger { color: #f56c6c; }
.data-table .act-link:hover { text-decoration: underline; }

/* ---- Importance dots ---- */
.imp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.imp-1 { background: #e4e7ed; }
.imp-2 { background: #b3d8ff; }
.imp-3 { background: #409eff; }
.imp-4 { background: #e6a23c; }
.imp-5 { background: #f56c6c; }

/* ---- Mindmap ---- */
.mind-canvas { flex: 1; overflow: auto; padding: 20px; background: #fafbfd; }

/* ---- TreeNode (mindmap) ---- */
.mind-tree { display: flex; gap: 30px; align-items: flex-start; min-width: max-content; }
.mind-col { display: flex; flex-direction: column; gap: 10px; }
.mind-branch { display: flex; flex-direction: column; gap: 6px; margin-left: 28px; padding-left: 24px; border-left: 2px solid #dce3ec; }
.mnode {
    border-radius: 6px; padding: 8px 12px; min-width: 100px; max-width: 160px;
    cursor: pointer; position: relative;
}
.mnode .mnode-name { font-size: 12px; font-weight: 600; }
.mnode .mnode-meta { font-size: 10px; margin-top: 2px; opacity: .7; }
.mnode.l1 { background: #2d9d78; color: #fff; }
.mnode.l2 { background: #e74c3c; color: #fff; }
.mnode.l3 { background: #3498db; color: #fff; }
.mnode.l4 { background: #f8f9fa; color: #53657d; border: 1px solid #d8e0ea; }
.mstock { background: #fff; border: 1px solid #dce3ec; border-radius: 4px; padding: 5px 8px; font-size: 11px; min-width: 80px; }
.mstock .mstock-name { font-weight: 600; }
.mstock .mstock-reason { font-size: 10px; color: #909399; margin-top: 2px; }

/* ========== Edit Panel (right) ========== */
.edit-panel {
    background: #fff; border-left: 1px solid #e4e7ed;
    display: flex; flex-direction: column; overflow-y: auto;
}
.ep-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid #e4e7ed;
    font-weight: 600; font-size: 14px; position: sticky; top: 0; background: #fff; z-index: 2;
}
.ep-actions { display: flex; gap: 8px; align-items: center; }
.ep-close {
    border: none; background: none; font-size: 18px; color: #c0c4cc; cursor: pointer;
    padding: 0 4px;
}
.ep-close:hover { color: #f56c6c; }
.ep-body { padding: 12px 16px 24px; flex: 1; overflow-y: auto; }
.ep-section { margin-bottom: 14px; }
.ep-section label { display: block; font-size: 12px; color: #909399; margin-bottom: 4px; }
.ep-section label small { font-size: 10px; color: #c0c4cc; }
.ep-section input, .ep-section textarea, .ep-section select {
    width: 100%; padding: 7px 10px; border: 1px solid #dcdfe6; border-radius: 4px;
    font-size: 13px;
}
.ep-section input:focus, .ep-section textarea:focus, .ep-section select:focus {
    border-color: #409eff;
}
.ep-readonly { background: #f5f7fa !important; color: #909399 !important; cursor: default; }
.ep-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.ep-row label { font-size: 12px; color: #909399; }
.ep-row input, .ep-row select {
    width: 100%; padding: 7px 10px; border: 1px solid #dcdfe6; border-radius: 4px;
    font-size: 13px; margin-top: 3px;
}
.ep-row input:focus, .ep-row select:focus { border-color: #409eff; }
.ep-check { display: flex !important; align-items: center; gap: 6px; }
.ep-check input[type="checkbox"] { width: auto; margin-top: 0; }

/* ---- Stocks in panel ---- */
.stock-search-row { display: flex; gap: 6px; margin-bottom: 8px; }
.stock-search-row input { flex: 1; padding: 6px 8px; border: 1px solid #dcdfe6; border-radius: 4px; font-size: 12px; }
.stock-list { max-height: 220px; overflow-y: auto; font-size: 11px; }
.stock-item {
    display: grid; grid-template-columns: 1fr 50px auto;
    align-items: center; gap: 6px; padding: 5px 8px;
    border-bottom: 1px solid #f0f2f5;
}
.stock-item:hover { background: #f5f7fa; }
.stock-item .si-code { font-family: monospace; color: #909399; }
.stock-item .si-reason { font-size: 10px; color: #c0c4cc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-item .si-del { color: #f56c6c; cursor: pointer; font-size: 14px; }
.stock-item .si-del:hover { background: #fef0f0; border-radius: 3px; }

.ep-footer { margin-top: 20px; }
.ep-footer button { width: 100%; padding: 9px; }
.ep-btn {
    padding: 5px 10px; border: 1px solid #dcdfe6; border-radius: 4px;
    background: #fff; color: #606266; font-size: 11px;
}
.ep-btn.danger { color: #f56c6c; border-color: #fab6b6; }

/* ========== Checkbox column ========== */
.col-cb { width: 32px; text-align: center; }
.col-cb input { width: auto; cursor: pointer; }

/* ========== Confirm box ========== */
.confirm-box { max-width: 380px; text-align: center; padding: 24px; }

/* ========== Modals ========== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.modal-box {
    background: #fff; border-radius: 8px; padding: 24px; max-width: 520px;
    width: 90%; max-height: 80vh; overflow: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,.15);
}
.modal-box.wide { max-width: 720px; }
.modal-box h3 { margin-bottom: 16px; font-size: 16px; }
.modal-close { float: right; border: none; background: none; font-size: 20px; color: #c0c4cc; cursor: pointer; }
.modal-close:hover { color: #f56c6c; }

/* ---- Dashboard ---- */
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.dash-card {
    text-align: center; padding: 16px 8px; border: 1px solid #e4e7ed; border-radius: 6px;
    background: #fafbfc;
}
.dash-val { font-size: 28px; font-weight: 700; color: #303133; }
.dash-label { font-size: 12px; color: #909399; margin-top: 4px; }

/* ---- Sync Steps ---- */
.sync-steps { margin-bottom: 20px; }
.sync-step {
    display: flex; align-items: center; gap: 12px; padding: 12px 0;
    border-bottom: 1px solid #f0f2f5;
}
.step-num {
    width: 28px; height: 28px; border-radius: 50%; background: #ecf5ff; color: #409eff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
    flex-shrink: 0;
}
.step-info { flex: 1; }
.step-info strong { font-size: 13px; }
.step-info p { font-size: 11px; color: #909399; margin-top: 2px; }

.sync-log { margin-top: 16px; }
.sync-log h4 { font-size: 13px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sync-log .data-table { max-height: 240px; overflow: auto; display: block; }

/* ========== Loading ========== */
.loading-tip { color: #c0c4cc; padding: 20px; text-align: center; font-size: 12px; }

/* ========== Responsive hide ========== */
.col-code, .col-date { }
@media (max-width: 1200px) { .col-date { display: none; } }
