:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --sidebar: rgba(247, 247, 248, 0.88);
  --sidebar-hover: rgba(0, 0, 0, 0.055);
  --text: #111111;
  --muted: #6f6f6f;
  --line: rgba(0, 0, 0, 0.1);
  --line-soft: rgba(0, 0, 0, 0.06);
  --bubble: #f4f4f4;
  --danger: #b42318;
  --focus: rgba(16, 163, 127, 0.16);
  --primary: #111111;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(246, 247, 249, 0.9)),
    #ffffff;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.side-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  border-right: 1px solid var(--line-soft);
  background: var(--sidebar);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: var(--text);
  padding: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 6px;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-strong);
}

.brand-mark span {
  width: 14px;
  height: 14px;
  border: 2px solid #111;
  border-left-color: transparent;
  border-radius: 50%;
}

.brand strong {
  display: block;
  max-width: 160px;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.new-chat,
.admin-link {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.new-chat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  background: var(--surface);
  padding: 0 12px;
  font-weight: 650;
}

.new-chat::after {
  content: "";
  position: absolute;
  inset: -70% auto -70% -42%;
  width: 38%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.74), transparent);
  transform: translateX(-120%) rotate(14deg);
}

.new-chat.is-sparking::after {
  animation: sweep 520ms ease;
}

.new-chat span:first-child {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.new-chat:hover,
.admin-link:hover {
  background: var(--sidebar-hover);
  transform: translateY(-1px);
}

.sidebar-space {
  flex: 1;
}

.conversation-section {
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow: hidden;
}

.sidebar-label {
  padding: 8px 10px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.conversation-list {
  display: grid;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px 30px;
  align-items: center;
  border-radius: var(--radius);
}

.conversation-row:hover,
.conversation-row.active {
  background: var(--sidebar-hover);
}

.conversation-item {
  width: 100%;
  min-height: 36px;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #343541;
  padding: 0 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-action {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #8a8a8a;
  font-size: 15px;
  opacity: 0.72;
}

.conversation-action[data-pinned="true"] {
  color: #111;
  opacity: 1;
}

.conversation-row:hover .conversation-action,
.conversation-row.active .conversation-action,
.conversation-action:focus-visible {
  opacity: 1;
}

.conversation-action:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #111;
}

.conversation-action.danger:hover {
  color: var(--danger);
}

.conversation-empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

.admin-link {
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: #4b5563;
  font-size: 14px;
}

.chat-panel {
  display: grid;
  min-width: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.7);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 62px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 10px 22px;
}

.chat-header p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
}

.chat-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.auth-button,
.model-select,
.ghost-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  font-size: 13px;
}

.auth-button {
  position: relative;
  max-width: 190px;
  overflow: hidden;
  padding: 0 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-button.is-user {
  padding-left: 13px;
  padding-right: 30px;
}

.auth-button.is-user::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid #555;
  border-bottom: 1.5px solid #555;
  transform: translateY(-65%) rotate(45deg);
}

.model-select {
  width: min(300px, 30vw);
  max-width: 300px;
  outline: 0;
  padding: 0 32px 0 11px;
}

.model-select:focus,
.auth-box input:focus,
.auth-button:focus-visible,
.new-chat:focus-visible,
.composer:focus-within {
  border-color: rgba(17, 17, 17, 0.4);
  box-shadow: 0 0 0 3px var(--focus);
  outline: 0;
}

.account-menu {
  position: relative;
}

.account-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: 240px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.16);
  padding: 8px;
  animation: popoverIn 130ms ease both;
}

.account-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 8px 10px;
}

.account-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.account-card strong,
.account-card small {
  display: block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card strong {
  font-size: 14px;
}

.account-card small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.account-popover a,
.account-popover button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
  text-decoration: none;
}

.account-popover a:hover,
.account-popover button:hover {
  background: rgba(0, 0, 0, 0.055);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    filter 180ms ease;
}

.messages.is-resetting {
  opacity: 0;
  filter: blur(8px);
  transform: translateY(12px) scale(0.992);
}

.empty-state {
  display: grid;
  height: 100%;
  min-height: 340px;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.empty-state div {
  width: min(620px, 100%);
}

.empty-state h2 {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 32px;
  font-weight: 650;
  line-height: 1.15;
}

.empty-state p {
  margin: 0 auto;
  max-width: 460px;
  color: var(--muted);
  line-height: 1.7;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 14px;
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 22px 24px;
  animation: messageIn 220ms ease both;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 36px;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  max-width: min(620px, 100%);
  border-radius: 18px;
  background: var(--bubble);
  padding: 10px 14px;
}

.avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.message.user .avatar {
  background: #ececec;
  color: #333;
}

.bubble {
  min-width: 0;
  color: #111;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  max-width: min(680px, 100%);
}

.message.error .bubble {
  color: var(--danger);
}

.image-gallery {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.image-gallery img {
  display: block;
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 42px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #111;
  animation: pulse 900ms infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.typing span:nth-child(3) {
  animation-delay: 240ms;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "files files files"
    "attach input send";
  gap: 10px;
  width: min(840px, calc(100% - 32px));
  margin: 0 auto 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.09);
  padding: 10px;
}

.attachment-tray {
  grid-area: files;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 2px 0;
}

.file-input {
  display: none;
}

.file-chip,
.message-files span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  min-height: 28px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #fff;
  color: #343541;
  padding: 0 9px;
  font-size: 12px;
}

.file-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip.image-file {
  border-color: rgba(16, 163, 127, 0.22);
  background: rgba(16, 163, 127, 0.08);
}

.file-chip button {
  display: grid;
  width: 18px;
  height: 18px;
  min-width: 18px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
  padding: 0;
}

.attach-button {
  grid-area: attach;
}

.composer textarea {
  grid-area: input;
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.6;
  padding: 10px 8px;
}

.composer button {
  grid-area: send;
  display: grid;
  align-self: end;
  min-width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.attach-button,
.composer .attach-button {
  grid-area: attach;
  background: #f4f4f4;
  color: #111;
}

.attach-button span {
  font-size: 22px;
  line-height: 1;
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

#sendButton span {
  font-size: 0;
}

#sendButton span::before {
  content: "↑";
  font-size: 20px;
  line-height: 1;
}

.composer button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.auth-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 20px;
  z-index: 20;
}

.hidden {
  display: none !important;
}

.auth-box {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.18);
  padding: 24px;
}

.auth-box h2 {
  margin: 0 0 18px;
  font-size: 24px;
  font-weight: 650;
}

.auth-box label {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: #333;
  font-size: 14px;
  font-weight: 650;
}

.auth-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: rgba(255, 255, 255, 0.86);
  padding: 12px;
}

.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.auth-actions button {
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 16px;
}

.auth-actions button[type="submit"] {
  border: 0;
  background: #111;
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  font-weight: 650;
}

.auth-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 14px;
}

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

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

@keyframes sweep {
  from {
    transform: translateX(-120%) rotate(14deg);
  }
  to {
    transform: translateX(420%) rotate(14deg);
  }
}

@keyframes popoverIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

  .side-panel {
    display: none;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .chat-header h1 {
    font-size: 17px;
  }

  .header-actions {
    gap: 6px;
  }

  .model-select {
    width: min(190px, 45vw);
  }

  .account-popover {
    right: 0;
    width: min(240px, calc(100vw - 24px));
  }

  .message,
  .message.user {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    padding: 18px 14px;
  }

  .message.user .avatar {
    grid-column: 1;
  }

  .message.user .bubble {
    grid-column: 2;
    justify-self: start;
  }

  .composer {
    width: calc(100% - 20px);
    margin-bottom: 10px;
  }
}
