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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  color: #333;
  min-height: 100vh;
}

header {
  padding: 16px 24px;
  background: #f8f8f8;
  border-bottom: 1px solid #e0e0e0;
}

header h1 { font-size: 18px; color: #111; }

main {
  display: grid;
  grid-template-columns: 200px 1fr 320px;
  height: calc(100vh - 70px);
}

nav#plan-list {
  background: #f8f8f8;
  border-right: 1px solid #e0e0e0;
  padding: 12px 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.plan-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, opacity 0.2s;
}
.plan-item .toggle-icon {
  font-size: 10px;
  cursor: pointer;
}
.plan-item .drag-handle {
  font-size: 10px;
  color: #bbb;
  cursor: grab;
  letter-spacing: -2px;
  user-select: none;
}
.plan-item .drag-handle:active { cursor: grabbing; }
.plan-item.dragging {
  opacity: 0.4;
  background: #f0f0f0;
}
.plan-item.drag-over {
  border-left-color: #2a9d8f;
  background: #e8f4f0;
}
.plan-item-label { flex: 1; }
.plan-item:hover { background: #eee; }
.plan-item.active { background: #e8f4f0; border-left-color: #2a9d8f; }

section#tree {
  padding: 16px;
  overflow-y: auto;
}

aside#detail {
  background: #f8f8f8;
  border-left: 1px solid #e0e0e0;
  padding: 16px;
  overflow-y: auto;
}

.tree-group { margin-bottom: 16px; }
.tree-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  font-weight: 600;
  margin-bottom: 6px;
  padding-left: 4px;
}

