/* Layout Engine - Dynamic Split Pane System */

#layout-root {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Split container */
.layout-split {
  display: flex;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.layout-split.horizontal {
  flex-direction: row;
}

.layout-split.vertical {
  flex-direction: column;
}

/* Child within a split */
.layout-child {
  overflow: hidden;
  position: relative;
  min-width: 0;
  min-height: 0;
}

/* Leaf node - contains tab bar + panel content */
.layout-leaf {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

/* Tab bar */
.layout-tab-bar {
  display: flex;
  height: 28px;
  min-height: 28px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
  gap: 0;
  user-select: none;
  flex-shrink: 0;
}

.layout-tab-bar::-webkit-scrollbar {
  height: 2px;
}

.layout-tab-bar::-webkit-scrollbar-thumb {
  background: var(--border-color);
}

/* Hide tab bar when only one tab */
.layout-tab-bar.single-tab {
  display: none;
}

/* Individual tab */
.layout-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  height: 100%;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  max-width: 160px;
}

.layout-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.layout-tab.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent);
}

.layout-tab .tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout-tab .tab-close {
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layout-tab:hover .tab-close {
  opacity: 0.6;
}

.layout-tab .tab-close:hover {
  opacity: 1;
  background: var(--bg-hover);
}

/* Panel content area */
.layout-panel-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

/* Resize handles between children */
.layout-resize-handle {
  flex-shrink: 0;
  z-index: 10;
  transition: background 0.15s;
}

.layout-resize-handle.horizontal {
  width: 4px;
  cursor: col-resize;
  background: var(--border-color);
}

.layout-resize-handle.vertical {
  height: 4px;
  cursor: row-resize;
  background: var(--border-color);
}

.layout-resize-handle:hover,
.layout-resize-handle.active {
  background: var(--accent);
}

/* Empty leaf placeholder */
.layout-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
  user-select: none;
}

.layout-empty span {
  padding: 12px 24px;
  border: 1px dashed var(--border-color);
  border-radius: 6px;
  cursor: pointer;
}

.layout-empty span:hover {
  border-color: var(--accent);
  color: var(--text-secondary);
}

/* Button Panel */
.button-panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  height: 100%;
  align-content: start;
}

.button-panel-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
  min-height: 60px;
  word-break: break-word;
}

.button-panel-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.button-panel-btn .btn-icon {
  font-size: 18px;
}

.button-panel-btn .btn-label {
  font-size: 11px;
  line-height: 1.2;
}

.button-panel-edit {
  border-style: dashed;
  opacity: 0.5;
}

.button-panel-edit:hover {
  opacity: 1;
}

/* Profile picker dropdown */
.profile-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.profile-picker-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 8px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.profile-picker-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.profile-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  min-width: 180px;
  z-index: 2000;
  max-height: 300px;
  overflow-y: auto;
}

.profile-dropdown-item {
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-dropdown-item:hover {
  background: var(--bg-hover);
}

.profile-dropdown-item.active {
  color: var(--accent);
}

.profile-dropdown-item .profile-delete {
  margin-left: auto;
  opacity: 0;
  color: var(--error);
  font-size: 14px;
}

.profile-dropdown-item:hover .profile-delete {
  opacity: 0.6;
}

.profile-dropdown-item .profile-delete:hover {
  opacity: 1;
}

.profile-dropdown-sep {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

.profile-dropdown-input {
  display: flex;
  padding: 4px 8px;
  gap: 4px;
}

.profile-dropdown-input input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
  padding: 3px 6px;
  font-size: 12px;
  outline: none;
}

.profile-dropdown-input button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 3px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
}

/* Zoom overlay indicator */
.layout-zoomed-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  z-index: 20;
  cursor: pointer;
  opacity: 0.7;
}

.layout-zoomed-indicator:hover {
  opacity: 1;
}
