:root {
  --domi: #b3261e; --domi-bg: #fdecea;
  --elezi: #1f4e9c; --elezi-bg: #e8eefa;
  --mix: #6d3fb0; --mix-bg: #f1eafa;
  --spouse: #8a8a8a;
  --loose: #9a9a9a; --loose-bg: #f4f4f4;
  --ink: #1d1d1f; --muted: #6b6b70; --line: #e3e3e6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); background: #fafafa; }

.bar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 5;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 19px; color: var(--domi); white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 340px; }
.search input { width: 100%; padding: 8px 64px 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.search span { position: absolute; right: 10px; top: 9px; font-size: 12px; color: var(--muted); }
.tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.tools .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
button {
  white-space: nowrap;
  font: inherit; font-size: 13px; padding: 7px 11px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
button:hover { background: #f3f3f5; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--domi); border-color: var(--domi); color: #fff; }
button.primary.on { background: #fff; color: var(--domi); }
button.danger { color: var(--domi); border-color: #f0c4c0; }
.status { font-size: 12px; color: var(--muted); min-width: 70px; text-align: right; }
.status.err { color: var(--domi); font-weight: 600; }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 40px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; display: grid; min-width: 220px;
}
.menu-list[hidden] { display: none; }
.menu-list button { border: 0; text-align: left; }

body:not(.editing) .edit-only { display: none !important; }

#stage { position: fixed; inset: 56px 0 34px 0; }
#svg { width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#svg.dragging { cursor: grabbing; }
#svg .node { cursor: pointer; }
#svg .node:hover rect { filter: brightness(.97); }
#svg .sel rect { stroke-width: 3.5; }
#svg .hit rect { stroke: #f2a900 !important; stroke-width: 3.5; }
#hint { position: absolute; left: 12px; bottom: 8px; font-size: 12px; color: var(--muted); pointer-events: none; }

#panel {
  position: fixed; right: 12px; top: 68px; width: 310px; z-index: 6;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 14px; display: grid; gap: 10px;
  max-height: calc(100% - 120px); overflow: auto;
}
#panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head button { border: 0; padding: 4px 8px; }
#panel label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
#panel label.check { display: flex; align-items: center; gap: 6px; }
#panel input[type=text] { font: inherit; font-size: 14px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
#panel input[type=text]:disabled { background: #fafafa; border-color: transparent; padding-left: 0; font-weight: 600; }
.info { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.info:empty { display: none; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.actions .full { grid-column: 1 / -1; }
.actions select { font: inherit; font-size: 13px; padding: 6px; border-radius: 8px; border: 1px solid var(--line); }

.legend {
  position: fixed; inset: auto 0 0 0; height: 34px; display: flex; gap: 18px; align-items: center;
  padding: 0 14px; font-size: 12px; color: var(--muted); background: #fff; border-top: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap;
}
.sw { display: inline-block; width: 18px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1.5px solid; }
.sw.domi { border-color: var(--domi); background: var(--domi-bg); }
.sw.elezi { border-color: var(--elezi); background: var(--elezi-bg); }
.sw.mix { border-color: var(--mix); background: var(--mix-bg); }
.sw.spouse { border-color: var(--spouse); background: #fff; }
.sw.loose { border-color: var(--loose); background: var(--loose-bg); border-style: dashed; }

@media (max-width: 760px) {
  .bar { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .bar h1 { font-size: 16px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  #zoomIn, #zoomOut, .tools .sep { display: none; }
  .tools { gap: 4px; }
  button { padding: 7px 9px; }
  #hint { display: none; }
  #panel { left: 8px; right: 8px; top: auto; bottom: 42px; width: auto; max-height: 55%; }
  .status { position: absolute; right: 10px; bottom: -18px; }
}

@media print {
  @page { size: A3 landscape; margin: 8mm; }
  .bar, #panel, #hint { display: none !important; }
  html, body { overflow: visible; background: #fff; }
  #stage { position: static; }
  #svg { width: 100%; height: 92vh; }
  .legend { position: static; border: 0; }
}
