/* Structure Editor — clean default styling. Not polished. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e4e4e1;
  --border-strong: #cfcfcb;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #2c5aa0;
  --accent-soft: #e6eef8;
  --selected: #fff7cc;
  --selected-stroke: #b89200;
  --unit-fill: #ffffff;
  --unit-stroke: #333;
  --edge: #333;
  --warning: #a15c00;
  --error: #b00020;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

/* --- Toolbar --- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.toolbar-title {
  flex: 0 0 auto;
  justify-content: center;
}

.toolbar-status {
  min-width: 160px;
  justify-content: flex-end;
}

.toolbar-org {
  flex: 1 1 auto;
  min-width: 320px;
}

.tool-btn {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
}

.tool-btn:hover { background: var(--accent-soft); }
.tool-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.model-name {
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  text-align: center;
  min-width: 240px;
  color: var(--text);
}

.chart-filter,
.graph-search {
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 0 8px;
}

.chart-filter {
  max-width: 190px;
}

.graph-search {
  min-width: 180px;
  flex: 1 1 220px;
}

.zoom-btn {
  width: 30px;
  padding: 6px 0;
  font-weight: 650;
}

.zoom-level {
  min-width: 44px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-muted);
  text-align: center;
}

.model-name:hover { border-color: var(--border); }
.model-name:focus { border-color: var(--accent); outline: none; background: var(--surface); }

.status {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}
.status.warning { color: var(--warning); }
.status.error { color: var(--error); }

/* --- Main layout --- */

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
}

