/* Manage view — file ops + chat + reconcile, scoped to one project.
 * Originated from lab/style.css; integrated into main dashboard SPA. */

/* When manage view is active, the body becomes a fullscreen flex column and
 * everything else (main header, userBar, statsBar, gameListView, etc.) is hidden. */
body.manage-active {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.manage-active > *:not(#manageView):not(.modal-overlay):not(.reconcile-result-panel):not(.lab-preview-overlay):not(.pending-panel) {
  display: none !important;
}

#manageView {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
               "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif;
  background: #1a1a1a;
  color: #e0e0e0;
}
body.manage-active #manageView { display: flex; }

/* --- Header --- */
#manageView .lab-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: #252525;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#manageView .brand {
  font-weight: 600;
  font-size: 16px;
  color: #4caf50;
  letter-spacing: 1px;
}

#manageView .back-to-list {
  background: transparent;
  border: 1px solid #444;
  color: #ccc;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
#manageView .back-to-list:hover { border-color: #888; color: #fff; }

#manageView .manage-project-name {
  font-size: 14px;
  color: #ddd;
  font-weight: 500;
}

#manageView .lab-actions { display: flex; gap: 8px; }

#manageView .btn-reconcile {
  background: #2d4030;
  color: #e0e0e0;
  border: 1px solid #4caf50;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
#manageView .btn-reconcile:hover:not(:disabled) { background: #3d5040; }
#manageView .btn-reconcile:disabled { opacity: 0.4; cursor: not-allowed; }

#manageView .status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #999;
}
#manageView .status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #555;
}
#manageView .status-dot.active { background: #4caf50; box-shadow: 0 0 6px #4caf50; }
#manageView .status-dot.busy   { background: #ff9800; box-shadow: 0 0 6px #ff9800; }
#manageView .status-dot.error  { background: #f44336; }

/* --- Layout --- */
#manageView .lab-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(440px, 1.4fr);
  overflow: hidden;
  min-height: 0;
}

#manageView .left-pane, #manageView .right-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#manageView .left-pane { border-right: 1px solid #333; }

/* --- Tabs --- */
#manageView .tabs {
  display: flex;
  background: #252525;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#manageView .tab {
  background: transparent;
  border: none;
  color: #888;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 2px solid transparent;
}
#manageView .tab:hover { color: #ccc; }
#manageView .tab.active {
  color: #e0e0e0;
  border-bottom-color: #4caf50;
}

#manageView .tab-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#manageView .tab-content.hidden { display: none; }

/* File browser */
#manageView .file-breadcrumb {
  padding: 8px 14px;
  background: #1f1f1f;
  border-bottom: 1px solid #333;
  font-size: 12px;
  color: #aaa;
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}
#manageView .crumb {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
}
#manageView .crumb:hover { color: #4caf50; background: #2a2a2a; }
#manageView .crumb-sep { color: #555; margin: 0 2px; }

#manageView .file-grid {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

#manageView .file-row {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  gap: 10px;
  cursor: pointer;
  border-bottom: 1px solid #222;
  font-size: 13px;
  user-select: none;
}
#manageView .file-row:hover { background: #2a2a2a; }
#manageView .file-row.selected { background: #2d4030; }
#manageView .file-row .row-actions {
  display: none;
  gap: 4px;
  flex-shrink: 0;
}
#manageView .file-row:hover .row-actions { display: flex; }
#manageView .row-actions button {
  background: #333;
  border: 1px solid #555;
  color: #ddd;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
}
#manageView .row-actions button.danger:hover {
  background: #5a2828;
  border-color: #c44;
  color: #fff;
}

#manageView .file-grid.drag-over {
  background: rgba(76, 175, 80, 0.1);
  outline: 2px dashed #4caf50;
  outline-offset: -10px;
}

#manageView .file-icon {
  width: 22px;
  font-size: 15px;
  flex-shrink: 0;
  text-align: center;
}
#manageView .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#manageView .file-size {
  font-size: 11px;
  color: #888;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Pending chip — exists in #manageView header, panel floats globally */
