:root {
  color-scheme: light;
  --page: #f7f8fa;
  --paper: #ffffff;
  --ink: #17181a;
  --muted: #747982;
  --faint: #a7acb4;
  --line: #e8eaee;
  --blue: #4b72e8;
  --blue-soft: #edf2ff;
  --green: #24a26a;
  --green-soft: #eaf7f1;
  --violet-soft: #f2efff;
  --danger: #c74747;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 "Segoe UI Variable Text", "Microsoft YaHei UI", "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, textarea, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  border-inline: 1px solid var(--line);
}
.view {
  min-height: 100dvh;
  padding: 0 18px calc(78px + env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
}
.view.active { display: flex; }
.conversation-view { padding: 0; height: 100dvh; min-height: 0; overflow: hidden; }

.page-header {
  min-height: 92px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 14px;
}
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; }
h1, h2, p { letter-spacing: 0; }
.page-header h1 { margin: 0; font-size: 25px; line-height: 1.2; }
.icon-button {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #f4f5f7;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
button:disabled { cursor: default; opacity: .45; }

.connection-line, .activity-track {
  min-height: 34px;
  display: grid;
  grid-template-columns: 8px auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  color: var(--muted);
  border-block: 1px solid var(--line);
  font-size: 12px;
}
.connection-line span, .activity-track span, .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}
.connection-line b, .activity-track b { color: var(--ink); font-weight: 600; }
.connection-line small, .activity-track small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection-line.online span, .activity-track.running span, .status-dot.online { background: var(--green); }
.connection-line.online b { color: var(--green); }
.connection-line.connecting span { background: #d69d35; animation: pulse 1s ease-in-out infinite; }
.connection-line.offline span, .status-dot.offline { background: var(--danger); }
.activity-track.running { color: var(--blue); background: #f8faff; }
.activity-track.running b { color: var(--blue); }
.activity-track.waiting span { background: #d69d35; }

.filter-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 14px 0 8px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  min-height: 33px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #f1f3f6;
  color: #58606d;
  cursor: pointer;
  font-size: 12px;
}
.filter-chip.active { border-color: #cbd8ff; background: var(--blue-soft); color: #3159c8; font-weight: 600; }
.section-heading { min-height: 42px; display: flex; align-items: center; justify-content: space-between; }
.section-heading b { font-size: 14px; }
.section-heading span { color: var(--muted); font-size: 12px; }

.thread-list { min-height: 0; flex: 1; }
.thread-row {
  width: 100%;
  min-height: 78px;
  padding: 10px 0;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.thread-avatar, .codex-avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: #315ac8;
  font-weight: 700;
}
.thread-row:nth-child(3n+2) .thread-avatar { color: #14725c; background: var(--green-soft); }
.thread-row:nth-child(3n+3) .thread-avatar { color: #7451bd; background: var(--violet-soft); }
.thread-copy { min-width: 0; }
.thread-copy b, .thread-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-copy b { margin-bottom: 3px; font-size: 14px; }
.thread-copy small { color: var(--muted); font-size: 12px; }
.thread-time { align-self: start; padding-top: 8px; color: var(--faint); font-size: 11px; white-space: nowrap; }
.thread-state { color: var(--blue) !important; }

.cache-note, .sync-note {
  flex: 0 0 auto;
  padding: 8px 0;
  color: #588074;
  background: var(--green-soft);
  text-align: center;
  font-size: 11px;
}
.cache-note { margin-top: 8px; border-radius: 8px; }

.project-list { display: grid; align-content: start; gap: 0; }
.project-row {
  width: 100%;
  min-height: 90px;
  padding: 14px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.project-row b, .project-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-row b { margin-bottom: 5px; font-size: 15px; }
.project-row small { color: var(--muted); font-size: 11px; }
.project-count { align-self: center; padding: 4px 8px; border-radius: 999px; background: #f1f3f6; color: #5c6370; font-size: 11px; }

.conversation-header {
  min-height: 66px;
  flex: 0 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.conversation-identity { min-width: 0; text-align: center; }
.conversation-identity h1, .conversation-identity small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-identity h1 { margin: 0; font-size: 15px; }
.conversation-identity small { color: var(--green); font-size: 11px; }
.activity-track { min-height: 28px; padding: 0 14px; border-top: 0; }
.message-feed {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 24px;
  background: #fbfcfd;
  overscroll-behavior: contain;
}
.message-row { display: flex; gap: 9px; margin-bottom: 16px; align-items: flex-start; }
.message-row.user { justify-content: flex-end; }
.codex-avatar { width: 32px; height: 32px; flex: 0 0 auto; color: white; background: #5c78cf; font-size: 12px; }
.message-bubble {
  max-width: min(82%, 600px);
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 5px 8px 8px 8px;
  background: var(--paper);
  box-shadow: 0 3px 10px rgba(35, 48, 76, .035);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.user .message-bubble { border: 0; border-radius: 8px 5px 8px 8px; background: var(--blue-soft); color: #294c9d; }
.stream-caret::after { content: ""; display: inline-block; width: 5px; height: 15px; margin-left: 3px; background: var(--blue); vertical-align: -2px; animation: blink .8s steps(1) infinite; }

.timeline-panel {
  margin: 0 0 14px 41px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
}
.timeline-panel summary, .panel-head {
  min-height: 40px;
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}
.timeline-panel summary::-webkit-details-marker { display: none; }
.timeline-panel summary b, .panel-head b { font-size: 12px; }
.timeline-panel summary span, .panel-head span { color: var(--muted); font-size: 11px; }
.panel-body { padding: 0 11px 11px; color: #606977; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-panel { background: #f8f9fb; }
.tool-command { margin: 0 9px 9px; padding: 8px; border-radius: 6px; background: #eceff3; color: #455064; font: 11px/1.5 Consolas, monospace; overflow-wrap: anywhere; }
.file-list { margin: 0; padding: 0 12px 11px 28px; color: #566071; font-size: 12px; overflow-wrap: anywhere; }

.action-panel { margin-bottom: 14px; padding: 12px; border-color: #dce3f4; box-shadow: 0 7px 20px rgba(47, 75, 135, .06); }
.action-panel h3 { margin: 0 0 5px; font-size: 13px; }
.action-panel p { margin: 0 0 11px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.action-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.action-buttons button, .answer-button, .user-input-form button {
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  cursor: pointer;
  font-size: 12px;
}
.action-buttons .allow, .user-input-form .submit-answer { border-color: var(--blue); background: var(--blue); color: white; font-weight: 600; }
.question-block { margin-bottom: 10px; }
.question-block b { display: block; margin-bottom: 6px; font-size: 12px; }
.question-options { display: grid; gap: 6px; }
.question-option { display: flex; align-items: flex-start; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 12px; }
.question-option small { display: block; color: var(--muted); }
.question-block input[type="text"] { width: 100%; min-height: 38px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; }

.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.skill-selection { margin: 0 0 7px 4px; color: #365cb9; font-size: 11px; }
.skill-selection span { display: inline-block; padding: 4px 8px; border-radius: 999px; background: var(--blue-soft); }
.skill-selection button { width: 24px; height: 24px; border: 0; background: transparent; cursor: pointer; }
.composer {
  min-height: 50px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 40px;
  align-items: end;
  gap: 6px;
  padding: 5px;
  border: 1px solid #dce0e7;
  border-radius: 8px;
  background: #f7f8fa;
}
.composer .icon-button { width: 36px; height: 36px; min-width: 36px; border: 0; background: #eceef2; font-size: 17px; }
.composer textarea { min-height: 36px; max-height: 120px; resize: none; padding: 8px 2px 5px; border: 0; outline: 0; background: transparent; color: var(--ink); overflow-y: auto; }
.send-button, .stop-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send-button { background: var(--blue); color: white; font-size: 19px; }
.stop-button { background: #f2e7e7; color: var(--danger); font-size: 12px; }

.settings-list { border-top: 1px solid var(--line); }
.setting-row { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.setting-row b, .setting-row small { display: block; }
.setting-row small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.setting-action { width: 100%; min-height: 44px; margin-top: 18px; border: 1px solid #e0caca; border-radius: 8px; background: #fff7f7; color: var(--danger); cursor: pointer; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100%, 758px);
  height: calc(66px + env(safe-area-inset-bottom));
  padding: 5px 10px env(safe-area-inset-bottom);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.bottom-nav button { border: 0; background: transparent; color: #969ca6; cursor: pointer; }
.bottom-nav button span, .bottom-nav button b { display: block; }
.bottom-nav button span { font-size: 18px; line-height: 21px; }
.bottom-nav button b { font-size: 11px; font-weight: 500; }
.bottom-nav button.active { color: var(--blue); }
.bottom-nav button.active b { font-weight: 700; }

.sheet-backdrop, .auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  align-items: end;
  background: rgba(28, 31, 37, .3);
}
.bottom-sheet {
  width: min(100%, 760px);
  max-height: min(70dvh, 560px);
  margin: 0 auto;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  background: var(--paper);
  overflow: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.skill-list { display: grid; }
.skill-row { min-height: 58px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.skill-row b, .skill-row small { display: block; }
.skill-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.auth-overlay { place-items: center; align-items: center; padding: 18px; background: rgba(247, 248, 250, .88); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.auth-dialog { width: min(100%, 380px); padding: 26px; border: 1px solid rgba(255, 255, 255, .85); border-radius: 8px; background: rgba(255, 255, 255, .78); box-shadow: 0 16px 46px rgba(31, 40, 61, .12); }
.codex-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #5574cf; color: white; font-weight: 800; }
.auth-dialog h1 { margin: 17px 0 5px; font-size: 22px; }
.auth-dialog p { margin: 0 0 20px; color: var(--muted); }
.auth-dialog label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.auth-dialog input { width: 100%; height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.auth-error { min-height: 28px; padding-top: 5px; color: var(--danger); font-size: 12px; }
.primary-button { width: 100%; height: 44px; border: 0; border-radius: 7px; background: var(--blue); color: white; cursor: pointer; font-weight: 700; }
.empty-state { padding: 36px 12px; color: var(--muted); text-align: center; font-size: 13px; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 760px) {
  .app-shell { border: 0; }
  .view { padding-inline: 14px; }
  .conversation-view { padding-inline: 0; }
  .message-feed { padding-inline: 12px; }
  .timeline-panel { margin-left: 40px; }
}

@media (min-width: 900px) {
  body { padding-block: 18px; }
  .app-shell { min-height: calc(100dvh - 36px); border-radius: 8px; overflow: hidden; box-shadow: 0 18px 50px rgba(30, 38, 55, .09); }
  .view { min-height: calc(100dvh - 36px); }
  .conversation-view { height: calc(100dvh - 36px); }
  .bottom-nav { bottom: 18px; border-radius: 0 0 8px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
