:root {
  color-scheme: dark;
  --bg: #0d0e12;
  --panel: #181819;
  --stage: #181819;
  --ink: #f5f5f6;
  --muted: #94969c;
  --line: #2a2e39;
  --chip: #222632;
  --brand: #2970ff;
  --mine: #1f3f86;
  font-family: "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button, input, textarea { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.stage.chat-stage {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}
.chat-list,
.library-filters {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.chat-list:hover,
.library-filters:hover {
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}
.messages,
.files,
.library-main {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}
.chat-list::-webkit-scrollbar,
.library-filters::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.files::-webkit-scrollbar,
.library-main::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.chat-list::-webkit-scrollbar-track,
.library-filters::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.files::-webkit-scrollbar-track,
.library-main::-webkit-scrollbar-track {
  background: transparent;
}
.chat-list::-webkit-scrollbar-thumb,
.library-filters::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 99px;
}
.chat-list:hover::-webkit-scrollbar-thumb,
.library-filters:hover::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.files::-webkit-scrollbar-thumb,
.library-main::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 99px;
}
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-y: overlay;
  overscroll-behavior: contain;
}
.stage.chat-stage.list-closed { grid-template-columns: minmax(0, 1fr); }
.chat-list button {
  flex: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-list button[aria-current="true"] { background: var(--chip); color: var(--ink); }
.chat-list #new-chat { color: var(--ink); margin-bottom: 8px; }
.chat-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-main .messages {
  position: absolute;
  inset: 0;
  padding: 12px 0 0;
}
.stage.library-stage {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}
.stage.library-stage.filters-closed {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.library-filters {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  overflow: auto;
  overflow: overlay;
}
.library-filters button {
  flex: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
}
.library-filters button[aria-current="true"] { background: var(--chip); color: var(--ink); }
.library-main { min-width: 0; overflow: auto; padding: 28px 28px 40px; }
.library-main h1 { margin: 0 0 20px; font-size: 28px; }
.library-main h2 { margin: 0 0 12px; font-size: 16px; }
.artifacts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.artifact {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.preview {
  height: 132px;
  border-radius: 12px;
  background: #10131a;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview img { width: 100%; height: 100%; object-fit: cover; }
.badge { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }
.artifact strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artifact span { color: var(--muted); font-size: 12px; }

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
}
.brand .link { font-size: 12px; justify-content: center; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--chip);
  border: 1px solid var(--line);
}

.nav, .files, .activity { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; }

.nav button, .files button, .files a, .ghost, .files .label {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
}
.nav-icon { flex: none; }

.nav button[aria-current="true"], .tabs button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
}

.files { margin-top: 16px; overflow: auto; }
.files a {
  color: inherit;
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.files .label, .tabs, .status { color: var(--muted); font-size: 12px; }
.rail .foot { margin-top: auto; padding: 12px; display: flex; gap: 8px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--stage); position: relative; }
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.top > div { flex: 1; min-width: 0; }
.top h1 { margin: 0; font-size: 16px; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.messages, .panel {
  flex: 1;
  overflow: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
}
.session-col {
  width: min(768px, calc(100% - 32px));
  margin-inline: auto;
}
.session-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: min(768px, calc(100% - 32px));
  margin-inline: auto;
  padding: 0 0 12px;
  background: var(--stage);
  pointer-events: none;
}
.session-foot .composer { pointer-events: auto; }
#paper { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.page-turns, .turn { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.day-stamp { margin: 0; text-align: center; color: var(--muted); font-size: 12px; }
.fold-head {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(680px, 100%);
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 24px;
  text-align: left;
  cursor: pointer;
}
.fold-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { flex: none; opacity: 0; transition: transform 0.15s, opacity 0.15s; }
.fold-head:hover .chevron,
.fold-head[aria-expanded="true"] .chevron,
.explore-head .chevron { opacity: 1; }
.explore { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.timeline-ticker { position: relative; }
.timeline-ticker-slot { height: 28px; overflow: hidden; }
.timeline-ticker-track { display: flex; flex-direction: column; }
.timeline-ticker-row {
  box-sizing: border-box;
  flex: 0 0 28px;
  height: 28px;
  overflow: hidden;
}
.timeline-ticker-live { min-width: 0; }
.live-shimmer {
  color: transparent;
  background-image: linear-gradient(100deg, var(--muted) 0%, var(--muted) 40%, var(--ink) 50%, var(--muted) 60%, var(--muted) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: live-shimmer 1.8s linear infinite;
}
@keyframes live-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -120% 0; }
}
.fold-head[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.fold-body { white-space: pre-wrap; color: var(--muted); font-size: 15px; line-height: 28px; }
.fold-box {
  max-width: min(680px, 100%);
  max-height: 320px;
  margin-top: 6px;
  border-radius: 12px;
  background: var(--chip);
  padding: 10px 14px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-y: overlay;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.fold-box:hover { scrollbar-color: rgba(255, 255, 255, 0.35) transparent; }
.fold-box::-webkit-scrollbar { width: 6px; height: 6px; }
.fold-box::-webkit-scrollbar-track { background: transparent; }
.fold-box::-webkit-scrollbar-thumb { background: transparent; border-radius: 99px; }
.fold-box:hover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.35); }
.fold-live { color: var(--muted); font-size: 15px; }
.panel { gap: 12px; }
.stage > .status, .session-foot .status { padding: 0 0 8px; }
.composer {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  width: 100%;
  margin: 0;
  padding: 6px 6px 6px 10px;
  border-radius: 28px;
  background: #1f1f20;
  border: 1px solid #343438;
}
.composer textarea {
  flex: 1;
  box-sizing: border-box;
  resize: none;
  height: 36px;
  min-height: 36px;
  max-height: 124px;
  line-height: 22px;
  padding: 7px 0;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: inherit;
  overflow: hidden;
  scrollbar-width: none;
}
.composer textarea::-webkit-scrollbar { width: 0; height: 0; }

.bubble {
  max-width: 100%;
  min-width: 0;
  padding: 14px 16px;
  border-radius: 22px;
  background: #1f1f20;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
}
.bubble.user {
  margin-left: auto;
  max-width: min(420px, 100%);
  padding: 8px 14px;
  border-radius: 18px;
  background: #2f6bff;
  color: #fff;
}
.reply {
  position: relative;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.reply .bubble.assistant { max-width: none; white-space: normal; }
.agent-md { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.agent-md > :first-child { margin-top: 0; }
.agent-md > :last-child { margin-bottom: 0; }
.agent-md :where(p, ul, ol, pre, blockquote, hr) { margin-block: 0.8em; }
.agent-md :is(h1, h2, h3, h4, h5, h6) {
  margin-top: 1.25em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.25;
}
.agent-md :where(h1) { font-size: 1.5em; }
.agent-md :where(h2) { font-size: 1.25em; }
.agent-md :where(h3, h4, h5, h6) { font-size: 1em; }
.agent-md :where(ul) { list-style: disc; padding-left: 1.4em; }
.agent-md :where(ol) { list-style: decimal; padding-left: 1.4em; }
.agent-md :where(li) { margin-block: 0.25em; }
.agent-md :where(hr) { height: 1px; border: none; background: var(--line); }
.agent-md :where(a) { color: #7aa2ff; text-decoration: none; }
.agent-md :where(a:hover) { text-decoration: underline; }
.agent-md :where(blockquote) {
  margin-left: 0;
  border-left: 0.25em solid var(--line);
  padding: 0 1em;
  color: var(--muted);
}
.agent-md :where(code) {
  font-size: 13px;
  border-radius: 6px;
  background: rgba(175, 184, 193, 0.2);
  padding: 0.2em 0.4em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.agent-md .md-code {
  margin-block: 0.8em;
  border-radius: 6px;
  background: #181819;
  overflow: auto;
}
.agent-md .md-code pre {
  margin: 0;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}
.agent-md .md-code code { background: none; padding: 0; }
.turn-time {
  position: absolute;
  left: 4px;
  top: 100%;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.reply:hover .turn-time { opacity: 1; }
.time { color: var(--muted); font-size: 12px; }

.composer-plus {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
}
.composer-send {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2f6bff;
  color: #fff;
}
.primary, .icon {
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 14px;
}
.icon { background: var(--chip); color: var(--ink); border: 1px solid var(--line); }

.who { padding: 16px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.link {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 20rem;
  color: var(--muted);
}
.link-mark {
  width: 16px;
  height: 16px;
  flex: none;
  display: inline-flex;
  color: var(--muted);
}
.link[data-state="on"] .link-mark,
.link[data-state="run"] .link-mark { color: #17b26a; }
.link .status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 6px; padding: 10px; }
.tabs button { background: transparent; border: 0; color: var(--muted); border-radius: 999px; padding: 6px 8px; }
.card {
  text-align: left;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: inherit;
}
.card strong, .card span { display: block; }
.day { color: var(--muted); font-size: 13px; margin-top: 8px; }
.empty { color: var(--muted); }
.sheet {
  position: absolute;
  inset: 52px 18px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}
.stage { position: relative; }
.error { color: #ffb4ab; font-size: 13px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 10px 12px 6px; }
  .nav { flex-direction: row; overflow-x: auto; padding-bottom: 8px; }
  .nav button { flex: none; }
  .files, .rail .foot { display: none; }
  .stage.library-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .stage.chat-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
  .chat-list,
  .chat-main { grid-area: 1 / 1; }
  .chat-list {
    z-index: 5;
    max-height: none;
    height: 100%;
    background: var(--stage);
    border-right: 0;
    border-bottom: 0;
  }
  .library-filters {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .library-filters button { flex: none; white-space: nowrap; }
  .library-main { padding: 16px 16px 28px; }
  .library-main h1 { font-size: 22px; margin-bottom: 14px; }
  .artifacts { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
  .session-col,
  .session-foot { width: min(768px, calc(100% - 16px)); }
}
