:root {
  --bg: #fff;
  --side: #f5f5f7;
  --bar: #f6f6f6;
  --line: #d9d9de;
  --ink: #1d1d1f;
  --dim: #6e6e73;
  --accent: #0a7aff;
  --sel: rgba(10, 122, 255, .12);
  --canvas: #e8e8ea;
  --field: #fff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1e; --side: #252526; --bar: #2b2b2d; --line: #3a3a3c;
    --ink: #f2f2f7; --dim: #98989d; --accent: #3b8eff; --sel: rgba(59, 142, 255, .22);
    --canvas: #161617; --field: #1c1c1e;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--field); border-radius: 6px;
  padding: 3px 10px; cursor: default; white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--side); }
button:disabled { opacity: .4; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.on { background: var(--sel); border-color: var(--accent); color: var(--accent); }
button.plain { border: 0; background: none; padding: 3px 6px; }
input[type=text], input[type=number], input[type=password], input[type=date], textarea, select {
  border: 1px solid var(--line); border-radius: 5px; background: var(--field); padding: 3px 6px;
  outline: none; min-width: 0;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--sel); }

/* toolbar */
.bar {
  height: 44px; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: var(--bar); border-bottom: 1px solid var(--line); flex: none;
}
.bar .title { font-weight: 600; font-size: 14px; }
.bar .spacer { flex: 1; }
.bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.bar input.name { font-weight: 600; font-size: 14px; border-color: transparent; background: none; width: 260px; }
.bar input.name:hover { border-color: var(--line); }
.bar input[type=date] { border-color: transparent; background: none; color: var(--dim); }
.bar input[type=date]:hover { border-color: var(--line); }
.bar .status { color: var(--dim); min-width: 56px; text-align: right; }
.bar .zoom { min-width: 44px; text-align: center; color: var(--dim); font-variant-numeric: tabular-nums; }
.bar .back { font-size: 18px; line-height: 1; padding: 2px 8px; }