.tree-resource {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.tree-resource:hover { background: #f0f0f0; }
.tree-resource.selected { background: #e8f4f0; font-weight: 600; }

.resource-name { flex: 1; }
.resource-type { font-size: 11px; color: #999; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.healthy { background: #2a9d8f; }
.status-dot.unhealthy { background: #e74c3c; }
.status-dot.unknown { background: #000; }

.detail-field { margin-bottom: 12px; }
.detail-field label { font-size: 11px; color: #888; text-transform: uppercase; }
.detail-field .value { font-size: 14px; margin-top: 2px; }

h2 { font-size: 14px; margin-bottom: 12px; color: #111; }

.empty { color: #999; font-size: 13px; padding: 16px; }

.section-toggle {
  margin-top: 20px;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  user-select: none;
  padding: 6px 0;
}
.section-toggle:hover { color: #111; }
.toggle-icon {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 10px;
  margin-right: 6px;
}
.toggle-icon.rotated {
  transform: rotate(90deg);
}
.section-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.section-content.expanded {
  max-height: 2000px;
}

.metadata-item {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid #eee;
}
.metadata-key {
  color: #888;
  min-width: 120px;
  font-weight: 500;
}
.metadata-value {
  color: #333;
  word-break: break-all;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}
.status-dot.pulse {
  animation: pulse 0.4s ease-in-out;
}

.inline-toggle {
  font-size: 11px;
  color: #888;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
  margin-top: 4px;
}
.inline-toggle:hover { color: #555; }
.inline-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 16px;
}
.inline-content.expanded {
  max-height: 400px;
}

.history-item {
  padding: 6px 0;
  border-bottom: 1px solid #eee;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}
.history-header .transition {
  display: flex;
  align-items: center;
  gap: 4px;
}
.history-header .timestamp {
  color: #888;
  white-space: nowrap;
  font-size: 11px;
}

.resource-header {
  cursor: pointer;
  user-select: none;
}
.resource-header h2 {
  font-size: 14px;
  color: #111;
  margin-bottom: 0;
}
.resource-header .toggle-icon {
  font-size: 10px;
  margin-right: 6px;
}

@keyframes pulse-text {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}
.pulse-text {
  animation: pulse-text 0.4s ease-in-out;
}

.status-toggle-row {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  padding: 4px 0;
}
.status-toggle-row:hover { color: #111; }
.status-label {
  font-size: 14px;
  font-weight: normal;
}
.reason-text {
  font-size: 12px;
  color: #666;
  padding: 4px 0;
  font-family: monospace;
}

.status-text-healthy { color: #2a9d8f; }
.status-text-unhealthy { color: #e74c3c; }
.status-text-unknown { color: #000; }

/* View tabs */
#view-tabs {
  margin-top: 8px;
  display: flex;
  gap: 4px;
}
.view-tab {
  background: none;
  border: none;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  color: #666;
  border-bottom: 2px solid transparent;
}
.view-tab:hover { color: #111; }
.view-tab.active { color: #111; border-bottom-color: #2a9d8f; }

/* View panels */
.view-panel { display: none; }
.view-panel.active {
  display: grid;
  grid-template-columns: 1fr 320px;
  height: 100%;
}
#view-discovery.active {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Editor */
#editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f4f4f4;
  border-bottom: 1px solid #e0e0e0;
}
#editor-status { font-size: 12px; color: #888; }
#btn-apply {
  background: #2a9d8f;
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
#btn-apply:hover { background: #238b7e; }
#btn-apply:disabled { background: #ccc; cursor: not-allowed; }
#editor {
  flex: 1;
  min-height: 400px;
}
#editor-errors {
  max-height: 150px;
  overflow-y: auto;
  background: #fff5f5;
  border-top: 1px solid #e0e0e0;
}
#editor-errors:empty { display: none; }
.error-item {
  padding: 4px 12px;
  font-size: 12px;
  color: #c0392b;
  border-bottom: 1px solid #fde0de;
}

/* Layout: hide detail panel when editor is active */
main.editor-active { grid-template-columns: 200px 1fr; }
main.editor-active #detail { display: none; }

.hidden { display: none !important; }

/* Plan tree children */
.nav-controls {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
}
.new-plan-link {
  display: inline;
  font-size: 12px;
  color: #2a9d8f;
  text-decoration: underline;
  cursor: pointer;
}
.new-plan-link:hover { color: #21867a; }

.folder-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.folder-item:hover { background: #eee; }
.folder-toggle { font-size: 14px; cursor: pointer; }
.folder-label { flex: 1; font-weight: 500; }
.folder-divider { border-top: 1px solid #e0e0e0; margin: 8px 12px; }

.archive-folder {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: #888;
  cursor: pointer;
  margin-top: 12px;
  border-top: 1px solid #eee;
}
.archive-folder:hover { color: #555; }
.archive-folder.empty-archive { cursor: default; }
.archive-folder.empty-archive:hover { color: #888; }
.archived-item { opacity: 0.7; }

.nav-version-footer {
  font-size: 11px;
  color: #999;
  padding: 12px 16px;
  margin-top: auto;
  border-top: 1px solid #e0e0e0;
}

.plan-children {
  padding-left: 12px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.plan-children.folder-children {
  padding-left: 0;
}
.plan-children.expanded {
  max-height: 1000px;
  overflow: visible;
}
.plan-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px 5px 8px;
  font-size: 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.plan-child:hover { background: #eee; }
.plan-child.active { background: #e8f4f0; border-left-color: #2a9d8f; }
.plan-child-label { flex: 1; }
.plan-child-label.draft { }
.plan-child-label.current { font-weight: 600; }

/* Kebab menu */
.kebab-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #888;
  padding: 0 4px;
  line-height: 1;
}
.kebab-btn:hover { color: #333; }
.kebab-menu {
  position: absolute;
  right: 8px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 130px;
}
.kebab-menu-item {
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.kebab-menu-item:hover { background: #f0f0f0; }

/* Center panel */
#center-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#view-resources {
  flex: 1;
  overflow-y: auto;
}
#view-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Read-only editor indicator */
#editor.readonly-mode { opacity: 0.85; }

/* Tags toggle within plan children */
.tags-toggle {
  cursor: pointer;
  gap: 4px;
}
.tags-toggle .toggle-icon {
  font-size: 9px;
}
.tags-children {
  padding-left: 8px;
}
.empty-tags {
  font-size: 11px;
  color: #aaa;
  padding: 4px 12px;
  font-style: italic;
}
.plan-child-label.prior { font-style: italic; color: #888; }
