:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #0f1a20;
  --text: #e9edef;
  --muted: #8696a0;
  --border: rgba(255, 255, 255, 0.08);
  --me: #005c4b;
  --you: #202c33;
  --accent: #00a884;
  --shadow: 0 15px 45px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --sidebar-width: 270px;
  --vh: 100vh;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 30% -10%, rgba(0, 168, 132, 0.15), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(0, 122, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 18px;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
}

body::before {
  content: '';
  position: fixed;
  inset: -20%;
  background: radial-gradient(circle at 20% 20%, rgba(0, 168, 132, 0.15), transparent 55%),
    radial-gradient(circle at 80% 30%, rgba(0, 122, 255, 0.12), transparent 60%);
  filter: blur(40px);
  animation: bgDrift 16s ease-in-out infinite alternate;
  z-index: -1;
}

@keyframes bgDrift {
  from {
    transform: translate3d(-20px, -10px, 0) scale(1);
  }
  to {
    transform: translate3d(20px, 15px, 0) scale(1.04);
  }
}

.app-shell {
  width: min(1200px, 100%);
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 30%), var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-panel h1 {
  margin: 0 0 8px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.input-group input {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.send-btn {
  border: none;
  border-radius: 16px;
  padding: 14px 18px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(120deg, var(--accent), #00715c);
  box-shadow: 0 12px 30px rgba(0, 168, 132, 0.35);
}

.error-banner {
  background: rgba(230, 0, 0, 0.12);
  border: 1px solid rgba(230, 0, 0, 0.35);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width) auto;
  gap: 18px;
  width: min(1200px, 100%);
  align-items: stretch;
}

.workspace .app,
.workspace .sidebar {
  height: min(calc(var(--vh) - 24px), 820px);
}

.sidebar {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

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

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.session-item {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease;
}

.session-item.active {
  border-color: var(--accent);
  background: rgba(0, 168, 132, 0.15);
}

.app {
  height: min(86vh, 820px);
  min-height: 420px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: 22px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent), var(--panel-2);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.25), transparent 55%),
    linear-gradient(135deg, rgba(0, 168, 132, 0.9), rgba(0, 122, 255, 0.65));
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.title strong {
  font-size: 15px;
}

.title span {
  font-size: 12px;
  color: var(--muted);
}

.actions,
.iconbtn-group {
  display: flex;
  gap: 10px;
}

.iconbtn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

.iconbtn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.iconbtn:active {
  transform: scale(0.96);
}

.chat {
  position: relative;
  overflow-y: auto;
  padding: 20px 16px 10px;
  background: radial-gradient(900px 500px at 50% 0%, rgba(255, 255, 255, 0.03), transparent 60%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 35%),
    var(--panel);
  min-height: 0;
  flex: 1;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.message-row {
  display: flex;
  margin: 12px 0;
}

.message-row.me {
  justify-content: flex-end;
}

.message-row.you {
  justify-content: flex-start;
}

.bubble {
  max-width: min(80%, 560px);
  padding: 12px 14px 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  line-height: 1.4;
  font-size: 14px;
  background: var(--you);
  word-break: break-word;
  animation: bubbleIn 0.25s ease;
  transition: transform 0.2s ease;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.bubble.me {
  background: var(--me);
  border-top-right-radius: 10px;
}

.bubble.you {
  border-top-left-radius: 10px;
}

.meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  color: rgba(233, 237, 239, 0.7);
}

.attachment-group {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-pill {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
}

.attachment-preview {
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
}

.typing-indicator {
  margin: 6px 16px 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 4px;
}

.typing-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  animation: typing 1s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.composer {
  padding: 12px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  position: sticky;
  bottom: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.field {
  flex: 1;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.35;
  max-height: 140px;
  min-height: 24px;
}

textarea::placeholder {
  color: rgba(134, 150, 160, 0.9);
}

.send {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(0, 168, 132, 0.35);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 45%), rgba(0, 168, 132, 0.22);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

.send:active {
  transform: scale(0.95);
}

.hint {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.empty-state {
  position: absolute;
  inset: 80px 20px 100px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.empty-illustration {
  font-size: 32px;
}

.new-message-badge {
  position: sticky;
  bottom: 90px;
  align-self: flex-end;
  margin-right: 16px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: 18px;
  width: min(320px, 90%);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-actions button {
  padding: 12px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
}

.modal-actions .ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.modal-actions .danger {
  background: linear-gradient(120deg, #ff4d4d, #e60000);
  color: #fff;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: 2;
  }
  .app {
    order: 1;
  }
}

@media (max-width: 520px) {
  body {
    padding: 0;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .workspace .app,
  .workspace .sidebar {
    height: calc(100vh - 12px);
  }
  .card,
  .sidebar,
  .app {
    border-radius: 0;
  }
  .hint {
    display: none;
  }
  .bubble {
    max-width: 90%;
  }
}
