body {
  overflow: hidden;
}

.icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.shell {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 64px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--color-canvas);
  transition: grid-template-columns var(--motion-normal) var(--ease-standard);
}

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

.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 0.75rem;
  overflow: visible;
  color: var(--color-text);
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  transition: width var(--motion-normal) var(--ease-standard);
}

.sidebar-scrim {
  display: none;
}

.sidebar-head {
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.25rem;
}

.sidebar-brand {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-mark,
.welcome-mark,
.assistant-mark {
  display: grid;
  flex: none;
  place-items: center;
  color: var(--color-on-accent);
  background: var(--color-accent);
  font-weight: 700;
  line-height: 1;
}

.brand-mark {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.55rem;
  font-size: 0.78rem;
}

.icon-btn {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  cursor: pointer;
  transition:
    color var(--motion-fast) var(--ease-standard),
    background var(--motion-fast) var(--ease-standard);
}

.icon-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.sidebar-expand-btn,
.sidebar-mobile-close-btn {
  display: none;
}

.new-chat-btn,
.settings-btn,
.theme-option,
.history-item {
  width: 100%;
  border: 0;
  color: var(--color-text);
  background: transparent;
  cursor: pointer;
}

.new-chat-btn {
  display: flex;
  min-height: 2.5rem;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.45rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 560;
  text-align: left;
  transition: background var(--motion-fast) var(--ease-standard);
}

.new-chat-btn:hover,
.new-chat-btn.is-active {
  background: var(--color-surface-hover);
}

.new-chat-btn .icon {
  width: 1.12rem;
  height: 1.12rem;
}

.history {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  margin-top: 1.1rem;
}

.history-label {
  margin: 0;
  padding: 0 0.7rem 0.45rem;
  color: var(--color-text-subtle);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.history-scroll {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--color-border-strong) transparent;
  scrollbar-width: thin;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.history-more {
  min-height: 1px;
}

.history-empty {
  margin: 0.5rem 0.7rem;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.history-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  min-height: 2.25rem;
  padding: 0.55rem 0.7rem;
  overflow: hidden;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.25;
  text-align: left;
  transition: background var(--motion-fast) var(--ease-standard);
}

.history-item:hover,
.history-item.is-active {
  background: var(--color-surface-hover);
}

.history-title {
  display: block;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  flex: none;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.sidebar-settings {
  position: relative;
  display: flex;
  flex: none;
  flex-direction: column;
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--color-border);
}

.logout-form,
.language-form {
  width: 100%;
  margin: 0;
}

.settings-btn {
  display: flex;
  min-height: 2.5rem;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 0.88rem;
  text-align: left;
  transition:
    color var(--motion-fast) var(--ease-standard),
    background var(--motion-fast) var(--ease-standard);
}

.settings-btn:hover,
.settings-btn[aria-expanded="true"] {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.settings-btn .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.settings-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.5rem);
  left: 0;
  z-index: 40;
  display: none;
  gap: 0.15rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-md);
  animation: menu-in var(--motion-fast) var(--ease-standard) both;
}

.settings-menu.is-open {
  display: grid;
}

.settings-title {
  margin: 0;
  padding: 0.35rem 0.55rem 0.45rem;
  color: var(--color-text-muted);
  font-size: 0.73rem;
  font-weight: 600;
}

.language-option {
  display: flex;
  width: 100%;
  min-height: 2.35rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
}

.theme-option {
  display: grid;
  grid-template-columns: 1.25rem 1fr auto;
  min-height: 2.35rem;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.45rem;
  font-size: 0.84rem;
  text-align: left;
}

.theme-option:hover,
.theme-option[aria-pressed="true"] {
  background: var(--color-surface-hover);
}

.theme-option::after {
  content: "✓";
  color: var(--color-accent);
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0;
}

.theme-option[aria-pressed="true"]::after {
  opacity: 1;
}

.theme-option .icon {
  width: 1rem;
  height: 1rem;
  color: var(--color-text-muted);
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--color-canvas);
}

.workspace-sidebar-open-btn {
  display: none;
}

