:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --ink: #172033;
  --muted: #64748b;
  --line: #d5deea;
  --accent: #2563eb;
  --accent-2: #0f766e;
  --danger: #dc2626;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  border-radius: 7px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9eb2ce;
  background: #f8fbff;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: white;
  background: #172033;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.title-input {
  width: min(38vw, 420px);
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 19px;
  font-weight: 750;
  padding: 2px 0;
}

.save-status {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

#save-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #16a34a;
}

#save-dot.pending {
  background: #f59e0b;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.danger {
  color: var(--danger);
  border-color: #fecaca;
}

.shell {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr) 310px;
}

.toolbar,
.properties {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow: auto;
}

.properties {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.tool {
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
}

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

.toolbar-rule {
  height: 1px;
  margin: 12px 0;
  background: var(--line);
}

.toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #f8fafc;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 36px;
  z-index: 2;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: min(520px, calc(100% - 48px));
  padding: 14px 16px;
  color: #334155;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.empty-state span {
  color: var(--muted);
  font-size: 13px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

#selection-kind {
  color: var(--muted);
  font-size: 12px;
}

.properties-body {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field-title {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 9px;
  background: white;
  color: var(--ink);
}

.field textarea {
  min-height: 70px;
  resize: vertical;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #475569;
  font-size: 13px;
}

.property-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hint,
.shortcuts {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.shortcuts {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.shortcuts h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 13px;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 5px;
  border: 1px solid #cbd5e1;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
  text-align: center;
}

.context-menu {
  position: fixed;
  z-index: 20;
  width: 190px;
  padding: 6px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.context-menu button {
  width: 100%;
  border: 0;
  justify-content: flex-start;
  text-align: left;
}

.danger-text {
  color: var(--danger);
}

.node-shape,
.edge-line,
.resize-handle,
.anchor {
  vector-effect: non-scaling-stroke;
}

.erd-label {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  font-size: 15px;
  fill: #0f172a;
  user-select: none;
  pointer-events: none;
}

.small-label {
  font-size: 12px;
  fill: #334155;
}

.selection-box {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.resize-handle {
  fill: white;
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: nwse-resize;
}

.anchor {
  fill: #ffffff;
  stroke: var(--accent-2);
  stroke-width: 2;
  opacity: 0;
  cursor: crosshair;
}

.node:hover .anchor,
.node.selected .anchor {
  opacity: 1;
}

.connector-preview {
  stroke: var(--accent-2);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  fill: none;
  vector-effect: non-scaling-stroke;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 132px minmax(0, 1fr);
  }

  .properties {
    position: absolute;
    right: 10px;
    top: 84px;
    bottom: 10px;
    z-index: 4;
    width: min(310px, calc(100vw - 160px));
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
}
