:root {
  --ink: #0c1f18;
  --ink-soft: #1a3329;
  --muted: #6b8176;
  --line: #d5e3db;
  --line-strong: #b7cec2;
  --panel: #ffffff;
  --panel-soft: #f3f8f5;
  --rail: #0f2a21;
  --rail-2: #16362b;
  --rail-line: rgba(255, 255, 255, 0.08);
  --rail-text: #e8f5ee;
  --rail-muted: #9bb5a8;
  --accent: #1fa971;
  --accent-deep: #0d7a50;
  --accent-bright: #2fd48a;
  --accent-soft: #e4f7ee;
  --bubble-out: #d8f5e6;
  --bubble-in: #ffffff;
  --danger: #c23b32;
  --danger-bg: #fdeceb;
  --ok: #0c8a52;
  --ok-bg: #dff7ea;
  --warn: #9a6700;
  --warn-bg: #fff3d6;
  --sidebar-w: 340px;
  --radius: 16px;
  --shadow: 0 24px 60px rgba(8, 28, 20, 0.16);
  --shadow-soft: 0 10px 28px rgba(8, 28, 20, 0.08);
  --font: "Outfit", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 8% -10%, rgba(47, 212, 138, 0.18), transparent 55%),
    radial-gradient(700px 480px at 100% 0%, rgba(15, 42, 33, 0.18), transparent 50%),
    linear-gradient(160deg, #e9f3ed 0%, #d7e8df 45%, #c9ddd3 100%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-radius: 0;
}

@media (min-width: 1200px) {
  body { padding: 18px; }
  .app {
    height: calc(100vh - 36px);
    border-radius: 24px;
    border: 1px solid rgba(15, 42, 33, 0.08);
  }
}

/* ---- Contacts rail (dark theme) ---- */
.contacts-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(500px 280px at 0% 0%, rgba(47, 212, 138, 0.16), transparent 60%),
    linear-gradient(180deg, var(--rail) 0%, var(--rail-2) 100%);
  color: var(--rail-text);
}

.contacts-header {
  padding: 20px 16px 14px;
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--rail-line);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  flex-shrink: 0;
  background:
    linear-gradient(145deg, #36e39a 0%, #149a62 55%, #0a6a45 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.28),
    0 8px 20px rgba(0, 0, 0, 0.25);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-right-color: transparent;
  transform: rotate(45deg);
}

.brand-mark.lg {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  margin: 0 auto 16px;
}

.brand-mark.lg::after { inset: 18px; }

.brand-name {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #fff;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--rail-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.brand-row .icon-btn { margin-left: auto; }

.brand-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account-switcher select {
  max-width: 150px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 7px 8px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 650;
}

.brand-actions .icon-btn {
  margin-left: 0;
  position: relative;
  width: 36px;
  height: 36px;
}

.logs-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-bright);
  color: #063524;
  font-size: 0.65rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px var(--rail);
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input,
.modal input,
.composer-extras input,
.composer-extras textarea,
.composer-extras select,
.type-select select,
.tpl-search input,
.tpl-field select,
.tpl-vars input {
  width: 100%;
  font: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), background 0.18s var(--ease);
}

.search-row input::placeholder { color: rgba(232, 245, 238, 0.45); }

.modal input,
.composer-extras input,
.composer-extras textarea,
.composer-extras select,
.type-select select,
.tpl-field select,
.tpl-vars input,
.tpl-search input {
  background: var(--panel-soft);
  color: var(--ink);
  border-color: var(--line);
}

.tpl-search input::placeholder,
.modal input::placeholder { color: #8aa194; }

.search-row input:focus,
.modal input:focus,
.composer-extras input:focus,
.composer-extras textarea:focus,
.composer-extras select:focus,
.type-select select:focus,
.composer-input:focus,
.tpl-search input:focus,
.tpl-field select:focus,
.tpl-vars input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 169, 113, 0.22);
}

.contacts-pane .icon-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--rail-text);
}

