:root {
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-card: #1f2b47;
  --bg-hover: #253555;
  --text: #e0e0e0;
  --text-muted: #8892a4;
  --text-dim: #5a6577;
  --accent: #4fc3f7;
  --green: #66bb6a;
  --red: #ef5350;
  --yellow: #ffa726;
  --purple: #ab47bc;
  --gray: #78909c;
  --border: #2a3a55;
  --radius: 6px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Consolas', 'Monaco', 'Lucida Console', 'Courier New', monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* Auth overlay */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 300px;
}

.auth-box h2 {
  font-size: 16px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}

.auth-box input[type="password"] {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-box input[type="password"]:focus {
  border-color: var(--accent);
}

.auth-box button {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  transition: opacity 0.15s;
}

.auth-box button:hover {
  opacity: 0.85;
}

/* App layout */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#search {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  padding: 6px 10px;
  width: 100%;
  transition: border-color 0.15s;
}

#search:focus {
  border-color: var(--accent);
}

#project-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

#project-list::-webkit-scrollbar {
  width: 4px;
}

#project-list::-webkit-scrollbar-track {
  background: transparent;
}

#project-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.section-label {
  color: var(--text-dim);
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 10px 12px 4px;
  text-transform: uppercase;
  user-select: none;
}

.project-row {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 6px;
  padding: 6px 10px 6px 12px;
  transition: background 0.1s;
  user-select: none;
}

.project-row:hover {
  background: var(--bg-hover);
}

.project-row.selected {
  background: var(--bg-hover);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}

.project-name {
  color: var(--text);
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-row.deprioritized .project-name {
  color: var(--text-dim);
}

/* Status dot */
.status-dot {
  border-radius: 50%;
  flex-shrink: 0;
  height: 7px;
  width: 7px;
}

.status-dot.active { background: var(--green); }
.status-dot.idle { background: var(--gray); }
.status-dot.blocked { background: var(--red); }
.status-dot.waiting_human { background: var(--yellow); }
.status-dot.training,
.status-dot.processing { background: var(--purple); }
.status-dot.no-session {
  background: transparent;
  border: 2px solid var(--text-dim);
  width: 6px;
  height: 6px;
}
.status-dot.unknown { background: var(--text-dim); }

/* Needs-human icon */
.needs-human-icon {
  color: var(--yellow);
  flex-shrink: 0;
  font-size: 11px;
}

/* Priority button */
.priority-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1;
  padding: 2px 3px;
  transition: color 0.15s;
}

.priority-btn:hover {
  color: var(--accent);
}

/* Main view */
#main-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  font-size: 14px;
}

#main-view::-webkit-scrollbar {
  width: 6px;
}

#main-view::-webkit-scrollbar-track {
  background: transparent;
}

#main-view::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.empty-state {
  align-items: center;
  color: var(--text-dim);
  display: flex;
  height: 60vh;
  justify-content: center;
}

/* Project header */
#project-header {
  margin-bottom: 16px;
}

#project-header h1 {
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.goal-line {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.meta-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-badge {
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  text-transform: uppercase;
}

.status-badge.active { background: rgba(102, 187, 106, 0.15); color: var(--green); }
.status-badge.idle { background: rgba(120, 144, 156, 0.15); color: var(--gray); }
.status-badge.blocked { background: rgba(239, 83, 80, 0.15); color: var(--red); }
.status-badge.waiting_human { background: rgba(255, 167, 38, 0.15); color: var(--yellow); }
.status-badge.training,
.status-badge.processing { background: rgba(171, 71, 188, 0.15); color: var(--purple); }
.status-badge.unknown { background: rgba(90, 101, 119, 0.15); color: var(--text-dim); }

.meta-pill {
  color: var(--text-dim);
  font-size: 11px;
}

.meta-pill span {
  color: var(--text-muted);
}

.current-task {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
}

.current-task em {
  color: var(--text);
  font-style: normal;
}

/* Question panel */
#question-panel {
  margin-bottom: 16px;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.question-label {
  color: var(--yellow);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.question-text {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 4px;
}

.question-context {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 12px;
}

.suggestion-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.suggestion-btn {
  background: rgba(255, 167, 38, 0.1);
  border: 1px solid rgba(255, 167, 38, 0.3);
  border-radius: var(--radius);
  color: var(--yellow);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  transition: background 0.15s;
}

.suggestion-btn:hover {
  background: rgba(255, 167, 38, 0.2);
}

.custom-input-row {
  display: flex;
  gap: 8px;
}

.custom-input-row input[type="text"] {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  padding: 6px 10px;
  transition: border-color 0.15s;
}

.custom-input-row input[type="text"]:focus {
  border-color: var(--yellow);
}

.send-btn {
  background: none;
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  color: var(--yellow);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 14px;
  transition: background 0.15s, color 0.15s;
}

.send-btn:hover {
  background: var(--yellow);
  color: #000;
}

/* Idle controls */
#idle-controls {
  margin-bottom: 16px;
}

.idle-btn-row {
  display: flex;
  gap: 8px;
}

.idle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 14px;
  transition: border-color 0.15s, color 0.15s;
}

