:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --line: #ded7c8;
  --ink: #1e2320;
  --muted: #6c716b;
  --green: #1f8a58;
  --amber: #b7791f;
  --red: #c2413d;
  --teal: #0f766e;
  --tool: #ede8dc;
  --shadow: 0 10px 30px rgba(36, 31, 22, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #f2eee4;
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  min-height: 0;
  height: 100dvh;
}

.topbar,
.thread-header {
  min-height: 72px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.thread-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p,
.thread-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.send-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}

.icon-button:active,
.send-button:active {
  transform: translateY(1px);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(194, 65, 61, 0.12);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 138, 88, 0.16);
}

.search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.search-wrap input,
.login-panel input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 11px 12px;
  min-height: 42px;
  color: var(--ink);
  outline: none;
}

.search-wrap input:focus,
.login-panel input:focus,
.composer textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.thread-list {
  overflow: auto;
  padding: 8px;
  min-height: 0;
}

.thread-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  background: transparent;
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 9px;
  align-items: start;
  color: var(--ink);
}

.thread-item.active {
  border-color: #c8bfae;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.thread-item .mini-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  margin-top: 5px;
  background: #9ca3af;
}

.thread-item.busy .mini-dot {
  background: var(--amber);
}

.thread-item h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  letter-spacing: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail {
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--surface);
}

.thread-title-block {
  min-width: 0;
  flex: 1;
}

.thread-title-block h2,
.thread-title-block p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-only {
  display: none;
}

.job-strip {
  border-bottom: 1px solid var(--line);
  background: #fff7e6;
  color: #6b4e16;
  padding: 8px 14px;
  font-size: 12px;
  line-height: 1.35;
}

.hidden {
  display: none !important;
}

.messages {
  overflow: auto;
  min-height: 0;
  padding: 18px clamp(12px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.message {
  max-width: min(760px, 92%);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.45;
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: #dff2e8;
  border: 1px solid #b8dec9;
}

.message.assistant {
  align-self: flex-start;
  background: #f5f0e6;
  border: 1px solid var(--line);
}

.message.status,
.message.tool {
  align-self: center;
  max-width: min(680px, 96%);
  background: var(--tool);
  color: #4f554f;
  border: 1px solid #d8d0c0;
  font-size: 12px;
}

.message.final {
  border-left: 4px solid var(--green);
}

.message .meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 5px;
  white-space: nowrap;
}

.message details {
  margin-top: 6px;
}

.message summary {
  cursor: pointer;
  color: var(--teal);
}

.composer {
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 9px;
  border-top: 1px solid var(--line);
  background: #f8f5ed;
}

.composer textarea {
  min-height: 42px;
  max-height: 132px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}

.send-button {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.send-button:disabled,
.composer textarea:disabled {
  opacity: 0.45;
}

.login {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--paper);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  position: relative;
  z-index: 11;
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 22px;
}

.login-panel input,
.login-panel button {
  position: relative;
  z-index: 12;
}

.login-panel .mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #dff2e8;
  color: var(--green);
  font-size: 24px;
  margin-bottom: 12px;
}

.login-panel h1 {
  margin: 0 0 16px;
  font-size: 24px;
  letter-spacing: 0;
}

.login-panel label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-panel button {
  margin-top: 12px;
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--green);
  background: var(--green);
  color: white;
}

.error {
  color: var(--red);
  font-size: 12px;
  min-height: 16px;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 100vw 100vw;
    width: 200vw;
    transition: transform 180ms ease;
  }

  body.in-thread .app-shell {
    transform: translateX(-100vw);
  }

  .sidebar {
    border-right: 0;
  }

  .detail {
    width: 100vw;
  }

  .mobile-only {
    display: inline-grid;
  }

  .message {
    max-width: 94%;
    font-size: 14px;
  }
}