.contacts-pane .icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: #e8f1ec;
  color: var(--ink-soft);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}

.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.accent {
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-deep));
  color: #fff;
  box-shadow: 0 8px 18px rgba(13, 122, 80, 0.35);
}

.status {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}
.pending { background: rgba(255, 243, 214, 0.9); color: var(--warn); }
.ready { background: rgba(223, 247, 234, 0.95); color: var(--ok); }
.missing { background: rgba(253, 236, 235, 0.95); color: var(--danger); }

.contact-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding: 8px;
}

.contact-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: transparent;
  padding: 11px 12px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s var(--ease);
}

.contact-item:hover { background: rgba(255, 255, 255, 0.06); }
.contact-item.active {
  background: rgba(47, 212, 138, 0.14);
  box-shadow: inset 0 0 0 1px rgba(47, 212, 138, 0.22);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.contact-meta { min-width: 0; }
.contact-name {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
}
.contact-preview {
  margin: 3px 0 0;
  color: var(--rail-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-time {
  color: var(--rail-muted);
  font-size: 0.7rem;
  font-weight: 600;
  align-self: start;
  margin-top: 4px;
}

.pane-empty {
  margin: auto;
  padding: 24px;
  text-align: center;
  color: var(--rail-muted);
}

/* ---- Chat ---- */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(15, 42, 33, 0.06) 1px, transparent 0),
    linear-gradient(180deg, #f4faf7 0%, #eaf4ef 100%);
  background-size: 22px 22px, auto;
}

.chat-placeholder {
  margin: auto;
  padding: 24px;
}

.placeholder-card {
  max-width: 400px;
  text-align: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px 30px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
  animation: rise 0.4s var(--ease);
}

.placeholder-card h2 {
  margin: 0 0 8px;
  letter-spacing: -0.04em;
  font-size: 1.7rem;
}

.placeholder-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.chat-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.chat-header .avatar { width: 42px; height: 42px; }
.back-btn { display: none; }

.chat-title { flex: 1; min-width: 0; }
.chat-title h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.muted {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.message-thread {
  flex: 1;
  overflow: auto;
  padding: 18px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.day-sep {
  align-self: center;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin: 8px 0;
}

.msg {
  max-width: min(520px, 86%);
  padding: 9px 12px 7px;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(12, 42, 30, 0.06);
  animation: rise 0.28s var(--ease);
}

.msg.out {
  align-self: flex-end;
  background: linear-gradient(180deg, #e4fbea, #cff3dc);
  border: 1px solid rgba(31, 169, 113, 0.18);
  border-bottom-right-radius: 5px;
}

.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.msg.failed {
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
}

.msg.has-webhook {
  cursor: pointer;
}

.msg.has-webhook:hover {
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

.msg-kind {
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin-bottom: 4px;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.94rem;
  line-height: 1.4;
}

.msg-meta {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.66rem;
  font-weight: 650;
  color: var(--muted);
}

.msg.failed .msg-meta { color: var(--danger); }

.thread-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 280px;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ---- Composer ---- */
.composer-bar {
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  padding: 12px 14px 14px;
  display: grid;
  gap: 8px;
}

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

.type-select { flex: 1; min-width: 0; }
.type-select select {
  padding: 8px 10px;
  font-size: 0.86rem;
  font-weight: 650;
  background: var(--panel-soft);
}

.tpl-launch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.composer-extras {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.composer-extras .wide { grid-column: 1 / -1; }
.composer-extras label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.78rem;
  color: #2a4a3d;
}

.composer-extras textarea {
  min-height: 90px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.4;
}

.composer-extras .check {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: row;
}

.composer-extras .check input { width: auto; }

.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer-input {
  flex: 1;
  min-height: 46px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 12px 16px;
  font: inherit;
  font-size: 0.95rem;
  background: #fff;
  outline: none;
  line-height: 1.35;
}

.send-btn,
.primary,
.ghost {
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  padding: 11px 16px;
  transition: transform 0.15s var(--ease), background 0.15s var(--ease), opacity 0.15s var(--ease);
}

.send-btn,
.primary {
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-deep));
  color: #fff;
  box-shadow: 0 10px 20px rgba(13, 122, 80, 0.28);
}

.send-btn {
  border-radius: 24px;
  min-width: 88px;
  height: 46px;
  padding: 0 18px;
}

.send-btn:hover,
.primary:hover { transform: translateY(-1px); }

.send-btn:disabled,
.primary:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.ghost {
  background: #e8f1ec;
  color: #2d5243;
}
.ghost:hover { background: #d7e8df; }
.ghost.sm,
.primary.sm {
  padding: 8px 12px;
  font-size: 0.82rem;
}

.composer-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 10000;
  max-width: min(480px, calc(100vw - 24px));
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.84rem;
  white-space: pre-wrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  animation: rise 0.25s var(--ease);
}
.toast.success {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #b7e7cb;
}
.toast.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f1c6c0;
}

.hidden { display: none !important; }

/* ---- Modal base ---- */
.modal {
  border: 0;
  border-radius: 20px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
  animation: pop 0.28s var(--ease);
}
.modal::backdrop {
  background: rgba(8, 24, 18, 0.55);
  backdrop-filter: blur(4px);
}
.modal form {
  display: grid;
  gap: 14px;
  padding: 22px;
}
.modal h3 {
  margin: 0;
  letter-spacing: -0.03em;
}
.modal label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.86rem;
}
.modal small {
  font-weight: 500;
  color: var(--muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
  font-weight: 500;
}

.settings-account-box {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.settings-account-value {
  margin: 0 0 8px;
  font-weight: 700;
}

.settings-webhook-url {
  display: block;
  overflow-x: auto;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #0f2a21;
  color: #d7f5e6;
  font-family: var(--mono);
  font-size: 0.72rem;
  word-break: break-all;
}

/* ---- Template modal ---- */
.modal.template-modal {
  width: min(980px, calc(100vw - 16px));
  max-height: min(90vh, 800px);
  overflow: hidden;
  border-radius: 22px;
}

.tpl-shell {
  display: flex;
  flex-direction: column;
  height: min(90vh, 800px);
  max-height: min(90vh, 800px);
  background: var(--panel);
}

.tpl-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(500px 180px at 0% 0%, rgba(47, 212, 138, 0.12), transparent 60%),
    linear-gradient(180deg, #f8fcfa, #eef6f1);
}

.tpl-eyebrow {
  margin: 0 0 4px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.tpl-top h3 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.04em;
}

.tpl-recipient {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 500;
}

.tpl-body {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  flex: 1;
  min-height: 0;
}

.tpl-browse {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
  background:
    radial-gradient(400px 220px at 0% 0%, rgba(47, 212, 138, 0.12), transparent 55%),
    linear-gradient(180deg, #12352a, #0f2a21);
  color: var(--rail-text);
}

.tpl-search { display: flex; gap: 8px; }
.tpl-search input {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: transparent;
}
.tpl-search input::placeholder { color: rgba(232, 245, 238, 0.45); }
.tpl-browse .icon-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--rail-text);
}

.tpl-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tpl-filter {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--rail-muted);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 750;
  cursor: pointer;
  text-transform: capitalize;
}

.tpl-filter.active {
  background: linear-gradient(145deg, var(--accent-bright), var(--accent-deep));
  border-color: transparent;
  color: #fff;
}

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

.tpl-item {
  display: grid;
  gap: 8px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  font: inherit;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.tpl-item:hover {
  background: rgba(255, 255, 255, 0.09);
  transform: translateY(-1px);
}

.tpl-item.active {
  background: rgba(47, 212, 138, 0.16);
  border-color: rgba(47, 212, 138, 0.35);
  box-shadow: inset 3px 0 0 var(--accent-bright);
}

.tpl-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.tpl-item-title {
  font-weight: 750;
  font-size: 0.92rem;
  line-height: 1.25;
  color: #fff;
}

.tpl-item-code {
  color: var(--rail-muted);
  font-size: 0.72rem;
  font-weight: 550;
  font-family: var(--mono);
}

.tpl-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tpl-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tpl-badge.status-approved,
.tpl-badge.status-active {
  background: rgba(223, 247, 234, 0.95);
  color: var(--ok);
}

.tpl-badge.status-pending,
.tpl-badge.status-draft {
  background: rgba(255, 243, 214, 0.95);
  color: var(--warn);
}

.tpl-badge.status-rejected,
.tpl-badge.status-failed {
  background: rgba(253, 236, 235, 0.95);
  color: var(--danger);
}

.tpl-badge.category {
  background: rgba(180, 220, 255, 0.2);
  color: #cfe8ff;
}

.tpl-pane .tpl-badge.category {
  background: #e7f0ff;
  color: #2a4f9b;
}

.tpl-status {
  margin: 0;
  color: var(--rail-muted);
  font-size: 0.74rem;
  font-weight: 600;
}

.tpl-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(15, 42, 33, 0.05) 1px, transparent 0),
    #f7fbf8;
  background-size: 18px 18px, auto;
}

.tpl-empty {
  margin: auto;
  padding: 28px;
}

.tpl-empty-card {
  max-width: 300px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: var(--shadow-soft);
}

.tpl-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 800;
}