#manageView .chip {
  background: #2d3a4f;
  border: 1px solid #2196f3;
  color: #cfe0ff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
}
#manageView .chip:hover:not(:disabled) { background: #3d4a5f; }
#manageView .chip:disabled { opacity: 0.4; cursor: not-allowed; }
#manageView .chip[hidden] { display: none !important; }

.pending-panel {
  position: fixed;
  top: 56px;
  right: 20px;
  background: #252525;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 12px;
  min-width: 320px;
  max-width: 480px;
  max-height: 70vh;
  overflow: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  color: #e0e0e0;
}
.pending-panel h3 { font-size: 13px; margin-bottom: 8px; color: #ccc; }
.pending-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid #333; font-size: 12px;
}
.pending-item:last-child { border-bottom: none; }
.pending-op { width: 50px; font-weight: 600; }
.pending-op.upload { color: #4caf50; }
.pending-op.delete { color: #f44336; }
.pending-files {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: #ddd;
}
.pending-restore {
  background: #2d4030; border: 1px solid #4caf50; color: #ddd;
  padding: 2px 8px; font-size: 11px; border-radius: 3px; cursor: pointer;
}
.pending-restore:hover { background: #3d5040; }

/* Logs (inside manageView) */
#manageView .logs-layout {
  display: grid;
  grid-template-rows: minmax(120px, 30%) 1fr;
  height: 100%;
  overflow: hidden;
}
#manageView .log-sessions {
  overflow: auto;
  border-bottom: 1px solid #333;
  background: #1f1f1f;
}
#manageView .log-session {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid #2a2a2a;
}
#manageView .log-session:hover { background: #2a2a2a; }
#manageView .log-session.selected { background: #2d3a4f; }
#manageView .log-mode {
  width: 70px;
  padding: 2px 6px;
  border-radius: 3px;
  text-align: center;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#manageView .log-mode.task { background: #2d4030; color: #8eda8e; }
#manageView .log-mode.chat { background: #1e3a4a; color: #82b9d9; }
#manageView .log-mode.reconcile { background: #4a3a1e; color: #d9b682; }
#manageView .log-mode.arch-review { background: #3a2d4a; color: #c9a4e0; }
#manageView .log-mode.session { background: #333; color: #aaa; }
#manageView .log-meta { flex: 1; overflow: hidden; }
#manageView .log-file {
  color: #ddd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#manageView .log-stats { font-size: 10px; color: #777; }

#manageView .log-viewer {
  overflow: auto;
  padding: 16px;
  background: #161616;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.55;
}
/* Commit banner at top of a session log — links the session to its git commit(s) */
#manageView .log-commits {
  padding: 10px 12px;
  border-radius: 6px;
  background: #1c2433;
  border: 1px solid #2f3d52;
}
#manageView .log-commits-title {
  font-size: 11px;
  color: #8a94a6;
  margin-bottom: 6px;
}
#manageView .log-commits-title code {
  color: #8a94a6;
}
#manageView .log-commit {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 2px 0;
}
#manageView .log-commit code {
  flex: none;
  color: #6ea8fe;
  font-size: 12px;
}
#manageView .log-commit span {
  color: #cfd6e4;
  word-break: break-word;
}
/* Chat-style log entries: user (right, green) / assistant (left, blue) / action chip (left, dim) */
#manageView .log-bubble {
  padding: 8px 12px;
  border-radius: 6px;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 92%;
}
#manageView .log-bubble-user {
  background: #2d4030;
  color: #e0e0e0;
  align-self: flex-end;
  border: 1px solid #3d5040;
}
#manageView .log-bubble-assistant {
  background: #1e2a3a;
  color: #e0e0e0;
  align-self: flex-start;
  border: 1px solid #2a3a4f;
}
#manageView .log-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  background: #1f1f1f;
  border: 1px solid #333;
  color: #aaa;
  font-size: 11px;
  align-self: flex-start;
  max-width: 92%;
}
#manageView .log-chip-icon { font-size: 12px; }
#manageView .log-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Result panel rendered inline inside the chat (reconcile / task results).
 * Overrides the floating-panel styles below so it flows with chat bubbles
 * and survives scroll-back instead of being dismissable. */
