/* ============================================================================
 *  PyBaMM 实验台 —— 界面样式
 *  零外部依赖（不引 CDN），离线可用。
 * ========================================================================== */

:root {
  --bg: #0b0f14;
  --bg-soft: #111823;
  --panel: #151d2a;
  --panel-2: #1b2534;
  --line: #26303f;
  --txt: #e6edf5;
  --txt-dim: #8b9bb0;
  --txt-mute: #5f6f85;
  --accent: #4ade80;
  --accent-2: #38bdf8;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

code, .mono { font-family: var(--mono); }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  background: linear-gradient(180deg, #101823 0%, #0d141d 100%);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 26px; line-height: 1;
  width: 44px; height: 44px; display: grid; place-items: center;
  background: rgba(74, 222, 128, .12);
  border: 1px solid rgba(74, 222, 128, .3);
  border-radius: 12px;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .3px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--txt-mute); }
.sub code { color: var(--txt-dim); }

.status {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--txt-dim);
  background: var(--panel); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 999px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--txt-mute); box-shadow: 0 0 0 3px rgba(255,255,255,.04);
}
.dot.on { background: var(--accent); box-shadow: 0 0 10px rgba(74,222,128,.7); }
.dot.off { background: var(--err); box-shadow: 0 0 10px rgba(248,113,113,.6); }
.ver { font-family: var(--mono); font-size: 12px; color: var(--txt-mute); }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 22px 40px;
  max-width: 1680px; margin: 0 auto;
  align-items: start;
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel.side { position: sticky; top: 86px; }
@media (max-width: 1000px) { .panel.side { position: static; } }

.panel-title {
  margin: 0 0 16px; font-size: 13px; font-weight: 650;
  letter-spacing: 1.6px; text-transform: uppercase; color: var(--txt-mute);
}

/* ---------- 表单 ---------- */
.field { margin-bottom: 18px; }
.lbl {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--txt-dim);
  margin-bottom: 8px;
}
.lbl.inline { margin: 0; }
.unit { font-size: 11px; color: var(--txt-mute); font-weight: 400; }
.val {
  margin-left: auto; font-family: var(--mono); font-size: 13px;
  color: var(--accent); font-weight: 600;
}

.model-cards { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.mcard {
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  padding: 9px 8px; cursor: pointer;
  background: var(--panel-2); color: var(--txt-dim);
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 12px; text-align: left; transition: .14s;
}
.mcard b { font-size: 13px; color: var(--txt); font-family: var(--mono); }
.mcard span { font-size: 10.5px; line-height: 1.3; color: var(--txt-mute); }
.mcard:hover { border-color: #3b4a5e; }
.mcard.active {
  border-color: var(--accent); background: rgba(74,222,128,.09); color: var(--txt);
}
.mcard.active b { color: var(--accent); }

input[type=range] {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 5px; border-radius: 3px; background: var(--line); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 0 4px rgba(74,222,128,.16);
}
input[type=range]::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%; border: none;
  background: var(--accent); cursor: pointer;
}

.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.quick button, .presets button {
  background: var(--panel-2); color: var(--txt-dim);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 10px; font-size: 11.5px; cursor: pointer; transition: .14s;
}
.quick button:hover, .presets button:hover { border-color: var(--accent); color: var(--txt); }
.quick button.active { border-color: var(--accent); color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }

.vars {
  display: grid; grid-template-columns: 1fr; gap: 5px;
  max-height: 268px; overflow-y: auto; padding-right: 4px;
}
.vars label {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: 11.5px; color: var(--txt-dim); cursor: pointer;
  padding: 5px 8px; border-radius: 7px; border: 1px solid transparent;
  background: var(--panel-2); min-width: 0;
}
.vars label:hover { border-color: var(--line); }
.vars label.on { border-color: rgba(56,189,248,.45); color: var(--txt); }
.vars input { accent-color: var(--accent-2); margin: 1px 0 0; flex: none; }
.vw { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.vlabel { font-size: 11.5px; color: inherit; line-height: 1.25; }
.vname {
  font-family: var(--mono); font-size: 10px; color: var(--txt-mute);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3;
}

details summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸"; color: var(--txt-mute); font-size: 11px; }
details[open] summary::before { content: "▾"; }
.hint {
  margin-left: auto; font-family: var(--mono); font-size: 10.5px;
  color: var(--txt-mute); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px;
}
textarea {
  width: 100%; margin-top: 9px; resize: vertical;
  background: #0c1219; color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; font-family: var(--mono); font-size: 11.5px;
  line-height: 1.5;
}
textarea:focus { outline: none; border-color: var(--accent-2); }
.note { margin: 8px 0 0; font-size: 11px; color: var(--txt-mute); line-height: 1.5; }
.err { margin: 6px 0 0; font-size: 11.5px; color: var(--err); min-height: 14px; }

.actions { display: flex; gap: 9px; margin-top: 4px; }
.btn {
  flex: 1; padding: 11px 14px; border-radius: 9px; cursor: pointer;
  font-size: 13px; font-weight: 600; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--txt); transition: .14s;
}
.btn.primary {
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 100%);
  border-color: #22c55e; color: #06240f;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { flex: 0 0 auto; background: transparent; color: var(--txt-dim); font-weight: 500; }
.btn.ghost:hover { color: var(--txt); border-color: #3b4a5e; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* ---------- 结果区 ---------- */
.metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px;
}
@media (max-width: 700px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.metric {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 13px;
  display: flex; flex-direction: column; gap: 3px;
}
.mk { font-size: 10.5px; color: var(--txt-mute); letter-spacing: .4px; }
.mv { font-size: 16px; font-weight: 650; font-family: var(--mono); color: var(--txt); }

.chart-wrap {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px 8px; margin-bottom: 14px;
}
.chart-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; flex-wrap: wrap; }
.chart-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--txt-dim); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend button {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); color: var(--txt-dim);
  border-radius: 999px; padding: 3px 10px 3px 7px; font-size: 11.5px; cursor: pointer;
  font-family: var(--mono);
}
.legend button.off { opacity: .38; text-decoration: line-through; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: block; }

