:root {
  --bg: #0d1118;
  --bg-2: #161b23;
  --card: rgba(22, 27, 35, 0.98);
  --card-soft: rgba(255, 255, 255, 0.02);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.11);
  --text: #edf2ff;
  --muted: #95a0bd;
  --accent: #5e9cff;
  --accent-2: #89b8ff;
  --danger: #ff7f96;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  --radius-xl: 10px;
  --radius-lg: 8px;
  --radius-md: 6px;
  --font-display: "Avenir Next", "Helvetica Neue", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(94, 156, 255, 0.06), transparent 24%),
    linear-gradient(180deg, #0a0d13 0%, #10151d 52%, #141a23 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.shell {
  width: min(1420px, calc(100vw - 16px));
  margin: 8px auto;
}

.auth-shell,
.app-shell {
  display: grid;
  gap: 10px;
}

.auth-shell {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.86fr);
}

.intro-panel,
.auth-card,
.sidebar,
.conversation-shell,
.modal-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.012), rgba(255, 255, 255, 0.006)), var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.intro-panel {
  min-height: calc(100vh - 16px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.intro-panel h1,
.auth-copy h2,
.conversation-copy h2,
.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: -0.04em;
}

.intro-panel h1 {
  font-size: clamp(2.9rem, 7vw, 4.8rem);
  line-height: 0.95;
  margin-bottom: 12px;
}

.beta-mark {
  margin: auto 0 0;
  color: rgba(149, 160, 189, 0.72);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.intro-copy,
.info-tile p,
.auth-copy p,
.section-header p,
.muted,
.subtle-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.58;
}

.info-tile,
.chats-card,
.tools-card {
  background: var(--card-soft);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-lg);
}

.info-tile {
  padding: 14px;
}

.tile-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.info-tile strong {
  display: block;
  margin-bottom: 7px;
}

.auth-card {
  min-height: calc(100vh - 16px);
  padding: 20px;
}

.tab-row {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 18px;
}

