:root {
  color-scheme: dark;
  --bg: #212121;
  --panel: #171717;
  --panel-strong: #2f2f2f;
  --surface: #303030;
  --surface-hover: #3a3a3a;
  --text: #f4f4f4;
  --muted: #b4b4b4;
  --faint: #8f8f8f;
  --border: #4a4a4a;
  --soft-border: #252525;
  --button: #f4f4f4;
  --button-text: #111111;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.18);
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--soft-border);
  padding: 10px;
  gap: 10px;
}

.sidebar-top,
.topbar,
.composer-actions,
.topbar-actions {
  display: flex;
  align-items: center;
}

.sidebar-top {
  gap: 8px;
}

.icon-button,
.tool-button,
.send-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.icon-button:hover,
.tool-button:hover {
  background: var(--panel-strong);
}

.new-chat-button,
.profile-button,
.chat-item,
.chat-menu-button,
.chat-menu-item,
.subtle-button,
.primary-button,
.auth-submit,
.auth-switch,
.auth-close {
  border: 0;
  border-radius: 8px;
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  min-height: 38px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.new-chat-button:hover {
  background: var(--panel-strong);
}

.button-icon {
  line-height: 1;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

.search-box:focus-within {
  border-color: var(--accent);
  background: #202020;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.chat-list {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 3px;
  overflow: auto;
  padding: 2px 0;
}

.nav-caption {
  margin: 14px 10px 5px;
  color: var(--faint);
  font-size: 12px;
}

.chat-row {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  min-height: 38px;
  border-radius: 8px;
  direction: ltr;
}

.chat-row:hover,
.chat-row.active,
.chat-row.menu-open {
  background: var(--panel-strong);
}

.chat-item {
  min-height: 38px;
  padding: 9px 10px;
  text-align: right;
  direction: rtl;
  color: var(--text);
  background: transparent;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-menu-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: 0 1px;
  color: var(--muted);
  background: transparent;
  opacity: 0;
}

.chat-row:hover .chat-menu-button,
.chat-row.active .chat-menu-button,
.chat-row.menu-open .chat-menu-button {
  opacity: 1;
}

.chat-menu-button:hover {
  color: var(--text);
  background: #404040;
}

.chat-menu {
  position: absolute;
  left: 4px;
  top: 34px;
  z-index: 8;
  display: grid;
  min-width: 205px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #303030;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.42);
  direction: rtl;
}

.chat-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 36px;
  padding: 0 9px;
  color: var(--text);
  background: transparent;
  text-align: right;
}

.menu-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: currentColor;
}

.menu-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-menu-item:hover {
  background: #3d3d3d;
}

.chat-menu-item.danger {
  color: #ff6b6b;
}

.chat-menu-separator {
  height: 1px;
  margin: 6px 4px;
  background: #4a4a4a;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
}

.profile-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text);
}

.profile-button:hover {
  background: var(--panel-strong);
}

.profile-button.logged-in .avatar {
  background: var(--accent);
  color: #071f19;
}

.avatar,
.brand-mark {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #f4f4f4;
  color: #111111;
  font-weight: 700;
}

.avatar {
  width: 28px;
  height: 28px;
  font-size: 13px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: relative;
  min-width: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% -10%, rgba(255, 255, 255, 0.035), transparent 28%), var(--bg);
  overflow: hidden;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 18px;
}

.mobile-menu {
  display: none;
}

.topbar-actions {
  gap: 8px;
}

.subtle-button,
.primary-button {
  min-height: 38px;
  padding: 0 14px;
}

.subtle-button {
  background: transparent;
  color: var(--text);
}

.subtle-button:hover {
  background: var(--panel-strong);
}

.primary-button {
  background: var(--button);
  color: var(--button-text);
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
}

.auth-modal.open {
  display: grid;
}

.auth-dialog {
  position: relative;
  width: min(100%, 420px);
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #2f2f2f;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.auth-close {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  color: var(--text);
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.auth-close:hover,
.auth-switch:hover {
  background: #3d3d3d;
}

.auth-dialog h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.auth-copy {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-field input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
  background: #212121;
  color: var(--text);
}

.auth-field input:focus {
  border-color: #777;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: #ff7b7b;
  font-size: 13px;
}

.auth-submit {
  min-height: 44px;
}

.auth-switch {
  width: 100%;
  min-height: 38px;
  margin-top: 10px;
  background: transparent;
  color: var(--text);
}

.auth-modal.login-mode .auth-name-field {
  display: none;
}

.conversation {
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: auto;
  padding: 18px 18px 128px;
}

.welcome-state,
.messages {
  width: min(100%, 820px);
}

.welcome-state {
  display: grid;
  align-content: center;
  gap: 24px;
  min-height: 100%;
  padding-bottom: 210px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  justify-self: center;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(28px, 4vw, 36px);
  line-height: 1.18;
  font-weight: 600;
}

.messages {
  display: none;
  flex-direction: column;
  gap: 24px;
  padding: 12px 0 32px;
}

.messages.has-content {
  display: flex;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  direction: rtl;
}

.message-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.message.assistant .message-avatar {
  background: #f4f4f4;
  color: #111111;
}

.message-content {
  max-width: 720px;
  line-height: 1.75;
  word-break: break-word;
}

.message-content p {
  margin: 0;
}

.composer {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: min(100%, 820px);
  padding: 10px 18px 14px;
  transform: translateX(-50%) translateY(-34vh);
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  z-index: 2;
}

.chat-active .composer {
  transform: translateX(-50%) translateY(0);
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer-box:focus-within {
  border-color: #6b6b6b;
}

textarea {
  min-height: 36px;
  max-height: 170px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 8px 10px;
  line-height: 1.55;
  color: var(--text);
  background: transparent;
}

.composer-actions {
  gap: 4px;
}

.send-button {
  background: #f4f4f4;
  color: #111111;
}

.send-button:disabled {
  cursor: default;
  background: #676767;
  color: #b9b9b9;
}

.disclaimer {
  margin: 9px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.sidebar-collapsed .app-shell {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar-collapsed .sidebar {
  overflow: hidden;
  padding: 0;
  border: 0;
}

.sidebar-collapsed .mobile-menu {
  display: inline-grid;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: min(86vw, 300px);
    transform: translateX(-105%);
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.38);
    transition: transform 180ms ease;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-grid;
  }

  .topbar {
    padding-inline: 10px;
  }

  .topbar-actions {
    display: none;
  }

  .conversation {
    padding-inline: 14px;
  }

  .composer {
    padding-inline: 10px;
    transform: translateX(-50%) translateY(-28vh);
  }

  .chat-active .composer {
    transform: translateX(-50%) translateY(0);
  }

  .profile-text {
    display: inline;
  }
}