.canvas-region {
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

#canvas.panning { cursor: grabbing; }
#canvas.placing { cursor: crosshair; }

/* --- Units ---
   TUG symbology:
     Unit / Thing (Object) → circle with a horizontal line beneath it, name below
     Actor                 → per-actor figure selection, name below
*/

.unit { cursor: pointer; }

.class-hit, .actor-hit {
  fill: transparent;
  stroke: none;
}

/* Class "Object" glyph — circle + underline */
.class-circle {
  fill: var(--unit-fill);
  stroke: var(--unit-stroke);
  stroke-width: 2;
}

.class-underline {
  stroke: var(--unit-stroke);
  stroke-width: 2;
  stroke-linecap: butt;
}

.unit.selected .class-circle {
  fill: var(--selected);
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
}

.unit.selected .class-underline {
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
}

.unit.place-target .class-circle,
.unit.place-target .class-underline {
  stroke: var(--accent);
  stroke-dasharray: 4 2;
}

/* Actor glyph — simple */
.actor-ellipse {
  fill: var(--unit-fill);
  stroke: var(--unit-stroke);
  stroke-width: 2.2;
}

.actor-line {
  stroke: var(--unit-stroke);
  stroke-width: 2.2;
  stroke-linecap: butt;
  fill: none;
}

.unit.selected .actor-ellipse {
  fill: var(--selected);
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
}

.unit.selected .actor-line {
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
}

.unit.place-target .actor-ellipse,
.unit.place-target .actor-line {
  stroke: var(--accent);
  stroke-dasharray: 4 2;
}

/* Actor glyph — Calendar people */
.actor-head,
.actor-body {
  fill: var(--unit-fill);
  stroke: var(--unit-stroke);
  stroke-width: 2.2;
}

.actor-center {
  stroke: var(--unit-stroke);
  stroke-width: 1.7;
  stroke-linecap: round;
  fill: none;
}

.actor-body {
  stroke-linejoin: round;
}

.unit.selected .actor-head,
.unit.selected .actor-body {
  fill: var(--selected);
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
}

.unit.selected .actor-center {
  stroke: var(--selected-stroke);
  stroke-width: 2;
}

.unit.place-target .actor-head,
.unit.place-target .actor-body,
.unit.place-target .actor-center {
  stroke: var(--accent);
  stroke-dasharray: 4 2;
}

/* Labels */
.unit-stereotype {
  font-size: 10px;
  font-family: var(--mono);
  fill: var(--text-muted);
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
  pointer-events: none;
}

.unit-hint {
  font-size: 10px;
  fill: var(--text-muted);
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
  pointer-events: none;
}

.unit .unit-label {
  font-size: 14px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: middle;
  fill: var(--text);
  user-select: none;
  pointer-events: none;
}

.unit-rename {
  position: absolute;
  padding: 2px 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  text-align: center;
  outline: none;
}

/* Instance nodes */
.instance {
  pointer-events: all;
  cursor: pointer;
}

.instance-box {
  fill: #ffffff;
  stroke: #64748b;
  stroke-width: 1.4;
}

.instance-role .instance-box {
  fill: #f8fafc;
  stroke: #0f766e;
}

.instance-person .instance-box {
  fill: #ffffff;
  stroke: #6366f1;
}

.instance-org-unit .instance-box {
  fill: #f8fafc;
  stroke: #475569;
}

.instance-label {
  font-size: 12px;
  font-weight: 650;
  fill: var(--text);
}

.instance-subtitle {
  font-size: 10px;
  fill: var(--text-muted);
}

.instance.search-match .instance-box {
  fill: #fff7ed;
  stroke: #f97316;
  stroke-width: 2.4;
}

.instance.selected .instance-box {
  fill: #fff7ed;
  stroke: #f97316;
  stroke-width: 2.6;
}

/* --- Relationships --- */

.edge {
  stroke: var(--edge);
  stroke-width: 1.5;
  fill: none;
  color: var(--edge); /* for markers that use currentColor */
}

.edge.selected {
  stroke: var(--selected-stroke);
  stroke-width: 2.5;
  color: var(--selected-stroke);
}

.instance-edge {
  stroke: #64748b;
  stroke-width: 1.4;
  fill: none;
  color: #64748b;
}

.link-reports_to .instance-edge {
  stroke: #0f766e;
  stroke-width: 1.8;
  color: #0f766e;
}

.link-fills_role .instance-edge,
.link-belongs_to .instance-edge {
  stroke: #94a3b8;
  stroke-dasharray: 4 3;
  color: #94a3b8;
}

.instance-link-label {
  font-size: 10px;
  fill: #475569;
  paint-order: stroke;
  stroke: white;
  stroke-width: 3px;
  stroke-linejoin: round;
}

.edge-hit {
  stroke: transparent;
  stroke-width: 12;
  fill: none;
  cursor: pointer;
}

.cardinality-label {
  font-size: 11px;
  fill: var(--text-muted);
  font-family: var(--mono);
  user-select: none;
  pointer-events: none;
}

/* --- Selection panel --- */

.selection-panel {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  max-height: 55vh;
  overflow-y: auto;
}

.selection-panel[hidden] {
  display: none;
}

.panel-close {
  position: absolute;
  z-index: 6;
  top: 8px;
  right: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 18px;
  line-height: 1;
}

.panel-close:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.panel-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.selection-panel label {
  display: flex;
  gap: 4px;
  align-items: center;
  color: var(--text-muted);
}

.selection-panel input[type=text] {
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
}

.selection-panel select {
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
}

/* Attribute / service sections */

.feature-section {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.feature-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.feature-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

.feature-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feature-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.feature-row.new-row {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.feature-row input[type=text] {
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--mono);
}

.row-remove {
  padding: 0 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.row-remove:hover {
  color: var(--error);
  border-color: var(--border);
}

.row-add {
  padding: 3px 8px;
  margin-left: 4px;
  font: inherit;
  font-size: 12px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: 3px;
  cursor: pointer;
}
.row-add:hover {
  background: var(--accent-soft);
}

.selection-panel .kind-badge {
  padding: 2px 8px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}

.selection-panel .unit-link {
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
}
.selection-panel .unit-link:hover { background: var(--accent-soft); }

.instance-panel-top {
  align-items: baseline;
}

.panel-title {
  font-size: 14px;
  color: var(--text);
}

.detail-section {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(100px, max-content) minmax(0, 1fr);
  gap: 6px 12px;
}

.detail-row {
  display: contents;
}

.detail-label {
  color: var(--text-muted);
  font-size: 12px;
}

.detail-value {
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.contact-input {
  width: min(420px, 100%);
  box-sizing: border-box;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

textarea.contact-input {
  resize: vertical;
  min-height: 46px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.instance-chip {
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.instance-chip:hover {
  background: var(--accent-soft);
}

.selection-panel .delete-btn {
  margin-left: auto;
  padding: 4px 10px;
  background: transparent;
  color: var(--error);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.selection-panel .delete-btn:hover { background: #fee; }

/* --- Mode banner (for place-relationship mode) --- */

.mode-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: var(--accent);
  color: white;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  pointer-events: none;
}

/* --- Text panel --- */

.text-region {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-bar {
  display: flex;
  gap: 0;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  align-items: center;
}

.tab-btn {
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.copy-btn {
  margin-left: auto;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-muted);
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

.text-content {
  flex: 1;
  margin: 0;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
  background: var(--surface);
}

.text-content.prose {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.6;
}

/* --- Issues panel --- */

.issues-panel {
  padding: 8px 14px;
  background: #fff8ec;
  border-top: 1px solid var(--border);
  font-size: 12px;
  max-height: 140px;
  overflow: auto;
}

.issues-panel .issue {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  align-items: flex-start;
}
.issues-panel .severity {
  font-family: var(--mono);
  font-weight: 600;
  min-width: 60px;
}
.issues-panel .severity.error { color: var(--error); }
.issues-panel .severity.warning { color: var(--warning); }
.issues-panel .severity.info { color: var(--text-muted); }
.issues-panel .code {
  font-family: var(--mono);
  color: var(--text-muted);
  min-width: 220px;
}