.tab {
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.tab.active {
  color: var(--text);
  background: rgba(94, 156, 255, 0.14);
}

.tab:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.chat-item:hover,
.search-result:hover,
.mobile-back:hover,
.profile-brief:hover {
  transform: translateY(-1px);
}

.auth-copy {
  margin-bottom: 16px;
}

.auth-copy h2 {
  font-size: 1.75rem;
  margin-bottom: 8px;
}

.panel {
  display: none;
}

.panel.active {
  display: grid;
}

.recovery-panel {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 0.88rem;
}

.field input,
.field textarea,
.search-inline input,
.composer textarea {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}

.field textarea,
.composer textarea {
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder,
.search-inline input::placeholder,
.composer textarea::placeholder {
  color: rgba(149, 160, 189, 0.82);
}

.field input:focus,
.field textarea:focus,
.search-inline input:focus,
.composer textarea:focus {
  border-color: rgba(94, 156, 255, 0.32);
  background: rgba(255, 255, 255, 0.05);
}

.primary-button,
.secondary-button,
.ghost-button,
.mobile-back,
.profile-brief {
  border-radius: var(--radius-md);
  padding: 11px 13px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

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

.primary-button {
  color: #06111d;
  background: linear-gradient(135deg, #5b96ea 0%, #84b6ff 100%);
  font-weight: 700;
}

.secondary-button {
  color: var(--text);
  background: rgba(94, 156, 255, 0.12);
  border: 1px solid rgba(94, 156, 255, 0.16);
}

.ghost-button,
.mobile-back,
.profile-brief {
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
}

.status-line {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.hidden {
  display: none !important;
}

.app-shell {
  grid-template-columns: 390px minmax(0, 1fr);
  min-height: calc(100vh - 16px);
}

.sidebar {
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.sidebar-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.profile-brief {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.profile-brief-copy {
  min-width: 0;
  display: grid;
}

.profile-brief-copy strong,
.profile-brief-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-brief-copy span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.chats-card,
.tools-card {
  padding: 12px;
}

.chats-card {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
}

.chats-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.chats-header h3,
.compact-header h3 {
  margin: 0;
}

.search-inline {
  display: block;
  margin-bottom: 10px;
}

.search-shell {
  position: relative;
}

.search-results,
.chat-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.search-results {
  position: absolute;
  top: calc(100% - 6px);
  left: 0;
  right: 0;
  z-index: 6;
  max-height: 220px;
  padding: 8px;
  border-radius: var(--radius-md);
  background: rgba(17, 22, 31, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
}

.chat-list {
  min-height: 0;
  align-content: start;
  grid-auto-rows: max-content;
  padding-right: 2px;
}

.search-result,
.chat-item {
  width: 100%;
  text-align: left;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.024);
  color: var(--text);
  cursor: pointer;
}

.chat-item {
  min-height: 66px;
}

.search-result-row,
.chat-item-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.search-result-copy,
.chat-copy {
  min-width: 0;
}

.search-result-copy strong,
.chat-copy strong {
  display: block;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-copy span,
.chat-preview,
.chat-time {
  color: var(--muted);
  font-size: 0.88rem;
}

.chat-item.active {
  border-color: rgba(94, 156, 255, 0.24);
  background: rgba(94, 156, 255, 0.08);
}

.chat-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  align-self: start;
  padding-top: 2px;
}

.conversation-shell {
  padding: 16px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
}

.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.conversation-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.conversation-copy {
  min-width: 0;
}

.mobile-back {
  display: none;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(94, 156, 255, 0.3), rgba(137, 184, 255, 0.18));
  color: #eaf2ff;
  font-weight: 700;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 0.86rem;
}

.avatar-md {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  font-size: 0.95rem;
}

.avatar-xl {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  font-size: 1.6rem;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.chat-list > .empty-state,
.search-results > .empty-state {
  min-height: 96px;
  padding: 18px 14px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.018);
}

.message {
  display: flex;
}

.message.mine {
  justify-content: flex-end;
}

.bubble {
  max-width: min(74%, 760px);
  border-radius: 8px;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.042);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.message.mine .bubble {
  background: rgba(94, 156, 255, 0.12);
  border-color: rgba(94, 156, 255, 0.18);
}

.bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 5px;
}

.bubble-text {
  line-height: 1.54;
  white-space: pre-wrap;
  word-break: break-word;
}

.attachment-card {
  display: grid;
  gap: 8px;
  min-width: 220px;
  max-width: min(100%, 360px);
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.attachment-card.image-card {
  padding: 8px;
}

.attachment-card img {
  width: 100%;
  display: block;
  max-height: 320px;
  object-fit: cover;
  border-radius: 6px;
}

.attachment-meta {
  display: grid;
  gap: 4px;
}

.attachment-meta span,
.attachment-loading {
  color: var(--muted);
  font-size: 0.84rem;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer-main {
  display: grid;
  gap: 8px;
}

.composer textarea {
  min-height: 56px;
  max-height: 180px;
}

.attachment-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-actions {
  min-width: 140px;
  display: grid;
  gap: 8px;
}

.ttl-inline {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.ttl-inline select {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  outline: none;
}

.ttl-inline select:focus {
  border-color: rgba(94, 156, 255, 0.32);
  background: rgba(255, 255, 255, 0.05);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
}

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

.modal-panel {
  position: relative;
  width: min(560px, calc(100vw - 20px));
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.settings-form {
  display: grid;
  gap: 10px;
}

.settings-avatar-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.upload-button {
  display: inline-flex;
  align-items: center;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 1040px) {
  .auth-shell,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .intro-panel,
  .auth-card,
  .sidebar,
  .conversation-shell {
    min-height: auto;
  }

}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.chat-open .sidebar {
    display: none;
  }

  .app-shell:not(.chat-open) .conversation-shell {
    display: none;
  }

  .mobile-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .conversation-header {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 8px, 100%);
    margin: 4px auto;
  }

  .intro-panel,
  .auth-card,
  .sidebar,
  .conversation-shell,
  .modal-panel {
    padding: 12px;
    border-radius: 8px;
  }

  .sidebar-top {
    grid-template-columns: 1fr;
  }

  .sidebar-tools {
    flex-wrap: wrap;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    min-width: 0;
  }

  .bubble {
    max-width: 90%;
  }

  .settings-avatar-row {
    flex-direction: column;
    align-items: start;
  }

  .inline-actions,
  .attachment-toolbar {
    width: 100%;
  }
}

.compact-button {
  padding: 7px 10px;
  font-size: 0.82rem;
}

.key-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
}

.key-card-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.key-card code {
  display: block;
  overflow-wrap: anywhere;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  color: var(--text);
}

.key-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.88rem;
}
