/* Plot 在线工作台 */

:root {
  --bg: #f4f4f8;
  --panel: #ffffff;
  --panel-2: #fbfafd;
  --ink: #17151f;
  --ink-2: #454154;
  --sub: #85818f;
  --line: #e7e4ee;
  --line-2: #dcd8e6;
  --violet: #7c3aed;
  --violet-d: #6425d0;
  --violet-dd: #3f167f;
  --violet-soft: #f3edff;
  --violet-soft-2: #e7dcff;
  --green: #159b6b;
  --red: #d64545;
  --radius: 9px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, monospace;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 13px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }

.app { height: 100vh; display: flex; flex-direction: column; }

/* ================= 顶栏 ================= */
.topbar {
  height: 52px; flex: 0 0 52px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: #fff; border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 7px; }
.brand img { border-radius: 7px; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.top-divider { width: 1px; height: 18px; background: var(--line); }
.proj { display: flex; align-items: center; gap: 9px; min-width: 0; }
.proj-name {
  width: 190px; border: 1px solid transparent; background: transparent;
  border-radius: 6px; padding: 4px 7px; font-size: 12.5px; font-weight: 600;
  outline: none;
}
.proj-name:hover { background: var(--panel-2); }
.proj-name:focus { background: #fff; border-color: var(--violet-soft-2); box-shadow: 0 0 0 3px rgba(124, 58, 237, .08); }
.save-state { font-size: 11px; color: #a6a1b2; white-space: nowrap; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.tb-btn {
  border: 0; background: none; border-radius: 6px;
  padding: 6px 10px; font-size: 12.5px; color: var(--ink-2);
  cursor: pointer; transition: background .14s, color .14s; white-space: nowrap;
}
.tb-btn:hover { background: var(--violet-soft); color: var(--violet-d); }
.tb-home { color: var(--sub); }
.insp-toggle { display: none; color: var(--violet-d); border: 1px solid var(--violet-soft-2); background: var(--violet-soft); }

/* ================= 工作区 ================= */
.workspace {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 208px minmax(0, 1fr) 286px;
}
.nav {
  background: #faf9fc; border-right: 1px solid var(--line);
  padding: 12px 8px 8px; display: flex; flex-direction: column; overflow-y: auto;
}
.nav-sec { margin-bottom: 16px; }
.nav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .7px; color: #9993a6; text-transform: uppercase;
}
.nav-add {
  width: 18px; height: 18px; border: 1px solid var(--line-2); background: #fff;
  border-radius: 4px; color: var(--sub); font-size: 13px; line-height: 1;
  cursor: pointer; padding: 0;
}
.nav-add:hover { border-color: var(--violet); color: var(--violet-d); background: var(--violet-soft); }
.nav-count { font-size: 10px; background: #ece9f3; border-radius: 999px; padding: 0 6px; color: var(--sub); font-weight: 600; }
.nav-list { display: grid; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 8px; border-radius: 6px; font-size: 12.3px; color: var(--ink-2);
  cursor: pointer; border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: #fff; border-color: var(--line); }
.nav-item.on { background: #fff; border-color: var(--line-2); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(20, 18, 31, .04); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 2px; background: var(--violet); flex: 0 0 6px; }
.nav-item .dot.dot-g { background: #0ea5e9; }
.nav-item .dot.dot-r { background: #f59e0b; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-empty { padding: 4px 9px; font-size: 11px; color: #b5b0bf; }
.nav-foot {
  margin-top: auto; padding: 10px 8px 2px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; font-size: 10px; color: #b0abba;
}

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ================= 视图工具条 ================= */
.view-bar {
  height: 48px; flex: 0 0 48px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: #fff; border-bottom: 1px solid var(--line);
}
.view-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.view-title h1 { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.chip {
  font-size: 10px; color: var(--violet-d); background: var(--violet-soft);
  border: 1px solid var(--violet-soft-2); border-radius: 4px; padding: 1px 6px;
  white-space: nowrap; font-weight: 600;
}
.view-tools { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.v-btn {
  height: 27px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--line-2); background: #fff; color: var(--ink-2);
  font-size: 11.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  transition: border-color .14s, color .14s, background .14s;
}
.v-btn:hover { border-color: var(--violet); color: var(--violet-d); }
.v-primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.v-primary:hover { background: var(--violet-d); border-color: var(--violet-d); color: #fff; }

/* 分析菜单 */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 32px; z-index: 30;
  width: 196px; background: #fff; border: 1px solid var(--line-2);
  border-radius: 9px; box-shadow: 0 16px 34px -16px rgba(30, 16, 60, .35);
  padding: 5px;
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 9px; border-radius: 6px; font-size: 12.5px; color: var(--ink-2); cursor: pointer;
}
.menu button:hover { background: var(--violet-soft); color: var(--violet-d); }

/* ================= 数据表 ================= */
.sheet-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.sheet { flex: 1; overflow: auto; padding: 0 0 10px; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 12px; table-layout: fixed; }
.grid th, .grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grid thead th {
  position: sticky; top: 0; z-index: 5; background: #faf9fc;
  padding: 0; height: 36px; font-weight: 600; color: var(--ink-2);
}
.grid .g-corner {
  position: sticky; left: 0; top: 0; z-index: 8; width: 42px; min-width: 42px;
  background: #f6f4fa; border-right: 1px solid var(--line-2);
}
.grid .g-rowh {
  position: sticky; left: 0; z-index: 4; width: 42px; min-width: 42px;
  background: #faf9fc; text-align: center; font-size: 10.5px;
  color: #a09aad; font-family: var(--mono); font-weight: 400;
}
.grid .g-col { width: 118px; min-width: 118px; }
.col-head {
  display: flex; align-items: center; gap: 3px; padding: 0 5px; height: 36px;
}
.col-head input {
  min-width: 0; flex: 1; border: 0; background: transparent;
  font-size: 11.5px; font-weight: 600; color: var(--ink); outline: none;
  border-radius: 4px; padding: 3px 4px;
}
.col-head input:focus { background: #fff; box-shadow: 0 0 0 2px var(--violet-soft-2); }
.col-head .x-tag {
  font-size: 9px; color: #0e7490; background: #e0f2fe; border-radius: 3px;
  padding: 0 4px; font-weight: 700;
}
.col-del {
  width: 16px; height: 16px; border: 0; background: none; color: #c5c0ce;
  cursor: pointer; font-size: 12px; padding: 0; line-height: 1; opacity: 0;
}
.grid thead th:hover .col-del { opacity: 1; }
.col-del:hover { color: var(--red); }
.grid td { padding: 0; background: #fff; }
.grid td input {
  width: 100%; height: 30px; border: 0; background: transparent;
  padding: 0 8px; font-family: var(--mono); font-size: 11.8px; color: var(--ink);
  outline: none; text-align: right;
}
.grid td input:focus { background: #faf7ff; box-shadow: inset 0 0 0 1.5px var(--violet); }
.grid tbody tr:nth-child(even) td { background: #fdfdfe; }
.grid tbody tr:hover td { background: #faf9fe; }
.grid td.empty-cell input::placeholder { color: #d3cedb; }
.sheet-hint {
  flex: 0 0 auto; padding: 8px 14px; border-top: 1px solid var(--line);
  background: #fbfafd; font-size: 11px; color: var(--sub);
}
kbd {
  font: 10.5px/1 var(--mono); background: #fff; border: 1px solid var(--line-2);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px;
}

/* ================= 图表 ================= */
.chart-stage {
  flex: 1; min-height: 0; overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, #ddd8e6 1px, transparent 0) 0 0 / 18px 18px,
    var(--bg);
  display: flex; flex-direction: column; align-items: center;
  padding: 26px 22px 22px; gap: 12px;
}
.chart-paper {
  background: #fff; border: 1px solid var(--line);
  box-shadow: 0 18px 44px -26px rgba(30, 16, 60, .3);
  border-radius: 4px; padding: 6px; max-width: 100%;
}
.chart-paper svg { display: block; max-width: 100%; height: auto; }
.chart-meta {
  font-size: 10.5px; color: #9a95a7; text-align: center;
  max-width: 620px; line-height: 1.7;
}

/* ================= 结果 ================= */
.result-stage {
  flex: 1; min-height: 0; overflow: auto; padding: 26px 22px 40px;
  display: flex; justify-content: center; align-items: flex-start;
}
.result-paper {
  width: 100%; max-width: 860px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 18px 40px -30px rgba(30, 16, 60, .3);
  padding: 30px 34px 34px;
}
.rp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 18px; }
.rp-head h2 { font-size: 17px; }
.rp-sub { font-size: 11.5px; color: var(--sub); margin-top: 3px; }
.rp-kicker { font-size: 10px; letter-spacing: 1px; color: var(--violet-d); font-weight: 700; text-transform: uppercase; }
.rp-section { margin-bottom: 22px; }
.rp-section h3 { font-size: 12.5px; margin-bottom: 9px; color: var(--ink-2); }
.rp-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rp-table th, .rp-table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: right; }
.rp-table th:first-child, .rp-table td:first-child { text-align: left; }
.rp-table thead th { background: #fbfaff; font-size: 11px; color: var(--sub); font-weight: 600; }
.rp-table td { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }
.rp-table td.sig { color: var(--violet-d); font-weight: 700; }
.rp-note {
  background: #fbf9ff; border: 1px solid var(--violet-soft-2); border-radius: 8px;
  padding: 12px 14px; font-size: 12px; color: var(--ink-2); line-height: 1.8;
}
.rp-note b { color: var(--violet-d); }
.rp-meta { margin-top: 22px; padding-top: 12px; border-top: 1px dashed var(--line-2); font-size: 10.5px; color: #a8a2b4; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ================= 右侧检查器 ================= */
.inspector {
  background: #faf9fc; border-left: 1px solid var(--line);
  overflow-y: auto; padding: 12px 12px 30px;
}
.insp-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10.5px; font-weight: 700; letter-spacing: .7px; color: #9993a6;
  text-transform: uppercase; padding: 2px 2px 10px;
}
.insp-group { margin-bottom: 16px; }
.insp-group > h4 {
  font-size: 10.5px; color: #9993a6; font-weight: 700; letter-spacing: .5px;
  margin: 0 0 7px 2px;
}
.insp-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.insp-row > label { font-size: 12px; color: var(--ink-2); flex: 0 0 auto; }
.insp-row .grow { flex: 1; min-width: 0; }
.insp-field {
  height: 27px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff;
  padding: 0 7px; font-size: 11.5px; color: var(--ink-2); outline: none; width: 100%;
}
.insp-field:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124, 58, 237, .08); }
select.insp-field { cursor: pointer; }
.insp-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.insp-check { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); cursor: pointer; margin-bottom: 7px; }
.insp-check input { accent-color: var(--violet); }
.insp-note { font-size: 10.5px; color: #a19bab; line-height: 1.7; margin: 4px 0 8px; }
.insp-empty { font-size: 11.5px; color: #aaa5b5; line-height: 1.8; padding: 6px 4px; }
.mini-btn {
  width: 100%; height: 29px; border: 1px solid var(--line-2); background: #fff;
  border-radius: 6px; font-size: 11.5px; color: var(--ink-2); cursor: pointer;
}
.mini-btn:hover { border-color: var(--violet); color: var(--violet-d); }
.mini-btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.mini-btn.primary:hover { background: var(--violet-d); }
.stat-list { display: grid; gap: 6px; }
.stat-item {
  display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px;
  padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px;
}
.stat-item span { color: var(--sub); }
.stat-item b { font-family: var(--mono); font-weight: 600; color: var(--ink-2); }
.theme-row { display: flex; gap: 6px; flex-wrap: wrap; }
.theme-chip {
  border: 1px solid var(--line-2); background: #fff; border-radius: 6px;
  padding: 4px 7px; font-size: 10.5px; color: var(--ink-2); cursor: pointer;
}
.theme-chip.on { border-color: var(--violet); color: var(--violet-d); background: var(--violet-soft); }
.swatch-row { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .08); cursor: pointer; position: relative; }
.swatch.on::after { content: ""; position: absolute; inset: 3px; border: 2px solid #fff; border-radius: 3px; }

/* ================= 弹窗 ================= */
.modal-root {
  position: fixed; inset: 0; z-index: 100; background: rgba(24, 16, 40, .38);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  width: 100%; max-width: 430px; background: #fff; border-radius: 12px;
  box-shadow: 0 30px 70px -24px rgba(20, 10, 40, .5);
  padding: 20px 22px 18px; max-height: 86vh; overflow-y: auto;
}
.modal.wide { max-width: 620px; }
.modal h3 { font-size: 15px; margin-bottom: 4px; }
.modal .m-sub { font-size: 11.5px; color: var(--sub); margin-bottom: 16px; }
.modal .m-row { margin-bottom: 12px; }
.modal .m-row > label { display: block; font-size: 11.5px; color: var(--ink-2); margin-bottom: 5px; }
.modal .m-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .btn-cancel { border: 1px solid var(--line-2); background: #fff; border-radius: 7px; height: 32px; padding: 0 14px; font-size: 12px; cursor: pointer; }
.modal .btn-go { border: 0; background: var(--violet); color: #fff; border-radius: 7px; height: 32px; padding: 0 16px; font-size: 12px; cursor: pointer; }
.modal .btn-go:hover { background: var(--violet-d); }
.modal .m-msg { font-size: 12px; color: var(--ink-2); line-height: 1.8; }
.modal .m-msg p { margin: 0 0 8px; }
.modal .m-msg ul { margin: 0; padding-left: 18px; }
.modal .m-msg code { font-family: var(--mono); font-size: 11px; background: #f5f3fa; border-radius: 3px; padding: 1px 4px; }

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #241a38; color: #fff; border-radius: 8px;
  padding: 9px 16px; font-size: 12px; z-index: 200;
  box-shadow: 0 14px 30px -14px rgba(0, 0, 0, .5);
  animation: toastIn .18s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ================= 响应式 ================= */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 188px minmax(0, 1fr) 250px; }
}
@media (max-width: 1020px) {
  .workspace { grid-template-columns: 180px minmax(0, 1fr); }
  .inspector {
    position: fixed; right: 0; top: 52px; bottom: 0; width: 260px; z-index: 40;
    box-shadow: -16px 0 34px -24px rgba(20, 10, 40, .4);
    transform: translateX(100%); transition: transform .2s;
  }
  .app.insp-open .inspector { transform: none; }
  .insp-toggle { display: inline-flex !important; }
}
@media (max-width: 780px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .nav {
    flex-direction: row; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 6px 8px; gap: 12px; flex: 0 0 auto;
  }
  .nav-sec { margin-bottom: 0; display: flex; align-items: center; gap: 6px; }
  .nav-head { padding: 0; white-space: nowrap; }
  .nav-list { display: flex; gap: 4px; }
  .nav-item { white-space: nowrap; max-width: 150px; }
  .nav-empty, .nav-foot { display: none; }
  .view-bar { height: auto; min-height: 48px; flex: 0 0 auto; flex-wrap: wrap; padding: 7px 10px; gap: 6px; }
  .view-title { width: 100%; }
  .view-tools { margin-left: 0; flex-wrap: wrap; }
  .top-actions .tb-btn[data-act="new"],
  .top-actions .tb-btn[data-act="open"],
  .top-actions .tb-btn[data-act="importCsv"] { display: none; }
  .proj-name { width: 120px; }
  .save-state { display: none; }
  .chart-stage { padding: 14px 10px; }
  .result-stage { padding: 14px 10px 30px; }
  .result-paper { padding: 20px 16px 24px; }
  .grid .g-col { width: 96px; min-width: 96px; }
}
