:root {
  --bg: #08110f;
  --panel: #0d1916;
  --panel-2: #10221d;
  --line: rgba(203, 239, 225, 0.1);
  --text: #ecf8f3;
  --muted: #8da69c;
  --green: #4ee1a0;
  --green-deep: #164c39;
  --bubble: #172a24;
  --danger: #ff7f7f;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 80% 0%, rgba(39, 122, 91, 0.18), transparent 30%),
    var(--bg);
}

button, textarea, input { font: inherit; }

button { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  width: min(1440px, 100%);
  height: 100dvh;
  margin: 0 auto;
  border-inline: 1px solid var(--line);
  background: rgba(8, 17, 15, 0.9);
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(13, 25, 22, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.brand-mark, .avatar, .empty-logo, .dialog-mark {
  display: grid;
  place-items: center;
  color: #06130e;
  background: linear-gradient(145deg, #82f3c1, #34c98b);
  box-shadow: 0 12px 30px rgba(52, 201, 139, 0.18);
}

.brand-mark { width: 42px; height: 42px; border-radius: 14px; font-weight: 900; }
.brand strong { display: block; font-size: 18px; letter-spacing: 0.01em; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.new-chat {
  margin: 18px 18px 8px;
  padding: 12px 14px;
  border: 1px solid rgba(78, 225, 160, 0.22);
  border-radius: 12px;
  background: rgba(78, 225, 160, 0.07);
  cursor: pointer;
  text-align: left;
}

.new-chat:hover { background: rgba(78, 225, 160, 0.12); }
.new-chat span { margin-right: 8px; color: var(--green); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px 10px; }

.chat-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  margin-bottom: 5px;
  padding: 10px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.chat-item:hover { background: rgba(255, 255, 255, 0.035); }
.chat-item.active { background: rgba(78, 225, 160, 0.1); }
.chat-item .mini-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--green);
  background: #173029;
  font-weight: 800;
}
.chat-item.active .mini-avatar { color: #07150f; background: var(--green); }
.chat-item strong, .chat-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item strong { display: block; margin-top: 2px; font-size: 14px; }
.chat-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.privacy-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.16);
}

.privacy-icon { color: var(--green); font-size: 24px; }
.privacy-card strong { display: block; font-size: 12px; }
.privacy-card span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }

.conversation { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-width: 0; }

.conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 17, 15, 0.84);
  backdrop-filter: blur(18px);
}

.menu-button { display: none; border: 0; background: transparent; font-size: 22px; cursor: pointer; }
.avatar { width: 44px; height: 44px; border-radius: 50%; font-weight: 900; }
.conversation-title { min-width: 0; }
.conversation-title strong { display: block; }
.conversation-title span { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-size: 12px; }
.conversation-title i { width: 7px; height: 7px; border-radius: 50%; background: #dbb455; }
.conversation-title span.online i { background: var(--green); box-shadow: 0 0 10px rgba(78, 225, 160, 0.7); }
.privacy-pill { margin-left: auto; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; }

.messages {
  overflow-y: auto;
  padding: 28px clamp(18px, 5vw, 78px);
  scroll-behavior: smooth;
}

.empty-state { display: grid; place-items: center; max-width: 520px; margin: 10vh auto 0; text-align: center; }
.empty-logo { width: 76px; height: 76px; border-radius: 26px; font-size: 32px; font-weight: 900; }
.empty-state h1 { margin: 22px 0 8px; font-size: clamp(24px, 4vw, 38px); }
.empty-state p { margin: 0; color: var(--muted); line-height: 1.65; }

.message-row { display: flex; margin: 10px 0; }
.message-row.user { justify-content: flex-end; }
.message-bubble {
  max-width: min(690px, 82%);
  padding: 12px 15px 8px;
  border: 1px solid var(--line);
  border-radius: 6px 18px 18px 18px;
  background: var(--bubble);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}
.message-row.user .message-bubble {
  border-color: rgba(78, 225, 160, 0.14);
  border-radius: 18px 6px 18px 18px;
  background: var(--green-deep);
}
.message-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.message-bubble time { display: block; margin-top: 7px; color: rgba(224, 245, 237, 0.48); font-size: 10px; text-align: right; }
.message-row.pending { opacity: 0.62; }

.error-banner {
  display: none;
  margin: 0 clamp(18px, 5vw, 78px) 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 127, 127, 0.25);
  border-radius: 10px;
  color: #ffd6d6;
  background: rgba(116, 31, 31, 0.3);
  font-size: 13px;
}
.error-banner.visible { display: block; }

.composer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 10px;
  padding: 14px clamp(18px, 5vw, 78px) 22px;
  border-top: 1px solid var(--line);
  background: rgba(8, 17, 15, 0.92);
}
.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  color: var(--text);
  background: var(--panel-2);
  line-height: 1.5;
}
.composer textarea:focus { border-color: rgba(78, 225, 160, 0.42); box-shadow: 0 0 0 3px rgba(78, 225, 160, 0.06); }
.send-button { width: 46px; height: 46px; border: 0; border-radius: 15px; color: #07150f; background: var(--green); cursor: pointer; font-weight: 900; }
.send-button:disabled { opacity: 0.35; cursor: not-allowed; }
.composer small { grid-column: 1 / -1; margin-top: -3px; color: rgba(141, 166, 156, 0.58); font-size: 10px; }

.token-dialog { width: min(430px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 22px; color: var(--text); background: #10201b; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55); }
.token-dialog::backdrop { background: rgba(2, 8, 6, 0.8); backdrop-filter: blur(8px); }
.token-dialog form { display: grid; gap: 14px; padding: 28px; text-align: center; }
.dialog-mark { width: 58px; height: 58px; margin: 0 auto; border-radius: 20px; font-size: 24px; font-weight: 900; }
.token-dialog h2 { margin: 4px 0 0; }
.token-dialog p { margin: 0; color: var(--muted); line-height: 1.5; }
.token-dialog code { color: var(--green); }
.token-dialog input { padding: 13px; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--text); background: #0a1512; }
.token-dialog button { padding: 13px; border: 0; border-radius: 12px; color: #07150f; background: var(--green); cursor: pointer; font-weight: 800; }
#tokenError { min-height: 16px; color: var(--danger); font-size: 12px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(310px, 88vw); transform: translateX(-102%); transition: transform 180ms ease; box-shadow: 20px 0 60px rgba(0, 0, 0, 0.4); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: block; }
  .conversation-header { min-height: 68px; padding: 10px 14px; }
  .avatar { width: 40px; height: 40px; }
  .privacy-pill { display: none; }
  .messages { padding: 20px 13px; }
  .composer { padding: 11px 12px 15px; }
  .message-bubble { max-width: 90%; }
}

