:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008069;
  --mine: #005c4b;
  --theirs: #202c33;
  --danger: #ea4335;
  --warn: #f7c948;
  --radius: 12px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent);
}

button,
input {
  font: inherit;
}

.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, rgba(0, 168, 132, 0.18), transparent 55%),
    linear-gradient(180deg, #0b141a 0%, #111b21 100%);
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-dark));
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
}

.brand p,
.login-card .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card form {
  margin-top: 22px;
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="email"],
input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}

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

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: #04140f;
}

.btn-primary:hover {
  background: #06c095;
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-danger {
  background: transparent;
  color: #ff8a80;
  border: 1px solid #5c2b2b;
}

.error {
  color: #ff8a80;
  font-size: 0.875rem;
  min-height: 1.2em;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.topbar .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #1d2a31;
  color: var(--text);
  font-size: 0.8rem;
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill.ready .dot {
  background: #25d366;
}
.status-pill.qr .dot,
.status-pill.starting .dot,
.status-pill.authenticated .dot {
  background: var(--warn);
}
.status-pill.disconnected .dot,
.status-pill.auth_failure .dot {
  background: var(--danger);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 360px 1fr;
}

.sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.sidebar-head {
  padding: 14px 14px 8px;
}

.sidebar-head h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.search-row {
  padding: 0 14px 12px;
}

.chat-list {
  overflow: auto;
  min-height: 0;
}

.chat-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid rgba(42, 57, 66, 0.65);
  background: transparent;
  color: inherit;
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
}

.chat-item:hover,
.chat-item.active {
  background: var(--panel-2);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #6b7c85;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.chat-item .row1,
.chat-item .row2 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-item .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item .time,
.chat-item .preview {
  color: var(--muted);
  font-size: 0.8rem;
}

.chat-item .preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #042018;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(rgba(11, 20, 26, 0.92), rgba(11, 20, 26, 0.92)),
    radial-gradient(circle at 20% 20%, rgba(0, 168, 132, 0.08), transparent 40%);
}

.chat-header {
  padding: 12px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
}

.chat-header .title {
  font-weight: 600;
}

.chat-header .sub {
  color: var(--muted);
  font-size: 0.8rem;
}

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

.bubble {
  max-width: min(72%, 560px);
  padding: 8px 10px 6px;
  border-radius: 10px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.bubble.mine {
  align-self: flex-end;
  background: var(--mine);
  border-top-right-radius: 2px;
}

.bubble.theirs {
  align-self: flex-start;
  background: var(--theirs);
  border-top-left-radius: 2px;
}

.bubble .meta {
  margin-top: 4px;
  text-align: right;
  color: rgba(233, 237, 239, 0.55);
  font-size: 0.7rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}

.composer textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
  border-radius: 22px;
  padding: 12px 16px;
}

.empty-state,
.connect-panel {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.connect-panel[hidden],
.empty-state[hidden],
#chat-view[hidden] {
  display: none !important;
}

.connect-panel {
  background: var(--panel);
}

.connect-panel img {
  width: 260px;
  height: 260px;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  margin: 16px 0;
}

.connect-panel h2,
.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace.show-chat .sidebar {
    display: none;
  }

  .workspace:not(.show-chat) .main {
    display: none;
  }
}
