:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #ebf0eb;
  background: #111512;
  font-size: 16px;
  --page: #111512;
  --rail: #171b18;
  --panel: #1c231e;
  --panel-hover: #232d26;
  --panel-active: #263a2e;
  --line: #323d34;
  --subtle-line: #292f2a;
  --text: #ebf0eb;
  --muted: #a8b2a9;
  --quiet: #829087;
  --mint: #a6e9b8;
  --mint-hover: #c0f5ce;
  --mint-ink: #15291c;
  --coral: #ffb8a4;
  --max-content: 51rem;
  --sidebar-width: 17rem;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p, ul { margin: 0; }
button, textarea, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}
::selection { background: #427851; color: #fff; }
.screen-reader {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.primary, .secondary, .quiet, .icon-button, .stop-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: .55rem;
  padding: .55rem .8rem;
  font-size: .9rem;
  font-weight: 650;
  line-height: 1.25;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.primary { background: var(--mint); color: var(--mint-ink); }
.primary:hover:not(:disabled) { background: var(--mint-hover); }
.primary:disabled { background: #2a3c30; color: #a0b6a5; }
.secondary { background: var(--panel); color: var(--text); border-color: var(--line); }
.secondary:hover:not(:disabled), .icon-button:hover:not(:disabled), .quiet:hover:not(:disabled) { background: var(--panel-hover); color: var(--text); }
.quiet, .icon-button { background: transparent; color: var(--muted); }
.icon-button { min-width: 2.75rem; padding: 0; font-size: 1.45rem; line-height: 1; }

.brand { display: flex; align-items: center; gap: .7rem; font-weight: 700; white-space: nowrap; }
.brand-symbol {
  display: grid;
  place-items: center;
  width: 2.05rem;
  height: 2.05rem;
  border-radius: .55rem;
  background: var(--mint);
  color: var(--mint-ink);
  font-size: 1.45rem;
  line-height: 1;
}
.sign-in {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.15rem;
  background: radial-gradient(ellipse at 50% 16%, #232f26 0%, var(--page) 55%);
}
.sign-card {
  width: min(100%, 26rem);
  padding: clamp(1.35rem, 5vw, 2rem);
  background: var(--rail);
  border: 1px solid var(--line);
  box-shadow: 0 1rem 4rem #070a076e;
  border-radius: 1rem;
}
.sign-brand { padding-bottom: 1.55rem; border-bottom: 1px solid var(--subtle-line); }
.sign-content { padding-top: 1.45rem; }
.sign-content h1 { font-size: 1.55rem; line-height: 1.3; margin-bottom: .5rem; }
.sign-content > p { color: var(--muted); font-size: .95rem; line-height: 1.55; }
.sign-content form { display: grid; gap: .7rem; margin-top: 1.3rem; }
.sign-content form .primary { margin-top: .35rem; }
.sign-content .secondary { margin-top: 1.15rem; }

.app-shell { height: 100dvh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); overflow: hidden; }
.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 .85rem;
  background: var(--rail);
  border-right: 1px solid var(--line);
}
.sidebar-top { height: 4.4rem; display: flex; align-items: center; justify-content: space-between; padding: 0 .2rem; }
.sidebar-actions { display: grid; gap: .35rem; padding: .55rem 0 1rem; }
.new-button, .history-button { justify-content: flex-start; }
.history-button { padding-left: .7rem; gap: .65rem; }
.history-button > span { margin-left: .13rem; }
.clock-icon { display: inline-block; position: relative; width: .86rem; height: .86rem; border: 1.5px solid currentColor; border-radius: 50%; flex: 0 0 auto; }
.clock-icon::before { content: ""; position: absolute; width: .26rem; height: .25rem; top: .16rem; left: .32rem; border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; }
.side-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; flex: 1; scrollbar-width: thin; }
.side-scroll h2 { font-size: .875rem; font-weight: 650; color: var(--muted); margin: .4rem .6rem .45rem; }
.sidebar-empty { color: var(--muted); font-size: .875rem; line-height: 1.5; padding: .6rem; }
.session-list, .history-list { list-style: none; padding: 0; display: grid; gap: .25rem; }
.session-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  gap: .55rem;
  min-height: 3.25rem;
  padding: .45rem .55rem;
  text-align: left;
  border: 1px solid transparent;
  border-radius: .6rem;
  color: var(--text);
  background: transparent;
}
.session-entry:hover { background: var(--panel-hover); }
.session-entry[aria-current="true"] { background: var(--panel-active); border-color: #3d6048; }
.session-info { min-width: 0; }
.session-name, .session-subtitle { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-name { font-weight: 600; font-size: .9rem; }
.session-subtitle { color: var(--muted); font-size: .78rem; margin-top: .13rem; }
.sidebar-bottom { display: flex; align-items: center; justify-content: space-between; gap: .2rem; padding: .45rem .05rem max(.45rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--subtle-line); }
.host-status { display: flex; gap: .5rem; align-items: center; padding-left: .55rem; color: var(--muted); font-size: .875rem; }
.logout-button { min-height: 2.45rem; font-size: .875rem; }
.mobile-menu, .sidebar-close, .sidebar-scrim { display: none; }

.main-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.thread-header {
  position: relative;
  min-width: 0;
  min-height: 4.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .55rem clamp(.85rem, 4vw, 2rem);
  border-bottom: 1px solid var(--subtle-line);
}
.thread-heading { display: flex; align-items: center; gap: .65rem; min-width: 0; flex: 1; }
.thread-labels { min-width: 0; }
.thread-heading h1, .thread-heading p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-heading h1 { font-size: 1.04rem; font-weight: 650; }
.thread-heading p { margin-top: .25rem; font-size: .8rem; color: var(--muted); }
.thread-status { flex: 0 0 auto; display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .86rem; }
.indicator { display: block; width: .47rem; height: .47rem; flex: 0 0 auto; border-radius: 50%; background: #8fe4a8; }
.thread-status[data-kind="idle"] .indicator { background: var(--quiet); }
.thread-status[data-kind="offline"] .indicator { background: #e9be7f; }
.thread-status[data-kind="running"] .indicator { box-shadow: 0 0 0 .19rem #8fe4a82d; }
.provider-icon {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 2.05rem;
  height: 2.05rem;
  border-radius: .55rem;
  font-size: 1.14rem;
  line-height: 1;
  font-weight: 700;
  color: var(--mint);
  background: #253a2d;
}
.provider-icon.claude { color: #f4c1ad; background: #442f2a; }
.provider-icon.codex { color: #c4d1ff; background: #303c59; }
.session-entry .provider-icon { width: 1.9rem; height: 1.9rem; font-size: .95rem; }

.page-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin: .5rem clamp(.85rem, 4vw, 2rem) 0;
  padding: .2rem .35rem .2rem .75rem;
  color: var(--coral);
  background: #382724;
  border: 1px solid #6d433a;
  border-radius: .55rem;
  font-size: .95rem;
  overflow-wrap: anywhere;
}
.page-error button { height: 2.25rem; min-height: 2.25rem; }
.timeline { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.timeline:focus-visible { outline-offset: -3px; }
.welcome { width: min(100% - 2rem, 30rem); text-align: center; margin: auto; padding: 1.6rem 0 2.7rem; }
.welcome-mark {
  display: inline-grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  margin-bottom: 1.25rem;
  color: var(--mint);
  background: #24382c;
  border: 1px solid #416451;
  border-radius: 1rem;
  box-shadow: 0 0 3rem #294a344a;
  font-size: 2.45rem;
  font-weight: 650;
}
.welcome h2 { font-size: clamp(1.55rem, 4vw, 2rem); line-height: 1.3; }
.welcome p { color: var(--muted); margin: .5rem 0 1.25rem; }
.provider-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.provider-card {
  display: flex;
  position: relative;
  align-items: center;
  text-align: left;
  gap: .5rem;
  min-width: 0;
  min-height: 3.7rem;
  padding: .6rem .65rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--panel);
  color: var(--text);
  font-size: .94rem;
  font-weight: 650;
  cursor: pointer;
}
.provider-card:hover, .provider-card:focus-within { border-color: #587961; background: var(--panel-hover); }
.provider-card:has(input:checked) { border-color: #7eb78c; background: var(--panel-active); }
.provider-card input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.provider-card:has(input:focus-visible) { outline: 2px solid var(--mint); outline-offset: 3px; }
.welcome-history { margin-top: .9rem; }

.thread-content { width: min(100%, var(--max-content)); margin: 0 auto; padding: 1.35rem clamp(.85rem, 3vw, 1.5rem) .7rem; }
.thread-placeholder { text-align: center; color: var(--muted); padding: clamp(1rem, 8vh, 4rem) 0; }
.message-list { display: grid; gap: 1.3rem; }
.message { min-width: 0; color: var(--text); }
.message.user { justify-self: end; max-width: min(43rem, 91%); }
.user .message-body {
  background: #23352a;
  border: 1px solid #385545;
  border-radius: .95rem .95rem .22rem .95rem;
  padding: .7rem .85rem;
}
.message-heading { display: flex; align-items: center; gap: .5rem; margin-bottom: .45rem; font-size: .9rem; font-weight: 650; color: var(--muted); }
.message-heading .provider-icon { width: 1.55rem; height: 1.55rem; font-size: .88rem; border-radius: .4rem; }
.message-body { color: var(--text); line-height: 1.65; overflow-wrap: anywhere; font-size: 1rem; }
.message-body.plain { white-space: pre-wrap; }
.message-body > * + * { margin-top: .65rem; }
.message-body h2, .message-body h3 { line-height: 1.35; font-size: 1.11rem; }
.message-body ul, .message-body ol { padding-inline-start: 1.45rem; margin-bottom: 0; }
.message-body code { font: .88em/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.message-body :not(pre) > code { padding: .1rem .23rem; background: #26322a; border-radius: .25rem; color: #cde5d3; }
.message-body pre {
  margin-bottom: 0;
  white-space: pre;
  overflow: auto;
  padding: .85rem;
  background: #0d110e;
  border: 1px solid var(--line);
  border-radius: .65rem;
  scrollbar-width: thin;
}
.message-body pre code { color: #dbe8dd; }
.event-panel { padding: .7rem .85rem; background: var(--panel); border: 1px solid var(--line); border-radius: .6rem; min-width: 0; }
.event-panel + .event-panel { margin-top: -.7rem; }
.event-panel summary { cursor: pointer; font-size: .9rem; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.event-panel h3 { font-size: .96rem; overflow-wrap: anywhere; }
.event-panel .event-detail { color: var(--muted); font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; margin: .35rem 0 0; line-height: 1.55; }
.event-panel.error { color: var(--coral); border-color: #6d433a; background: #372722; font-size: .95rem; overflow-wrap: anywhere; }
.approval-panel { border-color: #776045; background: #2b2520; }
.approval-panel .approval-actions { display: flex; gap: .5rem; margin-top: .6rem; }
.approval-panel .approval-result { color: var(--muted); font-size: .85rem; margin-top: .4rem; }
.approval-error { font-size: .9rem; color: var(--coral); margin-top: .4rem; }
.copy-message { font-size: .82rem; min-height: 2.1rem; margin: .35rem 0 0 -.35rem; padding: .35rem; }

.composer-area { padding: .45rem clamp(.8rem, 3vw, 1.5rem) max(.8rem, env(safe-area-inset-bottom)); }
.composer {
  width: min(100%, calc(var(--max-content) - 3rem));
  margin: 0 auto;
  display: grid;
  gap: .2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .85rem;
  padding: .55rem;
}
.composer:focus-within { border-color: #719780; }
.composer textarea {
  color: var(--text);
  background: transparent;
  border: none;
  outline: 0 solid transparent;
  resize: none;
  field-sizing: content;
  display: block;
  width: 100%;
  min-height: 2.55rem;
  max-height: min(9rem, 24vh);
  padding: .45rem .3rem;
  font-size: 1rem;
  line-height: 1.45;
}
.composer textarea:focus-visible { outline: 0; }
.composer textarea::placeholder, input::placeholder { color: var(--muted); }
.composer-controls { display: flex; justify-content: flex-end; align-items: center; gap: .45rem; }
.composer-caption { margin-right: auto; padding-left: .35rem; font-size: .8rem; color: var(--muted); }
.stop-button { color: var(--coral); background: #372722; border-color: #6d433a; }
.stop-button:hover:not(:disabled) { background: #4a312a; }
.stop-button:disabled { opacity: .65; }
.stop-button span[aria-hidden] { font-size: .72rem; }
.send-button { min-width: 4.15rem; }

dialog {
  padding: 0;
  width: min(100% - 2rem, 32rem);
  max-height: min(85dvh, 43rem);
  color: var(--text);
  background: var(--rail);
  border: 1px solid var(--line);
  border-radius: .9rem;
  box-shadow: 0 1rem 5rem #0009;
}
dialog::backdrop { background: #080c08bd; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: .5rem; border-bottom: 1px solid var(--subtle-line); padding: .55rem .8rem .55rem 1.2rem; }
.dialog-heading h2 { font-size: 1.1rem; }
.dialog-form, .history-body { padding: 1.15rem; display: grid; gap: .9rem; }
fieldset { margin: 0; padding: 0; border: 0; min-inline-size: 0; }
fieldset legend { padding: 0; margin: 0 0 .5rem; }
.field { display: grid; gap: .45rem; }
label, legend { font-size: .875rem; font-weight: 650; }
input:not([type="radio"]) { width: 100%; min-height: 2.75rem; border: 1px solid var(--line); border-radius: .55rem; padding: .6rem .7rem; background: var(--page); color: var(--text); font-size: 1rem; }
input:not([type="radio"]):focus { outline-offset: 1px; }
.form-error { color: var(--coral); font-size: .92rem; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .65rem; }
.history-list { max-height: 52dvh; overflow: auto; scrollbar-width: thin; }
.history-list .session-entry { border-color: var(--subtle-line); padding: .55rem .65rem; }
.history-list .session-entry[disabled] { opacity: .65; }
.history-status { color: var(--muted); font-size: .92rem; }
.history-status:empty { display: none; }
.history-date { font-size: .8rem; color: var(--muted); padding-left: .15rem; }

@media (max-width: 720px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    z-index: 4;
    inset: 0 auto 0 0;
    width: min(85vw, 19rem);
    transform: translateX(-102%);
    transition: transform .17s ease;
    visibility: hidden;
  }
  .sidebar.is-open { transform: translateX(0); visibility: visible; }
  .sidebar-scrim:not([hidden]) { display: block; position: fixed; z-index: 3; inset: 0; background: #080b08aa; }
  .sidebar-close, .mobile-menu { display: inline-flex; }
  .mobile-menu { margin-left: -.4rem; }
  .menu-icon { width: 1.05rem; height: .74rem; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; position: relative; }
  .menu-icon::before { content: ""; position: absolute; inset: calc(50% - 1px) 0 auto; height: 2px; background: currentColor; }
  .thread-header { min-height: 3.85rem; padding-inline: .8rem; gap: .5rem; }
  .thread-heading p { font-size: .77rem; }
  .thread-status { font-size: .8rem; gap: .35rem; }
  .thread-content { padding-top: .9rem; }
  .composer-caption { display: none; }
  .composer-area { padding-inline: .7rem; }
}
@media (max-width: 360px) {
  .provider-grid { gap: .4rem; }
  .provider-card { padding-inline: .4rem; font-size: .88rem; }
  .provider-card .provider-icon { width: 1.6rem; height: 1.6rem; font-size: .92rem; }
  .thread-heading > .provider-icon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
