/* AXE Command Centre */
:root {
  --bg: #191919;
  --surface: #1e1e1e;
  --surface-2: #252525;
  --surface-3: #2c2c2c;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --text: #e8e4e0;
  --text-2: #a8a29e;
  --text-3: #6b6560;
  --accent: #c9956b;
  --accent-dim: rgba(201,149,107,0.12);
  --green: #4ade80;
  --green-dim: rgba(74,222,128,0.1);
  --red: #f87171;
  --red-dim: rgba(248,113,113,0.1);
  --blue: #60a5fa;
  --blue-dim: rgba(96,165,250,0.1);
  --amber: #fbbf24;
  --amber-dim: rgba(251,191,36,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --r: 10px;
  --r-lg: 16px;
  --sidebar: 268px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

#app { display: flex; height: 100dvh; }

/* ═══ SIDEBAR ═══ */
#sidebar {
  width: var(--sidebar);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-header { padding: 20px 16px 16px; }

.brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 16px;
}

.brand {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 4px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.5px;
}

.new-task-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.new-task-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-hover);
}

.nav-group { padding: 8px 8px 4px; }

.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-3);
  padding: 8px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--r);
  transition: all 0.12s var(--ease);
  text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item svg { flex-shrink: 0; opacity: 0.6; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 6px;
  min-width: 24px;
  text-align: center;
}

/* Agents */
#agent-list { padding: 2px 0; }
.agent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 18px;
  font-size: 13px;
  color: var(--text-3);
  transition: color 0.15s;
}
.agent-row.online { color: var(--text-2); }

.agent-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--surface-3);
  flex-shrink: 0;
  transition: all 0.3s;
}
.agent-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px rgba(74,222,128,0.4);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
  transition: all 0.3s;
}
.conn-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px rgba(74,222,128,0.4);
}

.model-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  padding-left: 15px;
}

/* ═══ MAIN CONTENT ═══ */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.view.active { display: flex; }

/* ═══ FEED VIEW ═══ */
.view-inner {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.pulse-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pulse-card {
  background: var(--surface);
  padding: 16px 20px;
  text-align: center;
}

.pulse-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  transition: color 0.3s;
}

.pulse-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-top: 2px;
}

/* Fleet ticker card */
.pulse-fleet-ticker {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 12px 20px;
  text-align: left;
}

.pulse-fleet-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.pulse-fleet-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: all 0.3s;
}
.pulse-fleet-dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(74,222,128,0.4); }
.pulse-fleet-dot.warn { background: var(--amber); box-shadow: 0 0 8px rgba(251,191,36,0.3); }
.pulse-fleet-dot.bad { background: var(--red); box-shadow: 0 0 8px rgba(248,113,113,0.3); }

.pulse-fleet-pct {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.pulse-fleet-msg {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  animation: fadeMsg 0.3s var(--ease);
}

@keyframes fadeMsg {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.feed-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

#feed-entries {
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.feed-entry {
  padding: 14px 16px;
  margin-bottom: 6px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid transparent;
  animation: slideIn 0.2s var(--ease);
  transition: border-color 0.15s;
}
.feed-entry:hover { border-color: var(--border); }

.feed-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.feed-who {
  font-weight: 600;
  font-size: 13px;
}
.feed-who.system { color: var(--text-3); }
.feed-who.agent { color: var(--amber); }
.feed-who.commander { color: var(--accent); }
.feed-who.error { color: var(--red); }

.feed-tag {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
}
.feed-tag.fleet { background: var(--green-dim); color: var(--green); }
.feed-tag.memory { background: var(--blue-dim); color: var(--blue); }
.feed-tag.error { background: var(--red-dim); color: var(--red); }
.feed-tag.agent { background: var(--amber-dim); color: var(--amber); }
.feed-tag.task { background: var(--accent-dim); color: var(--accent); }
.feed-tag.dispatch { background: var(--amber-dim); color: var(--amber); }

.feed-ts {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

.feed-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}

/* ═══ COMPOSER ═══ */
.composer {
  padding: 8px 24px 16px;
  flex-shrink: 0;
}

.composer-box {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 6px 6px 6px 14px;
  transition: border-color 0.2s var(--ease);
}
.composer-box:focus-within { border-color: var(--accent); }

.composer-target {
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  font-family: var(--font);
  font-size: 14px;
  border: none;
  background: none;
  color: var(--text);
  outline: none;
  padding: 6px 4px;
  min-width: 0;
}
.composer-input::placeholder { color: var(--text-3); }

.composer-btns {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.composer-action {
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.composer-action:hover { background: var(--surface-2); color: var(--text-2); }

.composer-send {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s;
}
.composer-send:hover { opacity: 0.85; }

/* ═══ VIEW TOP BAR ═══ */
.view-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.view-top h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.view-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r);
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  padding: 8px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.12s;
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }

/* ═══ TASK CARDS ═══ */
.task-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  margin-bottom: 8px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid transparent;
  transition: all 0.15s var(--ease);
  cursor: default;
}
.task-card:hover { border-color: var(--border); background: var(--surface-2); }

.task-check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--text-3);
  flex-shrink: 0;
  margin-top: 1px;
  transition: all 0.15s;
}
.task-check.pending { border-color: var(--amber); }
.task-check.in_progress { border-color: var(--blue); background: var(--blue-dim); }
.task-check.done { border-color: var(--green); background: var(--green); }

