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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --green: #4ecca3;
  --yellow: #f0c040;
  --text: #eaeaea;
  --text-dim: #a0a0b0;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Login page ─────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-box h1 { margin-bottom: 8px; font-size: 1.5rem; }
.login-box .subtitle { color: var(--text-dim); margin-bottom: 24px; font-size: 0.9rem; }

.login-box input {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}

.login-box button:hover { opacity: 0.9; }
.error { color: var(--accent); margin-top: 12px; font-size: 0.85rem; }

/* ─── Layout ─────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 200px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  border-right: 1px solid var(--surface2);
}

.sidebar-header { padding: 0 20px 20px; border-bottom: 1px solid var(--surface2); }
.sidebar-header h2 { font-size: 1.1rem; }

.nav-list { list-style: none; padding: 12px 0; flex: 1; }
.nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--green); border-left: 3px solid var(--green); }

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--surface2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

.content {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

/* ─── Pages ──────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }
.page h1 { margin-bottom: 20px; font-size: 1.4rem; }

/* ─── Status grid ────────────────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.card-label { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }
.card-value { font-size: 1.2rem; font-weight: 600; }

/* ─── Action bar ─────────────────────────────────────────── */
.action-bar { margin-bottom: 24px; display: flex; gap: 12px; }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-warning { background: var(--yellow); color: #1a1a2e; }
.btn-success { background: var(--green); color: #1a1a2e; }
.btn-primary { background: var(--accent); color: white; }
.btn-small { background: var(--surface2); color: var(--text); border: none; padding: 6px 12px; border-radius: var(--radius); cursor: pointer; font-size: 0.8rem; }
.btn-small:hover { opacity: 0.8; }

/* ─── Message feed ───────────────────────────────────────── */
.section h2 { font-size: 1rem; margin-bottom: 12px; color: var(--text-dim); }

.message-feed {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--surface2);
}

.msg-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.85rem;
}
.msg-item:last-child { border-bottom: none; }
.msg-item .msg-meta { color: var(--text-dim); font-size: 0.75rem; }
.msg-item .msg-text { margin-top: 4px; }
.msg-in { border-left: 3px solid var(--green); padding-left: 8px; }
.msg-out { border-left: 3px solid var(--accent); padding-left: 8px; }

.empty { color: var(--text-dim); font-size: 0.85rem; }

/* ─── Chat list ──────────────────────────────────────────── */
.chat-list { display: flex; flex-direction: column; gap: 8px; }

.chat-row {
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--surface2);
  cursor: pointer;
}
.chat-row:hover { border-color: var(--green); }
.chat-row .chat-info { flex: 1; }
.chat-row .chat-id { font-weight: 500; font-size: 0.9rem; }
.chat-row .chat-last { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }
.chat-row .chat-actions { display: flex; gap: 8px; }
.chat-row.taken-over { border-color: var(--yellow); }

/* ─── Chat detail ────────────────────────────────────────── */
.chat-detail {
  margin-top: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--surface2);
}
.chat-detail.hidden { display: none; }
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.detail-messages { max-height: 400px; overflow-y: auto; }

/* ─── AllowList ──────────────────────────────────────────── */
.add-form { display: flex; gap: 12px; margin-bottom: 20px; }
.add-form input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.allowlist-table { display: flex; flex-direction: column; gap: 8px; }
.allowlist-row {
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--surface2);
}
.allowlist-row .number { font-family: monospace; font-size: 0.95rem; }

/* ─── Toast ──────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-info { background: var(--surface2); color: var(--text); }
.toast-error { background: var(--accent); color: white; }
.toast-success { background: var(--green); color: #1a1a2e; }

/* ─── Connection indicator ───────────────────────────────── */
.conn-indicator {
  position: fixed;
  top: 12px;
  right: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  background: var(--green);
  color: #1a1a2e;
}
.conn-indicator.disconnected { background: var(--accent); color: white; }
