:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --text: #e8eef7;
  --muted: #93a4bb;
  --accent: #4f8cff;
  --success: #3ecf8e;
  --danger: #ff6b6b;
  --border: #2f3f57;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #121a24;
}
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }

.status-cards { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.auto-send-toggle.active {
  background: #2f855a;
  border-color: #2f855a;
  color: #fff;
}
.auto-send-toggle:not(.active) {
  background: var(--panel-2);
  color: var(--muted);
}
.ai-mode-toggle.agentic {
  background: #6b46c1;
  border-color: #6b46c1;
  color: #fff;
}
.ai-mode-toggle:not(.agentic) {
  background: var(--panel-2);
  color: var(--muted);
}

.ai-panel {
  margin: 1rem 1rem 0;
  padding: 0.85rem 1rem;
}
.ai-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.ai-prompt {
  flex: 1;
  min-width: 180px;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.95rem;
}
.ai-mode-label {
  color: var(--muted);
  font-size: 0.8rem;
}
.stt-mic {
  min-width: 2.5rem;
  padding: 0.55rem 0.65rem;
  font-size: 1.1rem;
  line-height: 1;
}
.stt-mic.recording {
  background: #9b2c2c;
  border-color: #fc8181;
  animation: stt-pulse 1s ease-in-out infinite;
}
@keyframes stt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}
.stt-hint {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.stt-hint:empty { display: none; }
.ai-result {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 120px;
  overflow: auto;
}
.ai-result.hidden { display: none; }
.ai-result .reasoning { color: var(--muted); margin-top: 0.35rem; }

.ai-log-head {
  margin-top: 0.85rem;
  margin-bottom: 0.4rem;
}
.ai-log-head h3 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.ai-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.ai-log-list li {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.45;
}
.ai-log-list li:last-child { border-bottom: none; }
.ai-log-list .kind {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  margin-left: 0.35rem;
}
.ai-log-list .kind-ai_tx { background: #2c5282; color: #bee3f8; }
.ai-log-list .kind-ai_rx { background: #276749; color: #c6f6d5; }
.ai-log-list .kind-ai_ok { background: #2f855a; color: #c6f6d5; }
.ai-log-list .kind-ai_err { background: #9b2c2c; color: #fed7d7; }
.mode-badge {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: normal;
}
.scenario-list .empty-msg { color: var(--muted); font-size: 0.85rem; padding: 0.5rem; }
.ai-log-list .meta-line { color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; }
.ai-log-list .ts { color: var(--muted); font-size: 0.68rem; float: left; }

.card .card-sub { font-size: 0.75rem; color: var(--muted); margin-right: 0.25rem; }
.card.train-ready { border-color: var(--success); }
.card.train-ready strong { color: var(--success); }

.training-panel {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.training-stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
}
.training-stat span { color: var(--muted); }
#btnFeedbackUp.active { background: #2f855a; border-color: #2f855a; color: #fff; }
#btnFeedbackDown.active { background: #9b2c2c; border-color: #9b2c2c; color: #fff; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  min-width: 110px;
}
.card .label { display: block; color: var(--muted); font-size: 0.75rem; }
.card strong { font-size: 1.1rem; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 90px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.panel-head h2 { margin: 0; font-size: 1rem; }

.sidebar, .sideinfo { overflow-y: auto; }
.list-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.list-tab {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
}
.list-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.sidebar-pane { display: none; }
.sidebar-pane.active { display: block; }
.meta-form .field-ai[hidden],
.meta-form .field-manual[hidden] { display: none; }

.editor { display: flex; flex-direction: column; min-height: 0; }

.search {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.scenario-list, .robot-list, .activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.scenario-list li {
  padding: 0.65rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.35rem;
}
.scenario-list li:hover { background: var(--panel-2); }
.scenario-list li.active {
  border-color: var(--accent);
  background: #1e2a3d;
}
.scenario-list .id { color: var(--accent); font-size: 0.8rem; }
.scenario-list .intent { font-size: 0.9rem; margin-top: 0.15rem; }
.scenario-list .meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.success { background: #2f855a; border-color: #2f855a; }
.btn.danger { background: #9b2c2c; border-color: #9b2c2c; }

.meta-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.meta-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.meta-form input {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.tabs { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}
.tab.active { color: var(--text); border-color: var(--accent); background: #1e2a3d; }

.tab-pane { display: none; flex: 1; min-height: 0; }
.tab-pane.active { display: flex; flex-direction: column; gap: 0.6rem; }

.builder-toolbar { display: flex; gap: 0.5rem; }
.table-wrap { overflow: auto; flex: 1; border: 1px solid var(--border); border-radius: 8px; }
.events-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.events-table th, .events-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.45rem;
  text-align: right;
  vertical-align: top;
}
.events-table th { background: var(--panel-2); position: sticky; top: 0; }
.events-table input, .events-table select {
  width: 100%;
  min-width: 70px;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #162131;
  color: var(--text);
}
.ap-fields { display: grid; gap: 0.35rem; }

#jsonEditor {
  flex: 1;
  min-height: 320px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101722;
  color: #d7e3f4;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  padding: 0.75rem;
  direction: ltr;
  text-align: left;
}

.robot-list li, .activity-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
}
.robot-list .online { color: var(--success); }
.robot-list .offline { color: var(--danger); }
.activity-list .kind {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
  margin-left: 0.35rem;
}
.activity-list .msg { margin-top: 0.25rem; }
.activity-list .ts { color: var(--muted); font-size: 0.72rem; }

.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2a3b;
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 100;
}
.toast.hidden { display: none; }
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .meta-form { grid-template-columns: 1fr; }
}