.task-content { flex: 1; min-width: 0; }

.task-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
  line-height: 1.3;
}

.task-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.4;
  margin-bottom: 8px;
}

.task-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
}
.pill.high { background: var(--red-dim); color: var(--red); }
.pill.mid { background: var(--amber-dim); color: var(--amber); }
.pill.low { background: var(--blue-dim); color: var(--blue); }
.pill.status { background: var(--surface-3); color: var(--text-3); text-transform: uppercase; }
.pill.assignee { background: var(--accent-dim); color: var(--accent); }

/* ═══ MEMORY CARDS ═══ */
.memory-card {
  padding: 14px 18px;
  margin-bottom: 6px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid transparent;
  transition: all 0.15s var(--ease);
}
.memory-card:hover { border-color: var(--border); }

.memory-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.memory-type {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--blue-dim);
  color: var(--blue);
}

.memory-importance {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
}

.memory-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

.memory-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 6px;
  font-family: var(--mono);
}

.memory-stats-inline {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
}

/* ═══ FLEET ═══ */
.fleet-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.fleet-stat {
  padding: 20px;
  border-radius: var(--r);
  background: var(--surface);
  text-align: center;
}

.fleet-stat-val {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1px;
}
.fleet-stat-val.ok { color: var(--green); }
.fleet-stat-val.warn { color: var(--amber); }
.fleet-stat-val.bad { color: var(--red); }

.fleet-stat-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-top: 4px;
}

.fleet-node {
  margin-bottom: 20px;
}

.fleet-node-hdr {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.fleet-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fleet-dot.up { background: var(--green); box-shadow: 0 0 6px rgba(74,222,128,0.3); }
.fleet-dot.down { background: var(--red); }
.fleet-dot.degraded { background: var(--amber); }

.fleet-svc {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 3px;
  border-radius: var(--r);
  background: var(--surface);
  font-size: 13px;
  transition: background 0.12s;
}
.fleet-svc:hover { background: var(--surface-2); }

.fleet-svc-name { flex: 1; color: var(--text-2); }
.fleet-svc-lat {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-right: 14px;
}
.fleet-svc-up {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.fleet-svc-up.up { color: var(--green); background: var(--green-dim); }
.fleet-svc-up.down { color: var(--red); background: var(--red-dim); }

/* ═══ MODAL ═══ */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
  min-width: 420px;
  max-width: 520px;
  animation: modalIn 0.15s var(--ease);
}

.modal h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.modal-field { margin-bottom: 14px; }

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

.modal-field input,
.modal-field select,
.modal-field textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.modal-field input:focus,
.modal-field textarea:focus { border-color: var(--accent); }
.modal-field textarea { min-height: 80px; resize: vertical; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ═══ WELCOME SCREEN ═══ */
.feed-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px 40px;
  text-align: center;
  transition: opacity 0.3s var(--ease);
}
.feed-welcome.hidden { display: none; }

.welcome-logo {
  margin-bottom: 20px;
  opacity: 0.9;
}

.welcome-greeting {
  font-size: 32px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-3);
  margin-bottom: 32px;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
}

.welcome-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.welcome-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-hover);
}
.welcome-btn svg { opacity: 0.6; }
.welcome-btn:hover svg { opacity: 1; }

/* ═══ EMPTY STATE ═══ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }
.empty-text { font-size: 14px; }
.empty-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ═══ ANIMATIONS ═══ */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  #sidebar { width: 56px; }
  .sidebar-header { padding: 12px 8px; }
  .brand-sub, .nav-label, .nav-badge, .nav-item span:not(svg),
  #agent-list, .conn-status span:not(.conn-dot), .model-tag { display: none; }
  .brand { font-size: 14px; letter-spacing: 2px; }
  .new-task-btn span { display: none; }
  .new-task-btn { padding: 8px; justify-content: center; }
  .nav-item { justify-content: center; padding: 10px; }
  .pulse-bar { grid-template-columns: repeat(2, 1fr); }
  .view-body, .feed-scroll { padding: 12px 16px; }
  .composer { padding: 8px 12px 12px; }
  .view-top { padding: 16px; }
}
