:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #68625a;
  --line: #ded8ce;
  --accent: #116b5f;
  --accent-strong: #0b5148;
  --bot: #f7f7f4;
  --user: #e7f2ef;
  --shadow: 0 24px 80px rgba(33, 27, 18, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
}

.panel {
  width: 100%;
  height: min(860px, calc(100vh - 64px));
  min-height: 620px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.webhook-panel {
  height: min(860px, calc(100vh - 64px));
  min-height: 620px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.prompt-panel {
  height: min(860px, calc(100vh - 64px));
  min-height: 620px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.prompt-tab {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(120px, 220px) 1fr;
}

.bot-settings-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #fbfaf7;
}

.bot-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.bot-settings-form input[type="text"],
.bot-settings-form input[type="number"],
.bot-settings-form input[type="file"],
.bot-settings-form textarea,
.bot-settings-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  color: var(--ink);
  min-width: 0;
}

.bot-settings-form input[type="text"],
.bot-settings-form input[type="number"],
.bot-settings-form select {
  min-height: 38px;
}

.media-uploader {
  display: grid;
  gap: 8px;
}

.media-list {
  display: grid;
  gap: 6px;
}

.media-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.media-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: white;
  color: var(--ink);
  font-size: 13px;
}

.media-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.media-item button {
  border: 1px solid #f0c2ba;
  border-radius: 8px;
  background: #fff7f5;
  color: var(--danger);
  min-height: 32px;
  padding: 0 10px;
  cursor: pointer;
}

.bot-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.bot-danger-zone {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
}

.trash-button {
  width: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d7b8b0;
  border-radius: 8px;
  background: #fff7f4;
  color: #8a2f1f;
  cursor: pointer;
}

.trash-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.trash-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.memory-tab {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(120px, 220px) 1fr;
}

.memory-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 24px;
}

.memory-topbar {
  width: min(1480px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.memory-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.memory-workspace {
  width: min(1480px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
}

.memory-sidebar,
.contact-detail.full {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.memory-sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
}

.memory-search {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}

.memory-search input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  outline: none;
}

.memory-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.14);
}

.webhook-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.webhook-header h2 {
  margin: 0;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.refresh {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

.refresh.active-tab {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef7f4;
}

.prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.danger {
  border-color: #d7b8b0;
  color: #8a2f1f;
  background: #fff7f4;
}

.danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.webhook-empty,
.webhook-card {
  overflow: auto;
  padding: 18px;
}

.webhook-empty {
  color: var(--muted);
}

.webhook-card {
  display: grid;
  align-content: start;
  gap: 16px;
}

.webhook-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  font-size: 13px;
}

.webhook-meta dt {
  color: var(--muted);
}

.webhook-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.webhook-card section {
  display: grid;
  gap: 8px;
}

.webhook-card h3 {
  margin: 0;
  font-size: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.copy-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
  cursor: pointer;
}

.copy-button.copied {
  border-color: var(--accent);
  color: var(--accent);
}

.webhook-card pre {
  margin: 0;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171717;
  color: #f8f6f0;
  padding: 12px;
  font-size: 12px;
  line-height: 1.45;
}

.prompt-list {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}

.contact-list {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}

.contact-list.full {
  border-bottom: 0;
}

.prompt-item,
.contact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.prompt-item strong,
.prompt-item span,
.contact-item strong,
.contact-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-item span,
.contact-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.prompt-item.active,
.contact-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.12);
}

.contact-detail {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
}

.contact-detail.full {
  padding: 18px;
}

.contact-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #faf9f6;
}

.contact-memory-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.contact-detail-header h3,
.contact-detail-header p {
  margin: 0;
  overflow-wrap: anywhere;
}

.contact-detail-header h3 {
  font-size: 16px;
}

.contact-detail-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.memory-messages {
  display: grid;
  gap: 10px;
}

.memory-messages.full {
  align-content: start;
  grid-template-columns: minmax(0, 1fr);
}

.memory-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #faf9f6;
}

.memory-message.bot {
  background: var(--bot);
}

.memory-message.customer {
  background: var(--user);
  border-color: #c5ded8;
}

.memory-message strong,
.memory-message small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.memory-message p {
  margin: 6px 0 0;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.memory-message pre {
  margin: 8px 0 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171717;
  color: #f8f6f0;
  padding: 10px;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 23, 23, 0.5);
}

.confirm-modal {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.confirm-modal h2,
.confirm-modal p {
  margin: 0;
}

.confirm-modal h2 {
  font-size: 20px;
}

.confirm-modal p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.confirm-modal input {
  width: 100%;
  min-height: 42px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}

.confirm-modal input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.14);
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.prompt-editor {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
}

.prompt-editor label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.prompt-editor input[type="text"],
.prompt-editor input[type="password"],
.prompt-editor textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: white;
  outline: none;
  min-width: 0;
}

.settings-form {
  min-height: 0;
}

.settings-copy-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  padding: 10px;
}

.settings-copy-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.settings-copy-field code {
  display: block;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.settings-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  min-width: 0;
}

.channel-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  border: 0;
}

.channel-picker.compact {
  gap: 6px;
}

.channel-picker legend {
  width: 100%;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.channel-picker label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #faf9f6;
  color: var(--ink);
  cursor: pointer;
}

.channel-picker input {
  margin: 0;
}

.channel-picker label:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef7f4;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.prompt-editor input:focus,
.prompt-editor textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.14);
}

.prompt-options {
  display: grid;
  gap: 8px;
}

.prompt-options label {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  flex-direction: column;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.model-control {
  display: grid;
  gap: 5px;
  min-width: 0;
  flex: 1 1 220px;
  color: var(--muted);
  font-size: 13px;
}

.model-control select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  outline: none;
}

.model-control select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.14);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
}

.chat {
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0)),
    #fbfaf7;
}

.bubble {
  max-width: min(680px, 90%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bot);
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
  border-color: #c5ded8;
}

.bubble img {
  display: block;
  width: min(340px, 100%);
  max-height: 340px;
  object-fit: contain;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
}

.composer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: white;
}

.upload,
.send,
.icon-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.upload {
  padding: 0 14px;
  color: var(--ink);
  background: #faf9f6;
  width: 100%;
}

.upload input {
  display: none;
}

textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 107, 95, 0.14);
}

.send {
  padding: 0 18px;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  width: 100%;
  min-width: 0;
}

.send:hover {
  background: var(--accent-strong);
}

.send:disabled {
  opacity: 0.65;
  cursor: wait;
}

.preview {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f6;
  min-width: 0;
}

.preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  background: white;
}

@media (max-width: 1400px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .webhook-panel,
  .prompt-panel {
    width: 100%;
    height: auto;
    min-height: 520px;
  }
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .memory-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .memory-sidebar {
    min-height: 360px;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 0;
  }

  .panel,
  .webhook-panel,
  .prompt-panel {
    min-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: 0;
  }

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

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

  .model-control {
    min-width: 100%;
  }

  .send,
  .upload {
    width: 100%;
  }

  .memory-shell {
    padding: 0;
  }

  .memory-topbar,
  .memory-workspace {
    width: 100%;
  }

  .memory-topbar {
    padding: 18px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }

  .memory-sidebar,
  .contact-detail.full {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
}
