:root {
  --imm: #f59e0b;
  --con: #3b82f6;
  --root: #ef4444;
  --none: #94a3b8;
  --incident: #0f172a;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0e3a5f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- top bar ---- */
header.appbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
  z-index: 10;
}
header.appbar img { height: 38px; background:#fff; border-radius:6px; padding:3px; }
header.appbar .titles { line-height: 1.2; }
header.appbar .titles b { font-size: 17px; }
header.appbar .titles span { font-size: 12px; opacity: .8; display:block; }
header.appbar .spacer { flex: 1; }
header.appbar .toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit;
  border: none;
  border-radius: 7px;
  padding: 8px 13px;
  cursor: pointer;
  background: #e2e8f0;
  color: var(--ink);
  transition: background .15s, transform .05s;
}
button:hover { background: #cbd5e1; }
button:active { transform: translateY(1px); }
button.primary { background: #2563eb; color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.ghost { background: rgba(255,255,255,.14); color:#fff; }
button.ghost:hover { background: rgba(255,255,255,.28); }
button.danger { background: #fee2e2; color: #b91c1c; }
button.danger:hover { background: #fecaca; }
button.mini { padding: 3px 8px; font-size: 12px; border-radius: 6px; }

/* ---- layout ---- */
.main { flex: 1; display: flex; min-height: 0; }

aside.sidebar {
  width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
aside .side-head {
  padding: 12px; font-weight: 600; border-bottom: 1px solid var(--line);
  display:flex; align-items:center; justify-content:space-between;
}
aside .rec-list { overflow-y: auto; flex: 1; }
.rec {
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.rec:hover { background: #f8fafc; }
.rec.active { background: #e0edff; border-left: 3px solid #2563eb; }
.rec .rt { font-weight: 600; font-size: 14px; }
.rec .rm { font-size: 12px; color: var(--muted); margin-top: 2px; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.meta {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 14px;
}
.meta label { font-size: 11px; color: var(--muted); display:block; margin-bottom: 2px; }
.meta input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 6px; font: inherit;
}

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--panel); }
.tab {
  padding: 8px 16px; border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; background: #f8fafc; cursor: pointer; font-weight: 500;
}
.tab.active { background: #fff; color: #2563eb; box-shadow: 0 -2px 0 #2563eb inset; }

.panes { flex: 1; min-height: 0; position: relative; background: var(--panel); }
.pane { position: absolute; inset: 0; overflow: auto; padding: 16px; display: none; }
.pane.active { display: block; }

/* ---- editor / outline ---- */
.node-row { margin: 6px 0; }
.node-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--none);
  border-radius: 9px;
  background: #fff;
  padding: 8px 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.node-card.incident { border-left-color: var(--incident); background:#0f172a; color:#fff; }
.node-card.immediate { border-left-color: var(--imm); }
.node-card.contributing { border-left-color: var(--con); }
.node-card.root { border-left-color: var(--root); }
.node-card .nc-top { display: flex; align-items: center; gap: 8px; }
.node-card .tier-badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
  color: #fff; white-space: nowrap;
}
.badge-incident { background: var(--incident); }
.badge-immediate { background: var(--imm); }
.badge-contributing { background: var(--con); }
.badge-root { background: var(--root); }
.badge-none { background: var(--none); }

.node-card textarea {
  width: 100%; border: none; resize: none; font: inherit; background: transparent;
  color: inherit; outline: none; overflow: hidden; line-height: 1.4; padding: 2px 0;
}
.node-card.incident textarea::placeholder { color:#cbd5e1; }
.node-card select { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.node-card .nc-actions { display: flex; gap: 6px; margin-left: auto; }
.children { margin-left: 26px; border-left: 2px dashed var(--line); padding-left: 12px; }
.node-collapsed > .children { display: none; }
.twist { cursor: pointer; width: 18px; text-align:center; user-select:none; color: var(--muted); }
.node-card.incident .twist { color:#94a3b8; }

/* ---- diagram ---- */
#diagram-wrap { width: 100%; height: 100%; }
#diagram { width: 100%; height: auto; display:block; }
.legend { display:flex; gap:16px; flex-wrap:wrap; margin-bottom:10px; align-items:center; }
.legend .lg { display:flex; align-items:center; gap:6px; font-size:13px; }
.legend .sw { width:14px; height:14px; border-radius:3px; }
.empty-hint { color: var(--muted); padding: 40px; text-align:center; }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50;
}
#toast.show { opacity: .95; }

.dirty-dot { color: #f59e0b; font-size: 20px; line-height: 0; }
