:root {
  --bg: #f7f7f4;
  --sidebar: #eeeeeb;
  --sidebar-hover: #e4e4df;
  --panel: #ffffff;
  --ink: #1f211d;
  --muted: #777973;
  --soft: #a2a49d;
  --line: #deded8;
  --line-strong: #cecec6;
  --button: #242622;
  --button-hover: #000000;
  --running: #b88624;
  --danger: #b45342;
  --code: #191b17;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-overlay {
  display: none;
}

.brand {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 7px;
}

.mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #20211e;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.brand-title {
  font-size: 14px;
  font-weight: 670;
}

.brand-sub,
.subtitle,
.empty-sub {
  color: var(--muted);
  font-size: 12px;
}

.primary {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fbfbf8;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 560;
}

.primary:hover {
  background: #fff;
}

.section-title {
  padding: 9px 8px 2px;
  color: var(--soft);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
}

.job-list {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.job {
  border-radius: 8px;
  padding: 8px 9px;
  cursor: pointer;
  color: #343631;
}

.job:hover {
  background: var(--sidebar-hover);
}

.job.active {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.035);
}

.job-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.35;
}

.job-meta {
  margin-top: 3px;
  display: flex;
  justify-content: space-between;
  color: var(--soft);
  font-size: 11px;
}

.main {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr) auto;
  background: var(--bg);
}

.topbar {
  padding: 9px 22px;
  border-bottom: 1px solid rgba(222, 222, 216, 0.7);
  background: rgba(247, 247, 244, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-button {
  display: none;
}

.title {
  font-size: 14px;
  line-height: 1.3;
  font-weight: 680;
}

.status-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.outputs {
  margin-left: auto;
  margin-right: 12px;
  position: relative;
}

.outputs:empty {
  display: none;
}

.outputs-menu {
  position: relative;
}

.outputs-menu summary {
  height: 30px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  cursor: pointer;
  padding: 0 10px;
  font-size: 12px;
  list-style: none;
}

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

.outputs-list {
  position: absolute;
  z-index: 40;
  right: 0;
  top: 36px;
  width: min(360px, 80vw);
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 252, 0.98);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.14);
  padding: 6px;
}

.output-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 12px;
}

.output-item:hover {
  background: var(--sidebar-hover);
}

.output-name {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.output-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.output-name small {
  color: var(--soft);
}

.output-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.output-actions a {
  color: #246b5c;
  text-decoration: none;
  font-size: 11px;
}

.output-actions a:hover {
  text-decoration: underline;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4f8f67;
}

.dot.running {
  background: var(--running);
}

.dot.error {
  background: var(--danger);
}

.conversation {
  overflow: auto;
  padding: 30px 20px 24px;
}

.conversation-inner,
.message,
.empty {
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.empty {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.empty-title {
  font-size: 26px;
  font-weight: 640;
  letter-spacing: 0;
}

.message {
  margin-bottom: 22px;
  display: flex;
}

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

.message.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: min(680px, 88%);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.58;
  font-size: 14px;
}

.message.user .bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.02);
}

.message.assistant .bubble {
  padding: 2px 0;
  border: 0;
  background: transparent;
}

.markdown p {
  margin: 0 0 12px;
}

.markdown p:last-child {
  margin-bottom: 0;
}

.markdown h3,
.markdown h4,
.markdown h5 {
  margin: 18px 0 8px;
  font-size: 15px;
  line-height: 1.35;
}

.markdown h3:first-child,
.markdown h4:first-child,
.markdown h5:first-child {
  margin-top: 0;
}

.markdown ol,
.markdown ul {
  margin: 8px 0 14px;
  padding-left: 22px;
}

.markdown li {
  margin: 7px 0;
  padding-left: 2px;
}

.markdown blockquote {
  margin: 10px 0 14px;
  padding: 8px 12px;
  border-left: 3px solid var(--line-strong);
  color: #4e514b;
  background: rgba(255, 255, 255, 0.48);
  border-radius: 0 8px 8px 0;
}

.markdown blockquote p {
  margin: 0;
}

.markdown code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.7);
  padding: 1px 5px;
  font: 0.92em "SFMono-Regular", Consolas, ui-monospace, monospace;
}

.markdown pre {
  margin: 10px 0 14px;
  border-radius: 8px;
  background: var(--code);
  color: #e2e6dc;
  padding: 12px;
  overflow: auto;
}

.markdown pre code {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
}

.markdown a {
  color: #246b5c;
  text-decoration: none;
  border-bottom: 1px solid rgba(36, 107, 92, 0.28);
}

.markdown a:hover {
  border-bottom-color: currentColor;
}

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

.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  transform: translateY(2px);
  background: #282a25;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.debug {
  max-width: 820px;
  margin: 8px auto 0;
}

.debug summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 0;
}

.message.assistant .debug {
  max-width: min(680px, 88%);
  margin: 0;
}

.message.assistant .debug summary {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.58;
  list-style: none;
}

.message.assistant .debug summary::-webkit-details-marker {
  display: none;
}

.debug pre {
  margin: 0;
  border-radius: 8px;
  background: var(--code);
  color: #e2e6dc;
  padding: 12px;
  overflow: auto;
  font: 12px/1.45 "SFMono-Regular", Consolas, ui-monospace, monospace;
}

