:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #152d40;
  background: #eaf0f3;
  --line: #d8e2e8;
  --muted: #516577;
  --accent: #0c6195;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible, select:focus-visible, .drawing-surface:focus-visible {
  outline: 2px solid #1679ba;
  outline-offset: 2px;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: .8rem;
  padding: .85rem clamp(.8rem, 3vw, 2rem); flex-wrap: wrap;
}
.topbar-start, .brand, .history-actions, .export-actions, .drawing-header, .drawing-footer, .branch-bar, .branch-controls, .branches, .position-actions {
  display: flex; align-items: center; gap: .65rem;
}
.export-actions { flex-wrap: wrap; }
.brand { flex-wrap: wrap; }
.history-actions { gap: .3rem; }
h1 { font-size: 1rem; font-weight: 650; }
h2 { font-size: .98rem; margin-bottom: .65rem; }
.control, .primary, .secondary {
  border: 1px solid #b8cbd6; border-radius: .38rem; background: #fff;
  padding: .52rem .68rem; min-height: 2.2rem; font-size: .86rem; font-weight: 650;
}
.control:hover:not(:disabled) { background: #eaf5fb; }
.primary { background: #aee6fb; border-color: #aee6fb; color: #103044; }
.primary:hover:not(:disabled) { background: #dbf5ff; }
.secondary { background: transparent; border-color: #7e9aab; color: white; }
.secondary:hover:not(:disabled) { background: #23465e; }
.workspace {
  display: grid; grid-template-columns: minmax(12rem, 15rem) minmax(0, 1fr) minmax(12rem, 15rem);
  align-items: start; gap: .7rem; padding: .7rem; max-width: 112rem; margin: auto;
}
.panel { background: #fff; border: 1px solid var(--line); border-radius: .55rem; min-width: 0; }
.library, .properties { padding: .85rem; }
.catalog { display: grid; gap: .35rem; max-height: min(64vh, 43rem); overflow: auto; padding: .15rem; }
#catalog-empty { color: var(--muted); font-size: .88rem; padding-block: .45rem; }
.component {
  --catalog-icon-size: 2.75rem;
  display: grid; grid-template-columns: var(--catalog-icon-size) minmax(0, 1fr); align-items: center; gap: .55rem;
  width: 100%; text-align: left; border: 1px solid var(--line); border-radius: .4rem;
  background: white; padding: .35rem .45rem;
}
.component:hover:not(:disabled) { border-color: #78a8c0; background: #f0f8fc; }
.component strong { display: block; font-size: .85rem; overflow-wrap: anywhere; }
.component small { color: var(--muted); font-size: .72rem; }
.component :is(canvas, .symbol-fallback) { width: var(--catalog-icon-size); height: var(--catalog-icon-size); }
.symbol-fallback { display: grid; place-items: center; font-weight: 750; }
.drawing-header { justify-content: space-between; padding: .65rem .85rem; }
.drawing-header h2 { margin: 0; }
.snap-controls { display: flex; flex-wrap: wrap; gap: .55rem .85rem; }
label.snap, label.toggle { display: flex; align-items: center; gap: .4rem; margin: 0; }
.snap input, .toggle input { accent-color: var(--accent); }
.branch-bar { justify-content: space-between; padding: .42rem .65rem; border-top: 1px solid var(--line); background: #f7fafb; }
.branch-controls { min-width: 0; gap: .35rem; }
.branches { min-width: 0; overflow: auto; padding: .2rem; }
.branch-bar button { flex: none; }
#link-clones[aria-pressed="true"] { background: #e6f1f7; border-color: var(--accent); }
.branch-tab {
  flex: none; white-space: nowrap; max-width: min(13rem, 100%); overflow: hidden; text-overflow: ellipsis;
  border: 1px solid transparent; border-left: 3px solid var(--branch-color);
  border-radius: .32rem; background: #fff; padding: .46rem .65rem; font-size: .85rem;
}
.branch-tab[aria-pressed="true"] { background: #e6f1f7; border-color: var(--branch-color); font-weight: 700; }
.drawing-viewport { position: relative; height: clamp(24rem, 65vh, 50rem); border-block: 1px solid var(--line); }
.drawing-surface {
  position: relative; width: 100%; height: 100%; overflow: clip;
  background: #f5fafc radial-gradient(circle at 1px 1px, #9db5c3 1px, transparent 1px);
  background-size: var(--grid-spacing) var(--grid-spacing);
  background-position: var(--grid-x) var(--grid-y);
  cursor: crosshair; touch-action: none; user-select: none;
}
.drawing-surface:focus-visible { outline-offset: -2px; }
.drawing-world { position: absolute; inset: 0; transform-origin: 0 0; pointer-events: none; }
.drawing-surface.placing, .drawing-surface.placing button, .drawing-surface.linking-clones button { cursor: crosshair; }
.drawing-surface.panning, .drawing-surface.panning button { cursor: grabbing; }
#selection-window { position: absolute; z-index: 4; pointer-events: none; border: 1px solid #1579ba; background: #1687d329; }
#selection-window.crossing { border: 1px dashed #25823b; background: #38b3542b; }
.empty { position: absolute; top: 1.3rem; left: 1.35rem; max-width: min(90%, 23rem); color: var(--muted); font-size: .9rem; pointer-events: none; }
.zoom-controls {
  position: absolute; z-index: 6; right: .65rem; bottom: .65rem;
  display: flex; gap: .2rem; padding: .2rem; border: 1px solid var(--line);
  border-radius: .45rem; background: #f5fafc; box-shadow: 0 2px 6px #152d401a;
}
.zoom-controls button { min-width: 2rem; min-height: 2rem; padding: .32rem .45rem; }
#reset-view { min-width: 4.4rem; font-variant-numeric: tabular-nums; }
.drawing-item {
  position: absolute; transform: translate(-50%, -50%);
  display: grid; place-items: center; padding: 0; width: var(--symbol-size); height: var(--symbol-size);
  border: 1px solid var(--branch-color); border-radius: .35rem; background: #ffffffed;
  pointer-events: auto;
}
.drawing-item:hover, .drawing-item[aria-pressed="true"] { z-index: 1; box-shadow: inset 0 0 0 1px var(--branch-color); }
.drawing-item[aria-pressed="true"] { z-index: 2; }
.drawing-item.clone-pick { outline: 2px dashed var(--accent); outline-offset: 2px; z-index: 3; }
.drawing-item.clone-pick-main { outline-style: solid; }
.clone-label {
  position: absolute; top: 0; right: 0; padding: 0 .2rem; background: #e6f1f7; color: #103044;
  font-size: .55rem; font-weight: 700; pointer-events: none;
}
.drawing-item :is(canvas, .symbol-fallback) { width: calc(var(--symbol-size) - 2px); height: calc(var(--symbol-size) - 2px); pointer-events: none; }
.drawing-label {
  position: absolute; top: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  max-width: 9rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: .7rem; background: #f5fafce8; padding: 0 .18rem; pointer-events: none;
}
.drawing-item.label-right .drawing-label { top: 50%; left: calc(100% + 3px); transform: translateY(-50%); }
.drawing-item.pipe { width: auto; height: auto; border: 0; background: transparent; }
.drawing-item.pipe .pipe-geometry { width: auto; height: auto; }
.drawing-item.pipe:hover, .drawing-item.pipe[aria-pressed="true"] { box-shadow: none; }
.drawing-item.pipe:hover canvas, .drawing-item.pipe[aria-pressed="true"] canvas { filter: drop-shadow(0 0 2px var(--branch-color)); }
.connector-lead {
  position: absolute; border-top: 1px solid var(--branch-color); transform-origin: 0 50%;
  pointer-events: none;
}
.connector-lead.connection-pipe { border-top-width: 3px; }
.connector, #snap-indicator {
  position: absolute; display: block; pointer-events: none;
  border: 1px solid var(--branch-color); border-radius: 50%; transform: translate(-50%, -50%);
}
.connector { width: 7px; height: 7px; left: var(--port-x); top: var(--port-y); opacity: 0; background: white; }
.connector.centered { left: calc(50% + var(--port-x)); top: calc(50% + var(--port-y)); }
.placing .connector, .drawing-item:hover .connector, .drawing-item[aria-pressed="true"] .connector { opacity: 1; }
#snap-indicator { z-index: 5; width: 15px; height: 15px; border: 2px solid #077845; background: #43d69f4d; }
.color-field { display: flex; align-items: center; gap: .45rem; }
#branch-swatch { width: 1rem; height: 1rem; border: 1px solid #889ba8; border-radius: .2rem; flex: none; }
.drawing-footer { flex-wrap: wrap; min-height: 2.9rem; padding: .45rem .75rem; font-size: .8rem; color: var(--muted); }
#status:not(:empty) { flex: 1; color: #1c4b6a; }
label { display: grid; gap: .25rem; margin: .55rem 0; font-size: .84rem; }
input:not([type="checkbox"]), select {
  width: 100%; min-height: 2rem; padding: .3rem .42rem; border: 1px solid #b8cbd6;
  border-radius: .3rem; background: #fff;
}
.coordinates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.selection { border-top: 1px solid var(--line); margin-top: .9rem; padding-top: .8rem; }
.technical-name-field { position: relative; }
.technical-name-results {
  position: absolute; z-index: 3; top: calc(100% + .15rem); inset-inline: 0; max-height: 14rem;
  overflow: auto; border: 1px solid var(--line); border-radius: .3rem; background: #fff;
  box-shadow: 0 4px 12px #152d4026;
}
.technical-name-option {
  display: block; width: 100%; padding: .4rem .5rem; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; font-size: .8rem; overflow-wrap: anywhere;
}
.technical-name-option:last-child { border-bottom: 0; }
.technical-name-option:hover, .technical-name-option:focus { background: #e6f1f7; }
.technical-name-option:focus-visible { outline-offset: -2px; }
.position-actions { margin-top: .65rem; flex-wrap: wrap; }
.danger { color: #973734; }
.danger:hover:not(:disabled) { background: #fff1f0; }
fieldset { margin: .7rem 0 0; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: .35rem; }
legend { font-size: .83rem; padding: 0 .25rem; }
@media (max-width: 65rem) {
  .workspace { grid-template-columns: 12rem minmax(0, 1fr); }
  .properties { grid-column: 2; }
}
@media (max-width: 40rem) {
  .workspace { display: flex; flex-direction: column; }
  .panel { width: 100%; }
  .topbar { align-items: start; }
  .topbar-start { flex-direction: column; align-items: start; }
  .export-actions { flex-wrap: wrap; justify-content: flex-end; }
  .library label { display: inline-grid; width: calc(50% - .3rem); }
  .catalog { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 9rem; }
  .drawing-viewport { height: 20rem; }
}
