/* Constellation Writer — Workspace Layout */

/* === Top Bar === */
.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.topbar-logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: -0.5px;
}
.topbar-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.topbar-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(91, 156, 246, 0.15);
  color: var(--accent-blue);
}
.topbar-progress {
  flex: 1;
  max-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-progress .label {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.topbar-spacer { flex: 1; }
.topbar-progress-bar { flex: 1; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === Main Workspace === */
.workspace {
  display: flex;
  height: calc(100vh - var(--topbar-height) - var(--statusbar-height));
  overflow: hidden;
}

/* === Left Panel === */
.left-panel {
  width: var(--left-panel-width);
  min-width: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal), min-width var(--transition-normal);
  overflow: hidden;
}
.left-panel.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

/* Graph container (top) */
.graph-container {
  flex: 55 0 0;
  position: relative;
  background: var(--bg-graph);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.graph-container .graph-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  z-index: 10;
  background: linear-gradient(to bottom, var(--bg-graph), transparent);
}
.graph-header .label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#cy-mini {
  width: 100%;
  height: 100%;
}

/* Chunk list (bottom) */
.chunk-list-container {
  flex: 45 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chunk-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.chunk-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

/* Chunk item */
.chunk-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.chunk-item:hover {
  background: var(--hover-bg);
}
.chunk-item.active {
  background: rgba(91, 156, 246, 0.1);
  border-left-color: var(--accent-blue);
}
.chunk-item .chunk-order {
  font-size: 11px;
  color: var(--text-hint);
  min-width: 16px;
}
.chunk-item .chunk-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}
.chunk-item .chunk-words {
  font-size: 11px;
  color: var(--text-hint);
}
.chunk-item .chunk-icon {
  font-size: 12px;
  color: var(--node-illustration);
}
.chunk-item.dragging {
  opacity: 0.4;
}
.chunk-item.drag-over {
  border-top: 2px solid var(--accent-blue);
  background: rgba(91, 156, 246, 0.08);
}
.chunk-item .status-dot {
  cursor: pointer;
  transition: transform 0.15s;
}
.chunk-item .status-dot:hover {
  transform: scale(1.4);
}

/* === Center Panel === */
.center-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Graph full view */
.graph-full {
  flex: 1;
  position: relative;
  background: var(--bg-graph);
  overflow: hidden;
}
#cy-main {
  width: 100%;
  height: 100%;
}

/* Star field canvas (behind cytoscape) */
#star-field {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* Editor area */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-content {
  flex: 1;
  padding: 20px 32px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  outline: none;
  min-height: 200px;
}
.editor-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-hint);
}
.editor-content h1 { font-size: 1.6em; margin: 0.6em 0 0.3em; }
.editor-content h2 { font-size: 1.3em; margin: 0.5em 0 0.3em; }
.editor-content h3 { font-size: 1.1em; margin: 0.4em 0 0.2em; }
.editor-content p { margin-bottom: 0.8em; }
.editor-content ul, .editor-content ol { margin: 6px 0; padding-left: 24px; }
.editor-content li { margin: 3px 0; line-height: 1.6; }
.editor-content hr { border: 0; border-top: 1px solid var(--border, rgba(0,0,0,0.1)); margin: 16px 0; }
.editor-content blockquote {
  border-left: 3px solid var(--accent-blue);
  padding-left: 14px;
  margin: 0.8em 0;
  color: var(--text-secondary);
}
.editor-content code {
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}
.editor-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 12px 0;
}

/* Editor footer */
.editor-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--bg-surface);
}
.editor-footer .save-status {
  display: flex;
  align-items: center;
  gap: 4px;
}
.save-status.saving { color: var(--accent-orange); }
.save-status.saved { color: var(--accent-green); }
.save-status.error { color: var(--accent-red); }

/* === AI Panel === */
.ai-draft-area {
  margin-bottom: 12px;
}
.ai-messages {
  min-height: 150px;
  overflow-y: auto;
  margin-bottom: 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  align-items: flex-end;
}
.ai-input-field {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.4;
  font-size: 13px;
  padding: 8px 10px;
}
.ai-send-btn {
  align-self: flex-end;
  height: 36px;
  min-width: 36px;
}
.workflow-controls {
  margin-bottom: 0;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}
.workflow-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; cursor: pointer; user-select: none;
  font-size: 11px; color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.5px; font-weight: 600;
}
.workflow-toggle:hover { color: var(--text-secondary); }
.workflow-toggle .wf-arrow {
  transition: transform 0.2s; font-size: 10px;
}
.workflow-toggle .wf-arrow.collapsed { transform: rotate(-90deg); }
.workflow-body { overflow: hidden; transition: max-height 0.25s ease; }
.workflow-body.collapsed { max-height: 0 !important; padding: 0; }
.attach-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* === Right Panel === */
.right-panel {
  width: var(--right-panel-width);
  min-width: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal), min-width var(--transition-normal);
  overflow: hidden;
}
.right-panel.collapsed {
  width: 0;
  min-width: 0;
  border-left: none;
}
.right-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* === Outline tree === */
.outline-tree {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Panel collapse buttons */
.panel-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  z-index: 20;
  color: var(--text-hint);
  font-size: 10px;
  transition: all var(--transition-fast);
}
.panel-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}
.panel-toggle.left {
  left: 0;
  border-left: none;
}
.panel-toggle.right {
  right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  border-right: none;
}