.tpl-empty-card h4 {
  margin: 0 0 8px;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-size: 1.15rem;
}

.tpl-empty-card p {
  margin: 0;
  line-height: 1.45;
  font-size: 0.9rem;
}

.tpl-ready {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  animation: rise 0.3s var(--ease);
}

.tpl-ready-scroll {
  flex: 1;
  overflow: auto;
  padding: 18px 20px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.tpl-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tpl-heading h4 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.tpl-code {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.tpl-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.tpl-preview-card {
  border-radius: 18px;
  border: 1px solid rgba(31, 169, 113, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(232, 250, 240, 0.9)),
    linear-gradient(145deg, #dff8ea, #c9efd8);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.tpl-preview-label {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin-bottom: 10px;
}

.tpl-preview-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--ink);
}

.tpl-preview-footer {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid rgba(31, 169, 113, 0.18);
  color: var(--muted);
  font-size: 0.8rem;
}

.tpl-var-token {
  display: inline;
  background: #fff;
  border: 1px solid rgba(31, 169, 113, 0.28);
  border-radius: 7px;
  padding: 0 6px;
  font-weight: 700;
  color: var(--accent-deep);
  box-shadow: 0 1px 0 rgba(13, 122, 80, 0.08);
}

.tpl-field {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.84rem;
  color: #26473b;
}

.tpl-vars-block { display: grid; gap: 10px; }
.tpl-vars-title {
  font-size: 0.84rem;
  font-weight: 750;
  color: #26473b;
}
.tpl-vars { display: grid; gap: 10px; }
.tpl-vars label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 0.82rem;
}
.tpl-vars-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.tpl-send-bar {
  border-top: 1px solid var(--line);
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
}

