:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --text: #e7ecf3;
  --muted: #8b98a8;
  --accent: #2aabee;
  --accent2: #7c5cff;
  --ok: #3ddc84;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button,
input,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: 100vh;
  max-height: 100dvh;
}

.sidebar,
.right-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.right-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

.brand {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.max-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.max-gate-card {
  max-width: 360px;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  text-align: center;
}

.max-gate-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, #5b8def, #7c5cff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.max-gate-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.max-gate-card ol {
  text-align: left;
  margin: 16px 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
}

.max-gate-muted {
  font-size: 12px;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.nav-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
}

.nav-tab.active {
  background: var(--panel2);
  color: var(--text);
}

.chat-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.agent-cmds {
  font-size: 11px;
  color: var(--accent);
  margin: 0 0 8px !important;
}

body.max-only.embed-mode .app {
  grid-template-columns: 240px 1fr;
}

body.max-only.embed-mode .sidebar {
  display: flex;
}

@media (max-width: 640px) {
  body.max-only.embed-mode .app {
    grid-template-columns: 1fr;
  }
  body.max-only.embed-mode .sidebar {
    max-height: 42vh;
  }
}

.mode-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(42, 171, 238, 0.15);
  color: var(--accent);
}

.chat-list,
.agent-list {
  overflow: auto;
  padding: 8px;
  flex: 1;
}

.chat-item,
.agent-card {
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 6px;
  background: transparent;
  border: 1px solid transparent;
}

.chat-item.active,
.agent-card:hover {
  background: var(--panel2);
  border-color: var(--border);
}

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

.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.8);
  backdrop-filter: blur(8px);
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.me {
  align-self: flex-end;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  color: #fff;
}

.msg.them,
.msg.agent {
  align-self: flex-start;
  background: var(--panel2);
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  max-width: 100%;
}

.msg .from {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.composer input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 16px;
}

.composer button,
.btn {
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
}

.composer button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.panel-title {
  padding: 14px 16px 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.agent-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.agent-card p {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.btn-small {
  font-size: 12px;
  padding: 6px 10px;
}

.sbp-box {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}

.sbp-box input {
  width: 100%;
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.sbp-result {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--panel2);
  font-size: 12px;
  word-break: break-all;
}

.sbp-result a {
  color: var(--ok);
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar,
  .right-panel {
    display: none;
  }
}

body.embed-mode .sidebar {
  display: none;
}

body.embed-mode .app {
  grid-template-columns: 1fr 260px;
}

body.embed-mode .right-panel {
  display: flex;
}
