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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3250;
  --accent: #5b6af0;
  --accent-hover: #4a57d4;
  --text: #e2e4f0;
  --text-muted: #7b80a0;
  --success: #3ecf8e;
  --danger: #f56565;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="url"] {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-full { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}
.btn-danger:hover { background: rgba(245,101,101,0.1); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

/* ── Header ── */
.header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.header-logo span {
  color: var(--accent);
  margin-right: 6px;
}

/* ── Dashboard layout ── */
.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 17px;
  font-weight: 600;
}

/* ── Connection cards ── */
.connections-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.conn-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.conn-header {
  padding: 16px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.conn-info { flex: 1; min-width: 0; }

.conn-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn-username {
  font-size: 13px;
  color: var(--accent);
  margin-top: 2px;
}

.conn-url {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  margin-top: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.status-dot.inactive { background: var(--text-muted); }

.conn-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: flex-start;
}

/* ── Chat panel ── */
.chat-panel {
  border-top: 1px solid var(--border);
  display: none;
}

.chat-panel.open { display: flex; flex-direction: column; }

.chat-messages {
  padding: 16px 18px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 80%;
  font-size: 14px;
  line-height: 1.5;
  padding: 9px 13px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.chat-msg.bot {
  background: var(--bg3);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.chat-msg.bot.streaming { opacity: 0.85; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p { margin-top: 8px; font-size: 14px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  display: none;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 440px;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

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

/* ── QR code setup ── */
.totp-setup {
  text-align: center;
  padding: 16px 0;
}

.totp-setup img {
  border-radius: var(--radius);
  margin: 12px auto;
  display: block;
}

.totp-setup p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Loader ── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 480px) {
  .main { padding: 20px 16px; }
  .login-card { padding: 28px 20px; }
  .conn-actions { flex-wrap: wrap; }
  .chat-messages { max-height: 240px; }
}