.composer {
  padding: 12px 20px 18px;
  background: linear-gradient(to top, var(--bg) 78%, rgba(247, 247, 244, 0));
}

.workdir-row {
  width: min(820px, 100%);
  margin: 0 auto 8px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  color: var(--soft);
  font-size: 11px;
}

.workdir-row span {
  font-weight: 650;
}

#workdir {
  min-width: 0;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 7px;
  outline: none;
  background: transparent;
  color: var(--muted);
  padding: 0 7px;
  font-size: 11px;
}

#workdir:hover,
#workdir:focus {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.composer-actions {
  width: min(820px, 100%);
  margin: 0 auto;
  position: relative;
}

.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.upload-preview:empty {
  display: none;
}

.upload-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
  width: min(260px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.78);
  padding: 6px;
}

.upload-remove {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.upload-remove:hover {
  color: var(--danger);
  border-color: rgba(180, 83, 66, 0.5);
}

.upload-card.failed {
  border-color: rgba(180, 83, 66, 0.55);
}

.upload-card img,
.file-thumb {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--sidebar-hover);
}

.file-thumb {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.upload-info {
  min-width: 0;
}

.upload-info strong,
.upload-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-info strong {
  font-size: 12px;
}

.upload-info span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

#prompt {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: #ffffff;
  padding: 14px 96px 14px 15px;
  outline: none;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.045);
  font-size: 14px;
  line-height: 1.45;
}

#prompt:focus {
  border-color: #b8bbb2;
}

.file-input {
  display: none;
}

.attach,
#send {
  position: absolute;
  bottom: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--button);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.attach {
  right: 48px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.attach:hover {
  background: var(--sidebar-hover);
}

.attach:disabled {
  opacity: 0.45;
  cursor: default;
}

#send {
  right: 10px;
}

#send:hover {
  background: var(--button-hover);
}

#send:disabled {
  opacity: 0.45;
  cursor: default;
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .shell {
    display: block;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(82vw, 318px);
    max-height: none;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 18px 0 45px rgba(0, 0, 0, 0.12);
    transform: translateX(-104%);
    transition: transform 180ms ease;
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    z-index: 25;
    inset: 0;
    background: rgba(31, 33, 29, 0.24);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .brand {
    height: 44px;
  }

  .primary {
    height: 38px;
    font-size: 14px;
  }

  .job-list {
    padding-bottom: 12px;
  }

  .job {
    padding: 11px 10px;
  }

  .job-title {
    font-size: 14px;
  }

  .main {
    min-height: 100dvh;
    height: 100dvh;
    grid-template-rows: calc(50px + env(safe-area-inset-top)) minmax(0, 1fr) auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: env(safe-area-inset-top) 12px 8px;
    min-height: calc(50px + env(safe-area-inset-top));
    justify-content: flex-start;
    gap: 10px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .icon-button {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--ink);
    font-size: 17px;
    line-height: 1;
  }

  .topbar > div:first-of-type {
    min-width: 0;
    flex: 1;
  }

  .title {
    font-size: 15px;
  }

  .subtitle {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .status-wrap {
    flex: 0 0 auto;
    max-width: 96px;
    overflow: hidden;
    white-space: nowrap;
    font-size: 11px;
  }

  .outputs {
    margin-left: 0;
    margin-right: 6px;
  }

  .outputs-menu summary {
    height: 30px;
    max-width: 92px;
    padding: 0 8px;
    overflow: hidden;
    white-space: nowrap;
    font-size: 11px;
  }

  .outputs-list {
    right: -58px;
    width: min(330px, calc(100vw - 20px));
  }

  .conversation {
    padding: 18px 14px 16px;
    -webkit-overflow-scrolling: touch;
  }

  .conversation-inner,
  .message,
  .empty,
  .debug {
    max-width: 100%;
  }

  .empty {
    min-height: 54dvh;
    place-content: center;
    padding: 0 20px;
  }

  .empty-title {
    font-size: 23px;
    line-height: 1.2;
  }

  .message {
    margin-bottom: 18px;
  }

  .bubble {
    max-width: 92%;
    font-size: 15px;
    line-height: 1.62;
  }

  .message.user .bubble {
    border-radius: 17px;
    padding: 9px 13px;
  }

  .debug pre {
    max-height: 40dvh;
    font-size: 11px;
  }

  .message.assistant .debug {
    max-width: 92%;
  }

  .composer {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(247, 247, 244, 0.96);
    border-top: 1px solid rgba(222, 222, 216, 0.72);
  }

  .workdir-row {
    width: 100%;
    margin-bottom: 6px;
    font-size: 10px;
  }

  #workdir {
    height: 23px;
    font-size: 10px;
  }

  #prompt {
    width: 100%;
    min-height: 48px;
    max-height: 132px;
    border-radius: 16px;
    padding: 12px 88px 12px 13px;
    font-size: 16px;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
  }

  .composer-actions {
    width: 100%;
  }

  #send {
    right: 8px;
    bottom: 8px;
    width: 32px;
    height: 32px;
  }

  .attach {
    right: 46px;
    bottom: 8px;
  }

  body.sidebar-open .main {
    pointer-events: none;
  }
}
