:root {
  --bg: #f5efe3;
  --panel: #fffaf1;
  --panel-strong: #f0e3c8;
  --ink: #1e1f1c;
  --muted: #6f6b61;
  --accent: #b5542f;
  --accent-dark: #7e3418;
  --line: rgba(30, 31, 28, 0.12);
  --success: #1c7c54;
  --shadow: 0 18px 40px rgba(80, 54, 20, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(181, 84, 47, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(28, 124, 84, 0.14), transparent 28%),
    var(--bg);
  color: var(--ink);
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

button,
input,
textarea {
  font: inherit;
}

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

.sidebar {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.88);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand h1,
.brand p,
.hero h2,
.card h2,
.card h3 {
  margin: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent), #d9a441);
  color: white;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.content {
  padding: 24px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-layout {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
}

.login-hero,
.login-panel {
  min-height: 100%;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 24px;
}

.onboarding-card {
  margin-bottom: 18px;
}

.onboarding-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
}

.stat-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
}

.login-card,
.ws-card {
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: white;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: white;
}

textarea {
  resize: vertical;
}

.json-field {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.field-hint {
  margin: -8px 0 12px;
  font-size: 12px;
  color: var(--muted);
}

.field-error {
  margin: -8px 0 12px;
  font-size: 12px;
  color: #c0392b;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--accent);
  color: white;
  transition: transform 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

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

button:disabled:hover {
  transform: none;
  background: var(--accent);
}

button.secondary:disabled:hover {
  background: var(--panel-strong);
}

.link-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 999px;
  padding: 12px 16px;
  text-decoration: none;
  background: var(--panel-strong);
  color: var(--ink);
}

button.secondary {
  background: var(--panel-strong);
  color: var(--ink);
}

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

.stack {
  display: grid;
  gap: 10px;
}

.demo-box {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.65);
}

.demo-box summary {
  cursor: pointer;
  color: var(--muted);
}

.top-gap {
  margin-top: 12px;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

#kb-list .list-item h4 {
  word-break: break-word;
}

.list {
  display: grid;
  gap: 12px;
}

.list-item {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.list-item h4,
.list-item p {
  margin: 0;
}

.list-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.list-item.archived {
  opacity: 0.55;
  border-style: dashed;
}

.list-item.paused {
  border-left: 4px solid var(--accent);
  background: rgba(181, 84, 47, 0.08);
}

.badge-paused {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-dark);
  background: rgba(181, 84, 47, 0.2);
  vertical-align: middle;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}

.inline-check input {
  width: auto;
  margin: 0;
}

.channel-move {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.channel-move select {
  width: auto;
  flex: 1;
}

.json-box {
  min-height: 220px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 16px;
  border-radius: 18px;
  background: #201d18;
  color: #edf2f7;
}

.dialog-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
}

.dialog-card {
  box-shadow: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.6);
}

.dialog-item {
  text-align: left;
  width: 100%;
}

.dialog-phone {
  color: var(--ink);
  font-weight: 600;
}

.dialog-contact {
  margin-bottom: 12px;
}

.dialog-contact .copy-button {
  margin-left: 8px;
  padding: 2px 10px;
  font-size: 12px;
}

.active-item {
  outline: 2px solid rgba(181, 84, 47, 0.4);
}

.messages {
  display: grid;
  gap: 10px;
  min-height: 260px;
  max-height: 420px;
  overflow: auto;
  padding-right: 6px;
  margin-bottom: 14px;
}

.message-bubble {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.message-bubble.user {
  background: #f6efe6;
}

.message-bubble.bot {
  background: #eef6ef;
}

.message-bubble.operator {
  background: #fff3d8;
}

.message-bubble p {
  margin: 6px 0 0;
}

.message-bubble.undelivered {
  border: 1px dashed #c0392b;
  opacity: 0.8;
}

.delivery-error {
  display: block;
  margin-top: 6px;
  color: #c0392b;
  font-size: 12px;
  word-break: break-word;
}

.invite-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.invite-card {
  width: min(520px, 100%);
}

.hidden {
  display: none !important;
}

.wa-qr-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 18px;
}

.wa-qr-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 11, 0.48);
}

.wa-qr-dialog {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.wa-qr-warning {
  border: 1px solid rgba(181, 84, 47, 0.45);
  background: rgba(181, 84, 47, 0.1);
  color: #5a2815;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
  line-height: 1.4;
}

.wa-qr-status {
  margin: 8px 0;
  font-weight: 600;
  color: var(--ink);
}

.wa-qr-status-success {
  color: var(--success);
}

.wa-qr-status-error {
  color: #a02727;
}

.wa-qr-error {
  margin: 8px 0 0;
  border: 1px solid rgba(160, 39, 39, 0.5);
  background: rgba(190, 49, 49, 0.1);
  color: #8c2020;
  border-radius: 12px;
  padding: 10px 12px;
}

.wa-qr-qr-card {
  margin-top: 12px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  padding: 14px;
  text-align: center;
}

#wa-qr-image {
  width: 280px;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  display: none;
}

#wa-qr-image.is-visible {
  display: inline-block;
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .login-layout {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .grid {
    grid-template-columns: 1fr;
  }

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

  .span-2 {
    grid-column: auto;
  }

  .span-3 {
    grid-column: auto;
  }

  .two-column,
  .dialog-layout {
    grid-template-columns: 1fr;
  }
}
