:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #0f6cff;
  --accent2: #00aa5b;
  --danger: #d92d20;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
nav {
  background: #111827; color: #fff; padding: 12px 0;
  margin-bottom: 20px;
}
nav .wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
nav a { color: #e5e7eb; }
nav a:hover { color: #fff; }
nav .brand { font-weight: 700; color: #fff; margin-right: auto; font-size: 1.15rem; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
h1, h2 { margin-top: 0; }
.muted { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat { text-align: center; }
.stat .n { font-size: 1.8rem; font-weight: 700; }
label { display: block; margin: 10px 0 4px; font-weight: 600; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 100px; resize: vertical; }
.btn {
  display: inline-block; background: var(--accent); color: #fff !important;
  border: none; border-radius: 8px; padding: 10px 16px; cursor: pointer;
  font: inherit; text-decoration: none !important; margin: 4px 4px 4px 0;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: #374151; }
.btn.success { background: var(--accent2); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent) !important; border: 1px solid var(--border); }
.flash { background: #ecfdf3; border: 1px solid #abefc6; color: #067647; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.err { background: #fef3f2; border: 1px solid #fecdca; color: #b42318; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.info { background: #eff8ff; border: 1px solid #b2ddff; color: #175cd3; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
.msg { max-width: 75%; padding: 10px 12px; border-radius: 12px; margin: 8px 0; white-space: pre-wrap; }
.msg.in { background: #eef2ff; margin-right: auto; }
.msg.out { background: #ecfdf3; margin-left: auto; }
.msg .meta { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.thread { display: flex; flex-direction: column; }
.auth-box { max-width: 420px; margin: 40px auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; background: #e5e7eb; }
.badge.ok { background: #d1fadf; color: #067647; }
.badge.warn { background: #fef0c7; color: #b54708; }
.row-actions form { display: inline; }

/* Per-listing auto-reply switch */
.listing-toggle-form { display: flex; align-items: center; gap: 8px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; margin: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; transition: background .15s ease; }
.switch-slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s ease; }
.switch input:checked + .switch-slider { background: var(--accent2); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-label { color: var(--muted); font-size: .85rem; }

/* Account auto-reply off note + tooltip with link */
.listing-ar-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.account-ar-note {
  position: relative;
  display: inline-block;
  font-size: .75rem;
  color: #b54708;
  background: #fef0c7;
  border-radius: 999px;
  padding: 2px 8px;
  cursor: help;
}
.account-ar-note .tip-box {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 260px;
  padding: 10px 12px;
  background: #111827;
  color: #f9fafb;
  border-radius: 8px;
  font-size: .8rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  white-space: normal;
}
.account-ar-note:hover .tip-box,
.account-ar-note:focus-within .tip-box { display: block; }
.account-ar-note .tip-link {
  display: inline-block;
  margin: 8px 0 0;
  padding: 4px 10px;
  font-size: .75rem;
  color: #fff !important;
  border-color: #4b5563;
  background: #374151;
}

/* Sandbox / test chats */
.badge.test {
  background: #fef0c7;
  color: #b54708;
  margin-left: 6px;
  vertical-align: middle;
}
.chat-row-test {
  background: #fffbeb;
}
.chat-row-test td {
  border-bottom-color: #f5d0a9;
}
.thread-test {
  border: 1px dashed #f5d0a9;
  background: #fffdf7;
}
.icon-form { display: inline; margin: 0; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
}
.icon-btn:hover {
  background: #eff8ff;
  border-color: #b2ddff;
}
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Listings tabs: В обработке / Исключения */
.listings-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  padding: 4px;
  background: #fbf8f2;
  border: 1px solid #e7dfd2;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(91, 70, 45, .05);
}
.listings-tabs .tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  color: #786f63;
  border: 1px solid transparent;
  border-radius: 8px;
  text-decoration: none !important;
  font-weight: 600;
  font-size: .95rem;
  line-height: 1.2;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.listings-tabs .tab:hover {
  color: #4e463d;
  background: #f4eee5;
}
.listings-tabs .tab.active {
  color: #5c3b1f;
  background: #fff;
  border-color: #dfd3c3;
  box-shadow: 0 1px 3px rgba(91, 70, 45, .10);
}
.listings-tabs .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.listings-tabs .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.5rem;
  padding: 0 7px;
  border-radius: 999px;
  background: #eee8de;
  color: #756957;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}
.listings-tabs .tab.active .tab-count {
  background: #f4e3c2;
  color: #82551d;
}

@media (max-width: 480px) {
  .listings-tabs .tab {
    padding-inline: 10px;
    font-size: .9rem;
  }
}


/* CPC bid status on listings */
.bid-status { font-size: .8rem; max-width: 180px; line-height: 1.35; }
.bid-err { color: #b42318; margin-top: 2px; }
.bid-reason { margin-top: 2px; }
