:root {
  --accent: #4f6bfe;
  --accent-light: #eef1ff;
  --bg: #f6f7fb;
  --panel-bg: #ffffff;
  --border: #e6e8f0;
  --text: #1c1f2b;
  --text-muted: #6b7080;
  --bubble-in: #f0f1f5;
  --bubble-out: var(--accent);
  --radius: 14px;

  --telegram: #29a9eb;
  --email: #6b7280;
  --whatsapp: #25d366;
  --viber: #7360f2;
  --messenger: #0084ff;
  --instagram: #e1306c;
  --webchat: #4f6bfe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr 300px;
  height: 100vh;
}

/* ---------- Left pane: conversation list ---------- */

.conversation-list {
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conversation-list-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conversation-list-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.settings-link {
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.12s ease;
}

.settings-link:hover {
  opacity: 1;
}

.conversation-list-items {
  overflow-y: auto;
  flex: 1;
}

.conversation-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}

.conversation-row:hover {
  background: var(--bg);
}

.conversation-row.active {
  background: var(--accent-light);
}

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

.contact-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
  text-transform: capitalize;
}

.channel-badge.telegram { background: var(--telegram); }
.channel-badge.email { background: var(--email); }
.channel-badge.whatsapp { background: var(--whatsapp); }
.channel-badge.viber { background: var(--viber); }
.channel-badge.messenger { background: var(--messenger); }
.channel-badge.instagram { background: var(--instagram); }
.channel-badge.webchat { background: var(--webchat); }

.message-preview {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-list {
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Right pane: thread ---------- */

.conversation-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

.thread {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.thread-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  align-items: center;
  gap: 10px;
}

.thread-header .contact-name {
  font-size: 16px;
}

.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 60%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.bubble.inbound {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble.outbound {
  align-self: flex-end;
  background: var(--bubble-out);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.thread-composer {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
}

.thread-composer input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.thread-composer input:focus {
  border-color: var(--accent);
}

.thread-composer button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.thread-composer button:hover {
  opacity: 0.9;
}

.thread-composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
  flex-shrink: 0;
}

.composer-icon-btn:hover {
  background: var(--bg);
}

/* ---------- Composer mode tabs (Reply / Internal Note) ---------- */

.composer-mode-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
}

.composer-mode-tab {
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 999px 999px 0 0;
  cursor: pointer;
}

.composer-mode-tab.active {
  color: var(--accent);
  background: var(--accent-light);
}

.thread.note-mode .thread-composer {
  background: #fffbea;
  border-top-color: #f5e6a8;
}

.thread.note-mode .composer-mode-tabs {
  border-top: none;
  background: #fffbea;
}

.thread.note-mode #composer-input {
  background: #fff;
}

/* ---------- Attachments ---------- */

.pending-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.pending-attachment img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
}

.pending-attachment-remove {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}

.bubble-attachment-image {
  max-width: 220px;
  border-radius: 10px;
  display: block;
  margin-bottom: 4px;
}

.bubble-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* ---------- Internal note bubble ---------- */

.bubble.note {
  align-self: center;
  max-width: 80%;
  background: #fff8dc;
  border: 1px dashed #e8d68a;
  color: #7a6a1f;
  font-size: 13px;
}

.bubble.note .bubble-meta {
  color: #a3924a;
}

/* ---------- Typing indicator ---------- */

.typing-indicator {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Canned response picker ---------- */

.canned-picker {
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
}

.canned-picker-item {
  padding: 10px 24px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.canned-picker-item:hover,
.canned-picker-item.highlighted {
  background: var(--accent-light);
}

.canned-picker-item-title {
  font-size: 13px;
  font-weight: 600;
}

.canned-picker-item-shortcut {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-left: 6px;
}

.canned-picker-item-body {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canned-picker-empty {
  padding: 14px 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.canned-picker-manage {
  padding: 10px 24px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
}

.canned-picker-manage:hover {
  background: var(--bg);
}

/* ---------- Saved replies management modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 31, 43, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-close-btn {
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
}

.canned-modal-body {
  padding: 16px 20px;
}

.canned-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.canned-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.canned-list-item-text {
  min-width: 0;
}

.canned-list-item-title {
  font-size: 13px;
  font-weight: 600;
}

.canned-list-item-body {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canned-list-item-delete {
  border: none;
  background: none;
  color: #d33;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.canned-empty-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.canned-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.canned-form h3 {
  margin: 0 0 4px;
  font-size: 13px;
}

.canned-form input,
.canned-form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}

.canned-form input:focus,
.canned-form textarea:focus {
  border-color: var(--accent);
}

.canned-form button {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Right pane: customer CRM panel ---------- */

.customer-panel {
  border-left: 1px solid var(--border);
  background: var(--panel-bg);
  overflow-y: auto;
  padding-bottom: 24px;
}

.customer-panel-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.customer-panel-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.customer-panel-subtitle {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 2px;
}

.customer-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 4px;
}

.customer-panel input[type='text'],
.customer-panel input[type='email'],
.customer-panel textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}

.customer-panel input:focus,
.customer-panel textarea:focus {
  border-color: var(--accent);
}

#customer-save-btn {
  align-self: flex-start;
  margin-top: 4px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#customer-save-btn:hover {
  opacity: 0.9;
}

.customer-save-status {
  font-size: 12px;
  color: var(--text-muted);
}

.customer-channels-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.customer-channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
}

.customer-channel-row:hover {
  background: var(--accent-light);
}

.customer-channel-row.active {
  background: var(--accent-light);
  outline: 1px solid var(--accent);
}

.customer-channel-preview {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.customer-empty-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.customer-merge-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.customer-merge-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}

.customer-merge-result-row button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
