:root {
  --bg: #0a0a0f;
  --bg-soft: #11121a;
  --bg-card: #15161f;
  --fg: #e6e7ee;
  --fg-dim: #8b8d9b;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --sidebar-w: 220px;
}

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

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 15% 5%, rgba(124, 92, 255, 0.15), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(34, 211, 238, 0.1), transparent 45%);
  z-index: -1;
  pointer-events: none;
}

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--fg-dim); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ============ AUTH PAGE ============ */
body.auth { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
}
.auth-card .brand { margin-bottom: 28px; }
.auth-card h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-card .sub { color: var(--fg-dim); font-size: 14px; margin-bottom: 24px; }
form label {
  display: block; font-size: 12px; color: var(--fg-dim);
  margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500;
}
form label span { display: block; margin-bottom: 6px; }
form input[type=password] {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--fg); padding: 12px 14px;
  font-family: inherit; font-size: 15px; outline: none;
  transition: border-color 0.15s ease;
}
form input[type=password]:focus { border-color: var(--accent); }

button {
  font-family: inherit; font-size: 14px; font-weight: 600;
  border-radius: 10px; padding: 11px 18px; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--fg);
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: linear-gradient(135deg, var(--accent) 0%, #5b3ef0 100%);
  border-color: transparent; color: white;
}
button.primary.small { padding: 8px 14px; font-size: 13px; }
button.ghost {
  background: transparent; border-color: var(--border);
  color: var(--fg-dim); font-size: 13px; padding: 8px 14px;
}
button.ghost:hover { color: var(--fg); border-color: var(--border-strong); }

form button[type=submit] {
  width: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, #5b3ef0 100%);
  border-color: transparent; color: white; padding: 13px; font-size: 15px;
}

.err {
  margin-top: 14px; padding: 10px 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5; border-radius: 8px; font-size: 13px;
}
.ok {
  margin-top: 14px; padding: 10px 12px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac; border-radius: 8px; font-size: 13px;
}
.back { display: inline-block; margin-top: 20px; color: var(--fg-dim); font-size: 13px; text-decoration: none; }
.back:hover { color: var(--fg); }

/* ============ DASHBOARD LAYOUT ============ */
body.dash { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 28px 20px;
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand { margin-bottom: 32px; }

.tabs { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.tab {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  color: var(--fg-dim); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--fg); background: rgba(255, 255, 255, 0.04); }
.tab.active {
  color: var(--fg);
  background: rgba(124, 92, 255, 0.18);
}
.tab.active .tab-ico { color: var(--accent); }
.tab-ico { color: var(--fg-dim); font-size: 14px; width: 16px; text-align: center; }

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding-top: 20px; border-top: 1px solid var(--border); }
.sidebar-footer button { width: 100%; text-align: left; }

.content {
  padding: 32px 40px 80px;
  overflow-x: hidden;
  min-width: 0;
}

.content-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px;
  gap: 16px; flex-wrap: wrap;
}

.content-header h1 {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
}

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