.conversation-panes {
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.conversation-pane {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.conversation-pane-new {
  overflow-y: auto;
}

.new-conversation-content {
  display: flex;
  width: min(48rem, calc(100% - 2.5rem));
  min-height: 100%;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  padding: clamp(2rem, 9vh, 6rem) 0;
}

.welcome {
  margin-bottom: 1.75rem;
  text-align: center;
  animation: fade-rise 360ms var(--ease-standard) both;
}

.welcome-mark {
  width: 2.6rem;
  height: 2.6rem;
  margin: 0 auto 1rem;
  border-radius: 0.8rem;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
}

.welcome h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.welcome p {
  margin: 0.65rem auto 0;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.conversation-messages {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 1.65rem;
  padding: 2rem max(1.25rem, calc((100% - 52rem) / 2)) 1.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--color-border-strong) transparent;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
}

.message-list {
  display: contents;
}

.message-scroll-trigger {
  display: none;
}

.messages-more {
  min-height: 1px;
  flex: none;
}

.msg {
  width: 100%;
  animation: fade-rise 220ms var(--ease-standard) both;
}

.msg-inner {
  display: grid;
  width: min(48rem, 100%);
  grid-template-columns: 1.75rem minmax(0, 1fr);
  align-items: start;
  gap: 0.8rem;
  margin: 0 auto;
}

.msg-user .msg-inner {
  display: flex;
  justify-content: flex-end;
}

.assistant-mark {
  position: relative;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.55rem;
  font-size: 0.72rem;
}

.msg-inner:has(.thinking-item.is-pending) .assistant-mark::after {
  content: "";
  position: absolute;
  inset: -0.22rem;
  border: 1.5px solid transparent;
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: assistant-spin 0.8s linear infinite;
  pointer-events: none;
}

.msg-content {
  min-width: 0;
}

.msg-user .msg-content {
  max-width: min(75%, 34rem);
}

.msg-role {
  margin: 0 0 0.42rem;
  color: var(--color-text);
  font-size: 0.78rem;
  font-weight: 650;
}

.msg-body {
  color: var(--color-text);
  font-size: 0.96rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg-body:empty {
  display: none;
}

.msg-user .msg-body {
  padding: 0.65rem 0.9rem;
  border-radius: 1.15rem;
  background: var(--color-surface-soft);
  line-height: 1.5;
}

.msg-assistant .msg-body {
  padding: 0;
  border: 0;
  background: transparent;
}

.msg-markdown {
  white-space: normal;
}

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

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

.msg-markdown p,
.msg-markdown ul,
.msg-markdown ol,
.msg-markdown pre,
.msg-markdown blockquote {
  margin: 0 0 0.75rem;
}

.msg-markdown ul,
.msg-markdown ol {
  padding-left: 1.25rem;
}

.msg-markdown li + li {
  margin-top: 0.25rem;
}

.msg-markdown a {
  color: var(--color-accent);
}

.msg-markdown code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.msg-markdown :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 0.3rem;
  background: var(--color-surface-soft);
}

.msg-markdown pre {
  overflow-x: auto;
  padding: 0.75rem 0.9rem;
  border-radius: 0.6rem;
  background: var(--color-surface-soft);
  white-space: pre-wrap;
}

.msg-markdown h1,
.msg-markdown h2,
.msg-markdown h3 {
  margin: 0 0 0.55rem;
  font-size: 1.05rem;
  line-height: 1.35;
}

.msg-body.is-streaming::after {
  display: inline-block;
  margin-left: 0.15rem;
  color: var(--color-accent);
  content: "▋";
  animation: blink 1s steps(1) infinite;
}

.thinking-wrap {
  margin: 0 0 0.65rem;
}

.thinking-list {
  display: flex;
  max-width: min(42ch, 100%);
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.thinking-details summary {
  width: fit-content;
  color: color-mix(in srgb, var(--color-text) 82%, var(--color-canvas));
  font-size: 0.8rem;
  line-height: 1.35;
  cursor: pointer;
}

.thinking-details .thinking-list {
  margin-top: 0.35rem;
}

.thinking-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  color: color-mix(in srgb, var(--color-text) 82%, var(--color-canvas));
  font-size: 0.8rem;
  line-height: 1.35;
}

.thinking-wrap > .thinking-list > .thinking-item > span {
  background-image: linear-gradient(
    90deg,
    var(--color-text-muted) 0%,
    var(--color-text-muted) 40%,
    var(--color-text) 50%,
    var(--color-text-muted) 60%,
    var(--color-text-muted) 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: thinking-shimmer 1.6s linear infinite;
}

.thinking-wrap > .thinking-list > .thinking-item .thinking-subject {
  color: transparent;
  -webkit-text-fill-color: transparent;
  background-image: inherit;
  background-size: inherit;
  background-clip: text;
  -webkit-background-clip: text;
  animation: inherit;
}

.thinking-subject {
  font-style: italic;
}

.composer-dock {
  flex: none;
  padding: 0.45rem 1.25rem 0.9rem;
  background: var(--color-canvas);
}

.composer-dock .composer,
.composer-dock .composer-note,
.composer-dock .turn-notice {
  width: min(48rem, 100%);
  margin-right: auto;
  margin-left: auto;
}

.turn-notice {
  margin: 0 0 0.55rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  background: var(--color-danger-soft);
  font-size: 0.82rem;
  line-height: 1.4;
}

.turn-notice:empty {
  display: none;
}

.composer {
  display: flex;
  min-height: 3.5rem;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-xl);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-sm);
  transition:
    border-color var(--motion-fast) var(--ease-standard),
    box-shadow var(--motion-fast) var(--ease-standard);
}

.new-conversation-content .composer {
  box-shadow: var(--shadow-md);
}

.composer:focus-within {
  border-color: var(--color-accent-border);
  box-shadow: var(--focus-ring), var(--shadow-sm);
}

.composer textarea {
  field-sizing: content;
  width: 100%;
  min-height: 2.3rem;
  max-height: 12.5rem;
  padding: 0.42rem 0;
  overflow-y: auto;
  border: 0;
  outline: 0;
  color: var(--color-text);
  background: transparent;
  font-size: 0.96rem;
  line-height: 1.45;
  resize: none;
}

.composer textarea::placeholder {
  color: var(--color-text-subtle);
}

.composer textarea:disabled {
  cursor: wait;
}

.send-btn {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  flex: none;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--color-canvas);
  background: var(--color-text);
  cursor: pointer;
  transition:
    opacity var(--motion-fast) var(--ease-standard),
    transform var(--motion-fast) var(--ease-standard);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.send-btn:disabled {
  color: var(--color-text-subtle);
  background: var(--color-surface-hover);
  cursor: wait;
}

.send-btn .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.send-icon.is-hidden {
  display: none;
}

.send-spinner {
  display: none;
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.send-spinner.is-visible {
  display: block;
}

.composer-note {
  margin-top: 0.5rem;
  margin-bottom: 0;
  color: var(--color-text-subtle);
  font-size: 0.7rem;
  line-height: 1.35;
  text-align: center;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(0.25rem) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes assistant-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes thinking-shimmer {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: -100% 0;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 761px) {
  .shell.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
    padding-right: 0.5rem;
    padding-left: 0.5rem;
  }

  .shell.sidebar-collapsed .sidebar-head {
    justify-content: center;
    padding: 0;
  }

  .shell.sidebar-collapsed .sidebar-expand-btn {
    display: grid;
  }

  .shell.sidebar-collapsed .sidebar-brand,
  .shell.sidebar-collapsed .sidebar-collapse-btn,
  .shell.sidebar-collapsed .history,
  .shell.sidebar-collapsed .sidebar-label {
    display: none;
  }

  .shell.sidebar-collapsed .new-chat-btn,
  .shell.sidebar-collapsed .settings-btn {
    width: 2.5rem;
    justify-content: center;
    margin-right: auto;
    margin-left: auto;
    padding: 0;
  }

  .shell.sidebar-collapsed .sidebar-settings {
    width: 100%;
  }

  .shell.sidebar-collapsed .settings-menu {
    right: auto;
    bottom: 0;
    left: calc(100% + 0.75rem);
    width: 14rem;
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .workspace {
    height: 100%;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 280px);
    visibility: hidden;
    opacity: 0;
    border-right-color: var(--color-border-strong);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    transform: translateX(-100%);
  }

  .shell.mobile-sidebar-open .sidebar {
    width: min(86vw, 280px);
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.42);
    cursor: default;
  }

  .sidebar-scrim.is-visible {
    display: block;
  }

  .sidebar-collapse-btn {
    display: none;
  }

  .sidebar-mobile-close-btn {
    display: grid;
  }

  .workspace-sidebar-open-btn {
    position: absolute;
    top: 0.65rem;
    left: 0.65rem;
    z-index: 10;
    display: grid;
    background: var(--color-surface-alpha);
    box-shadow: var(--shadow-sm);
  }

  .conversation-messages {
    gap: 1.4rem;
    padding: 1.35rem 0.9rem 1rem;
    scrollbar-gutter: auto;
  }

  .msg-inner {
    grid-template-columns: 1.5rem minmax(0, 1fr);
    gap: 0.65rem;
  }

  .assistant-mark {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.45rem;
    font-size: 0.65rem;
  }

  .msg-user .msg-content {
    max-width: 88%;
  }

  .composer-dock {
    padding: 0.4rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  }

  .new-conversation-content {
    width: min(100% - 2rem, 48rem);
    padding: 4rem 0 max(1rem, env(safe-area-inset-bottom));
  }

  .new-conversation-content .welcome {
    margin-top: auto;
    margin-bottom: auto;
    padding-bottom: 1.5rem;
  }
}

@media (max-width: 420px) {
  .welcome {
    margin-bottom: 1.35rem;
  }

  .welcome-mark {
    width: 2.35rem;
    height: 2.35rem;
  }

  .welcome h1 {
    font-size: 1.7rem;
  }

  .welcome p {
    max-width: 31ch;
    font-size: 0.88rem;
  }

  .composer {
    min-height: 3.25rem;
    padding-left: 0.85rem;
  }

  .composer-note {
    padding: 0 0.35rem;
    font-size: 0.66rem;
  }
}

.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: auto;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(100%, 26rem);
  padding: 2rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.9rem;
  font-weight: 650;
}

.auth-heading {
  margin: 2rem 0 1.5rem;
}

.auth-heading h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}

.auth-heading p {
  margin: 0.5rem 0 0;
  color: var(--color-text-muted);
}

.auth-error {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-sm);
  color: var(--color-danger-strong);
  background: var(--color-danger-soft);
}

.auth-form {
  display: grid;
  gap: 0.625rem;
}

.auth-form label {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  background: var(--color-control);
  font: inherit;
}

.auth-form input:focus {
  border-color: var(--color-accent);
  outline: none;
  box-shadow: var(--focus-ring);
}

.auth-form button {
  margin-top: 1rem;
  padding: 0.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-on-accent);
  background: var(--color-accent);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.auth-form button:hover {
  background: var(--color-accent-hover);
}

.auth-switch {
  margin: 1.25rem 0 0;
  text-align: center;
  color: var(--color-text-muted);
}

.auth-switch a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}