#manageView .chat-messages .chat-msg-result {
  align-self: stretch;
  max-width: 100%;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  white-space: normal;
}
#manageView .chat-messages .reconcile-result-panel {
  position: static;
  top: auto;
  right: auto;
  width: auto;
  max-width: 100%;
  max-height: none;
  overflow: visible;
  box-shadow: none;
  z-index: auto;
}
#manageView .chat-messages .reconcile-result-panel .result-header {
  position: static;
  border-radius: 6px 6px 0 0;
}
#manageView .chat-messages .reconcile-result-panel .result-action-status {
  margin: 0 16px 14px;
  padding: 8px 12px;
  background: #1e3a1e;
  color: #8eda8e;
  border: 1px solid #2d5230;
  border-radius: 4px;
  font-size: 12px;
}

/* Reconcile result panel (floating variant retained for future use) */
.reconcile-result-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  overflow: auto;
  background: #1f1f1f;
  border: 1px solid #444;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
  z-index: 200;
  color: #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.reconcile-result-panel .result-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #333;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.reconcile-result-panel .result-header span.title { flex: 1; font-weight: 600; }
.reconcile-result-panel .result-header.success { background: #1e3a1e; color: #8eda8e; }
.reconcile-result-panel .result-header.info { background: #1e2a3a; color: #82b9d9; }
.reconcile-result-panel .result-header.warn { background: #3a2a1e; color: #ffa86b; }
.reconcile-result-panel .result-header .close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
}
.reconcile-result-panel .result-body {
  padding: 14px 16px;
  font-size: 12px;
}
.reconcile-result-panel .result-section { margin-bottom: 16px; }
.reconcile-result-panel .result-section:last-child { margin-bottom: 0; }
.reconcile-result-panel .result-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.reconcile-result-panel .result-commit {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.reconcile-result-panel .result-commit code {
  background: #2a2a2a;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  color: #4caf50;
}
.reconcile-result-panel .result-commit .subject {
  flex: 1;
  color: #ddd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.reconcile-result-panel .btn-revert {
  background: #5a2828;
  border: 1px solid #c44;
  color: #fff;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
}
.reconcile-result-panel .btn-revert:hover:not(:disabled) { background: #6a3030; }
.reconcile-result-panel .btn-revert:disabled { opacity: 0.5; cursor: not-allowed; }
.reconcile-result-panel .result-commit-body {
  margin-top: 8px;
  background: #161616;
  padding: 10px;
  border-radius: 4px;
  white-space: pre-wrap;
  color: #ccc;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  max-height: 240px;
  overflow: auto;
}
.reconcile-result-panel .result-export.success { color: #8eda8e; }
.reconcile-result-panel .result-export.warn { color: #ffa86b; }

.reconcile-result-panel .task-files {
  background: #161616;
  border-radius: 4px;
  padding: 8px 10px;
  max-height: 220px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
}
.reconcile-result-panel .task-file {
  display: flex;
  gap: 10px;
  padding: 2px 0;
  align-items: baseline;
}
.reconcile-result-panel .task-flag {
  width: 24px;
  flex-shrink: 0;
  font-weight: 600;
  text-align: center;
}
.reconcile-result-panel .task-file.mod .task-flag { color: #ffa86b; }
.reconcile-result-panel .task-file.new .task-flag { color: #8eda8e; }
.reconcile-result-panel .task-file.del .task-flag { color: #ff7373; }
.reconcile-result-panel .task-path { color: #ddd; word-break: break-all; }
.reconcile-result-panel .task-commit-msg {
  width: 100%;
  background: #161616;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
  box-sizing: border-box;
}
.reconcile-result-panel .task-commit-msg:focus { border-color: #4caf50; outline: none; }
.reconcile-result-panel .task-actions { display: flex; gap: 8px; }
.reconcile-result-panel .task-actions button {
  flex: 1;
  background: #2d4030;
  border: 1px solid #4caf50;
  color: #e0e0e0;
  padding: 7px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.reconcile-result-panel .task-actions button:hover:not(:disabled) { background: #3d5040; }
.reconcile-result-panel .task-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.reconcile-result-panel .task-actions .btn-task-stash { background: #2d3a4f; border-color: #4caf50; }
.reconcile-result-panel .task-actions .btn-task-stash:hover:not(:disabled) { background: #3d4a5f; }
.reconcile-result-panel .task-actions .btn-task-revert { background: #4a2828; border-color: #c44; }
.reconcile-result-panel .task-actions .btn-task-revert:hover:not(:disabled) { background: #5a3030; }
.reconcile-result-panel .result-summary {
  white-space: pre-wrap;
  color: #ddd;
  line-height: 1.55;
  background: #161616;
  padding: 10px;
  border-radius: 4px;
  max-height: 280px;
  overflow: auto;
}

/* Preview modal for file browser (renamed to avoid clash with main modal-overlay) */
.lab-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: pointer;
  padding: 20px;
}
.lab-preview-overlay .modal-content {
  max-width: 95vw;
  max-height: 95vh;
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lab-preview-overlay .modal-content img,
.lab-preview-overlay .modal-content video {
  max-width: 90vw;
  max-height: 85vh;
  display: block;
  background: #111;
}
.lab-preview-overlay .modal-content audio { width: min(600px, 90vw); }
.lab-preview-overlay .modal-content model-viewer {
  width: 90vw;
  height: 80vh;
  background: #111;
}
.lab-preview-overlay .modal-caption {
  color: #ccc;
  font-size: 13px;
  background: #1f1f1f;
  padding: 6px 12px;
  border-radius: 4px;
}
.lab-preview-overlay .modal-fallback {
  background: #1f1f1f;
  padding: 40px;
  color: #ccc;
  border-radius: 6px;
  text-align: center;
  min-width: 300px;
}
.lab-preview-overlay .modal-fallback a {
  color: #4caf50;
  text-decoration: none;
}
.lab-preview-overlay .modal-fallback a:hover { text-decoration: underline; }

#manageView .placeholder {
  text-align: center;
  color: #666;
  padding: 60px 20px;
  font-size: 13px;
  font-style: italic;
}

/* --- Right pane: chat --- */
#manageView .chat-messages {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: #1a1a1a;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#manageView .chat-msg {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 92%;
}
#manageView .chat-msg-user {
  background: #2d4030;
  color: #e0e0e0;
  align-self: flex-end;
  border: 1px solid #3d5040;
}
#manageView .chat-msg-assistant {
  background: #1e2a3a;
  color: #e0e0e0;
  align-self: flex-start;
  border: 1px solid #2a3a4f;
}
#manageView .chat-msg-tool {
  background: #2a2218;
  color: #ffb74d;
  align-self: flex-start;
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", monospace;
  border: 1px solid #4a3818;
}
#manageView .chat-msg-system {
  background: transparent;
  color: #888;
  align-self: center;
  font-size: 11px;
  font-style: italic;
}
#manageView .chat-msg-error {
  background: #3a1818;
  color: #f88;
  align-self: stretch;
  border: 1px solid #5a2828;
}

#manageView .chat-input {
  border-top: 1px solid #333;
  background: #252525;
  padding: 12px;
  flex-shrink: 0;
}

#manageView .chat-input textarea {
  width: 100%;
  background: #1a1a1a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
}
#manageView .chat-input textarea:focus { border-color: #4caf50; }
#manageView .chat-input textarea:disabled { opacity: 0.4; cursor: not-allowed; }

#manageView .chat-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

#manageView .chat-actions button {
  flex: 1;
  background: #2d4030;
  color: #e0e0e0;
  border: 1px solid #4caf50;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
#manageView .chat-actions button:hover:not(:disabled) { background: #3d5040; }
#manageView .chat-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

#manageView .btn-ask { background: #1e3a4a; border-color: #2196f3; }
#manageView .btn-ask:hover:not(:disabled) { background: #2a4a5a; }
#manageView .btn-readme { background: #3d2d3a; border-color: #c44a8c; }
#manageView .btn-readme:hover:not(:disabled) { background: #4d3d4a; }
#manageView .btn-arch { background: #2d2a4a; border-color: #8c4ac4; }
#manageView .btn-arch:hover:not(:disabled) { background: #3d3a5a; }

#manageView .btn-send-brief {
  background: #1e3a4a;
  border: 1px solid #4ca8c4;
  color: #cfe8ff;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
#manageView .btn-send-brief:hover { background: #2a4a5a; }
