:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #677384;
  --line: #dbe2ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --user: #0e7490;
  --user-dark: #155e75;
  --danger: #b42318;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

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

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 12px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 4;
}

.brand,
.top-actions,
.settings-header {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 190px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #17202c;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

#modelSelect,
#customModel {
  height: 40px;
}

#modelSelect {
  width: 156px;
  padding: 0 10px;
}

#customModel {
  width: min(210px, 40vw);
  padding: 0 12px;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  background: #eef3f7;
  color: #243244;
}

.icon-button:hover {
  background: #e3ebf2;
}

.icon-button svg,
.send-button svg,
.message-copy svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.chat-area {
  overflow-y: auto;
  padding: 28px clamp(14px, 4vw, 44px) 16px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(920px, 100%);
  margin: 0 auto;
}

.empty-state {
  display: grid;
  align-content: center;
  min-height: calc(100vh - 220px);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  display: block;
  font-size: clamp(24px, 4vw, 40px);
  line-height: 1.12;
  letter-spacing: 0;
  margin-bottom: 10px;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

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

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e6edf3;
  color: #263446;
  font-size: 12px;
  font-weight: 800;
}

.message.user .avatar {
  grid-column: 2;
  background: #d5eef2;
  color: var(--user-dark);
}

.bubble {
  position: relative;
  width: fit-content;
  max-width: min(760px, 100%);
  padding: 13px 44px 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(16, 24, 40, 0.06);
  overflow-wrap: anywhere;
  line-height: 1.68;
  white-space: pre-wrap;
}

.bubble.has-markdown {
  white-space: normal;
}

.message.user .bubble {
  justify-self: end;
  grid-column: 1;
  grid-row: 1;
  background: var(--user);
  border-color: var(--user);
  color: #ffffff;
}

.markdown-body {
  color: inherit;
  line-height: 1.68;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 12px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 16px 0 8px;
  line-height: 1.25;
  letter-spacing: 0;
}

.markdown-body h1 {
  font-size: 24px;
}

.markdown-body h2 {
  font-size: 20px;
}

.markdown-body h3 {
  font-size: 17px;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 22px;
}

.markdown-body li + li {
  margin-top: 4px;
}

.markdown-body blockquote {
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: #eef7f6;
  color: #334155;
}

.markdown-body code {
  padding: 2px 5px;
  border-radius: 6px;
  background: #eef3f7;
  color: #0f172a;
  font-family: "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  font-size: 0.92em;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #f8fafc;
  line-height: 1.55;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
}

.markdown-body a {
  color: var(--accent-dark);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 7px 9px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: #eef3f7;
  font-weight: 700;
}

.markdown-body.typing-live::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  border-radius: 999px;
  background: var(--accent);
  vertical-align: -0.18em;
  animation: caretPulse 0.8s ease-in-out infinite;
}

@keyframes caretPulse {
  0%,
  100% {
    opacity: 0.18;
  }

  50% {
    opacity: 1;
  }
}

.message.error .bubble {
  border-color: rgba(180, 35, 24, 0.32);
  color: var(--danger);
}

.message-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.62;
}

.message-copy:hover {
  background: rgba(15, 23, 42, 0.08);
  opacity: 1;
}

.message.user .message-copy:hover {
  background: rgba(255, 255, 255, 0.18);
}

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

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  animation: blink 1s ease-in-out infinite;
}

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

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

@keyframes blink {
  0%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer {
  padding: 14px clamp(14px, 4vw, 44px) 22px;
  background: linear-gradient(180deg, rgba(245, 247, 249, 0), var(--bg) 26%);
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 44px;
  gap: 10px;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

#promptInput {
  min-height: 44px;
  max-height: 180px;
  resize: none;
  padding: 10px 2px 8px 4px;
  border: 0;
  box-shadow: none;
  line-height: 1.5;
}

#promptInput:focus {
  box-shadow: none;
}

.send-button {
  align-self: end;
  background: var(--accent);
  color: #ffffff;
}

.image-button {
  align-self: end;
  background: #e8f2ee;
  color: #176b4d;
}

.image-button:hover {
  background: #d9eade;
}

.image-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.generated-image {
  display: block;
  width: min(100%, 640px);
  height: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.send-button:hover {
  background: var(--accent-dark);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  background: rgba(15, 23, 42, 0.32);
}

.login-overlay {
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.settings-panel {
  width: min(420px, 100%);
  height: 100%;
  padding: 20px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.settings-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.settings-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.login-panel {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px;
  color: var(--text);
}

.field textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.5;
}

.secondary-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  background: #eef3f7;
  color: #263446;
  cursor: pointer;
}

.secondary-button:hover {
  background: #e3ebf2;
}

.primary-button {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.access-error {
  min-height: 20px;
  margin: -4px 0 14px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand,
  .top-actions {
    width: 100%;
  }

  .top-actions {
    justify-content: flex-start;
  }

  #modelSelect {
    flex: 1;
    min-width: 0;
  }

  #customModel {
    width: 100%;
    order: 2;
  }

  .chat-area {
    padding-top: 18px;
  }

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

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

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

  .avatar {
    width: 34px;
    height: 34px;
  }

  .bubble {
    width: 100%;
  }

  .composer {
    padding-bottom: 14px;
  }
}
