:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --line: #0f172a;
  --accent: #0ea5e9;
  --entity-border: #1e293b;
  --drag-zone: #0f172a;
  --title-zone: #f8fafc;
  --text: #0f172a;
  --toolbar-h: 56px;
  --footer-h: 26px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, #dbeafe 0%, transparent 35%),
    radial-gradient(circle at 80% 80%, #e2e8f0 0%, transparent 40%),
    var(--bg);
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 25px rgba(15, 23, 42, 0.12);
  overflow: visible;
}

.brand {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.btn {
  flex: 0 0 auto;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn.active {
  border-color: var(--accent);
  color: #0369a1;
  background: #e0f2fe;
}

.zoom-level {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 0 8px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 700;
}

#canvas {
  position: relative;
  width: 100vw;
  height: calc(100vh - var(--toolbar-h) - var(--footer-h));
  margin-top: var(--toolbar-h);
}

#scene {
  position: absolute;
  inset: 0;
  transform-origin: top left;
}

#line-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: auto;
}

#entities-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.entity {
  position: absolute;
  min-width: 210px;
  width: 220px;
  min-height: 170px;
  border: 2px solid var(--entity-border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
  user-select: none;
}

.entity.selected {
  outline: 3px solid #7dd3fc;
  outline-offset: 2px;
}

.drag-handle {
  height: 36px;
  background: var(--drag-zone);
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: grab;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-bottom: 1px solid #334155;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-dots {
  opacity: 0.8;
  font-size: 14px;
}

.title-zone {
  background: var(--title-zone);
  padding: 8px 10px;
  border-bottom: 1px solid #cbd5e1;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entity-title {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  outline: none;
  padding: 6px 8px;
}

.entity-body {
  padding: 8px 10px 10px;
  background: #ffffff;
}

.attributes {
  min-height: 90px;
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  resize: vertical;
  outline: none;
  font-size: 13px;
  line-height: 1.4;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color: #0f172a;
  background: #fff;
}

.cardinality {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  font-size: 12px;
  border: 1px solid #94a3b8;
  border-radius: 8px;
  padding: 3px 5px;
  background: #fff;
  color: #0f172a;
  pointer-events: auto;
}

.relation-label {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, -50%);
  min-width: 120px;
  max-width: 200px;
  border: 1px solid #94a3b8;
  border-radius: 8px;
  padding: 4px 8px;
  background: #ffffff;
  color: #0f172a;
  font-size: 12px;
  text-align: center;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 140px;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
}

.context-item {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  padding: 7px 9px;
  cursor: pointer;
}

.context-item:hover {
  background: #e2e8f0;
}

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid #cbd5e1;
  color: #334155;
  font-size: 11px;
  text-align: center;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toolbar {
    padding: 10px 14px;
  }

  .brand {
    font-size: 13px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 14px;
  }

  .entity {
    min-width: 240px;
    width: 260px;
  }
}

@media (min-width: 1200px) {
  .toolbar {
    flex-wrap: nowrap;
  }
}

@media print {
  .toolbar {
    display: none;
  }

  .footer {
    display: none;
  }

  body {
    background: #fff;
  }
}
