.agent-root {
  position: relative;
  flex: 0 0 0;
  width: 0;
  min-width: 0;
  align-self: stretch;
  min-height: 0;
  overflow: hidden;
  transition: flex-basis 250ms ease, width 250ms ease;
}

.agent-tab {
  --tab-h: 56px;
  position: fixed;
  right: 0;
  z-index: 20;
  top: max(
    calc(var(--top) + var(--tab-h) / 2),
    min(
      calc(var(--top) + (100vh - var(--top)) / 2),
      calc(100vh - 74px - var(--tab-h) / 2)
    )
  );
  width: 40px;
  height: var(--tab-h);
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 12px 0 0 12px;
  background: var(--paper);
  color: var(--muted);
  box-shadow: 0 2px 10px rgba(28, 25, 21, 0.08);
  cursor: pointer;
  transform: translateY(-50%);
  transition: transform 160ms ease, color 160ms ease;
}

.agent-tab:hover {
  transform: translateY(-50%) translateX(-4px);
  color: var(--ink);
}

.agent-tab:focus {
  outline: var(--focus);
  outline-offset: 2px;
}

.agent-tab svg { width: 1.35rem; height: 1.35rem; display: block; }

.agent-tab .agent-badge {
  top: -0.3rem;
  left: -0.3rem;
  right: auto;
}

.agent-backdrop { display: none; }

.agent-drawer {
  --agent-gutter: 0.85rem;
  position: relative;
  z-index: 1;
  width: 26rem;
  min-width: 26rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
}

.agent-root:not(.is-open) .agent-notice,
.agent-root:not(.is-open) .agent-pins,
.agent-root:not(.is-open) .agent-pin-note,
.agent-root:not(.is-open) .agent-filter,
.agent-root:not(.is-open) .agent-pin-slot,
.agent-root:not(.is-open) .agent-thread,
.agent-root:not(.is-open) .agent-pill,
.agent-root:not(.is-open) .agent-compose { visibility: hidden; }

.agent-root:not(.is-open) .agent-brief-slot { display: none; }

.agent-head {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  padding: 0.55rem 0.45rem 0.35rem 0.85rem;
  flex: 0 0 auto;
}

.agent-head strong {
  flex: 0 0 auto;
  font-size: 1.05rem;
  font-weight: 650;
  white-space: nowrap;
}

.agent-head .agent-date { margin-left: auto; flex: 0 0 auto; }

.agent-close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
}

.agent-notice {
  display: block;
  width: 26rem;
  max-width: 100%;
  margin: 0;
  padding: 0 0.75rem 0.35rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.3;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.agent-notice:disabled { cursor: default; }

.agent-notice[hidden] { display: none !important; }

.agent-mark {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: auto;
  color: var(--brand);
}

.agent-mark svg { width: 1.35rem; height: 1.35rem; display: block; }

.agent-badge {
  position: absolute;
  top: -0.35rem;
  right: 0.28rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.22rem;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 0 0 2px var(--surface);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.05rem;
  text-align: center;
}

.agent-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
  animation: agent-pulse 2.4s ease-in-out infinite;
}

.agent-dot.is-ai { background: var(--accent-free); }

.agent-dot.is-ai { animation: none; }

