:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #f0f0ed;
  --text: #1d1d1b;
  --muted: #73736e;
  --faint: #a3a39d;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #d97757;
  --accent-text: #ffffff;
  --user: #ecebe6;
  --danger: #c4413a;
  --ok: #3f8f5a;
  --warn: #b7791f;
  --code-bg: #f1f0ec;
  --diff-add: rgba(46, 160, 67, 0.16);
  --diff-del: rgba(218, 54, 51, 0.14);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --panel: #1f1f1d;
    --panel-2: #2a2a27;
    --text: #ecebe6;
    --muted: #9d9c96;
    --faint: #6c6b66;
    --line: rgba(255, 255, 255, 0.08);
    --user: #2c2b28;
    --code-bg: #262623;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--top) + 8px) 8px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}

.bar .title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 4px;
}

.bar .title b {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar .title small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  color: var(--text);
  flex: none;
}

.icon-button:active {
  background: var(--panel-2);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.dot.online {
  background: var(--ok);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--danger);
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.banner {
  margin: 10px 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.banner.bad {
  color: var(--danger);
}

/* Chat list */

.filters {
  display: flex;
  gap: 8px;
  padding: 10px 12px 4px;
  overflow-x: auto;
}

.chip {
  flex: none;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.chip.on {
  background: var(--text);
  color: var(--bg);
}

.group-title {
  padding: 14px 16px 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 8px;
  padding: 10px 10px;
  border-radius: 12px;
  width: calc(100% - 16px);
  text-align: left;
}

.row:active {
  background: var(--panel-2);
}

.row .body {
  flex: 1;
  min-width: 0;
}

.row .name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row .name span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .meta {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.badge {
  flex: none;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

.badge.input {
  background: var(--accent);
  color: var(--accent-text);
}

.badge.error {
  background: var(--danger);
  color: #fff;
}

.kind {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.kind.claude {
  background: #d97757;
}

.kind.codex {
  background: #3b3b3b;
}

.kind.opencode {
  background: #4f6bd8;
}

.kind.antigravity {
  background: #2f9e8f;
}

.spinner {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottom) + 18px);
  width: 54px;
  height: 54px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 28px;
  box-shadow: var(--shadow);
}

.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}

/* Chat */

.entries {
  padding: 8px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry.user {
  align-self: flex-end;
  max-width: 88%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.bubble {
  background: var(--user);
  border-radius: 16px 16px 4px 16px;
  padding: 8px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.entry.user .actions {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.entry.user .actions button {
  color: var(--muted);
}

.undelivered {
  color: var(--danger);
  font-size: 12px;
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--panel-2);
}

.entry.image img {
  max-width: 100%;
  border-radius: 10px;
}

.entry.assistant {
  word-break: break-word;
}

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

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

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

.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 14px 0 6px;
  line-height: 1.3;
}

.markdown h2 {
  font-size: 18px;
}

.markdown h3 {
  font-size: 16px;
}

.markdown h4,
.markdown h5,
.markdown h6 {
  font-size: 15px;
}

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

.markdown li {
  margin: 2px 0;
}

.markdown li > p {
  margin: 0;
}

.markdown blockquote {
  border-left: 3px solid var(--line);
  padding-left: 10px;
  color: var(--muted);
}

.markdown code {
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 5px;
}

.markdown pre,
pre.output {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.markdown pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

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

.markdown hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.markdown .table {
  overflow-x: auto;
}

.markdown table {
  border-collapse: collapse;
  font-size: 13px;
}

.markdown th,
.markdown td {
  border: 1px solid var(--line);
  padding: 4px 8px;
}

.fold {
  border-radius: 10px;
}

.fold > .head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
}

.fold > .head:active {
  background: var(--panel-2);
}

.fold > .head .label {
  flex: none;
  color: var(--text);
  font-weight: 500;
}

.fold > .head .detail {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.fold > .head .state {
  flex: none;
  font-size: 12px;
}

.fold > .head .state.failed {
  color: var(--danger);
}

.fold > .head .state.completed {
  color: var(--ok);
}

.fold > .content {
  padding: 4px 8px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thinking .content {
  color: var(--muted);
  font-size: 14px;
}

pre.output {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff {
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.diff .path {
  padding: 6px 10px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  word-break: break-all;
}

.diff .lines {
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
}

.diff .line {
  white-space: pre;
  padding: 0 10px;
  min-width: max-content;
}

.diff .line.add {
  background: var(--diff-add);
}

.diff .line.del {
  background: var(--diff-del);
}

.diff .line.gap {
  color: var(--faint);
}

.todo-item {
  font-size: 13px;
}

.todo-item.done {
  color: var(--muted);
  text-decoration: line-through;
}

.notice {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

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

.link-button {
  color: var(--accent);
  font-size: 13px;
  text-align: left;
}

.working {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 12px;
  color: var(--muted);
  font-size: 13px;
}

.dock {
  flex: none;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(var(--bottom) + 8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 1px 0 var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
}

.card h4 {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.question-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.option {
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 14px;
  text-align: left;
}

.option.on {
  background: var(--accent);
  color: var(--accent-text);
}

.buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.button {
  padding: 8px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  font-weight: 500;
}

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

.button.danger {
  color: var(--danger);
}

.button:disabled {
  opacity: 0.5;
}

.queued {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.queued .text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queued button {
  color: var(--accent);
  font-size: 12px;
  flex: none;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--panel);
  border-radius: 18px;
  padding: 4px;
  box-shadow: 0 1px 0 var(--line);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  padding: 8px 6px;
  max-height: 40vh;
  line-height: 1.45;
}

.composer .icon-button {
  width: 36px;
  height: 36px;
  border-radius: 14px;
}

.send {
  background: var(--accent);
  color: var(--accent-text) !important;
}

.send:disabled {
  opacity: 0.4;
}

.stop {
  background: var(--text);
  color: var(--bg) !important;
}

.pending-images {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pending-image {
  position: relative;
}

.pending-image button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
}

.status-line {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  padding: 0 6px;
  overflow-x: auto;
  white-space: nowrap;
}

.status-line button {
  color: var(--muted);
  font-size: 12px;
}

.suggestions {
  max-height: 34vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.suggestion {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.suggestion b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.suggestion small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sheets */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  z-index: 10;
  animation: fade 0.15s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet {
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 8px 12px calc(var(--bottom) + 14px);
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    transform: translateY(30px);
  }
}

.sheet .grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 2px auto 10px;
}

.sheet h3 {
  margin: 4px 4px 10px;
  font-size: 16px;
}

.sheet .item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 8px;
  border-radius: 10px;
  text-align: left;
}

.sheet .item:active {
  background: var(--panel-2);
}

.sheet .item.danger {
  color: var(--danger);
}

.sheet .item small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sheet .item.selected {
  background: var(--panel-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 4px 12px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
}

.field select,
.field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.usage {
  margin: 6px 4px 14px;
}

.usage .meter {
  height: 8px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
  margin: 4px 0 2px;
}

.usage .meter div {
  height: 100%;
  background: var(--accent);
}

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

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--top) + 12px);
  transform: translateX(-50%);
  max-width: 92%;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 20;
  box-shadow: var(--shadow);
  animation: fade 0.2s ease-out;
}

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
}

.pair {
  padding: calc(var(--top) + 60px) 28px 40px;
  text-align: center;
  color: var(--muted);
}

.pair h1 {
  color: var(--text);
  font-size: 22px;
}

.dock > div:empty {
  display: none;
}