.tab-panel { animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.section-head h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

/* ============ HEALTH HERO ============ */
.hero-card {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.12), rgba(34, 211, 238, 0.05));
  border: 1px solid var(--border-strong);
  border-radius: 18px; padding: 28px; margin-bottom: 24px;
  display: grid; gap: 20px;
}
.health-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.health-pill {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-weight: 600; font-size: 15px;
}
.health-pill .pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--fg-dim); box-shadow: 0 0 0 0 currentColor;
  animation: pingdot 2s ease-in-out infinite;
}
@keyframes pingdot {
  0%   { box-shadow: 0 0 0 0 rgba(255,255,255,0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}
.health-pill[data-state=healthy] { border-color: rgba(34, 197, 94, 0.4); }
.health-pill[data-state=healthy] .pulse { background: var(--ok); color: var(--ok); }
.health-pill[data-state=degraded] { border-color: rgba(245, 158, 11, 0.4); }
.health-pill[data-state=degraded] .pulse { background: var(--warn); color: var(--warn); }
.health-pill[data-state=down] { border-color: rgba(239, 68, 68, 0.4); }
.health-pill[data-state=down] .pulse { background: var(--err); color: var(--err); }
.health-meta { font-size: 14px; }
.health-actions {
  display: flex; align-items: center; gap: 12px;
  padding-top: 14px; border-top: 1px solid var(--border);
}

/* ============ CARDS GRID ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 20px;
}
.card h3 {
  font-size: 12px; font-weight: 500; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px;
}
.card .kv { display: flex; flex-direction: column; gap: 6px; }
.card .kv .k {
  font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2;
}
.card .kv .sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--fg-dim);
}
.card .kv .ok   { color: var(--ok); }
.card .kv .warn { color: var(--warn); }
.card .kv .err  { color: var(--err); }

.card.wide { grid-column: 1 / -1; }

.tail {
  font-size: 12px; line-height: 1.7;
  color: var(--fg-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}

/* ============ CHANNELS ============ */
.channels-body { display: grid; gap: 16px; }
.chan-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 24px;
}
.chan-card h3 {
  font-size: 16px; font-weight: 600;
  margin-bottom: 18px;
  display: flex; align-items: center; gap: 10px;
}
.chan-card h3 .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.chan-card .rows { display: grid; grid-template-columns: 140px 1fr; gap: 8px 20px; font-size: 13px; }
.chan-card .rows dt { color: var(--fg-dim); }
.chan-card .rows dd { color: var(--fg); font-family: 'JetBrains Mono', monospace; word-break: break-all; }

/* ============ AGENTS ============ */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}
.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 22px;
  transition: border-color 0.15s ease;
}
.agent-card:hover { border-color: var(--border-strong); }
.agent-card .row1 {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.agent-card .name {
  font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
}
.agent-card .model-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.agent-card .model-pill[data-m=haiku]  { color: #67e8f9; border-color: rgba(103, 232, 249, 0.4); }
.agent-card .model-pill[data-m=sonnet] { color: #c4b5fd; border-color: rgba(196, 181, 253, 0.4); }
.agent-card .model-pill[data-m=opus]   { color: #fca5a5; border-color: rgba(252, 165, 165, 0.4); }
.agent-card .desc {
  font-size: 13px; color: var(--fg-dim); line-height: 1.55;
  margin-bottom: 12px;
}
.agent-card .meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--fg-dim);
}

/* ============ SKILLS ============ */
.skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.skill-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 22px;
  display: flex; flex-direction: column; gap: 10px;
}
.skill-card .row1 {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.skill-card .name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px; font-weight: 600;
  color: var(--fg);
}
.skill-card .name::before { content: '/'; color: var(--accent); }
.skill-card .sched {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--fg-dim);
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border);
}
.skill-card .desc { font-size: 13px; color: var(--fg-dim); line-height: 1.55; }
.skill-card .actions { margin-top: auto; padding-top: 4px; }
.skill-card .actions button { font-size: 12px; padding: 6px 14px; }
.skill-card .actions .run-ok  { color: var(--ok);  font-family: 'JetBrains Mono', monospace; font-size: 11px; margin-left: 8px; }
.skill-card .actions .run-err { color: var(--err); font-family: 'JetBrains Mono', monospace; font-size: 11px; margin-left: 8px; }

/* ============ CHAT ============ */
.chat-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  scroll-behavior: smooth;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  font-size: 14px;
  line-height: 1.5;
}
.chat-msg.in  { align-self: flex-start; }
.chat-msg.out { align-self: flex-end; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
}
.chat-msg.in  .chat-bubble {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.chat-msg.out .chat-bubble {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.22), rgba(91, 62, 240, 0.3));
  border: 1px solid rgba(124, 92, 255, 0.4);
  color: var(--fg);
  border-bottom-right-radius: 4px;
}
.chat-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--fg-dim);
  margin-top: 4px;
  padding: 0 6px;
}
.chat-msg.in  .chat-meta { text-align: left; }
.chat-msg.out .chat-meta { text-align: right; }
.chat-day {
  align-self: center;
  font-size: 11px;
  color: var(--fg-dim);
  font-family: 'JetBrains Mono', monospace;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  margin: 10px 0;
}

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 100; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 28px;
  width: 100%; max-width: 420px;
}
.modal-card h2 {
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 20px;
}
.modal-card form label {
  display: block; margin-bottom: 14px;
  font-size: 12px; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.modal-card form label span { display: block; margin-bottom: 6px; }
.modal-card form input[type=password] {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--fg); padding: 10px 12px;
  font-family: inherit; font-size: 14px; outline: none;
}
.modal-card form input[type=password]:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 820px) {
  body.dash { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; flex-wrap: wrap;
    padding: 16px 20px; gap: 12px;
  }
  .sidebar .brand { margin-bottom: 0; margin-right: auto; }
  .tabs { flex-direction: row; flex-wrap: wrap; width: 100%; gap: 2px; }
  .tab { padding: 8px 12px; font-size: 13px; }
  .sidebar-footer { flex-direction: row; border-top: 0; padding-top: 0; width: auto; }
  .content { padding: 24px 20px 60px; }
}
