:root {
  --bg: #0f1714;
  --panel: #16221d;
  --panel-2: #1c2b25;
  --line: #2a3d34;
  --text: #eef6f1;
  --muted: #9bb0a6;
  --brand: #1f8a5b;
  --brand-2: #2db87a;
  --in: #24352e;
  --out: #1f8a5b;
  --danger: #c45c5c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }

.hidden { display: none !important; }
.token-overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 10, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.token-card {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); text-align: center;
}
.token-card h2 { margin: 12px 0 8px; }
.token-card p { color: var(--muted); line-height: 1.6; }
.token-card input {
  width: 100%; margin: 10px 0 14px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.primary, .send {
  background: var(--brand); color: white; border: 0; border-radius: 10px;
  padding: 10px 16px; cursor: pointer;
}
.primary:hover, .send:hover { background: var(--brand-2); }
.error { color: #ffb4b4; }

.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; background: var(--brand);
  display: grid; place-items: center; font-weight: 800;
}
.brand-mark.lg { width: 56px; height: 56px; margin: 0 auto; font-size: 24px; }

.app-shell { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.sidebar { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.sidebar-header { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.brand-text h1 { margin: 0; font-size: 18px; }
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.status-pill {
  margin-right: auto; font-size: 11px; padding: 4px 8px; border-radius: 999px;
  background: #2a3d34; color: var(--muted);
}
.status-pill.ok { background: #1f3d2f; color: #8ee7b5; }
.status-pill.bad { background: #3d1f1f; color: #ffb4b4; }
.search-wrap { padding: 10px 12px; }
.search-wrap input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.conv-list { overflow: auto; flex: 1; }
.conv {
  padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid;
  grid-template-columns: 1fr auto; gap: 6px;
}
.conv:hover, .conv.active { background: var(--panel-2); }
.conv .name { font-weight: 700; }
.conv .snippet { color: var(--muted); font-size: 12px; grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta { color: var(--muted); font-size: 11px; }
.unread {
  background: var(--brand); color: white; border-radius: 999px; min-width: 20px;
  text-align: center; font-size: 11px; padding: 1px 6px;
}

.main { position: relative; background: #111c18; }
.main-empty { height: 100%; display: grid; place-items: center; color: var(--muted); text-align: center; }
.chat-panel { height: 100%; display: flex; flex-direction: column; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: #2a4a3c;
  display: grid; place-items: center; font-weight: 700;
}
.chat-header-text { flex: 1; min-width: 0; }
.chat-header-text .title { font-weight: 700; }
.chat-header-text .sub { color: var(--muted); font-size: 12px; }
.btn-ghost, .btn-back-list, .btn-attach {
  background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.btn-ghost.on { border-color: var(--brand-2); color: #8ee7b5; }
.messages { flex: 1; overflow: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: min(78%, 640px); padding: 9px 12px; border-radius: 14px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.bubble.in { align-self: flex-start; background: var(--in); }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble .time { display: block; margin-top: 4px; font-size: 11px; opacity: 0.8; }
.bubble img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 6px; }
.composer {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: flex; }
  .main { display: none; }
  .app-shell.mobile-chat-open .sidebar { display: none; }
  .app-shell.mobile-chat-open .main { display: block; }
  .btn-back-list { display: inline-flex; }
}
@media (min-width: 761px) {
  .btn-back-list { display: none; }
}