/* home */
.page { display: flex; flex-direction: column; height: 100%; }
.home { flex: 1; overflow: auto; padding: 24px; }
.home table { border-collapse: collapse; width: 100%; max-width: 820px; margin: 0 auto; }
.home td, .home th { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.home th { font-weight: 500; color: var(--dim); font-size: 12px; }
.home tr.row:hover { background: var(--side); }
.home tr.row { cursor: default; }
.home td.n { font-variant-numeric: tabular-nums; color: var(--dim); }
.home td.x { width: 1%; text-align: right; }
.home td.x button { visibility: hidden; }
.home tr.row:hover td.x button { visibility: visible; }
.empty { color: var(--dim); text-align: center; margin-top: 80px; }

/* sign in */
.signin { height: 100%; display: grid; place-items: center; }
.signin form { display: flex; flex-direction: column; gap: 10px; width: 240px; }
.signin h1 { font-size: 15px; margin: 0 0 4px; text-align: center; }
.signin .err { color: #d70015; min-height: 18px; text-align: center; }

/* editor */
.editor { display: grid; grid-template-rows: 44px 1fr; grid-template-columns: 228px 1fr 248px; height: 100%; }
.editor > .bar { grid-column: 1 / -1; }
.editor.ro { grid-template-columns: 200px 1fr 248px; }
.left, .right { background: var(--side); overflow: auto; min-height: 0; }
.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.right { border-left: 1px solid var(--line); padding: 12px; }
h2 { font-size: 11px; font-weight: 600; color: var(--dim); margin: 14px 0 6px; letter-spacing: .02em; }
.right h2:first-child { margin-top: 2px; }

.acts { padding: 8px 8px 6px; border-bottom: 1px solid var(--line); flex: none; }
.acts h2 { margin: 4px 4px 6px; }
.acts ol { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; }
.acts li { display: flex; gap: 8px; align-items: center; padding: 4px 8px; border-radius: 6px; user-select: none; }
.acts li .num { color: var(--dim); width: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.acts li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acts li.on { background: var(--accent); color: #fff; }
.acts li.on .num { color: rgba(255,255,255,.75); }
.acts li.drop { box-shadow: inset 0 2px 0 var(--accent); }
.acts li input { flex: 1; padding: 0 4px; }
.acts .foot { display: flex; gap: 4px; margin-top: 6px; }
.acts .foot button { padding: 1px 9px; }

.lib { padding: 4px 8px 16px; overflow: auto; flex: 1; }
.lib h2 { margin: 12px 4px 4px; }
.lib .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.lib .item {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px;
  border-radius: 6px; user-select: none; touch-action: none; text-align: center; font-size: 11px; color: var(--dim);
}
.lib .item:hover { background: var(--bg); color: var(--ink); }
.lib .item svg { width: 40px; height: 34px; }

.canvas { position: relative; overflow: hidden; background: var(--canvas); min-width: 0; min-height: 0; }
.canvas svg.cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; display: block; }
.canvas .float { position: fixed; pointer-events: none; width: 48px; height: 48px; opacity: .8; z-index: 20; }

/* drawing */
svg * { vector-effect: non-scaling-stroke; }
.sym .s, .cv .s, .pv .s { fill: #fff; stroke: #1d1d1f; stroke-width: 1; }
.n { fill: none; stroke: #1d1d1f; stroke-width: 1; }
.d { fill: none; stroke: #1d1d1f; stroke-width: 1; stroke-dasharray: 3 2; }
.f { fill: #1d1d1f; stroke: none; }
.g { fill: #ececee; stroke: #1d1d1f; stroke-width: 1; }
.a { fill: none; stroke: #1d1d1f; stroke-width: 1.2; stroke-dasharray: 7 4; }
.hd { stroke-width: 2.6; }
.tt { fill: #1d1d1f; font-weight: 600; text-anchor: middle; dominant-baseline: central; font-family: -apple-system, system-ui, sans-serif; }
.tx { fill: #1d1d1f; font-weight: 500; text-anchor: middle; dominant-baseline: central; font-family: -apple-system, system-ui, sans-serif; }
.lb { fill: #1d1d1f; font-weight: 600; text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; font-family: -apple-system, system-ui, sans-serif; pointer-events: none; }
.hit { fill: transparent; stroke: none; }
.lib .sym .s { fill: var(--bg); stroke: var(--ink); }
.lib .sym .n, .lib .sym .d, .lib .sym .a { stroke: var(--ink); }
.lib .sym .f, .lib .sym .tt, .lib .sym .tx { fill: var(--ink); }
.lib .sym .g { fill: var(--side); stroke: var(--ink); }

.floor { fill: #fff; stroke: none; }
.edge { fill: none; stroke: #1d1d1f; stroke-width: 2; stroke-linejoin: round; }
.grid line { stroke: #e4e4e8; stroke-width: 1; }
.cl { stroke: #c9c9ce; stroke-width: 1; stroke-dasharray: 8 5; }
.stp { fill: #fff; stroke: #1d1d1f; stroke-width: 1; }
.dim { stroke: #6e6e73; stroke-width: 1; fill: none; }
.dimt { fill: #6e6e73; text-anchor: middle; dominant-baseline: central; font-family: -apple-system, system-ui, sans-serif; }
.aud { fill: none; stroke: #b4b4b9; stroke-width: 1; }
.audt { fill: #9a9aa0; text-anchor: middle; dominant-baseline: central; font-family: -apple-system, system-ui, sans-serif; letter-spacing: .1em; }
@media (prefers-color-scheme: dark) {
  .aud { stroke: #555; } .audt, .dimt { fill: #8e8e93; } .dim { stroke: #8e8e93; }
}
.it { cursor: move; }
.ro .it { cursor: default; }
.selbox { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.selbb { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; }
.hnd { fill: #fff; stroke: var(--accent); stroke-width: 1.5; }
.hnd.rot { cursor: grab; }
.hnd.res { cursor: nwse-resize; }
.ghost { opacity: .55; pointer-events: none; }
.marq { fill: var(--sel); stroke: var(--accent); stroke-width: 1; }

/* inspector */
.right label.row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; margin: 6px 0; }
.right label.row > span { color: var(--dim); text-align: right; }
.right .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.right input, .right textarea, .right select { width: 100%; }
.right textarea { resize: vertical; min-height: 72px; }
.right .btns { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.right .ttl { font-weight: 600; font-size: 13px; }
.right .notes { white-space: pre-wrap; }
table.ct { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.ct td { padding: 2px 0; }
table.ct td:last-child { text-align: right; width: 36px; }
table.ct td.plus { color: #248a3d; }
table.ct td.minus { color: #d70015; }
.muted { color: var(--dim); }

/* menus, dialogs, toast */
.menu {
  position: fixed; z-index: 40; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 4px; min-width: 170px;
}
.menu div { padding: 4px 10px; border-radius: 5px; display: flex; justify-content: space-between; gap: 16px; }
.menu div:hover { background: var(--accent); color: #fff; }
.menu div kbd { font: inherit; opacity: .6; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; background: var(--bg); color: var(--ink);
  box-shadow: 0 14px 48px rgba(0,0,0,.25); width: 320px;
}
dialog::backdrop { background: rgba(0,0,0,.18); }
dialog h3 { margin: 0 0 12px; font-size: 13px; }
dialog label.row { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 10px; margin: 7px 0; }
dialog label.row input[type=checkbox] { justify-self: start; }
dialog .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .btns .l { margin-right: auto; }
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #1d1d1f; color: #fff;
  padding: 7px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
}
#toast.show { opacity: .92; }

/* print */
#print { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  #app, #toast { display: none !important; }
  #print { display: block; color: #000; }
  .pp { page-break-after: always; break-after: page; height: 188mm; display: flex; flex-direction: column; }
  .pp:last-child { page-break-after: auto; break-after: auto; }
  .pp header { display: flex; align-items: baseline; gap: 14px; border-bottom: 1px solid #000; padding-bottom: 4px; }
  .pp h1 { font-size: 16pt; margin: 0; }
  .pp header .ev { margin-left: auto; color: #555; font-size: 10pt; }
  .pp .body { flex: 1; display: grid; grid-template-columns: 1fr 52mm; gap: 6mm; min-height: 0; padding-top: 4mm; }
  .pp svg { width: 100%; height: 100%; }
  .pp .side { font-size: 9.5pt; }
  .pp .side h2 { color: #000; font-size: 9pt; margin: 8px 0 3px; text-transform: uppercase; letter-spacing: .06em; }
  .pp table.ct td.plus, .pp table.ct td.minus { color: #000; }
}