.agent-status {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-date {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.agent-pins,
.agent-pin-note,
.agent-filter,
.agent-pin-slot,
.agent-pill,
.agent-compose { flex: 0 0 auto; }

.agent-pin-slot { padding: 0 var(--agent-gutter, 0.85rem); }

.agent-brief-slot {
  flex: 0 0 auto;
  min-height: 0;
  max-height: 40%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.agent-brief-slot > .agent-brief {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--ink) 20%, transparent) transparent;
}

.agent-brief-slot > .agent-brief.is-folded {
  flex: 0 0 auto;
  align-self: flex-start;
  width: fit-content;
  max-height: none;
  overflow: visible;
}

.agent-context {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 0.35rem;
  padding: 0.15rem 0.45rem 0.15rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
}

.agent-context-name {
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-context-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.agent-opened {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  max-width: 100%;
  margin-top: 0.35rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.agent-opened-tag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.agent-opened p { margin: 0; }

.agent-results {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  max-width: 100%;
  margin-top: 0.35rem;
}

.agent-result-head,
.agent-result {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.agent-result-head {
  color: var(--muted);
  font-size: 0.68rem;
}

.agent-result {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.agent-free-count {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.agent-free-when {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.agent-invoice-card {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

.agent-invoice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 6px;
}

.agent-invoice-row:last-child { margin-bottom: 0; }

.agent-pins {
  display: flex;
  gap: 0.35rem;
  min-width: 0;
  padding: 0 0.85rem 0.35rem;
}

.agent-pins[hidden] { display: none; }

.agent-pin-chip {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  max-width: 33%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  padding: 0.08rem 0.15rem 0.08rem 0.45rem;
}

.agent-pin-jump {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.12rem 0;
  cursor: pointer;
}

.agent-pin-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  line-height: 1;
  padding: 0.1rem 0.28rem;
  cursor: pointer;
}

.agent-pin-note {
  margin: 0;
  padding: 0 0.85rem 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.agent-count {
  display: inline-grid;
  place-items: center;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 16%, var(--surface));
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 700;
}

.agent-filter {
  display: flex;
  gap: 0.15rem;
  margin: 0 0.85rem 0.35rem;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
}

.agent-filter button {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  font: inherit;
  font-size: 0.72rem;
  line-height: 1.2;
  padding: 0.18rem 0.3rem;
  cursor: pointer;
}

.agent-filter button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.agent-compose { padding: 0.35rem var(--agent-gutter, 0.85rem) 0.7rem; }

.agent-field { display: flex; gap: 0.4rem; align-items: flex-end; }

.agent-field textarea {
  flex: 1 1 auto;
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: var(--r-12);
  padding: 8px 12px;
  resize: none;
  min-height: 2.6rem;
  max-height: 9rem;
  line-height: 1.35;
}

.agent-field textarea:focus {
  outline: var(--focus);
  outline-offset: 1px;
}

.agent-send {
  width: 2.3rem;
  height: 2.3rem;
  border: 0;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--chip);
  flex: 0 0 auto;
  cursor: pointer;
}

.agent-send svg { width: 1.05rem; height: 1.05rem; display: block; }

.agent-hint { margin: 0.28rem 0 0; color: var(--muted); font-size: 0.72rem; }

.agent-thread {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.35rem var(--agent-gutter, 0.85rem) 0.15rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--ink) 20%, transparent) transparent;
}

.agent-thread-spacer { margin-top: auto; }

.agent-msg.is-user + .agent-msg.is-agent,
.agent-msg.is-agent + .agent-msg.is-user,
.agent-msg.is-user + .agent-stack,
.agent-stack + .agent-msg.is-user {
  margin-top: 7px;
}

.agent-msg {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  max-width: 85%;
}

.agent-msg.is-user { align-self: flex-end; align-items: flex-end; }

.agent-msg.is-agent, .agent-msg.is-muted { align-self: flex-start; align-items: flex-start; }

.agent-msg.is-agent { gap: 5px; }

.agent-turn {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  align-items: flex-start;
  max-width: 100%;
}

.agent-bubble {
  background: color-mix(in srgb, var(--today-wash) 62%, var(--surface));
  border-radius: 14px 14px 4px 14px;
  padding: 0.4rem 0.65rem;
  overflow: visible;
}

.agent-bubble.is-paper {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
}

.agent-bubble { white-space: pre-wrap; }

.agent-msg.is-agent .agent-opened,
.agent-msg.is-agent .agent-proposals {
  align-self: flex-start;
  max-width: 100%;
  margin-top: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px;
  padding: 0.4rem 0.65rem;
  overflow: visible;
}

.agent-copy p { margin: 0.12rem 0; }

.agent-copy ul,
.agent-copy ol { margin: 0.15rem 0; padding-left: 1.15rem; }

.agent-copy code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--chip);
  border-radius: 4px;
  padding: 0 0.15rem;
}

.agent-md-h { font-weight: 650; }

.agent-msg-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 11px;
}

