/* ============================================================
   UML Studio — style tokens
   Surface: Command / Inspect (editor + inspector)
   ============================================================ */
:root {
  --bg: #0a0c12;
  --panel: #0e121b;
  --panel-2: #121722;
  --line: #1e2635;
  --line-soft: #18202c;
  --ink: #e8edf7;
  --ink-dim: #98a4b8;
  --ink-mute: #66748c;
  --accent: #4f8cff;
  --accent-soft: #1b2c4d;
  --warn: #e0a13a;
  --danger: #e2574c;
  --ok: #33b27b;
  --canvas: #0a0c12;
  --grid: #151b26;
  --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --topbar-h: 46px;
  --status-h: 30px;
}
html[data-theme="light"] {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f2f4f8;
  --line: #dde2ea;
  --line-soft: #e8ecf2;
  --ink: #14202e;
  --ink-dim: #5a6779;
  --ink-mute: #8b97a8;
  --accent: #2f6fdd;
  --accent-soft: #e4edff;
  --canvas: #f6f7f9;
  --grid: #e4e8ef;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.4;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { background: var(--accent-soft); border-color: var(--accent); }
button:active { transform: translateY(1px); }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
button:disabled { opacity: .4; cursor: default; }
.mini { padding: 3px 8px; font-size: 12px; border-radius: 5px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.08); background: var(--accent); }

#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- topbar ---------- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; letter-spacing: .2px; }
.brand .logo { color: var(--accent); font-size: 16px; }
.brand .ver { font-size: 10px; color: var(--ink-mute); font-weight: 400; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.doc-name {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  width: 200px;
  font-weight: 500;
}
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--accent); background: var(--panel-2); }
.tb-group { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }

/* ---------- workspace ---------- */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.panel.left { width: 210px; flex: 0 0 auto; border-right: 1px solid var(--line); }
.panel.right { width: 336px; flex: 0 0 auto; border-left: 1px solid var(--line); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px 7px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--ink-mute); font-weight: 600;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head .hint { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11px; }

/* palette */
.palette { padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; overflow-y: auto; }
.pal-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 8px 4px 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  cursor: grab; text-align: center; color: var(--ink-dim);
}
.pal-item:hover { border-color: var(--accent); color: var(--ink); }
.pal-item svg { display: block; }
.pal-item span { font-size: 10.5px; white-space: nowrap; }

.doc-list { flex: 1 1 auto; overflow-y: auto; padding: 6px 8px 12px; }
.doc-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--ink-dim);
  border: 1px solid transparent;
}
.doc-item:hover { background: var(--panel-2); color: var(--ink); }
.doc-item.active { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.doc-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .del { opacity: 0; color: var(--ink-mute); padding: 0 3px; }
.doc-item:hover .del { opacity: 1; }
.doc-item .del:hover { color: var(--danger); background: transparent; border-color: transparent; }

/* ---------- stage / canvas ---------- */
.stage { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; position: relative; }
.canvas {
  flex: 1 1 auto; position: relative; overflow: hidden;
  background-color: var(--canvas);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: default;
  touch-action: none;
}
.canvas.no-grid { background-image: none; }
.canvas.panning { cursor: grabbing; }
.scene { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; width: 1px; height: 1px; pointer-events: none; }
.edges .edge-hit { pointer-events: stroke; cursor: pointer; }
.nodes { position: absolute; left: 0; top: 0; }

/* node */
.node {
  position: absolute;
  display: flex;
  cursor: move;
  user-select: none;
}
.node .shape { position: absolute; inset: 0; overflow: visible; }
.node .label {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  pointer-events: none;
}
.node[data-type="class"] .label { display: none; }
.node .cls { position: relative; flex: 1; display: flex; flex-direction: column; font-size: 12.5px; overflow: hidden; border-radius: 8px; }
.node .cls-head { padding: 7px 10px; font-weight: 600; text-align: center; border-bottom: 1px solid var(--cls-line); background: var(--cls-head-bg); }
.node .cls-sec { padding: 5px 10px; text-align: left; line-height: 1.5; font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; min-height: 14px; }
.node .cls-sec + .cls-sec { border-top: 1px solid var(--cls-line); }
.node[data-type="actor"] .label { align-items: flex-end; justify-content: center; padding-bottom: 3px; }
.node[data-type="text"] .label { justify-content: flex-start; text-align: left; }

.node.selected .shape { filter: drop-shadow(0 0 0 transparent); }
.node .sel-ring { position: absolute; inset: -4px; border: 1.5px solid var(--accent); border-radius: 8px; pointer-events: none; display: none; }
.node.selected .sel-ring { display: block; }
.node.hover .sel-ring { display: block; border-color: var(--accent); opacity: .45; }
.node.selected.hover .sel-ring { opacity: 1; }
.node .handle {
  position: absolute; width: 9px; height: 9px; right: -6px; bottom: -6px;
  background: var(--accent); border: 1.5px solid var(--panel); border-radius: 2px;
  cursor: nwse-resize; display: none;
}
.node.selected .handle { display: block; }
.node .port {
  position: absolute; width: 9px; height: 9px; border-radius: 50%;
  background: var(--panel); border: 1.5px solid var(--accent);
  opacity: 0; transition: opacity .1s; cursor: crosshair;
  pointer-events: none;
}
.node.selected .port, .node.hover .port { opacity: 1; pointer-events: auto; }
.node .port[data-side="n"] { left: 50%; top: -5px; margin-left: -4.5px; }
.node .port[data-side="s"] { left: 50%; bottom: -5px; margin-left: -4.5px; }
.node .port[data-side="w"] { left: -5px; top: 50%; margin-top: -4.5px; }
.node .port[data-side="e"] { right: -5px; top: 50%; margin-top: -4.5px; }

/* edges */
.edge .line { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.edge .edge-hit { stroke: transparent; stroke-width: 14; fill: none; }
.edge.selected .line { stroke: var(--accent) !important; }
.edge .elabel {
  font-size: 12.5px; fill: var(--ink-dim);
  paint-order: stroke; stroke: var(--canvas); stroke-width: 5px; stroke-linejoin: round;
  pointer-events: none; text-anchor: middle;
  font-family: var(--font);
}
.edge.selected .elabel { fill: var(--accent); }
.edge-temp { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 5 4; }

/* overlay bits */
.marquee {
  position: absolute; border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  pointer-events: none; z-index: 8;
}
.guides { position: absolute; inset: 0; pointer-events: none; z-index: 7; overflow: hidden; }
.guides .g { position: absolute; background: var(--accent); opacity: .55; }
.inline-edit {
  position: absolute; z-index: 12; resize: none; overflow: hidden;
  border: 1.5px solid var(--accent); border-radius: 6px;
  background: var(--panel); color: var(--ink);
  padding: 4px 6px; text-align: center; line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  outline: none;
}

/* statusbar */
.statusbar {
  height: var(--status-h); flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; gap: 10px;
  background: var(--panel); border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-dim);
}
.status-left, .status-right { display: flex; align-items: center; gap: 10px; }
.statusbar .dim { color: var(--ink-mute); }
.statusbar .warn { color: var(--warn); }
.statusbar .err { color: var(--danger); }
.zoom-val { min-width: 52px; font-variant-numeric: tabular-nums; }
.chk { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-dim); cursor: pointer; font-size: 11.5px; }
.chk input { accent-color: var(--accent); margin: 0; }

