:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --green: #00a884;
  --green-dark: #005c4b;
  --incoming: #202c33;
  --outgoing: #005c4b;
  --danger: #f15c6d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: #0a1014;
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.sidebar,
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.sidebar-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--panel-2);
  min-height: 72px;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 16px;
}

.muted {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 22px;
  cursor: pointer;
}

.webhook-banner {
  margin: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #182229;
  font-size: 12px;
}

.webhook-banner code {
  display: block;
  margin-top: 6px;
  color: #9be7c4;
  word-break: break-all;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.conversation-list li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.conversation-list li:hover,
.conversation-list li.active {
  background: #2a3942;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #6a7175;
  font-weight: 600;
}

.preview {
  min-width: 0;
}

.preview strong,
.preview p {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 24px 18px;
  color: var(--muted);
  font-size: 14px;
}

.chat {
  background:
    linear-gradient(rgba(11, 20, 26, 0.88), rgba(11, 20, 26, 0.88)),
    radial-gradient(circle at 20% 20%, #1a2a32, #0b141a 55%);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: min(72%, 560px);
  padding: 8px 10px;
  border-radius: 8px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.inbound {
  align-self: flex-start;
  background: var(--incoming);
}

.bubble.outbound {
  align-self: flex-end;
  background: var(--outgoing);
}

.bubble time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: #aebac1;
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 12px;
  background: var(--panel-2);
}

.template-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
  cursor: pointer;
}

.text-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.variable-fields {
  display: grid;
  gap: 10px;
}

.template-preview {
  min-height: 2.4em;
  white-space: pre-wrap;
}

.template-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 168, 132, 0.25);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input,
textarea,
button {
  font: inherit;
}

.composer input,
dialog input,
dialog textarea {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: #2a3942;
  color: var(--text);
  padding: 12px 14px;
}

.composer button,
dialog button {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  padding: 0 18px;
  cursor: pointer;
}

button.secondary {
  background: #2a3942;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  width: min(480px, 92vw);
}

dialog select {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: #2a3942;
  color: var(--text);
  padding: 12px 14px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog form {
  display: grid;
  gap: 12px;
}

dialog label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.error {
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 38%;
  }
}
