/* ============================================================
   AI Agent Hub — Dashboard Styles
   Dark theme, sidebar layout, pipeline board
   ============================================================ */

/* ---------- Core variables ---------- */
:root {
  --bg: #0f1117;
  --surface: #161b27;
  --surface-2: #1c2333;
  --border: #1e2736;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-light: #a5b4fc;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --purple: #a78bfa;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --transition: 0.15s ease;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  border: none;
  border-radius: var(--radius);
  transition: opacity var(--transition), background var(--transition);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:hover:not(:disabled) { opacity: 0.88; }

input, textarea, select {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
textarea {
  min-height: 96px;
  line-height: 1.5;
  resize: vertical;
  overflow-y: hidden;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  caret-color: var(--accent-light);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

/* ---------- App shell ---------- */
#app { display: none; height: 100%; }
#app.visible { display: flex; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 18px 20px 14px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.sidebar-logo span { color: var(--accent-light); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  user-select: none;
  position: relative;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-light);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-item .nav-label { flex: 1; font-size: 13px; font-weight: 500; }

.nav-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

.nav-badge.yellow { background: var(--yellow); color: #000; }
.nav-badge.red    { background: var(--red); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn-logout {
  width: 100%;
  padding: 8px 14px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn-logout:hover { color: var(--text); border-color: var(--text-muted); }

/* ---------- Main layout ---------- */
.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-right var(--transition), width var(--transition);
}

#app.preview-open .main-area {
  margin-right: 50vw;
}

#app.preview-open .content,
#app.preview-open .view.active {
  min-width: 0;
  overflow-x: hidden;
}

#app.preview-open .pipeline-board {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#app.preview-open .review-item-header,
#app.preview-open .blocked-answer-row {
  flex-wrap: wrap;
}

#app.preview-open .review-item-actions {
  width: 100%;
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

.status-pill.idle {
  background: rgba(100, 116, 139, 0.12);
  color: var(--text-muted);
  border-color: rgba(100, 116, 139, 0.25);
}
.status-pill.idle .dot { background: var(--text-muted); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ---------- Content area ---------- */
.content {
  flex: 1;
  padding: 28px 28px 48px;
  overflow-y: auto;
  min-width: 0;
}

.view { display: none; }
.view.active { display: block; min-width: 0; }

/* ---------- Section headers ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.section-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.card + .card { margin-top: 10px; }

/* ---------- Upload zone ---------- */
.upload-section { margin-bottom: 32px; }

.upload-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.upload-row .field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 180px; }
.upload-row label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
  color: var(--text-muted);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
  color: var(--accent-light);
}

.upload-zone .upload-icon { font-size: 32px; margin-bottom: 8px; }
.upload-zone .upload-hint { font-size: 12px; margin-top: 6px; color: var(--text-muted); }
.upload-zone input[type="file"] { display: none; }
.upload-browse-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.upload-browse-btn { pointer-events: all; }

.upload-instructions-field {
  margin-top: 14px;
}

