:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --text: #17202c;
  --muted: #667085;
  --line: #d7dee7;
  --accent: #2f7d32;
  --accent-strong: #1f5f25;
  --soft: #f6f8fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 Arial, sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100dvh;
  min-height: 100dvh;
}

.brand-mark {
  position: fixed;
  left: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 1;
  width: min(210px, 42vw);
  height: auto;
  opacity: 0.36;
  pointer-events: none;
  user-select: none;
}

.chat-pane,
.thread-pane {
  min-height: 0;
  padding: 14px;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.thread-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.topbar,
.thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.eyebrow,
.status,
.chat-preview,
.chat-time,
.empty-state span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  font-size: 18px;
}

.version-badge {
  display: inline-grid;
  min-width: 48px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eaf5ea;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.back-button {
  display: none;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.chat-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.chat-item.is-active {
  border-color: var(--accent);
  background: #f0f7ef;
}

.chat-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-preview {
  grid-column: 1 / -1;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.thread-body {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

.message-block {
  max-width: 860px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  white-space: pre-wrap;
}

.empty-state {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  min-height: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
  text-align: center;
}

.reply-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

textarea {
  width: 100%;
  min-height: 76px;
  max-height: 160px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}

.reply-form button {
  height: 42px;
  align-self: end;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.reply-form button:disabled,
textarea:disabled {
  cursor: default;
  opacity: 0.55;
}

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

  .app {
    grid-template-columns: 1fr;
    height: 100dvh;
    min-height: 100dvh;
  }

  .brand-mark {
    left: 12px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 170px;
    opacity: 0.34;
  }

  .chat-pane,
  .thread-pane {
    grid-row: 1;
    grid-column: 1;
    height: 100dvh;
    min-height: 0;
    padding: 10px;
    padding-bottom: 10px;
  }

  .thread-pane {
    display: none;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--bg);
    padding-bottom: 132px;
  }

  body.thread-open .chat-pane {
    display: none;
  }

  body.thread-open .thread-pane {
    display: grid;
  }

  .back-button {
    display: inline-grid;
    place-items: center;
  }

  .reply-form {
    position: fixed;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: 8px;
    z-index: 20;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
    box-shadow: 0 -8px 22px rgba(15, 23, 42, 0.12);
  }

  .reply-form button {
    width: 100%;
    height: 40px;
  }

  textarea {
    min-height: 52px;
    max-height: 72px;
    resize: none;
  }

  .thread-body {
    min-height: 0;
    padding-bottom: 2px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 16px;
  }

  .message-block {
    padding: 10px;
  }
}