/* === Status Bar === */
.statusbar {
  display: flex;
  align-items: center;
  height: var(--statusbar-height);
  padding: 0 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-tertiary);
  gap: 16px;
  flex-shrink: 0;
}
.statusbar-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.statusbar-spacer { flex: 1; }
.statusbar kbd {
  font-size: 10px;
  padding: 1px 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--font-sans);
}

/* === Preview Content === */
.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.8;
  color: var(--text-primary);
}

/* === Welcome Screen === */
.screen-welcome {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-base);
}
.welcome-header {
  padding: 40px 40px 20px;
  text-align: center;
}
.welcome-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 8px;
}
.welcome-header p {
  color: var(--text-secondary);
  font-size: 14px;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 20px 40px;
  overflow-y: auto;
  flex: 1;
}
.new-project-card {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-tertiary);
  min-height: 180px;
}
.new-project-card:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
.new-project-card .plus {
  font-size: 32px;
  margin-bottom: 8px;
}

/* === Workspace Screen === */
.screen-workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === Preview Screen === */
.screen-preview {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === New Project Screen === */
.screen-new-project {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-base);
  overflow: hidden;
}
.new-project-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 32px 40px 40px;
  width: 100%;
  flex: 1;
  overflow-y: auto;
}
.new-project-heading {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.form-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}


/* === Resizable Right Panel === */
.right-panel {
  position: relative;
}
.resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.active {
  background: var(--accent-blue);
}
.right-panel .ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  min-height: 80px;
}
.right-panel .tab-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#tab-ai {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#tab-ai .workflow-controls {
  flex-shrink: 0;
}
#tab-ai .ai-draft-area {
  flex-shrink: 0;
  max-height: 250px;
  overflow-y: auto;
}
#tab-ai .ai-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 80px;
}
#tab-ai .ai-input-row {
  flex-shrink: 0;
}
.editor-content pre {
  background: var(--bg-elevated, #f6f5f4);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.editor-content pre code {
  font-family: 'Courier New', Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  background: none;
  padding: 0;
}
.editor-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}
.editor-content th {
  background: var(--bg-elevated, #f6f5f4);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border, rgba(0,0,0,0.1));
  font-weight: 600;
}
.editor-content td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border, rgba(0,0,0,0.1));
}
.editor-content tr:hover td {
  background: rgba(0,0,0,0.02);
}

.inline-diagram {
  margin: 20px 0;
  text-align: center;
  user-select: none;
}
.inline-diagram img {
  max-width: 100%;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.inline-diagram figcaption {
  font-size: 13px;
  color: var(--text-tertiary, #888);
  margin-top: 8px;
  font-style: italic;
}
.editor-content .inline-diagram {
  cursor: default;
}

.preview-content h1 { font-size: 1.8em; margin: 0.8em 0 0.4em; }
.preview-content h2 { font-size: 1.4em; margin: 1em 0 0.4em; border-bottom: 1px solid var(--border, rgba(0,0,0,0.1)); padding-bottom: 6px; }
.preview-content h3 { font-size: 1.15em; margin: 0.8em 0 0.3em; }
.preview-content h4 { font-size: 1.05em; margin: 0.6em 0 0.2em; }
.preview-content h5 { font-size: 1em; margin: 0.5em 0 0.2em; font-weight: 600; }
.preview-content ul, .preview-content ol { margin: 8px 0; padding-left: 28px; }
.preview-content li { margin: 4px 0; line-height: 1.7; }
.preview-content hr { border: 0; border-top: 1px solid var(--border, rgba(0,0,0,0.1)); margin: 20px 0; }
.preview-content pre {
  background: var(--bg-elevated, #1e293b);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}
.preview-content pre code {
  font-family: 'Courier New', Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  background: none;
  padding: 0;
}
.preview-content code {
  background: var(--bg-elevated, #1e293b);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.preview-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 15px;
}
.preview-content th {
  background: var(--bg-elevated, #f6f5f4);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border, rgba(0,0,0,0.1));
  font-weight: 600;
}
.preview-content td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border, rgba(0,0,0,0.1));
}
.preview-content tr:hover td {
  background: rgba(255,255,255,0.03);
}

/* ── Block flash animation (AI content update) ── */
@keyframes block-flash-anim {
  0% { background-color: rgba(0, 117, 222, 0.18); }
  70% { background-color: rgba(0, 117, 222, 0.08); }
  100% { background-color: transparent; }
}
.editor-content .block-flash {
  animation: block-flash-anim 2s ease-out;
  border-radius: 4px;
}