.agent-link {
  color: var(--brand);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

button.agent-offer-link {
  display: inline;
  width: auto;
  margin: 0.12rem 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--brand);
  font: inherit;
  font-size: inherit;
  font-weight: 550;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
}

.agent-ms {
  margin: 0.15rem 0.85rem 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.agent-pill {
  align-self: center;
  margin: 0.15rem 0.85rem;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
}

.agent-muted { color: var(--muted); }

.agent-proposals { margin-top: 0.25rem; }

.agent-decide {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.agent-decide .primary,
.agent-decide .outline {
  padding: 6px 11px;
  width: auto;
}

button.agent-add {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  width: auto;
  padding: 2px 0 6px;
  font-size: 12.5px;
  cursor: pointer;
}

.agent-feed {
  display: flex;
  flex-direction: column;
}

.agent-day {
  align-self: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
}

.agent-team {
  position: relative;
  align-self: center;
  max-width: 92%;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: center;
}

.agent-team p { margin: 0; }

.agent-stack {
  align-self: flex-start;
  box-sizing: border-box;
  width: 85%;
  max-width: 85%;
  border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px;
  background: var(--card);
  padding: 0.4rem 0.65rem;
  overflow: visible;
}

.agent-event {
  position: relative;
  padding: 0.15rem 1.2rem 0.15rem 0;
}

.agent-event + .agent-event {
  border-top: 1px solid var(--line);
  margin-top: 0.35rem;
  padding-top: 0.4rem;
}

.agent-event-top {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
}

.agent-event-top .agent-time { margin-left: auto; }

.agent-event.is-new { animation: agent-in 0.32s ease; }

.agent-event.is-pin-mark,
.agent-msg.is-pin-mark,
.agent-team.is-pin-mark,
.agent-stack.is-pin-mark {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.agent-event.is-fresh {
  background: color-mix(in srgb, var(--today-wash) 55%, var(--surface));
  box-shadow: inset 3px 0 0 var(--brand);
}

.agent-time, .agent-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.agent-tag {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  line-height: 1.5;
  text-transform: uppercase;
}

.agent-tag.is-hold { color: var(--tag-hold); }

.agent-tag.is-offer { color: var(--accent-fixed); }

.agent-tag.is-alert { color: var(--accent-option); }

.agent-tag.is-edit { color: var(--text); }

.agent-tag.is-import,
.agent-tag.is-gap,
.agent-tag.is-brief,
.agent-tag.is-free { color: var(--muted); }

.agent-text { min-width: 0; }

.agent-text p { margin: 0; }

.agent-text strong { font-weight: 700; }

.agent-thinking {
  display: flex;
  align-self: flex-start;
  align-items: center;
  gap: 0.45rem;
  max-width: 92%;
  margin: 0;
  padding: 0;
  background: none;
  background-color: transparent;
  box-shadow: none;
  color: var(--muted);
}

.agent-thinking-mark {
  display: flex;
  flex: 0 0 auto;
  width: 1.05rem;
  height: 1.05rem;
  color: var(--text);
}

.agent-thinking-mark svg { width: 1.05rem; height: 1.05rem; display: block; }

.agent-thinking-text {
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--muted);
  background-image: linear-gradient(
    100deg,
    var(--muted) 0%,
    var(--muted) 40%,
    color-mix(in srgb, var(--surface) 78%, var(--text)) 50%,
    var(--muted) 60%,
    var(--muted) 100%
  );
  background-size: 220% 100%;
  background-repeat: no-repeat;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: agent-shimmer 1.6s linear infinite;
}

@keyframes agent-shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

.agent-pin {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  padding-right: 1.6rem;
}

.agent-pin p { margin: 0.12rem 0; }

.agent-kicker { color: var(--muted); font-size: 0.78rem; }

.agent-code { font-weight: 700; white-space: nowrap; }

.agent-x {
  position: absolute;
  top: 0.35rem;
  right: 0.05rem;
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.05rem 0.35rem;
  line-height: 1;
}

.agent-pin-btn {
  position: absolute;
  top: 0.28rem;
  right: 1.35rem;
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.68rem;
  line-height: 1;
  padding: 0.12rem 0.28rem;
  cursor: pointer;
}

.agent-event:hover .agent-pin-btn,
.agent-msg:hover .agent-pin-btn,
.agent-team:hover .agent-pin-btn,
.agent-event:focus-within .agent-pin-btn,
.agent-msg:focus-within .agent-pin-btn,
.agent-team:focus-within .agent-pin-btn,
.is-armed > .agent-pin-btn { opacity: 1; }

.agent-event:hover .agent-x,
.agent-event:focus-within .agent-x,
.agent-pin:hover .agent-x,
.agent-pin:focus-within .agent-x { opacity: 1; }

@media (max-width: 720px) {
.agent-event:hover .agent-pin-btn,
  .agent-msg:hover .agent-pin-btn,
  .agent-team:hover .agent-pin-btn { opacity: 0; }
.agent-event:focus-within .agent-pin-btn,
  .agent-msg:focus-within .agent-pin-btn,
  .agent-team:focus-within .agent-pin-btn,
  .is-armed > .agent-pin-btn { opacity: 1; }
}

.agent-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin-top: 0.35rem; }

.agent-table td {
  border-top: 1px solid var(--line);
  padding: 0.18rem 0.3rem 0.18rem 0;
  vertical-align: top;
}

.agent-table td.agent-face { white-space: nowrap; }

.agent-table td:last-child { text-align: right; color: var(--muted); white-space: nowrap; }

.agent-table td.is-count { color: var(--accent-option); }

.agent-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }

.agent-actions button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.12rem 0.48rem;
  font-size: 0.72rem;
}

.agent-actions button.is-primary {
  background: var(--ink);
  color: var(--chip);
  border-color: var(--ink);
}

@keyframes agent-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes agent-in {
  from { transform: translateY(-0.35rem); }
  to { transform: none; }
}

@media (min-width: 1200px) {
.agent-root {
    position: sticky;
    top: var(--top);
    align-self: flex-start;
    height: calc(100vh - var(--top));
    height: calc(100dvh - var(--top));
  }
.agent-root.is-open {
    flex-basis: 26rem;
    width: 26rem;
    background: var(--surface);
    border-left: 1px solid var(--line);
  }
}

@media (max-width: 1199px) {
.agent-root.is-open { overflow: visible; }
.agent-root.is-open .agent-drawer {
    position: fixed;
    top: var(--top);
    right: 0;
    bottom: 0;
    width: 92vw;
    min-width: 0;
    height: auto;
    z-index: 1101;
    box-shadow: -10px 0 28px rgba(28, 25, 21, 0.08);
  }
.agent-root.is-open .agent-backdrop {
    display: block;
    position: fixed;
    top: var(--top);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1090;
    background: rgba(28, 25, 21, 0.18);
  }
.agent-root.is-open .agent-notice { width: 100%; }
}

@media (max-width: 700px) {
.agent-tab {
    --tab-h: 46px;
    width: 34px;
  }
.agent-tab svg { width: 1.15rem; height: 1.15rem; }
}

@media (prefers-reduced-motion: reduce) {
.agent-dot { animation: none; }
.agent-event.is-new { animation: none; }
.agent-thinking-text {
    animation: none;
    background-image: none;
    -webkit-text-fill-color: currentColor;
    color: var(--muted);
  }
.agent-thread { scroll-behavior: auto; }
.agent-root,
  .agent-drawer,
  .agent-backdrop,
  .agent-tab { transition: none; }
.agent-tab:hover { transform: translateY(-50%); }
}