.upload-instructions-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.upload-instructions-field textarea {
  min-height: 96px;
  resize: vertical;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.btn-sm { padding: 6px 14px; font-size: 12px; font-weight: 600; }
.btn-green  { background: rgba(16,185,129,0.15); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.btn-red    { background: rgba(239,68,68,0.12); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-yellow { background: rgba(245,158,11,0.12); color: var(--yellow); border: 1px solid rgba(245,158,11,0.3); }
.btn-purple { background: rgba(167,139,250,0.12); color: var(--purple); border: 1px solid rgba(167,139,250,0.3); }
.btn-ghost  { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

.file-list { margin-top: 8px; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  margin: 3px 4px 3px 0;
  color: var(--text-muted);
}

/* ---------- Pipeline board ---------- */
.pipeline-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

@media (max-width: 900px) {
  .pipeline-board { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .pipeline-board { grid-template-columns: 1fr; }
}

.pipeline-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.pipeline-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pipeline-col-header .col-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.col-extracting .col-dot { background: var(--yellow); }
.col-building   .col-dot { background: var(--accent-light); }
.col-delivered  .col-dot { background: var(--green); }
.col-blocked    .col-dot { background: var(--red); }

.pipeline-col-body {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Project cards ---------- */
.project-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  transition: border-color var(--transition);
}

.project-card:hover { border-color: var(--accent); }

.project-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-card-client {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.progress-fill.extracting { background: var(--yellow); width: 20%; }
.progress-fill.planning   { background: var(--accent-light); width: 40%; }
.progress-fill.building   { background: var(--accent); width: 65%; }
.progress-fill.review     { background: var(--purple); width: 85%; }
.progress-fill.blocked    { background: var(--red); width: 50%; }
.progress-fill.delivered  { background: var(--green); width: 100%; }

.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.status-tag {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-extracting { background: rgba(245,158,11,0.15);  color: var(--yellow); }
.tag-planning   { background: rgba(165,180,252,0.15); color: var(--accent-light); }
.tag-building   { background: rgba(99,102,241,0.15);  color: var(--accent-light); }
.tag-review     { background: rgba(167,139,250,0.15); color: var(--purple); }
.tag-blocked    { background: rgba(239,68,68,0.15);   color: var(--red); }
.tag-delivered  { background: rgba(16,185,129,0.15);  color: var(--green); }
.tag-cancelled  { background: rgba(100,116,139,0.15); color: var(--text-muted); }

.cancel-confirm-row {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--red);
  margin-left: auto;
}

/* ---------- Review items ---------- */
.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  min-width: 0;
}

.review-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.review-item-title { font-size: 14px; font-weight: 600; }
.review-item-client { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.review-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

.review-feedback {
  margin-top: 10px;
  display: none;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.review-feedback.open { display: block; }

.review-feedback textarea {
  min-height: 112px;
  width: 100%;
  margin-bottom: 8px;
}

.review-feedback-actions {
  display: flex;
  justify-content: flex-end;
}

/* ---------- Blocked items ---------- */
.blocked-item {
  background: var(--surface);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}

.blocked-item-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.blocked-icon { font-size: 18px; margin-top: 1px; }

.blocked-item-title { font-size: 14px; font-weight: 600; }
.blocked-item-label {
  font-size: 12px;
  color: var(--text);
  margin-top: 4px;
  font-weight: 600;
}
.blocked-item-reason {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.blocked-item-resolution {
  font-size: 12px;
  color: var(--text);
  margin-top: 8px;
  line-height: 1.5;
}

.blocked-answer-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: flex-start;
}

.blocked-answer-row input { flex: 1; }

.blocked-system-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  align-items: center;
  justify-content: space-between;
}

.blocked-system-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

#app.preview-open .blocked-answer-row input {
  min-width: 0;
}

/* ---------- Projects table ---------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}

thead tr {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Settings ---------- */
.settings-section { max-width: 480px; margin-bottom: 32px; }

.settings-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.field-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 5px;
}

/* ---------- Login page ---------- */
#login-page {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

#login-page.visible { display: flex; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-form label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}

.btn-login {
  padding: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  margin-top: 6px;
}

.login-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  display: none;
}

.login-error.visible { display: block; }

/* ---------- Toast / snackbar ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: 320px;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#toast.success { border-color: rgba(16,185,129,0.4); color: var(--green); }
#toast.error   { border-color: rgba(239,68,68,0.4); color: var(--red); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Self-Improvement tab pills ---------- */
.tab-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 4px;
}

.tab-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.tab-pill:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Tab panes ---------- */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- Log viewer ---------- */
.log-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  max-height: 500px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Proposed improvement card ---------- */
.proposed-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.proposed-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.proposed-card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.proposed-card-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.proposed-card-body {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.proposed-card-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Pending model card ---------- */
.model-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.model-card-info { flex: 1; }
.model-card-name { font-weight: 600; font-size: 14px; color: var(--text); }
.model-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.model-card-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.model-card-status.approved { background: rgba(16,185,129,0.15); color: var(--green); }

.model-card-actions { display: flex; gap: 8px; }

/* ---------- Project detail view ---------- */
.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.detail-title-block { flex: 1; min-width: 0; }

.detail-client-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.detail-body {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .detail-body { grid-template-columns: 1fr; }
}

.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.activity-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  height: 480px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

.log-entry {
  display: flex;
  gap: 10px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

.log-entry:last-child { border-bottom: none; }

.log-entry.log-error { background: rgba(239,68,68,0.06); }
.log-entry.log-warn  { background: rgba(245,158,11,0.06); }

.log-ts {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 11px;
  padding-top: 1px;
}

.log-step {
  color: var(--accent-light);
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 11px;
  padding-top: 1px;
  min-width: 90px;
}

.log-msg { color: var(--text); word-break: break-word; }

.log-entry.log-error .log-msg { color: var(--red); }
.log-entry.log-warn  .log-msg { color: var(--yellow); }

/* btw log entries — cyan highlight */
.log-entry.log-btw {
  background: rgba(6, 182, 212, 0.06);
  border-left: 3px solid rgba(6, 182, 212, 0.5);
  padding-left: 10px;
}
.log-entry.log-btw .log-step { color: #06b6d4; }
.log-entry.log-btw .log-msg  { color: #a5f3fc; font-style: italic; }

/* /btw input row */
.btw-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
}

.btw-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  font-family: 'Courier New', monospace;
}

.btw-row input:focus {
  border-color: #06b6d4;
}

.btw-row input::placeholder { color: var(--text-muted); }

/* Agent status grid */
.agent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

.agent-tile {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 130px;
  flex: 1 1 130px;
  max-width: 200px;
}

.agent-tile.running { border-color: rgba(34,197,94,0.5); background: rgba(34,197,94,0.05); }
.agent-tile.done    { border-color: rgba(99,102,241,0.4); background: rgba(99,102,241,0.04); }
.agent-tile.error   { border-color: rgba(239,68,68,0.5);  background: rgba(239,68,68,0.05); }
.agent-tile.waiting { opacity: 0.45; }

.agent-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: #fff;
}

.agent-tile.running .agent-dot.running-dot {
  background: #22c55e;
  animation: agent-pulse 1.4s ease-in-out infinite;
}

.agent-tile.done .agent-dot.done-dot {
  background: #6366f1;
  font-size: 9px;
  width: 12px;
  height: 12px;
  margin-top: 2px;
}

.agent-tile.error .agent-dot.error-dot {
  background: #ef4444;
  font-size: 9px;
  width: 12px;
  height: 12px;
  margin-top: 2px;
}

@keyframes agent-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
  50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.agent-tile-body { min-width: 0; flex: 1; }

.agent-tile-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.agent-tile.running .agent-tile-name { color: #4ade80; }
.agent-tile.done    .agent-tile-name { color: #a5b4fc; }
.agent-tile.error   .agent-tile-name { color: #f87171; }

.agent-last-msg {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-refresh-ts {
  font-size: 11px;
  color: var(--text-muted);
}

.detail-steer-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.6;
}

.steer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.steer-send-status {
  font-size: 12px;
  color: var(--text-muted);
}

.steer-pending-box {
  margin-top: 14px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--yellow);
  line-height: 1.6;
  word-break: break-word;
}

.project-card.clickable { cursor: pointer; }
.project-card.clickable:hover { border-color: var(--accent); }

/* ---------- Discovery schedule card ---------- */
.schedule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.schedule-item-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.schedule-item-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Cancel confirmation modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 500;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal-dialog {
  background: var(--surface);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 14px;
  padding: 28px 28px 22px;
  width: 400px;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.modal-icon { font-size: 36px; margin-bottom: 12px; }

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.modal-body {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 22px;
  line-height: 1.6;
}

.modal-body strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 8px;
}

.modal-hint { font-size: 12px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- Deliverable preview modal ---------- */
#preview-modal {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: 50vw;
  background: transparent;
  z-index: 520;
  align-items: stretch;
  justify-content: flex-end;
  pointer-events: none;
  backdrop-filter: none;
}

#preview-modal.open { display: flex; }

#preview-modal .modal-dialog {
  width: 100%;
  max-width: none;
  max-height: none;
  height: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  border-color: var(--border);
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: -24px 0 48px rgba(0, 0, 0, 0.35);
}

.preview-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.preview-modal-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

#preview-modal-close {
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 4px 12px;
  font-size: 13px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.preview-modal-body {
  overflow-y: auto;
  padding: 20px 24px;
  flex: 1;
}

.preview-tab-pane.active { display: block; height: 100%; }

#preview-tab-files.active,
#preview-file-browser,
#preview-file-viewer {
  height: 100%;
}

#preview-file-browser {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-content {
  white-space: pre-wrap;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  overflow: auto;
  height: calc(100% - 48px);
}

.preview-modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.review-item-label {
  font-size: 11px;
  color: var(--green);
  margin-top: 3px;
  font-weight: 500;
}

/* ---------- Preview modal — tabs ---------- */
.preview-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-tab-pill {
  background: none;
  border: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.preview-tab-pill:hover { color: var(--text); }
.preview-tab-pill.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent);
}

.preview-tab-pane { display: none; }
/* ---------- Preview modal — rendered markdown ---------- */
.preview-md {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}
.preview-md h1 { font-size: 18px; font-weight: 700; margin: 0 0 12px; color: var(--text); }
.preview-md h2 { font-size: 15px; font-weight: 600; margin: 18px 0 8px; color: var(--text); }
.preview-md h3 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text); }
.preview-md p  { margin: 0 0 10px; }
.preview-md ul, .preview-md ol { margin: 0 0 10px 18px; }
.preview-md li { margin-bottom: 3px; }
.preview-md code {
  font-family: 'Consolas', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-light);
}
.preview-md pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 12px;
  overflow-x: auto;
}
.preview-md pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 12px;
}
.preview-md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.preview-md a { color: var(--accent-light); }
.preview-md strong { font-weight: 600; }
.preview-md em { font-style: italic; color: var(--text-muted); }
.preview-md blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

