:root {
  --paper: #f4f0e7;
  --paper-deep: #e8e0d2;
  --ink: #191815;
  --muted: #756f65;
  --line: rgba(25, 24, 21, 0.14);
  --signal: #e94d2b;
  --cyan: #1595a3;
  --card: rgba(255, 253, 248, 0.78);
  --shadow: 0 24px 80px rgba(38, 31, 24, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 15%, rgba(233, 77, 43, 0.12), transparent 25%),
    radial-gradient(circle at 8% 85%, rgba(21, 149, 163, 0.1), transparent 30%),
    var(--paper);
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  z-index: 100;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.13'/%3E%3C/svg%3E");
}

.is-hidden {
  display: none !important;
}

.eyebrow,
.thread-kicker {
  margin: 0;
  color: var(--signal);
  font: 700 0.68rem/1.2 Consolas, monospace;
  letter-spacing: 0.15em;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  position: relative;
  width: min(660px, 100%);
  padding: clamp(30px, 7vw, 76px);
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(250, 247, 239, 0.75);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.login-card::after {
  content: "";
  position: absolute;
  width: 230px;
  height: 230px;
  right: -95px;
  top: -80px;
  border: 34px solid var(--signal);
  border-radius: 50%;
  opacity: 0.88;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 54px;
  color: var(--paper);
  background: var(--ink);
  font: 800 1rem Consolas, monospace;
}

.login-card h1 {
  max-width: 550px;
  margin: 16px 0 20px;
  font-family: "STSong", "SimSun", serif;
  font-size: clamp(2.6rem, 8vw, 5.7rem);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.login-copy {
  max-width: 430px;
  color: var(--muted);
  line-height: 1.75;
}

.login-card form {
  margin-top: 42px;
}

label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.78rem;
}

.token-row {
  display: flex;
  gap: 8px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
}

input:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(21, 149, 163, 0.12);
}

.token-row input {
  min-width: 0;
  padding: 15px;
}

button {
  border: 0;
  color: #fff;
  background: var(--ink);
}

.token-row button {
  padding: 0 24px;
}

.form-error {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--signal);
  font-size: 0.8rem;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: rgba(238, 232, 220, 0.78);
  backdrop-filter: blur(18px);
}

.sidebar-head,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-head {
  padding: 28px 24px 18px;
}

.sidebar-head h2 {
  margin: 7px 0 0;
  font: 400 1.55rem "STSong", "SimSun", serif;
}

.new-thread {
  margin: 5px 24px 16px;
  padding: 14px 16px;
  text-align: left;
  background: var(--ink);
}

.new-thread span {
  margin-right: 9px;
  color: #ff8d72;
}

.search-wrap {
  padding: 0 24px 14px;
}

.search-wrap input {
  padding: 12px;
  background: transparent;
}

.thread-list {
  flex: 1;
  overflow: auto;
  padding: 0 12px 24px;
}

.thread-item {
  width: 100%;
  padding: 16px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.thread-item:hover,
.thread-item.is-active {
  background: rgba(255, 255, 255, 0.62);
}

.thread-item.is-active {
  box-shadow: inset 3px 0 var(--signal);
}

.thread-item strong {
  display: block;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-meta {
  display: flex;
  gap: 8px;
  margin-top: 7px;
  color: var(--muted);
  font: 0.7rem Consolas, monospace;
}

.status-pill {
  color: var(--cyan);
}

.sidebar-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.connection-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #35a365;
  box-shadow: 0 0 0 5px rgba(53, 163, 101, 0.13);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  min-height: 88px;
  padding: 18px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 240, 231, 0.68);
  backdrop-filter: blur(18px);
}

.thread-heading {
  min-width: 0;
}

.thread-heading h1 {
  max-width: 760px;
  margin: 5px 0 0;
  overflow: hidden;
  font: 400 clamp(1.15rem, 2.2vw, 1.8rem) "STSong", "SimSun", serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resume-button {
  flex: none;
  padding: 11px 17px;
  background: var(--signal);
}

.empty-state {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(700px, calc(100% - 40px));
  padding: 60px 0;
}

.empty-state h2 {
  margin: 18px 0;
  font: 400 clamp(2.5rem, 7vw, 6.5rem) / 0.98 "STSong", "SimSun", serif;
  letter-spacing: -0.06em;
}

.empty-state > p:last-child {
  max-width: 480px;
  color: var(--muted);
  line-height: 1.8;
}

.orbit {
  position: absolute;
  right: 2%;
  top: 5%;
  width: 230px;
  height: 230px;
  border: 1px solid rgba(233, 77, 43, 0.38);
  border-radius: 50%;
}

.orbit::before,
.orbit::after {
  content: "";
  position: absolute;
  inset: 22px -18px;
  border: 1px solid rgba(21, 149, 163, 0.35);
  border-radius: 50%;
  transform: rotate(42deg);
}

.orbit::after {
  inset: 70px -35px;
  transform: rotate(-24deg);
}

.orbit span {
  position: absolute;
  right: 28px;
  top: 22px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--signal);
}

.timeline {
  overflow: auto;
  padding: 32px clamp(16px, 5vw, 72px) 90px;
  scroll-behavior: smooth;
}

.turn-block {
  width: min(920px, 100%);
  margin: 0 auto 30px;
}

.message {
  margin: 0 0 16px;
}