.chart-opts { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.chart-opts select {
  background: var(--panel); border: 1px solid var(--line); color: var(--txt-dim);
  border-radius: 7px; padding: 4px 8px; font-size: 11.5px; font-family: var(--mono);
  cursor: pointer; max-width: 220px;
}
.chart-opts select:focus { outline: none; border-color: var(--accent-2); }
.chart-opts label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--txt-dim); cursor: pointer; white-space: nowrap;
}
.chart-opts input { accent-color: var(--accent); margin: 0; }

.canvas-holder { position: relative; height: 360px; }
@media (max-width: 700px) { .canvas-holder { height: 260px; } }
#chart { width: 100%; height: 100%; display: block; }
.tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: rgba(8, 13, 20, .95); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 11px;
  color: var(--txt); white-space: nowrap; z-index: 5; box-shadow: 0 6px 22px rgba(0,0,0,.5);
}
.tip.show { opacity: 1; }
.empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--txt-mute); font-size: 12.5px; pointer-events: none;
}
.empty.hide { display: none; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs .spacer { flex: 1; }
.tab {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt-dim);
  border-radius: 8px; padding: 6px 13px; font-size: 12.5px; cursor: pointer;
}
.tab.active { border-color: var(--accent); color: var(--accent); }
.tab.small { font-size: 11.5px; padding: 5px 11px; }
.badge {
  display: inline-block; min-width: 17px; padding: 0 5px; margin-left: 3px;
  background: var(--line); border-radius: 9px; font-size: 10.5px; text-align: center;
}
.tabpane { display: none; }
.tabpane.active { display: block; }

.table-scroll { max-height: 330px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11.5px; }
thead th {
  position: sticky; top: 0; background: var(--panel-2); color: var(--txt-dim);
  text-align: right; padding: 8px 11px; border-bottom: 1px solid var(--line);
  font-weight: 600; white-space: nowrap; z-index: 1;
}
thead th:first-child, thead th:nth-child(2) { text-align: left; }
tbody td {
  padding: 6px 11px; text-align: right; border-bottom: 1px solid rgba(38,48,63,.5);
  color: var(--txt-dim); white-space: nowrap;
}
tbody td:first-child, tbody td:nth-child(2) { text-align: left; }
tbody tr:hover td { background: rgba(56,189,248,.05); color: var(--txt); }

.events, .history { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow: auto; }
.events li {
  font-family: var(--mono); font-size: 12px; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px;
  background: var(--panel-2); color: var(--txt-dim);
}
.history li {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px;
  background: var(--panel-2); font-size: 12px; color: var(--txt-dim); cursor: pointer;
}
.history li:hover { border-color: var(--accent-2); }
.history li .h-model { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.history li .h-time { margin-left: auto; color: var(--txt-mute); font-size: 11px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt);
  padding: 11px 18px; border-radius: 10px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .22s; z-index: 60;
  max-width: min(560px, 90vw); box-shadow: 0 10px 34px rgba(0,0,0,.55);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--err); color: #fecaca; }
.toast.ok { border-color: var(--accent); }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b3646; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4759; }