.tpl-send-btn {
  width: 100%;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 0.98rem;
}

.tpl-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---- Request logs ---- */
.modal.logs-modal {
  width: min(980px, calc(100vw - 16px));
  max-height: min(90vh, 800px);
  overflow: hidden;
  border-radius: 22px;
}

/* ---- API lab ---- */
.modal.api-lab-modal {
  width: min(1100px, calc(100vw - 16px));
  max-height: min(92vh, 860px);
  overflow: hidden;
  border-radius: 22px;
}

.api-lab-shell {
  display: flex;
  flex-direction: column;
  height: min(92vh, 860px);
  max-height: min(92vh, 860px);
}

.api-lab-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(500px 180px at 0% 0%, rgba(47, 212, 138, 0.12), transparent 60%),
    linear-gradient(180deg, #f8fcfa, #eef6f1);
}

.api-lab-body {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  flex: 1;
  min-height: 0;
}

.api-lab-list-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
  background:
    radial-gradient(400px 220px at 0% 0%, rgba(47, 212, 138, 0.12), transparent 55%),
    linear-gradient(180deg, #12352a, #0f2a21);
  color: var(--rail-text);
}

.api-lab-list-pane input {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 11px 12px;
  font: inherit;
  outline: none;
}

.api-lab-list-pane input::placeholder { color: rgba(232, 245, 238, 0.45); }

