:root {
  --chat-ink: #36332e;
  --chat-muted: #98938a;
  --chat-panel: rgba(255, 255, 252, .96);
  --chat-accent: #cc7352;
}

body[data-screen="conversation"] .topbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  min-height: 78px;
  padding: max(13px, env(safe-area-inset-top)) 17px 8px;
}

body[data-screen="conversation"] .topbar > div { flex: initial; }
.conversation-identity { min-width: 0; text-align: center; }
body[data-screen="conversation"] .topbar h1 { margin: 0; color: var(--chat-ink); font: 550 17px/1.25 ui-sans-serif, system-ui, sans-serif; letter-spacing: .025em; }
body[data-screen="conversation"] .service-state { justify-content: center; margin-top: 3px; padding: 0; background: transparent; color: var(--chat-muted); font-size: 10px; }
body[data-screen="conversation"] .service-state i { width: 6px; height: 6px; }

.context-ring {
  --context-progress: 0deg;
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(#79b573 var(--context-progress), #e8e7e2 0);
  color: #68645c;
  font-size: 9px;
}
.context-ring::before { content: ""; position: absolute; width: 31px; height: 31px; border-radius: 50%; background: #fcfbf8; }
.context-ring span { position: relative; z-index: 1; }
.context-ring[hidden] { display: block; visibility: hidden; }

body[data-screen="conversation"] .chat {
  height: calc(min(860px, var(--app-viewport-height, 100dvh)) - 78px);
  padding: 10px 16px 134px;
  scroll-padding-bottom: 132px;
}

.message {
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
  margin-bottom: 9px;
}
.message.me { margin-bottom: 12px; }
.message-body { display: grid; justify-items: start; width: min(78%, 560px); min-width: 0; }
.message.me .message-body { justify-items: end; }
.avatar { flex: 0 0 32px; width: 32px; height: 32px; overflow: hidden; border-radius: 50%; }
.avatar img,.resident-avatar img,.conversation-avatar img,.avatar-editor-preview img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.bubble { max-width: 100%; margin-bottom: 5px; padding: 9px 13px; border-radius: 18px; color: var(--chat-ink); line-height: 1.55; overflow-wrap: anywhere; }
.message.me .bubble { border-radius: 18px; }

.message-markdown { min-width: 0; white-space: normal; }
.message-markdown > :first-child { margin-top: 0; }
.message-markdown > :last-child { margin-bottom: 0; }
.message-markdown p { margin: 0 0 .72em; }
.message-markdown p:last-child { margin-bottom: 0; }
.message-markdown ul,.message-markdown ol { margin: .55em 0; padding-left: 1.35em; }
.message-markdown blockquote { margin: .7em 0; padding-left: 10px; border-left: 2px solid #d6d2ca; color: #736f67; }
.message-markdown h1,.message-markdown h2,.message-markdown h3 { margin: .9em 0 .45em; font-size: 1.05em; line-height: 1.35; }
.message-markdown code { padding: .12em .35em; border-radius: 5px; background: rgba(81, 76, 68, .08); font: .88em/1.45 ui-monospace,"SFMono-Regular",Consolas,monospace; }
.message-markdown pre { max-width: 100%; margin: .7em 0; overflow: auto; padding: 11px 12px; border: 1px solid rgba(70, 65, 57, .08); border-radius: 10px; background: #e9e7e1; }
.message-markdown pre code { padding: 0; background: transparent; white-space: pre; }
.message-markdown a { color: #a95539; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.message-markdown th,.message-markdown td { padding: 5px 7px; border: 1px solid #ddd9d1; }

.time-divider { display: block; margin: 11px auto 13px; color: #aaa69e; font-size: 10px; text-align: center; }
.process-message .message-body { width: min(82%, 580px); }
.process-summary { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; padding: 3px 0 8px; border: 0; background: transparent; color: #858179; font-size: 13px; text-align: left; }
.process-summary:focus { outline: none; }
.process-summary:focus-visible { border-radius: 8px; box-shadow: 0 0 0 2px rgba(207,118,84,.22); }
.process-summary svg { width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.process-summary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.process-summary-spacer { flex: 1; }
.process-summary-chevron { font-size: 18px; line-height: 1; opacity: .55; }

.trace-overlay { position: fixed; z-index: 40; inset: 0; background: rgba(41, 38, 33, .28); opacity: 0; transition: opacity 160ms ease; }
.trace-overlay[hidden] { display: none; }
.trace-overlay.show { opacity: 1; }
.trace-sheet { position: fixed; z-index: 41; right: 4px; bottom: 0; left: 4px; display: flex; max-height: 78dvh; min-height: min(300px,48dvh); flex-direction: column; overflow: hidden; border: 1px solid rgba(68, 63, 55, .09); border-radius: 28px 28px 0 0; background: #fcfbf8; box-shadow: 0 -16px 45px rgba(42, 38, 32, .15); transform: translateY(102%); transition: transform 280ms cubic-bezier(.2,.8,.2,1); }
.trace-sheet[hidden] { display: none; }
.trace-sheet.show { transform: translateY(0); }
.trace-sheet-handle { width: 36px; height: 5px; margin: 8px auto 5px; border-radius: 3px; background: #d6d2ca; }
.trace-sheet-head { display: grid; grid-template-columns: 40px minmax(0,1fr) 40px; align-items: center; padding: 2px 15px 12px; }
.trace-sheet-head button { display: grid; width: 36px; min-width: 36px; height: 36px; padding: 0; aspect-ratio: 1; flex: 0 0 36px; place-items: center; border: 1px solid #e2dfd8; border-radius: 50%; background: #fffefa; color: #767169; font-size: 22px; font-weight: 300; line-height: 1; }
.trace-sheet-head h2 { margin: 0; color: #2f2c28; font-size: 17px; font-weight: 550; text-align: center; }
.trace-sheet-content { overflow-y: auto; padding: 12px 21px max(28px,env(safe-area-inset-bottom)); }
.trace-sheet-status { margin: 18px 0; color: var(--muted); font-size: .92rem; }
.trace-phase { display: grid; grid-template-columns: 20px minmax(0,1fr); gap: 13px; color: #37342f; }
.trace-phase-rail { display: flex; flex-direction: column; align-items: center; }
.trace-phase-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: #aaa69e; }
.trace-phase.tool .trace-phase-dot { width: 16px; height: 16px; display: grid; margin-top: 3px; place-items: center; background: transparent; color: #858078; font-size: 12px; }
.trace-phase-line { width: 1.5px; min-height: 22px; flex: 1; margin: 5px 0; background: #ddd9d2; }
.trace-phase-body { min-width: 0; padding: 0 0 22px; }
.trace-phase-body > strong { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 550; }
.trace-phase-body > small { display: block; color: #918c83; font-size: 11px; }
.trace-phase-body .message-markdown { color: #5f5b54; font-size: 14px; line-height: 1.58; }

body[data-screen="conversation"] .composer {
  z-index: 4;
  display: block;
  padding: 23px 12px max(9px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(252, 251, 248, .97) 32%, #fcfbf8 58%);
}
.composer-box {
  position: relative;
  display: grid;
  gap: 5px;
  padding: 9px 10px 8px;
  border: 1px solid rgba(69, 64, 56, .07);
  border-radius: 23px;
  background: var(--chat-panel);
  box-shadow: 0 9px 30px rgba(61, 56, 48, .1);
  backdrop-filter: blur(18px);
}
.composer .composer-box textarea {
  width: 100%;
  min-height: 25px;
  max-height: 120px;
  padding: 2px 4px;
  overflow-y: auto;
  resize: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 16px;
  line-height: 1.45;
}
.composer-actions { display: flex; align-items: center; gap: 7px; min-height: 35px; }
.composer-spacer { flex: 1; }
.composer .composer-box button { position: static; inset: auto; display: grid; flex: 0 0 35px; width: 35px; min-width: 35px; max-width: 35px; height: 35px; min-height: 35px; max-height: 35px; place-items: center; padding: 0; border: 0; border-radius: 50%; }
.composer .composer-icon { background: #f0efeb; color: #67635b; }
.composer .composer-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.composer #send { background: var(--chat-accent); color: #fff; }
.composer #send:disabled,.composer .composer-icon:disabled { background: #e5e3dd; color: #aaa69e; }
.composer .composer-box .model-label { display: block; flex: 0 1 auto; width: auto; min-width: 0; max-width: 132px; height: 32px; overflow: hidden; padding: 0 12px; border-radius: 16px; background: #f1efe9; color: #625e56; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.emoji-panel { display: flex; flex-wrap: wrap; gap: 5px; padding-top: 2px; border-top: 1px solid #efede8; }
.emoji-panel[hidden] { display: none; }
.composer .emoji-panel button { width: auto; min-width: 34px; height: 32px; padding: 0 7px; border-radius: 11px; background: #f5f3ef; color: var(--chat-ink); font-size: 16px; }
.reply-draft { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 7px 9px; border-left: 2px solid var(--chat-accent); border-radius: 7px; background: #f7f4ef; color: #77736b; font-size: 11px; }
.reply-draft[hidden] { display: none; }
.reply-draft span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer .reply-draft button { width: 25px; height: 25px; background: transparent; color: #8f8a81; font-size: 18px; }
.composer > p { margin: 5px 7px 0; }
.composer > p:empty { display: none; }
.attachment-status:empty { display: none; }

.model-panel { position: absolute; right: 0; bottom: calc(100% + 9px); left: 0; z-index: 8; padding: 14px; border: 1px solid #e6e2da; border-radius: 20px; background: #fffefa; box-shadow: 0 14px 38px rgba(58, 52, 44, .16); }
.model-panel[hidden] { display: none; }
.model-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.composer .composer-box .model-panel-head button { flex-basis: 28px; width: 28px; min-width: 28px; height: 28px; background: #f2f0eb; color: #77716a; font-size: 19px; }
.model-panel > p { margin: 11px 2px 6px; color: #8b867d; font-size: 11px; }
.model-options,.effort-options { display: flex; flex-wrap: wrap; gap: 6px; }
.composer .composer-box .model-options button,.composer .composer-box .effort-options button { display: block; flex: 0 0 auto; width: auto; min-width: 0; max-width: none; height: 33px; padding: 0 11px; border-radius: 17px; background: #f2f0eb; color: #655f57; font-size: 12px; }
.composer .composer-box .model-options button[aria-pressed="true"],.composer .composer-box .effort-options button[aria-pressed="true"] { background: #e9d8cf; color: #a45034; }
.composer .composer-box .model-apply { width: 100%; max-width: none; height: 38px; margin-top: 13px; border-radius: 19px; background: var(--chat-accent); color: white; }
.model-status { min-height: 0; margin: 7px 2px 0; color: #8a6256; font-size: 11px; }

@media (max-width: 360px) {
  body[data-screen="conversation"] .chat { padding-right: 13px; padding-left: 13px; }
  .message-body { width: 77%; }
  body[data-screen="conversation"] .composer { padding-right: 10px; padding-left: 10px; }
}

@media (max-width: 520px) {
  html,body { height: var(--app-viewport-height, 100dvh); min-height: var(--app-viewport-height, 100dvh); overflow: hidden; }
  .shell { height: var(--app-viewport-height, 100dvh); min-height: var(--app-viewport-height, 100dvh); }
}
