:root {
  --paper: #f5f1e8;
  --ink: #1b1e20;
  --muted: #66706d;
  --line: #d8d0c2;
  --panel: #fffaf0;
  --panel-strong: #ece4d6;
  --accent: #1f7a68;
  --accent-dark: #14584c;
  --danger: #b5473f;
  --gold: #c8993d;
  --blue: #315f8f;
  --shadow: 0 18px 50px rgba(42, 37, 28, 0.12);
  font-family: Aptos, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(90deg, rgba(27, 30, 32, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(27, 30, 32, 0.03) 1px, transparent 1px),
    var(--paper);
  background-size: 42px 42px;
  color: var(--ink);
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent-dark);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 0 16px;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.86);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.13);
}

.hidden {
  display: none !important;
}

.shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  font-weight: 700;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.status-pill {
  min-width: 86px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 250, 240, 0.7);
}

.status-pill.ok {
  color: var(--accent-dark);
  border-color: rgba(31, 122, 104, 0.35);
  background: rgba(31, 122, 104, 0.1);
}

.gate,
.setup {
  margin: 44px auto 0;
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
  padding: 24px;
}

.gate {
  display: grid;
  gap: 14px;
}

.gate-mark {
  width: 42px;
  height: 6px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--blue));
  border-radius: 999px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.error-line {
  min-height: 20px;
  color: var(--danger);
}

.muted-line {
  min-height: 22px;
  color: var(--muted);
}

.setup-head,
.thread-head,
.pane-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  margin-top: 18px;
}

.setup-grid label {
  display: grid;
  gap: 6px;
}

.setup-grid label span {
  color: var(--muted);
  font-size: 13px;
}

.setup-grid button {
  align-self: end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 42%) 1fr;
  gap: 18px;
  height: calc(100vh - 112px);
  padding-top: 18px;
}

.chat-pane,
.message-pane {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  box-shadow: var(--shadow);
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.pane-tools {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.pane-tools input {
  min-width: 0;
}

.table-head {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 12px;
  padding: 9px 14px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(236, 228, 214, 0.6);
}

.chat-list {
  min-height: 0;
  overflow: auto;
}

.chat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 12px;
  min-height: 72px;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(216, 208, 194, 0.75);
  cursor: pointer;
}

.chat-row:hover,
.chat-row.active {
  background: rgba(31, 122, 104, 0.08);
}

.chat-main {
  min-width: 0;
}

.chat-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  font-size: 11px;
}

.preview {
  margin-top: 7px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.time {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.message-pane {
  min-width: 0;
  overflow: hidden;
}

.empty-state {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 12px;
  color: var(--muted);
}

.empty-line {
  width: 120px;
  height: 4px;
  background: linear-gradient(90deg, var(--blue), var(--accent), var(--gold));
  border-radius: 999px;
}

.thread {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.thread-head {
  min-height: 74px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(236, 228, 214, 0.5);
}

.thread-head h2 {
  max-width: 72vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.message {
  display: grid;
  grid-template-columns: 126px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(216, 208, 194, 0.68);
}

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

.message-author {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-text {
  min-width: 0;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.media-label {
  display: inline-block;
  min-width: 40px;
  border: 1px solid rgba(31, 122, 104, 0.35);
  border-radius: 4px;
  padding: 2px 7px;
  color: var(--accent-dark);
  background: rgba(31, 122, 104, 0.1);
}

@media (max-width: 820px) {
  .shell {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-pane,
  .message-pane {
    height: calc(50vh - 36px);
  }

  .setup-grid,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .message {
    grid-template-columns: 86px minmax(0, 1fr);
  }
}
