:root {
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --sidebar-hover: #ececec;
  --sidebar-active: #ececec;
  --text: #0d0d0d;
  --muted: #6b6b6b;
  --faint: #8f8f8f;
  --line: #e5e5e5;
  --bubble: #f4f4f4;
  --code-bg: #f4f4f4;
  --inline-code: #ececec;
  --error-bg: #fef3f2;
  --error-text: #b42318;
  --error-line: #fecdca;
  --chip: #ffffff;
  --chip-hover: #f4f4f4;
  --send: #0d0d0d;
  --send-off: #d0d0d0;
  --focus: #0d0d0d;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --sidebar-w: 260px;
  --thread-w: 760px;
  --radius-xl: 26px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: #155eef;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app {
  display: flex;
  height: 100%;
  min-height: 100dvh;
}

.backdrop {
  display: none;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 10px 14px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px 10px;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.sidebar-close {
  display: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: var(--sidebar-hover);
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.new-chat:hover {
  background: var(--chip-hover);
}

.chat-nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 14px;
}

.nav-label {
  margin: 0 8px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--faint);
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  min-height: 36px;
}

.chat-item:hover,
.chat-item.active {
  background: var(--sidebar-active);
}

.chat-item-btn {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 10px;
}

.chat-del {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: none;
  place-items: center;
}

.chat-item:hover .chat-del,
.chat-item:focus-within .chat-del {
  display: grid;
}

.chat-del:hover {
  background: #e4e4e4;
  color: var(--text);
}

.sidebar-foot {
  margin: 10px 8px 2px;
  font-size: 12px;
  color: var(--faint);
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 8px;
  border-bottom: 1px solid transparent;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px 8px;
}

.thread-inner {
  width: min(100%, var(--thread-w));
  margin: 0 auto;
}

.empty {
  min-height: calc(100dvh - 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 8px 48px;
}

.empty h1 {
  margin: 0 0 28px;
  font-size: clamp(28px, 5vw, 32px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 640px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.3;
  max-width: 100%;
}

.chip:hover {
  background: var(--chip-hover);
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 18px 0 28px;
}

.msg {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

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

.bubble {
  max-width: min(100%, 560px);
  background: var(--bubble);
  border-radius: 22px;
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.assistant-col {
  display: flex;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.md {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  line-height: 1.7;
  word-break: break-word;
}

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

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

.md p {
  margin: 0 0 0.85em;
}

.md h1,
.md h2,
.md h3 {
  margin: 1.1em 0 0.45em;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.md h1 {
  font-size: 1.35em;
}

.md h2 {
  font-size: 1.18em;
}

.md h3 {
  font-size: 1.05em;
}

.md ul,
.md ol {
  margin: 0 0 0.85em;
  padding-left: 1.35em;
}

.md li {
  margin: 0.2em 0;
}

.md pre {
  margin: 0.7em 0 1em;
  padding: 12px 14px;
  background: var(--code-bg);
  border-radius: 12px;
  overflow-x: auto;
}

.md pre code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  background: none;
  padding: 0;
}

.md code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--inline-code);
  padding: 0.12em 0.38em;
  border-radius: 5px;
}

.md a {
  word-break: break-all;
}

.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  background: var(--text);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}

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

.error {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-line);
  border-radius: 12px;
  font-size: 14px;
}

.dock {
  position: sticky;
  bottom: 0;
  padding: 8px 16px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, #fff 72%, rgba(255, 255, 255, 0));
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c4a35a;
}
.status[data-state="on"]::before { background: #067647; }
.status[data-state="off"]::before { background: #b42318; }

.monitor {
  margin: auto -10px -14px;
  padding: 14px 14px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.monitor-kicker {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}

.monitor-model {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.monitor-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.monitor-grid div {
  min-width: 0;
}

.monitor-grid dt {
  font-size: 11px;
  color: var(--faint);
}

.monitor-grid dd {
  margin: 1px 0 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.monitor-foot {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.signout {
  width: calc(100% - 20px);
  margin: 8px 10px 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
}

.signout:hover {
  background: var(--chip-hover);
}

.login-body {
  overflow: auto;
  display: grid;
  place-items: center;
  background: #f7f7f8;
}

.login-card {
  width: min(100% - 32px, 380px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}

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

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.login-lead {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-form input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

.login-form input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.login-error {
  margin: 0;
  color: var(--error-text);
  font-size: 13px;
}

.login-btn {
  height: 40px;
  margin-top: 6px;
  border: 0;
  border-radius: 10px;
  background: #111;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.login-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.composer {
  width: min(100%, var(--thread-w));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 10px 10px 10px 12px;
  box-shadow: var(--shadow);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

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

.preview {
  position: relative;
  width: 56px;
  height: 56px;
}
.preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.preview button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  padding: 0;
}

.attach {
  flex-shrink: 0;
}

.bubble-media {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.bubble-media img {
  max-width: 180px;
  max-height: 140px;
  border-radius: 10px;
  display: block;
}

.composer textarea {
  flex: 1;
  min-height: 24px;
  max-height: 200px;
  border: 0;
  resize: none;
  background: transparent;
  padding: 6px 0;
  line-height: 1.5;
  font-size: 16px;
}

.composer textarea::placeholder {
  color: #8a8a8a;
}

.send {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--send);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.send:disabled {
  background: var(--send-off);
  cursor: not-allowed;
}

.send .icon-stop,
.send.streaming .icon-send {
  display: none;
}

.send.streaming .icon-stop {
  display: block;
}

.send.streaming:disabled {
  background: var(--send);
  cursor: pointer;
}

.hint {
  width: min(100%, var(--thread-w));
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--faint);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.08);
  }

  .sidebar-close {
    display: grid;
  }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    z-index: 20;
  }

  .backdrop[hidden] {
    display: none;
  }

  .topbar {
    display: flex;
  }

  .empty {
    min-height: calc(100dvh - 260px);
  }

  .bubble {
    max-width: 88%;
  }

  .assistant-col {
    gap: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .caret {
    transition: none;
    animation: none;
  }
}