.message.user {
  max-width: 80%;
  margin-left: auto;
  padding: 16px 18px;
  color: #fff;
  background: var(--ink);
}

.message.agent {
  max-width: 88%;
  padding: 4px 0 12px 22px;
  border-left: 3px solid var(--signal);
  font-family: "STSong", "SimSun", serif;
  font-size: 1.08rem;
  line-height: 1.75;
  white-space: pre-wrap;
}

.tool-card {
  margin: 12px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--card);
}

.tool-card header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font: 0.72rem Consolas, monospace;
}

.tool-card pre {
  max-height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  font: 0.76rem/1.55 Consolas, monospace;
  white-space: pre-wrap;
}

.composer {
  padding: 10px clamp(16px, 5vw, 72px) 18px;
  background: linear-gradient(transparent, var(--paper) 24%);
}

.composer > * {
  width: min(920px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.composer-state {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font: 0.72rem Consolas, monospace;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 12px 45px rgba(39, 31, 23, 0.1);
}

.composer-box textarea {
  max-height: 160px;
  resize: none;
  padding: 9px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.composer-box button {
  width: 43px;
  height: 43px;
  flex: none;
  border-radius: 50%;
  font-size: 1.35rem;
  background: var(--signal);
}

.composer-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
}

.icon-button,
.text-button {
  color: var(--ink);
  background: transparent;
}

.text-button {
  color: var(--signal);
}

.mobile-only {
  display: none;
}

dialog {
  width: min(520px, calc(100% - 28px));
  padding: 28px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(19, 17, 14, 0.52);
  backdrop-filter: blur(5px);
}

dialog h2 {
  margin: 10px 0 28px;
  font: 400 2rem "STSong", "SimSun", serif;
}

dialog input {
  padding: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.dialog-actions button {
  padding: 11px 18px;
}

.dialog-actions .secondary {
  color: var(--ink);
  background: var(--paper-deep);
}

.approval-card pre {
  max-height: 300px;
  overflow: auto;
  padding: 14px;
  color: #e9e5db;
  background: #24221e;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  max-width: min(420px, calc(100% - 36px));
  padding: 13px 16px;
  color: #fff;
  background: var(--ink);
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .mobile-only {
    display: inline-grid;
    place-items: center;
  }

  .sidebar {
    position: fixed;
    inset: 0 12% 0 0;
    z-index: 30;
    box-shadow: 25px 0 70px rgba(25, 24, 21, 0.24);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .topbar {
    min-height: 74px;
    gap: 12px;
    padding: 12px 14px;
  }

  .thread-heading {
    flex: 1;
  }

  .thread-heading h1 {
    font-size: 1.08rem;
  }

  .resume-button {
    padding: 9px 11px;
    font-size: 0.78rem;
  }

  .empty-state {
    padding: 38px 8px;
  }

  .orbit {
    width: 155px;
    height: 155px;
    opacity: 0.72;
  }

  .timeline {
    padding: 22px 14px 76px;
  }

  .message.user,
  .message.agent {
    max-width: 94%;
  }

  .composer {
    padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  }

  .login-card::after {
    width: 150px;
    height: 150px;
    border-width: 24px;
  }
}



/* UI FIXES V2 */
html,
body {
  height: 100%;
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  overflow: hidden;
}

.thread-list {
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.workspace {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.timeline {
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.thread-list::-webkit-scrollbar,
.timeline::-webkit-scrollbar {
  width: 9px;
}

.thread-list::-webkit-scrollbar-thumb,
.timeline::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 10px;
  background: rgba(25, 24, 21, 0.28);
  background-clip: padding-box;
}

.project-group {
  border-top: 1px solid var(--line);
}

.project-heading {
  width: 100%;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 7px;
  padding: 15px 12px 10px;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.project-heading strong {
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-icon {
  width: 16px;
  height: 12px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 2px;
  color: var(--muted);
  font-size: 0;
}

.folder-icon::before {
  content: "";
  width: 7px;
  height: 3px;
  position: relative;
  left: -3px;
  top: -7px;
  border: 1px solid currentColor;
  border-bottom: 0;
  background: var(--paper-deep);
}

.project-count {
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 12px;
  color: var(--muted);
  background: rgba(25, 24, 21, 0.06);
  font: 0.66rem Consolas, monospace;
  text-align: center;
}

.project-chevron {
  color: var(--muted);
  transition: transform 0.2s ease;
}

.project-group.is-collapsed .project-chevron {
  transform: rotate(-90deg);
}

.project-group.is-collapsed .project-sessions {
  display: none;
}

.project-sessions {
  padding: 0 0 9px 22px;
}

.project-sessions .thread-item {
  padding: 12px 12px;
  border-top: 0;
  border-left: 1px solid rgba(25, 24, 21, 0.11);
}

.project-sessions .thread-item.is-active {
  border-left-color: var(--signal);
  box-shadow: inset 3px 0 var(--signal);
}

.topbar-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 9px;
}

.details-button {
  padding: 10px 13px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.38);
  font-size: 0.76rem;
}

.details-button.is-active {
  color: var(--paper);
  background: var(--ink);
}

.visible-empty {
  width: min(920px, 100%);
  margin: 12vh auto;
  padding: 28px;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

.empty-list-note {
  padding: 18px 12px;
}

@media (max-width: 760px) {
  .topbar-actions {
    gap: 5px;
  }

  .details-button {
    max-width: 68px;
    padding: 8px;
    line-height: 1.2;
  }
}