/* ---------- right panel ---------- */
.tabs { display: flex; flex: 0 0 auto; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: transparent; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 6px; color: var(--ink-mute); font-size: 12px;
}
.tab:hover { background: var(--panel-2); color: var(--ink); border-color: transparent; border-bottom-color: var(--line); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); background: transparent; }
.tabbody { flex: 1 1 auto; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; }
.pane.active { display: flex; }
.pane-bar { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }

.inspector { flex: 1 1 auto; overflow-y: auto; padding: 10px; }
.inspector .empty { color: var(--ink-mute); font-size: 12px; line-height: 1.6; }
.insp-sec { margin-bottom: 14px; }
.insp-sec > h4 {
  margin: 0 0 7px; font-size: 10.5px; letter-spacing: .7px; text-transform: uppercase;
  color: var(--ink-mute); font-weight: 600;
}
.field { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.field > label { flex: 0 0 62px; color: var(--ink-dim); font-size: 12px; }
.field > input[type="text"], .field > input[type="number"], .field > select, .field > textarea {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 7px; outline: none;
}
.field > input:focus, .field > select:focus, .field > textarea:focus { border-color: var(--accent); }
.field > input[type="color"] {
  flex: 0 0 34px; height: 26px; padding: 1px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 5px;
}
.field > input[type="range"] { flex: 1; accent-color: var(--accent); }
.field textarea { min-height: 58px; resize: vertical; font-family: var(--mono); font-size: 11.5px; }
.field .val { color: var(--ink-mute); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.code {
  flex: 1 1 auto; min-height: 120px; width: 100%; resize: none;
  background: var(--panel); border: none; border-top: 1px solid var(--line-soft);
  padding: 9px 10px; outline: none;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  tab-size: 2; white-space: pre; overflow: auto;
  color: var(--ink);
}
.errors {
  flex: 0 0 auto; max-height: 34%; overflow-y: auto;
  border-top: 1px solid var(--line-soft); padding: 6px 10px; font-size: 11.5px;
  font-family: var(--mono); color: var(--ink-mute); background: var(--panel-2);
}
.errors:empty { display: none; }
.errors .e { padding: 2px 0; color: var(--danger); }
.errors .e .loc { color: var(--ink-mute); margin-right: 6px; }
.errors .ok { color: var(--ok); }

/* ---------- modal ---------- */
[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3, 5, 10, .62);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(2px);
}
.modal-card {
  width: min(760px, 100%); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal-card > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.modal-body { padding: 14px; overflow-y: auto; font-size: 12.5px; line-height: 1.65; color: var(--ink-dim); }
.modal-body h3 { color: var(--ink); font-size: 13px; margin: 16px 0 6px; }
.modal-body h3:first-child { margin-top: 0; }
.modal-body code { font-family: var(--mono); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--ink); font-size: 11.5px; }
.modal-body pre {
  background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 6px;
  padding: 10px; overflow-x: auto; font-family: var(--mono); font-size: 11.5px; line-height: 1.55;
  color: var(--ink);
}
.modal-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.modal-body th, .modal-body td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line-soft); }
.modal-body th { color: var(--ink-mute); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.modal-body kbd {
  font-family: var(--mono); font-size: 11px; background: var(--panel-2);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--ink);
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-mute); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .panel.left { width: 168px; }
  .panel.right { width: 290px; }
  .doc-name { width: 130px; }
}
