:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f6f6f7;
  --panel-2: #efeff1;
  --text: #111111;
  --muted: #8a8d92;
  --line: #e7e7e9;
  --bubble: #f3f3f4;
  --user: #2d8a76;
  --user-text: #ffffff;
  --accent: #111111;
  --danger: #b42318;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 12px);
  border-right: 1px solid var(--line);
  background: var(--bg);
  z-index: 20;
}

.sidebar-top {
  display: grid;
  gap: 10px;
  align-items: center;
}

.sidebar-new {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.search-box {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
}

.icon-button,
.plain-icon,
.round-button {
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--text);
}

.sidebar-new,
.icon-button,
.plain-icon,
.round-button,
.sheet-primary,
.workdir-custom button,
.workdir-details summary,
.attachment button {
  transition:
    transform 0.16s cubic-bezier(0.2, 0.9, 0.2, 1),
    background-color 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease;
}

.sidebar-new:active,
.sidebar-new.touch-press,
.sheet-primary:active,
.sheet-primary.touch-press,
.workdir-custom button:active,
.workdir-custom button.touch-press,
.workdir-details summary:active,
.workdir-details summary.touch-press {
  transform: scale(0.985);
}

.icon-button:active,
.icon-button.touch-press,
.plain-icon:active,
.plain-icon.touch-press,
.round-button:active,
.round-button.touch-press,
.attachment button:active,
.attachment button.touch-press {
  transform: scale(0.92);
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 24px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #dceeff, #dff8ea);
  color: #1d4b3f;
  font-weight: 700;
}

.avatar.small {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

.workdir-panel {
  display: grid;
  gap: 8px;
}

.workdir-panel label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.workdir-panel select,
.workdir-custom input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
}

.workdir-custom {
  display: grid;
  grid-template-columns: 1fr 54px 54px;
  gap: 8px;
}

.workdir-custom button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
}

.workflow-list {
  min-height: 0;
  overflow: auto;
  margin-top: 16px;
  padding-right: 4px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.workflow-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition:
    background-color 0.16s ease,
    box-shadow 0.16s ease;
}

.workflow-item.has-alert {
  background: #f8fbfa;
}

.workflow-item:active,
.workflow-item.touch-press {
  background: var(--panel);
}

.workflow-item.active {
  background: var(--panel);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.workflow-dot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #eaf5ff;
  color: #4c667c;
  font-size: 14px;
}

.workflow-alert {
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
}

.workflow-title,
.workflow-meta {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-title {
  font-size: 16px;
  font-weight: 700;
}

.workflow-meta,
.workflow-empty {
  color: var(--muted);
  font-size: 12px;
}

.workflow-empty {
  padding: 18px 4px;
}

.small-button {
  width: 38px;
  height: 38px;
  font-size: 18px;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  z-index: 15;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 14px);
  z-index: 40;
  transform: translateX(-50%);
  max-width: min(88vw, 420px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 700;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

.chat-topbar {
  display: grid;
  grid-template-columns: 48px 1fr 86px;
  align-items: center;
  min-height: 66px;
  padding: env(safe-area-inset-top) 16px 8px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  z-index: 5;
}

.top-actions {
  display: grid;
  grid-template-columns: 42px 42px;
  justify-content: end;
  align-items: center;
}

.plain-icon {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 26px;
}

.plain-icon.small-plain {
  width: 40px;
  height: 40px;
  font-size: 22px;
}

.plain-icon.has-alert::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: #22c55e;
}

.chat-title {
  display: grid;
  justify-items: center;
  min-width: 0;
}

.chat-title strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}

.chat-title span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 20px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  margin: 0 0 14px;
}

.message.user {
  justify-content: flex-end;
}

.message.system {
  justify-content: center;
}

.bubble {
  position: relative;
  max-width: min(86%, 700px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.58;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--bubble);
}

.bubble-content {
  white-space: inherit;
}

.bubble-copy {
  position: absolute;
  top: 5px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  opacity: 0;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.bubble:hover .bubble-copy,
.bubble:focus-within .bubble-copy {
  opacity: 1;
}

.bubble-copy:active {
  transform: scale(0.9);
}

.send-state {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  vertical-align: -1px;
  border-radius: 50%;
}

.bubble.sending .send-state {
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.bubble.delivered .send-state {
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.9);
}

.user .bubble {
  color: var(--user-text);
  background: var(--user);
}

.system .bubble {
  color: var(--muted);
  background: transparent;
  font-size: 13px;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.message-images a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message-images img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.composer {
  position: relative;
  padding: 8px 16px 12px;
}

.action-sheet {
  position: absolute;
  left: 16px;
  right: auto;
  bottom: 76px;
  z-index: 10;
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  transform-origin: 28px calc(100% + 10px);
  animation: sheet-pop 0.18s cubic-bezier(0.2, 0.9, 0.2, 1);
}

.action-sheet[hidden] {
  display: none;
}

.sheet-primary {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.sheet-secondary {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

.workdir-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.workdir-details summary {
  min-height: 42px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.workdir-details summary::-webkit-details-marker {
  display: none;
}

.workdir-details summary::after {
  content: "›";
  float: right;
  color: var(--muted);
}

.workdir-details[open] summary::after {
  transform: rotate(90deg);
}

.workdir-details .workdir-panel {
  padding: 0 10px 10px;
}

.attachment-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 0 8px;
}

.attachment {
  position: relative;
  flex: 0 0 auto;
  width: 66px;
  height: 66px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
}

.composer-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: end;
  min-height: 64px;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
  transition: box-shadow 0.18s ease;
}

.composer:focus-within .composer-row {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
}

.round-button {
  width: 44px;
  height: 44px;
  border: 2px solid var(--text);
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}

.round-button.send {
  background: var(--text);
  color: var(--bg);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  resize: none;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  padding: 10px 4px;
  line-height: 1.45;
  font-size: 17px;
}

textarea::placeholder {
  color: #aeb0b4;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

@keyframes sheet-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow);
  }

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

  .chat {
    height: 100dvh;
  }

  .bubble {
    max-width: 92%;
    font-size: 16px;
  }

  .bubble-copy {
    opacity: 0.72;
  }
}
