:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d9dee7;
  --text: #1f2933;
  --muted: #697586;
  --accent: #0b7285;
  --accent-dark: #075866;
  --danger: #b42318;
  --warning: #a15c00;
  --ok: #1f7a4d;
  --agent: #eef6f8;
  --user: #f1f4f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

button:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

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

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 14px;
  font-weight: 700;
}

h3 {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.topbar p,
.section-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.auth {
  width: min(420px, 48vw);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.layout {
  height: calc(100vh - 73px);
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 320px;
  overflow: hidden;
}

.contacts,
.conversation,
.side {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.side {
  border-right: 0;
  overflow: auto;
}

.section-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.section-head.compact {
  min-height: auto;
  padding: 0 0 10px;
  border-bottom: 0;
}

.contact-list {
  height: calc(100% - 58px);
  overflow: auto;
}

.contact-item {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}

.contact-item.active {
  background: #e8f3f5;
}

.contact-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.contact-sub,
.last-message,
.details,
.badge {
  color: var(--muted);
  font-size: 12px;
}

.last-message {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
}

.badge.warn {
  background: #fff3df;
  color: var(--warning);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

.badge.ok {
  background: #e4f5eb;
  color: var(--ok);
}

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.actions {
  display: flex;
  gap: 8px;
}

.messages {
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  max-width: min(680px, 82%);
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--user);
}

.message.agent {
  align-self: flex-end;
  background: var(--agent);
}

.message.user {
  align-self: flex-start;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.38;
}

.composer {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.side .panel {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.review-panel {
  background: #fffdf8;
}

.draft-list,
.decision-list {
  display: grid;
  gap: 10px;
}

.draft-list {
  margin-top: 2px;
}

.draft-item,
.decision-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.draft-head,
.decision-head,
.draft-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.draft-meta,
.source-message,
.decision-item,
.decision-summary {
  color: var(--muted);
  font-size: 12px;
}

.source-message {
  padding: 8px;
  border-left: 3px solid #c8b36b;
  background: #fff8e5;
  overflow-wrap: anywhere;
}

.draft-item textarea {
  min-height: 92px;
  line-height: 1.35;
}

.draft-actions {
  justify-content: flex-end;
}

.link-button {
  min-height: auto;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--accent-dark);
  font-weight: 700;
}

.empty.tight {
  padding: 6px 0;
}

.stack {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

.details {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  padding: 16px;
}

@media (max-width: 980px) {
  .layout {
    height: auto;
    min-height: calc(100vh - 73px);
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .contacts,
  .conversation,
  .side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .contact-list {
    max-height: 280px;
  }

  .messages {
    min-height: 360px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .auth {
    width: 100%;
  }
}
