/* Base Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f5f5;
}

#diagram-container {
  position: relative;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: auto;
}

/* Grid Layout */
.diagram-grid {
  display: grid;
  gap: 16px;
  position: relative;
  min-width: 800px;
}

/* Row Headers */
.row-header {
  display: flex;
  align-items: center;
  padding: 12px;
  background: #e3f2fd;
  border-left: 4px solid #2196f3;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.row-header:hover {
  background: #bbdefb;
}

.row-header.empty-label {
  background: transparent;
  border-left: none;
  pointer-events: none;
}

/* Column Headers */
.column-header {
  padding: 12px;
  background: #f3e5f5;
  border-top: 4px solid #9c27b0;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s;
}

.column-header:hover {
  background: #e1bee7;
}

.column-header.empty-label {
  background: transparent;
  border-top: none;
  pointer-events: none;
}

/* Grid Cells */
.grid-cell {
  position: relative;
  min-height: 100px;
  border: 1px dashed #ddd;
  padding: 8px;
}

/* Blocks */
.block {
  position: relative;
  padding: 12px;
  border: 2px solid #666;
  border-radius: 4px;
  background: white;
  margin-bottom: 8px;
  min-height: 70px;
  cursor: pointer;
  transition: all 0.2s;
}

.block:last-child {
  margin-bottom: 0;
}

.block:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.block.has-description:hover {
  border-color: #2196f3;
}

/* Parent Blocks */
.block.parent-block {
  background: #fafafa;
  border-color: #333;
  border-width: 3px;
}

.block.nested-parent {
  background: #f5f5f5;
  border-style: dashed;
  margin: 8px 0;
}

/* Leaf Blocks */
.block.leaf-block {
  background: white;
  border-color: #999;
}

.block.leaf-block.important {
  border-color: #ff5722;
  background: #fff3e0;
}

/* Block Labels */
.block-label {
  font-weight: 600;
  margin: 0;
  color: #333;
}

.block-label.empty-label {
  display: none;
}

/* Nested Block Container */
.block-children {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #ddd;
}

/* Connections Layer */
.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.connections-svg {
  width: 100%;
  height: 100%;
}

/* Connection Lines */
.connection {
  fill: none;
  stroke: #666;
  stroke-width: 2;
  marker-end: url(#arrowhead);
}

.connection.data-flow {
  stroke: #2196f3;
  stroke-width: 2.5;
}

.connection.feedback-flow {
  stroke: #ff9800;
  stroke-dasharray: 5, 5;
}

.connection.cross-layer {
  stroke: #4caf50;
  stroke-width: 3;
}

.connection-label {
  font-size: 12px;
  fill: #666;
  pointer-events: none;
}

.connection-label.empty-label {
  display: none;
}

/* Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: white;
  padding: 32px;
  border-radius: 8px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overlay-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 32px;
  cursor: pointer;
  color: #666;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.overlay-close:hover {
  background: #f5f5f5;
  color: #333;
}

#overlay-title {
  margin: 0 0 16px 0;
  color: #333;
  font-size: 24px;
}

#overlay-description {
  margin: 0;
  color: #666;
  line-height: 1.6;
}

/* Responsive */
@media (max-width: 768px) {
  .diagram-grid {
    min-width: auto;
    gap: 10px;
  }
  
  .overlay-content {
    padding: 20px;
  }
}

/* Custom Row/Column Classes (examples) */
.conceptual-row {
  background: #e8f5e9;
  border-left-color: #4caf50;
}

.structural-row {
  background: #fff3e0;
  border-left-color: #ff9800;
}

.primary-column {
  background: #e3f2fd;
  border-top-color: #2196f3;
}

.secondary-column {
  background: #fce4ec;
  border-top-color: #e91e63;
}