:root {
  --bg: #0b0e14;
  --surface: #131823;
  --surface-2: #1a2130;
  --border: #263147;
  --text: #e6ecf5;
  --muted: #8b9bb4;
  --primary: #6366f1;
  --primary-hover: #7c7ff6;
  --accent: #06b6d4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

input, textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--primary); }

.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.pill-muted { background: var(--surface-2); color: var(--muted); }
.pill-ok { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.pill-warn { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.pill-accent { background: rgba(6, 182, 212, 0.15); color: #67e8f9; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 8px;
}

.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login-card form { display: grid; gap: 12px; }
.error-text { color: #fca5a5; font-size: 13px; margin-top: 10px; }

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 4px;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(99, 102, 241, 0.16); color: #c7d2fe; font-weight: 600; }

.sidebar-stats {
  margin-top: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.main-content {
  padding: 22px 26px;
  overflow-y: auto;
  max-height: 100vh;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.panel-header h2 { margin: 0 0 4px; font-size: 22px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.subtitle-sm { margin: 0 0 12px; color: var(--muted); font-size: 12px; }

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

.input-inline { width: auto; min-width: 170px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h3 { margin: 0 0 12px; font-size: 16px; }

.plaza-grid {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 16px;
  align-items: start;
}

.chat-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  min-height: 460px;
}

.messages-feed {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
  margin-bottom: 12px;
}

.msg-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
}

.msg-sender { font-weight: 700; color: var(--text); }
.msg-slug { color: var(--muted); }
.msg-time { margin-left: auto; color: var(--muted); font-size: 11px; }
.msg-body { white-space: pre-wrap; font-size: 14px; }

.chat-composer { display: grid; gap: 6px; }
.composer-row { display: flex; gap: 8px; }
.composer-row select { max-width: 210px; }
.hint { color: var(--muted); font-size: 11px; }

.inbox-card { max-height: calc(100vh - 140px); overflow-y: auto; }
.inbox-list { display: grid; gap: 8px; }
.inbox-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 12px;
}

.connect-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.copy-row { display: flex; gap: 6px; }

.instructions-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  margin-top: 8px;
}

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.agent-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.agent-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

.split-2 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.split-notes {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
}

.form-stack { display: grid; gap: 10px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.btn-row { display: flex; gap: 8px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.stack-list { display: grid; gap: 10px; max-height: 600px; overflow-y: auto; }
.list-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
}

.list-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-box {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h3 { margin: 0; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 60;
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .plaza-grid, .split-2, .split-notes, .connect-grid, .form-row-2, .form-row-3 {
    grid-template-columns: 1fr;
  }
}