/* ---------- Preview modal — file browser ---------- */
.preview-file-list { display: flex; flex-direction: column; gap: 2px; }

.preview-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
}
.preview-file-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.preview-file-icon { font-size: 16px; flex-shrink: 0; }

.preview-file-info { flex: 1; min-width: 0; }
.preview-file-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-file-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.preview-file-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.badge-html     { background: rgba(239,68,68,.15);  color: #f87171; }
.badge-css      { background: rgba(99,102,241,.15); color: var(--accent-light); }
.badge-javascript { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-python   { background: rgba(16,185,129,.15); color: #34d399; }
.badge-markdown { background: rgba(100,116,139,.15); color: #94a3b8; }
.badge-json     { background: rgba(167,139,250,.15); color: var(--purple); }
.badge-csv      { background: rgba(16,185,129,.15); color: #34d399; }
.badge-text     { background: rgba(100,116,139,.15); color: #94a3b8; }
.badge-excel    { background: rgba(16,185,129,.15); color: #34d399; }
.badge-pdf      { background: rgba(239,68,68,.15);  color: #f87171; }

.preview-file-viewer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.preview-file-viewer-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  font-family: 'Consolas', monospace;
}

/* ---------- Preview modal — URL button ---------- */
.preview-url-btn {
  background: var(--surface-2);
  color: var(--accent-light);
  border: 1px solid var(--border);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  text-decoration: none;
  flex-shrink: 0;
}
.preview-url-btn:hover { opacity: 0.8; text-decoration: none; }

@media (max-width: 1100px) {
  #app.preview-open .main-area {
    margin-right: 0;
  }

  #preview-modal {
    width: 100vw;
  }

  #preview-modal .modal-dialog {
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  }
}

@media (max-width: 900px) {
  .review-item-header {
    flex-direction: column;
  }

  .review-item-actions {
    width: 100%;
  }
}
