/* ══════════════════════════════════════════════════════════════
   Prometheus Agent - Control Panel Styles
   Dark theme, responsive, Director(blue)/Executor(green)/Gemini(orange)
   ══════════════════════════════════════════════════════════════ */

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

:root {
  --bg:       #0b0e14;
  --bg2:      #131720;
  --bg3:      #1a1f2e;
  --bg4:      #222838;
  --border:   #2a3040;
  --text:     #e2e8f0;
  --text2:    #94a3b8;
  --text3:    #4a5568;
  --accent:   #7c6af7;

  /* 三角色颜色 */
  --director: #60a5fa;
  --executor: #4ade80;
  --gemini:   #fb923c;

  --success:  #4ade80;
  --warn:     #facc15;
  --error:    #f87171;
  --info:     #60a5fa;

  --radius:   8px;
  --radius-lg:12px;
}

body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ── 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(--text3); }

/* ══ Header ══ */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.logo {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--director), var(--accent));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.header-title h1 {
  font-size: 16px; font-weight: 700; line-height: 1.2;
}
.header-title .subtitle {
  font-size: 11px; color: var(--text3);
}

.header-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 12px;
}

.conn-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text2);
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--error);
  transition: background 0.3s;
  flex-shrink: 0;
}
.dot.connected { background: var(--success); }
.dot.thinking  { background: var(--warn); animation: pulse 1s infinite; }

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

/* ══ Main Container ══ */
.main-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ══ Section Shared ══ */
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

/* ══ Task Input ══ */
.task-input-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-row textarea {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  min-height: 42px;
  max-height: 120px;
}
.input-row textarea:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-secondary {
  background: var(--bg4);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger {
  background: var(--error);
  color: #fff;
}

.hidden { display: none !important; }

.intervene-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.intervene-row input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.intervene-row input:focus {
  border-color: var(--accent);
}

/* ══ Panels Row ══ */
.panels-row {
  display: flex;
  gap: 14px;
  min-height: 0;
  flex: 1;
}

/* ── Execution Panel ── */
.exec-panel {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}

.exec-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  max-height: 50vh;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text3);
}
.empty-icon { margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }
.empty-hint { font-size: 12px; margin-top: 4px; color: var(--text3); }

/* ─ 执行轮次卡片 ─ */
.round-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.round-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg4);
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  cursor: pointer;
  user-select: none;
}
.round-header:hover { background: var(--bg3); }
.round-header .round-num {
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

.round-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ─ 角色区块 ─ */
.role-block {
  border-left: 3px solid var(--border);
  padding: 8px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg3);
  font-size: 13px;
}
.role-block.director {
  border-left-color: var(--director);
}
.role-block.executor {
  border-left-color: var(--executor);
}
.role-block.gemini {
  border-left-color: var(--gemini);
}

.role-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.role-label.director { color: var(--director); }
.role-label.executor { color: var(--executor); }
.role-label.gemini   { color: var(--gemini); }

.role-content {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─ 工具调用卡片（执行面板内） ─ */
.tool-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 4px 0;
  font-size: 12px;
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
}
.tool-card-header:hover { background: var(--bg3); }

.tool-name {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: var(--executor);
  font-weight: 600;
}
.tool-status-icon { font-size: 14px; }
.tool-status-icon.ok { color: var(--success); }
.tool-status-icon.fail { color: var(--error); }
.tool-status-icon.running { color: var(--warn); animation: pulse 1s infinite; }
.tool-duration {
  margin-left: auto;
  color: var(--text3);
  font-size: 11px;
}

.tool-card-body {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  display: none;
}
.tool-card-body.open { display: block; }

.tool-detail-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 2px;
}
.tool-detail-content {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 150px;
  overflow-y: auto;
  background: var(--bg2);
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}

/* ─ Gemini 评估区块 ─ */
.gemini-score {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 14px;
}
.gemini-score.approved { color: var(--success); }
.gemini-score.continue { color: var(--warn); }

/* ── Status Panel ── */
.status-panel {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}
.status-item + .status-item {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.status-label {
  font-size: 12px;
  color: var(--text2);
}
.status-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.status-sub-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.current-step {
  font-size: 13px;
  color: var(--text2);
  padding: 6px 0;
}

/* 进度条 */
.progress-bar {
  height: 8px;
  background: var(--bg4);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--director));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.progress-text {
  font-size: 11px;
  color: var(--text3);
  text-align: right;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-idle    { background: var(--bg4); color: var(--text3); }
.badge-running { background: rgba(96,165,250,0.15); color: var(--director); }
.badge-done    { background: rgba(74,222,128,0.15); color: var(--success); }
.badge-error   { background: rgba(248,113,113,0.15); color: var(--error); }

/* History list */
.history-list {
  max-height: 150px;
  overflow-y: auto;
}
.history-item {
  padding: 6px 0;
  font-size: 12px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.history-item:hover { color: var(--text); }
.history-item:last-child { border-bottom: none; }
.history-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ══ Tool Call Log Section ══ */
.tool-log-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.log-filters {
  display: flex; gap: 4px;
}

.filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text3);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text2); border-color: var(--text3); }
.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tool-log-scroll {
  max-height: 200px;
  overflow-y: auto;
}

.tool-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tool-log-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg2);
}
.tool-log-table td {
  padding: 6px 8px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tool-log-table tr:hover td {
  background: var(--bg3);
  color: var(--text);
}
.tool-log-table .status-ok { color: var(--success); }
.tool-log-table .status-fail { color: var(--error); }
.tool-log-table .status-pending { color: var(--warn); }

.tool-args {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 11px;
}

/* ══ Result Section ══ */
.result-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.result-content {
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
  overflow-y: auto;
  max-height: 400px;
}

/* Markdown 渲染 */
.result-content h1, .result-content h2, .result-content h3 {
  margin: 12px 0 6px;
  color: var(--text);
}
.result-content p { margin: 6px 0; }
.result-content code {
  background: var(--bg4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 13px;
}
.result-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.result-content pre code {
  background: transparent;
  padding: 0;
}
.result-content ul, .result-content ol {
  padding-left: 20px;
  margin: 6px 0;
}
.result-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text2);
}
.result-content a {
  color: var(--director);
  text-decoration: none;
}
.result-content a:hover {
  text-decoration: underline;
}

/* ══ Dialog Overlay ══ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.dialog-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: 90%;
}

.dialog-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.dialog-body {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.dialog-input-row {
  display: flex;
  gap: 8px;
}
.dialog-input-row input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}
.dialog-input-row input:focus {
  border-color: var(--accent);
}

/* ══ Animations ══ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.round-card { animation: fadeIn 0.25s ease-out; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
.role-block { animation: slideIn 0.2s ease-out; }

/* streaming cursor */
.streaming::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }

/* ══ Responsive ══ */
@media (max-width: 768px) {
  header { padding: 8px 14px; }
  .header-title .subtitle { display: none; }

  .main-container { padding: 10px 12px; gap: 10px; }

  .panels-row {
    flex-direction: column;
  }

  .status-panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .status-card {
    flex: 1;
    min-width: 140px;
  }

  .exec-scroll {
    max-height: 40vh;
  }

  .tool-args { max-width: 120px; }

  .dialog-box {
    margin: 20px;
  }
}

@media (max-width: 480px) {
  .status-panel {
    flex-direction: column;
  }
  .status-card {
    min-width: unset;
  }
}
