:root {
  --vivi-green: #1f500d;
  --vivi-green-deep: #16380a;
  --vivi-green-soft: #eef4ea;
  --vivi-ink: #121212;
  --vivi-text: rgba(18, 18, 18, 0.75);
  --vivi-muted: rgba(18, 18, 18, 0.5);
  --vivi-white: #ffffff;
  --vivi-canvas: #f1f1f1;
  --vivi-line: rgba(18, 18, 18, 0.12);
  --vivi-live: #c62828;
  --font: "Lato", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--vivi-text);
  background: var(--vivi-canvas);
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.utility-bar {
  background: var(--vivi-green);
  color: rgba(255, 255, 255, 0.88);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px 16px;
}

.brand { display: flex; align-items: baseline; gap: 10px; color: inherit; }
.inbox-top .brand:hover .brand-name { color: var(--vivi-green); }
.brand-name {
  color: var(--vivi-ink);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.28em;
}
.brand-tag {
  color: var(--vivi-green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--vivi-ink);
  background: var(--vivi-white);
  color: var(--vivi-ink);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn-primary {
  background: var(--vivi-green);
  border-color: var(--vivi-green);
  color: var(--vivi-white);
}
.btn-ghost { min-height: 36px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 8px; }

.login-page { min-height: 100vh; display: flex; flex-direction: column; }
.login-main { flex: 1; display: grid; place-items: center; padding: 48px 0; }
.login-card {
  width: min(440px, calc(100% - 40px));
  background: var(--vivi-white);
  border: 1px solid var(--vivi-line);
  padding: 44px 40px 40px;
}
.lead { margin: 12px 0 24px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field label {
  color: var(--vivi-ink);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid rgba(18, 18, 18, 0.28);
  background: var(--vivi-white);
  color: var(--vivi-ink);
}
.field textarea { min-height: 120px; resize: vertical; }
.token-field {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  letter-spacing: 0;
  overflow-x: auto;
}

.alert { margin-bottom: 18px; padding: 12px 14px; border: 1px solid #e0b4b4; background: #fdf4f4; color: #7a1f1f; }
.banner {
  background: #fff7ed;
  color: #7c2d12;
  padding: 10px 16px;
  font-size: 14px;
  border-bottom: 1px solid #fed7aa;
}

.inbox-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.inbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--vivi-white);
  border-bottom: 1px solid var(--vivi-line);
}
.inbox-top-meta { display: flex; align-items: center; gap: 10px; }
.user-chip { color: var(--vivi-ink); font-size: 14px; }
.user-chip span { display: block; color: var(--vivi-muted); font-size: 12px; }

.inbox { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.inbox-list {
  border-right: 1px solid var(--vivi-line);
  background: var(--vivi-white);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.search-form { padding: 12px; }
.search-form input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--vivi-line); }
.filters { display: flex; gap: 4px; padding: 0 12px 12px; flex-wrap: wrap; }
.filters-sub { padding-top: 0; }
.filters-sub .filter {
  background: #efe8d8;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  padding: 6px 9px;
}
.filters-sub .filter.is-active { background: var(--vivi-ink); color: #fff; }
.filter {
  appearance: none;
  border: 0;
  background: var(--vivi-green-soft);
  color: var(--vivi-ink);
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.filter.is-active { background: var(--vivi-green); color: #fff; }
.client-queue {
  display: block;
  margin-top: 2px;
  color: var(--vivi-muted);
  font-size: 11px;
}
.thread-queue-select {
  min-width: 180px;
  max-width: 260px;
  height: 36px;
  border: 1px solid var(--vivi-line);
  background: var(--vivi-white);
  padding: 0 10px;
  font: inherit;
}
.operator-queues-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
}
.operator-queue-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 6px;
  align-items: center;
}
.operator-queue-row input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--vivi-line);
}
.operator-queue-row .btn {
  padding: 6px 10px;
  min-width: 36px;
}
.client-list { overflow: auto; flex: 1; }
.client-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--vivi-line);
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: none;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  color: inherit;
}
.client-row:hover, .client-row.is-active { background: var(--vivi-green-soft); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--vivi-green); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.client-main { min-width: 0; }
.client-name { color: var(--vivi-ink); font-weight: 700; }
.client-phone, .client-match { display: block; }
.client-phone { font-size: 12px; color: var(--vivi-muted); }
.client-match {
  margin-top: 3px;
  overflow: hidden;
  color: var(--vivi-muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.client-time { font-size: 12px; color: var(--vivi-muted); white-space: nowrap; }

.inbox-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #f7f4ef; }
.thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 16px 20px;
  background: var(--vivi-white);
  border-bottom: 1px solid var(--vivi-line);
}
.thread-head-main { min-width: 0; }
.thread-head h1 { margin: 0; font-size: 20px; color: var(--vivi-ink); }
.thread-head p { margin: 4px 0 0; font-size: 13px; }
.thread-head .btn { flex: 0 0 auto; white-space: nowrap; }
.thread-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.thread-head-actions .btn.is-active {
  background: var(--vivi-green);
  border-color: var(--vivi-green);
  color: #fff;
}
.thread-head-actions .btn[data-bot-settings] {
  min-width: 11.5rem;
  font-variant-numeric: tabular-nums;
}
.thread-head-actions .btn[data-bot-settings].is-active {
  background: #b86a1a;
  border-color: #b86a1a;
  color: #fff;
}
.thread-head-actions .btn[data-bot-reply-last] {
  white-space: nowrap;
}
.thread-messages { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.bubble {
  max-width: min(72%, 560px);
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  font-variant-emoji: emoji;
}
.bubble.in { align-self: flex-start; background: var(--vivi-white); border: 1px solid var(--vivi-line); }
.bubble.out { align-self: flex-end; background: var(--vivi-green); color: #fff; }
.emoji {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", sans-serif;
  font-style: normal;
  font-weight: 400;
  font-variant-emoji: emoji;
  line-height: 1;
  white-space: nowrap;
}
.bubble.out .emoji { color: initial; }
.bubble.is-reaction {
  max-width: min(48%, 320px);
  padding: 8px 12px;
}
.bubble.is-reaction .reaction-emoji { font-size: 26px; }
.bubble .meta { display: block; margin-top: 6px; font-size: 11px; opacity: 0.7; letter-spacing: 0.04em; }
.bubble-actions { align-self: flex-start; }
.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--vivi-white);
  border-top: 1px solid var(--vivi-line);
}
.composer[hidden] { display: none !important; }
.composer textarea { flex: 1; min-height: 48px; resize: none; padding: 10px 12px; border: 1px solid var(--vivi-line); }

.modal {
  width: min(720px, calc(100% - 32px));
  border: 1px solid var(--vivi-line);
  padding: 24px;
}
.modal::backdrop { background: rgba(18, 18, 18, 0.35); }
.modal h2 { margin: 0 0 8px; color: var(--vivi-ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.check { display: flex; gap: 8px; align-items: center; margin: 0 0 16px; color: var(--vivi-ink); }

.bot-settings-section { margin: 0 0 22px; }
.bot-settings-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--vivi-ink);
}
.bot-settings-section .lead { margin: 0 0 12px; }
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 12px;
  color: var(--vivi-ink);
}
.switch span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch strong { font-size: 14px; font-weight: 700; }
.switch em { font-style: normal; font-size: 12px; color: var(--vivi-muted); }
.switch input[type="checkbox"] {
  appearance: none;
  width: 44px;
  height: 24px;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: #cfcfcf;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.switch input[type="checkbox"]:checked { background: var(--vivi-green); }
.switch input[type="checkbox"]:checked::after { transform: translateX(20px); }
.bot-hold-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.hint, .notice { font-size: 13px; color: var(--vivi-muted); }
.notice { min-height: 1.2em; }
.empty { padding: 24px; color: var(--vivi-muted); }

.client-row.is-unread .client-name { font-weight: 700; color: var(--vivi-ink); }
.client-row.is-unread { background: #fff8e8; }
.client-row.is-operator { box-shadow: inset 3px 0 0 var(--vivi-live); }
.client-row.is-bot-hold { box-shadow: inset 3px 0 0 #b86a1a; }
.client-row.is-operator.is-bot-hold { box-shadow: inset 3px 0 0 var(--vivi-live), inset 6px 0 0 #b86a1a; }

.day-sep {
  align-self: center;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vivi-muted);
  background: rgba(255, 255, 255, 0.8);
  padding: 4px 10px;
  border-radius: 999px;
}
.quote {
  border-left: 3px solid rgba(18, 18, 18, 0.2);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  opacity: 0.8;
  overflow-wrap: break-word;
  word-break: normal;
}
.bubble.out .quote { border-left-color: rgba(255, 255, 255, 0.55); }
.bubble-img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-bottom: 6px;
}
.doc-link {
  display: inline-block;
  max-width: 100%;
  margin-bottom: 6px;
  text-decoration: underline;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.media-missing {
  font-size: 12px;
  opacity: 0.75;
  margin-bottom: 6px;
  font-style: italic;
}
.tick { margin-left: 6px; letter-spacing: 0; font-weight: 700; }
.tick.sent { opacity: 0.7; }
.tick.delivered { opacity: 0.95; }
.tick.read { color: #8ec8ff; }
.bubble.in .tick.read { color: #1d6fd8; }
.tick.fail { color: #ffb4b4; background: #9b1c1c; border-radius: 50%; width: 16px; height: 16px; display: inline-grid; place-items: center; font-size: 11px; }
.bubble.in .tick.fail { color: #fff; }

.composer { flex-wrap: wrap; }
.session-hint {
  flex: 1 0 100%;
  margin: 0 0 4px;
  color: #7c2d12;
  font-size: 13px;
}

.modal-wide { width: min(860px, calc(100% - 32px)); max-height: 90vh; overflow: auto; }
.outbound-title { margin: 24px 0 10px; color: var(--vivi-ink); font-size: 16px; }
.outbound-list { max-height: 280px; overflow: auto; border: 1px solid var(--vivi-line); }
.outbound-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--vivi-line);
  font-size: 13px;
}
.outbound-row:last-child { border-bottom: 0; }
.outbound-filters { padding: 0 0 12px; }

.template-preview {
  margin: 0 0 16px;
  padding: 14px 16px;
  background: var(--vivi-green-soft);
  border: 1px solid var(--vivi-line);
}
.template-preview[hidden] { display: none !important; }
.template-preview-label {
  margin: 0 0 8px;
  color: var(--vivi-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.template-preview-text {
  margin: 0;
  color: var(--vivi-ink);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  min-width: 220px;
  max-width: min(420px, calc(100% - 32px));
  padding: 14px 18px;
  background: var(--vivi-green);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 28px rgba(18, 18, 18, 0.18);
}
.toast[hidden] { display: none !important; }

@media (max-width: 800px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox-list { max-height: 40vh; }
}