.idle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.idle-send-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
  min-width: 120px;
}

.idle-send-input:focus {
  border-color: var(--accent);
  outline: none;
}

.idle-btn-send {
  border-color: var(--accent);
  color: var(--accent);
}

/* Last agent message */
.last-message-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 10px;
}

.last-message-summary {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.last-message-summary::before {
  content: '\25B6 ';
  font-size: 10px;
  color: var(--text-dim);
}

.last-message-summary.expanded::before {
  content: '\25BC ';
}

.last-message-full {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.5;
}

/* View toggle */
.view-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
}

.view-toggle button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 4px 14px;
  transition: background 0.1s, color 0.1s;
}

.view-toggle button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.view-toggle button:last-child {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.view-toggle button.active {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}

/* Task tree */
#task-container {
  padding-bottom: 40px;
}

.task-list {
  list-style: none;
}

.task-list .task-list {
  margin-left: 20px;
  margin-top: 2px;
}

.task-item {
  margin-bottom: 2px;
}

.task-line {
  align-items: center;
  border-radius: var(--radius);
  display: flex;
  gap: 6px;
  padding: 3px 6px;
  transition: background 0.1s;
}

.task-line:hover {
  background: var(--bg-hover);
}

.task-status-icon {
  flex-shrink: 0;
  font-size: 13px;
  width: 16px;
  text-align: center;
}

.task-name {
  color: var(--text);
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
}

.task-name.done {
  color: var(--text-dim);
  text-decoration: line-through;
}

.task-name.blocked {
  color: var(--red);
}

.task-name.pending {
  color: var(--text-muted);
}

/* HPC badge */
.hpc-badge {
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 10px;
  padding: 1px 5px;
}

/* Link icon */
.link-icon-wrap {
  flex-shrink: 0;
  position: relative;
}

.link-icon {
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  text-decoration: none;
  transition: color 0.15s;
}

.link-icon:hover {
  color: var(--accent);
}

.new-dot {
  background: var(--red);
  border-radius: 50%;
  height: 5px;
  position: absolute;
  right: -2px;
  top: -2px;
  width: 5px;
}

/* [do] button */
.do-btn {
  background: none;
  border: 1px solid var(--green);
  border-radius: 3px;
  color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  font-size: 11px;
  padding: 1px 7px;
  transition: background 0.15s, color 0.15s;
}

.do-btn:hover {
  background: var(--green);
  color: #000;
}

/* Next step section */
.next-steps-section {
  margin-top: 16px;
}

.next-steps-label {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.next-step-line {
  align-items: flex-start;
  color: var(--text-muted);
  display: flex;
  font-size: 12px;
  gap: 6px;
  line-height: 1.5;
  padding: 2px 6px;
}

.next-step-arrow {
  color: var(--text-dim);
  flex-shrink: 0;
}

.next-step-text {
  color: var(--text-muted);
  flex: 1;
}

.next-step-do {
  flex-shrink: 0;
}

/* Flat view sections */
.flat-section-label {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
}

/* Confirmation overlay */
#confirm-overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 500;
}

.confirm-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  padding: 20px 24px;
  width: 90%;
}

.confirm-box h3 {
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
}

.confirm-preview {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 16px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.confirm-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-cancel {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 16px;
  transition: border-color 0.15s;
}

.confirm-cancel:hover {
  border-color: var(--text-muted);
}

.confirm-send {
  background: none;
  border: 1px solid var(--green);
  border-radius: var(--radius);
  color: var(--green);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 16px;
  transition: background 0.15s, color 0.15s;
}

.confirm-send:hover {
  background: var(--green);
  color: #000;
}

/* Mobile */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  #main-view {
    padding: 14px 16px;
  }
}