.api-lab-list {
  flex: 1;
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
}

.api-lab-group-title {
  margin: 4px 0 0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--rail-muted);
}

.api-lab-item {
  display: grid;
  gap: 6px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.api-lab-item:hover { background: rgba(255, 255, 255, 0.09); }
.api-lab-item.active {
  background: rgba(47, 212, 138, 0.16);
  border-color: rgba(47, 212, 138, 0.35);
}

.api-lab-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-method {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.api-method.get { background: #dff7ea; color: #0c8a52; }
.api-method.post { background: #e7f0ff; color: #2a4f9b; }
.api-method.put { background: #fff3d6; color: #9a6700; }
.api-method.delete { background: #fdeceb; color: #c23b32; }

.api-lab-item-path {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: #d7f5e6;
  word-break: break-all;
}

.api-lab-item-name {
  font-size: 0.84rem;
  font-weight: 700;
  color: #fff;
}

.api-lab-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #f7fbf8;
}

.api-lab-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}

.api-lab-ready {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.api-lab-ready-scroll {
  flex: 1;
  overflow: auto;
  padding: 18px 20px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.api-lab-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.api-path {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.api-lab-desc {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.45;
}

.api-lab-docs {
  margin: 0;
  font-size: 0.82rem;
}

.api-lab-fields { display: grid; gap: 10px; }

.api-lab-fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.api-lab-fields-grid label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #26473b;
}

.api-lab-body-editor {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f2a21;
  color: #d7f5e6;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
  outline: none;
}

.api-lab-footer {
  border-top: 1px solid var(--line);
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.9);
  display: grid;
  gap: 12px;
}

.api-lab-footer-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.api-lab-response {
  max-height: 220px;
}

@media (max-width: 820px) {
  .api-lab-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 36%) 1fr;
  }
  .api-lab-list-pane {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .modal.api-lab-modal {
    width: calc(100vw - 10px);
    max-height: 94vh;
  }
  .api-lab-shell {
    height: 94vh;
    max-height: 94vh;
  }
  .api-lab-fields-grid {
    grid-template-columns: 1fr;
  }
}

.logs-shell {
  display: flex;
  flex-direction: column;
  height: min(90vh, 800px);
  max-height: min(90vh, 800px);
}

.logs-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(500px 180px at 0% 0%, rgba(47, 212, 138, 0.12), transparent 60%),
    linear-gradient(180deg, #f8fcfa, #eef6f1);
}

.logs-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logs-body {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  flex: 1;
  min-height: 0;
}

.logs-list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #12352a;
  color: var(--rail-text);
}

.logs-list {
  flex: 1;
  overflow: auto;
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 12px;
}

.logs-empty {
  margin: auto;
  padding: 24px;
  text-align: center;
  color: var(--rail-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.logs-item {
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.logs-item:hover { background: rgba(255, 255, 255, 0.09); }
.logs-item.active {
  background: rgba(47, 212, 138, 0.16);
  border-color: rgba(47, 212, 138, 0.35);
}

.logs-item-title {
  font-weight: 750;
  font-size: 0.86rem;
  color: #fff;
}

.logs-item-meta {
  color: var(--rail-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.logs-detail-pane {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #f7fbf8;
  padding: 16px 18px;
}

.logs-detail-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}

.logs-detail {
  display: grid;
  gap: 14px;
  animation: rise 0.25s var(--ease);
}

.logs-detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logs-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.logs-block-head .logs-copy {
  flex-shrink: 0;
}

.logs-detail-head h4 {
  margin: 0;
  letter-spacing: -0.03em;
}

.logs-detail-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.logs-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.logs-section + .logs-section {
  margin-top: 4px;
}

.logs-section-head {
  display: grid;
  gap: 2px;
  padding-bottom: 4px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.logs-section-title {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.logs-section-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

#logsEngagiveSection .logs-section-title {
  color: #1f8f63;
}

#logsLocalSection .logs-section-title {
  color: var(--accent-deep);
}

.logs-block {
  display: grid;
  gap: 8px;
}

.logs-block-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.logs-code {
  margin: 0;
  max-height: 240px;
  overflow: auto;
  background: #0f2a21;
  color: #d7f5e6;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Webhook updates ---- */
.webhook-config {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.webhook-config-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.webhook-config-copy > span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.webhook-config code {
  display: block;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--accent-deep);
  padding: 7px 9px;
  font-family: var(--mono);
  font-size: 0.74rem;
}

.webhook-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
}

.webhook-config-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.webhook-list-pane {
  padding-top: 12px;
}

.webhook-filter-label {
  margin: 0 12px 5px;
  color: var(--rail-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.webhook-filter {
  margin: 0 12px 4px;
  width: calc(100% - 24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 9px 10px;
  font: inherit;
  font-size: 0.78rem;
}

.webhook-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.webhook-item-row .logs-item-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.74rem;
}

@media (max-width: 620px) {
  .webhook-config {
    flex-direction: column;
  }
  .webhook-config-actions {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
  }
}

/* ---- Accounts manager ---- */
.modal.accounts-modal {
  width: min(980px, calc(100vw - 24px));
  max-height: 90vh;
  padding: 0;
  border: 0;
  border-radius: 22px;
  overflow: hidden;
  background: var(--panel);
}

.accounts-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: min(780px, 90vh);
}

.accounts-body {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  min-height: 0;
}

.accounts-list-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--rail);
  color: var(--rail-text);
  min-height: 0;
}

.accounts-new {
  width: 100%;
}

.accounts-form-pane {
  overflow: auto;
  padding: 16px 18px 20px;
}

.account-form {
  display: grid;
  gap: 12px;
  max-width: 560px;
}

.account-form label {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.account-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}

.account-form small {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
}

.account-advanced {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.account-advanced summary {
  cursor: pointer;
  font-weight: 750;
  font-size: 0.8rem;
}

.account-advanced label {
  margin-top: 10px;
}

.account-webhook-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.ghost.danger {
  color: var(--danger);
}

.primary.sm,
.ghost.sm {
  font-size: 0.78rem;
  padding: 7px 10px;
}

@media (max-width: 820px) {
  .accounts-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 35%) 1fr;
  }
  .accounts-list-pane {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .modal.accounts-modal {
    width: calc(100vw - 10px);
  }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .contacts-pane,
  .chat-pane { grid-column: 1; grid-row: 1; }
  .app.show-chat .contacts-pane { display: none; }
  .app:not(.show-chat) .chat-pane { display: none; }
  .back-btn { display: inline-grid; }
  .composer-extras { grid-template-columns: 1fr; }
  body { padding: 0; }
  .app { height: 100dvh; border-radius: 0; }
}

@media (max-width: 820px) {
  .tpl-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(210px, 40%) 1fr;
  }
  .tpl-browse {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .modal.template-modal,
  .modal.logs-modal,
  .modal.api-lab-modal {
    width: calc(100vw - 10px);
    max-height: 94vh;
    border-radius: 18px;
  }
  .tpl-shell,
  .logs-shell,
  .api-lab-shell {
    height: 94vh;
    max-height: 94vh;
  }
  .logs-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 38%) 1fr;
  }
  .logs-list-pane {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
}
