*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1e1e2e;
  --surface:   #181825;
  --overlay:   #313244;
  --muted:     #6c7086;
  --text:      #cdd6f4;
  --subtext:   #a6adc8;
  --blue:      #89b4fa;
  --green:     #a6e3a1;
  --yellow:    #f9e2af;
  --red:       #f38ba8;
  --mauve:     #cba6f7;
  --accent:    #89dceb;
  --entity-w:  260px;
  --header-h:  36px;
  --row-h:     28px;
}

html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 13px; }

/* ── Toolbar ── */
#toolbar {
  height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--overlay);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  position: relative;
  z-index: 100;
}
.app-title { font-weight: 700; color: var(--blue); letter-spacing: 2px; margin-right: 8px; }
.toolbar-left, .toolbar-center, .toolbar-right { display: flex; align-items: center; gap: 6px; }
.toolbar-center { margin: 0 auto; }

button {
  background: var(--overlay);
  color: var(--text);
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 4px 10px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--muted); border-color: var(--blue); }
button:active { background: var(--blue); color: var(--surface); }

kbd { font: inherit; font-size: 11px; color: var(--muted); }

input[type="text"], select {
  background: var(--overlay);
  color: var(--text);
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
  outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--blue); }

#diagram-name { width: 140px; }
#diagram-select { width: 160px; }

#save-status { font-size: 11px; color: var(--green); min-width: 50px; }

#rel-mode-indicator { display: none; color: var(--yellow); font-size: 11px; font-weight: 600; }

/* ── Canvas ── */
#canvas-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 44px);
}

#canvas {
  width: 100%;
  height: 100%;
  cursor: default;
  background:
    radial-gradient(circle, var(--overlay) 1px, transparent 1px) 0 0 / 24px 24px;
}
#canvas.panning { cursor: grab; }
#canvas.rel-mode { cursor: crosshair; }

/* ── SVG Entity Styles (applied via class on SVG elements) ── */
.entity-bg       { fill: var(--surface); stroke: var(--overlay); stroke-width: 1.5; rx: 6; }
.entity-bg.selected { stroke: var(--blue); stroke-width: 2; }
.entity-header   { fill: var(--overlay); rx: 6; }
.entity-name     { fill: var(--text); font-size: 13px; font-weight: 600; font-family: inherit; }
.entity-add-btn  { fill: var(--muted); font-size: 16px; cursor: pointer; }
.entity-add-btn:hover { fill: var(--green); }
.entity-divider  { stroke: var(--overlay); stroke-width: 1; }

.field-row-bg         { fill: transparent; }
.field-row-bg.focused { fill: rgba(137,180,250,0.08); }
.field-key-icon  { fill: var(--yellow); font-size: 11px; }
.field-name-text { fill: var(--text); font-size: 12px; font-family: inherit; }
.field-type-text { fill: var(--subtext); font-size: 11px; font-family: inherit; cursor: pointer; }
.field-type-text:hover { fill: var(--blue); }
.field-keytype-text { font-size: 10px; font-weight: 700; font-family: inherit; cursor: pointer; }
.field-keytype-text:hover { opacity: 0.7; }
.kt-pk { fill: var(--yellow); }
.kt-fk { fill: var(--mauve); }
.kt-uk { fill: var(--green); }
.kt-none { fill: var(--muted); }

/* ── Relationship lines ── */
.rel-line    { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.rel-line.selected { stroke: var(--blue); stroke-width: 2; }
.rel-symbol  { stroke: var(--muted); stroke-width: 1.5; fill: none; }
.rel-symbol-opt { stroke: var(--muted); stroke-width: 1.5; fill: var(--surface); }

/* ── Inline editor overlay ── */
#inline-editor {
  position: absolute;
  display: none;
  background: var(--overlay);
  color: var(--text);
  border: 2px solid var(--blue);
  border-radius: 3px;
  padding: 0 4px;
  font: inherit;
  font-size: 12px;
  z-index: 200;
  outline: none;
}

/* ── Type / keytype picker overlays ── */
#type-picker, #keytype-picker {
  position: absolute;
  display: none;
  z-index: 200;
  min-width: 160px;
}

/* ── Cardinality picker ── */
#cardinality-picker {
  position: absolute;
  display: none;
  background: var(--surface);
  border: 1px solid var(--overlay);
  border-radius: 6px;
  padding: 8px;
  z-index: 300;
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.cp-title { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
#cardinality-picker button {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
  padding: 6px 8px;
}
#cardinality-picker button:last-child { margin-bottom: 0; }

/* ── Field connector dots ── */
.field-connector {
  fill: var(--surface);
  stroke: var(--muted);
  stroke-width: 1.5;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.15s;
}
.entity:hover .field-connector { opacity: 1; }
.field-connector:hover { fill: var(--blue); stroke: var(--blue); }

/* ── Rubber band line while dragging a connection ── */
.rel-temp-line {
  stroke: var(--blue);
  stroke-width: 1.5;
  stroke-dasharray: 6,3;
  fill: none;
  pointer-events: none;
}
