:root {
  color-scheme: light;
  /* MTC Group CRM-inspired neutral/green palette */
  --bg0: #f3f4f3;
  --bg1: #ffffff;
  --bg2: #eef1ef;
  --surface: #ffffff;
  --surface-2: #f6f7f6;
  --surface-3: #ebf3ee;
  --card: #ffffff;
  --card2: #f8faf8;
  --stroke: #dfe4e1;
  --stroke-2: #c8d1cc;
  --text: #202520;
  --text-strong: #0d120f;
  --muted: #5f6962;
  --muted-2: #879189;

  /* Primary CRM green */
  --accent: #18864b;
  --accent-2: #14743f;
  --accent-weak: rgba(24, 134, 75, 0.10);
  --accent-ring: rgba(24, 134, 75, 0.22);

  /* Status colors tuned for light surfaces */
  --success: #18864b;
  --success-weak: rgba(24, 134, 75, 0.11);
  --danger: #d92d20;
  --danger-weak: rgba(217, 45, 32, 0.10);
  --warning: #b7791f;
  --warning-weak: rgba(183, 121, 31, 0.12);

  --shadow-sm: 0 1px 2px rgba(16, 24, 20, 0.05);
  --shadow: 0 8px 24px rgba(16, 24, 20, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 20, 0.15);
  --radius: 8px;
  --radius-sm: 8px;
  --radius-lg: 12px;
}
* { box-sizing: border-box; }
body.app-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Be Vietnam Pro", ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg0);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.app-body > .main-shell { flex: 1 0 auto; }
body.app-body > .site-foot { flex-shrink: 0; margin-top: 0; }
/* Retained for backward compat but made invisible */
.bg-blobs { display: none; }

/* ── Top nav ── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  margin: 0;
  border-radius: 0;
  background: var(--bg1);
  border: none;
  border-bottom: 1px solid var(--stroke);
  box-shadow: none;
  backdrop-filter: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text-strong);
  letter-spacing: 0;
}
.brand-dot {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28);
}
.brand-dot::after {
  content: "Z";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #ffffff;
  font-size: .85rem;
  font-weight: 700;
}
.nav-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}
.nav-pills a {
  text-decoration: none;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  transition: background .15s, color .15s;
}
.nav-pills a:hover {
  background: var(--surface-2);
  color: var(--text-strong);
}
.nav-pills a.nav-muted { opacity: .55; font-size: .8rem; }
.nav-pills a.active {
  background: var(--surface-3);
  color: var(--text-strong);
  border-color: transparent;
}
/* Dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown > .nav-btn {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}
.nav-dropdown > .nav-btn:hover,
.nav-dropdown.open > .nav-btn {
  background: var(--surface-2);
  color: var(--text-strong);
}
.nav-dropdown > .nav-btn.active {
  background: var(--surface-3);
  color: var(--text-strong);
  border-color: transparent;
}
.nav-dropdown > .nav-btn .arrow { font-size: 9px; opacity: .7; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 170px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  text-decoration: none;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: var(--surface-2); color: var(--text); }
.nav-dropdown-menu a.active { background: var(--accent-weak); color: var(--accent-2); }
/* ── Auth slot ── */
.nav-auth { margin-left: auto; }
.btn-nav-login,
.nav-pills a.btn-nav-login {
  text-decoration: none;
  display: inline-block;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  transition: background .15s;
}
.btn-nav-login:hover,
.nav-pills a.btn-nav-login:hover {
  color: #fff;
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.user-dropdown .user-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px;
  background: var(--surface);
  border: 1px solid var(--stroke);
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: .78rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-label {
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .85rem; color: var(--text);
}

.nav-pills .nav-sep {
  width: 1px;
  height: 18px;
  background: var(--stroke);
  opacity: .6;
  align-self: center;
  margin: 0 6px;
}

/* ── Main layout ── */
.main-shell {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

/* ── Hero ── */
.hero {
  text-align: left;
  padding: 24px 0 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--stroke);
}
.hero-badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-weak);
  border: 1px solid var(--accent-ring);
  color: var(--accent-2);
  margin-bottom: 12px;
}
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
  color: var(--text-strong);
}
.gradient-text {
  /* Removed gradient — keep inline color for compat */
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  color: var(--accent-2);
}
.hero p.lead {
  margin: 0;
  max-width: 640px;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.6;
}

/* ── Grid & cards ── */
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: stretch; }
.card {
  flex: 1;
  min-width: 280px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-sm);
  backdrop-filter: none;
}
.card h2, .card h3 {
  margin-top: 0;
  letter-spacing: 0;
  color: var(--text-strong);
  font-weight: 600;
}
.card h3 { font-size: 1rem; margin-bottom: 14px; }
.card h2 { font-size: 1.1rem; margin-bottom: 14px; }

/* ── Forms ── */
label {
  display: block;
  font-size: .78rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  margin-top: 14px;
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  margin-top: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, select:hover, textarea:hover {
  border-color: var(--stroke-2);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
select {
  background-color: var(--surface);
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%235f6962' stroke-width='1.5' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
select option,
select optgroup {
  background-color: var(--surface);
  color: var(--text);
}

/* ── Buttons ── */
button, .btn {
  cursor: pointer;
  margin-top: 10px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  font-family: inherit;
  font-weight: 500;
  font-size: .88rem;
  color: #ffffff;
  background: var(--accent);
  box-shadow: none;
  transition: background .15s, border-color .15s;
}
button:hover, .btn:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  filter: none;
  transform: none;
}
button:disabled, .btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}
button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--stroke);
}
button.secondary:hover, .btn.secondary:hover {
  background: var(--surface-2);
  border-color: var(--stroke-2);
}
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
button.ghost:hover, .btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: none;
}
button.danger:hover {
  background: #b42318;
  border-color: #b42318;
}

/* ── Code / pre ── */
code, pre {
  font-family: ui-monospace, "SF Mono", Consolas, Menlo, monospace;
  font-size: .82rem;
}
code {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  color: var(--accent-2);
}
pre {
  margin: 12px 0 0;
  padding: 14px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 360px;
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  color: var(--text);
}

/* ── Utility text ── */
.muted { color: var(--muted); font-size: .88rem; line-height: 1.55; }
.ok { color: var(--success); font-weight: 500; }
.err { color: var(--danger); font-weight: 500; }
.page-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-strong);
}
.page-sub {
  margin: 0 0 24px;
  color: var(--muted);
  max-width: 720px;
  font-size: .92rem;
}

/* ── QR box ── */
.qr-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: #ffffff;
  display: inline-block;
  border: 1px solid var(--stroke);
}
.qr-box img { display: block; width: 260px; height: 260px; border-radius: 6px; image-rendering: pixelated; }
#qrPhase { margin-bottom: 8px; color: #111827; font-weight: 500; font-size: .85rem; }

/* ── Bot list (management overview) ── */
.bot-list-card { flex: 1 1 100%; }
.bot-list-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.bot-list-head h3 { margin: 0; }
.bot-list-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bot-list-actions button { margin-top: 0; }
.bot-search { min-width: 220px; max-width: 320px; }

.bot-table-wrap { overflow-x: auto; border: 1px solid var(--stroke); border-radius: var(--radius); }
.bot-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.bot-table th, .bot-table td {
  text-align: left; padding: 11px 14px;
  border-bottom: 1px solid var(--stroke);
  vertical-align: middle;
}
.bot-table th {
  font-size: .74rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); background: var(--surface-2);
  position: sticky; top: 0;
}
.bot-table tbody tr:hover { background: var(--surface-2); }
.bot-table tbody tr:last-child td { border-bottom: none; }
.bot-table tbody tr.is-selected { background: var(--accent-weak); }

.bot-cell-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bot-avatar {
  flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .82rem;
  overflow: hidden;
}
.bot-avatar img { width: 100%; height: 100%; object-fit: cover; }
.bot-name { font-weight: 500; color: var(--text-strong); }
.bot-phone { color: var(--muted); font-size: .82rem; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--stroke-2);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-2);
}
.badge.ok { background: var(--success-weak); color: var(--success); border-color: var(--accent-ring); }
.badge.ok::before { background: var(--success); }
.badge.warn { background: var(--warning-weak); color: var(--warning); border-color: rgba(183,121,31,.24); }
.badge.warn::before { background: var(--warning); }
.badge.err { background: var(--danger-weak); color: var(--danger); border-color: rgba(217,45,32,.22); }
.badge.err::before { background: var(--danger); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button {
  margin-top: 0;
  padding: 5px 10px;
  font-size: .78rem;
}

.bot-empty {
  padding: 32px 20px; text-align: center;
  color: var(--muted); font-size: .9rem;
}

/* ── Status box (friendly status panel) ── */
.status-box {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}
.status-box.empty { display: none; }
.status-dot-lg {
  flex-shrink: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted-2);
  box-shadow: 0 0 0 3px rgba(138,148,166,0.15);
}
.status-box.is-ok .status-dot-lg { background: var(--success); box-shadow: 0 0 0 3px var(--success-weak); }
.status-box.is-warn .status-dot-lg { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-weak); }
.status-box.is-err .status-dot-lg { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-weak); }
.status-box.is-info .status-dot-lg { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.status-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status-title { font-weight: 600; color: var(--text-strong); font-size: .92rem; }
.status-sub { color: var(--muted); font-size: .82rem; line-height: 1.45; }

/* ── Footer ── */
.site-foot {
  text-align: center;
  padding: 20px;
  color: var(--muted-2);
  font-size: .78rem;
  border-top: 1px solid var(--stroke);
  margin-top: 32px;
}

/* ── Lists ── */
ol.steps, ul.steps { padding-left: 1.2rem; color: var(--muted); line-height: 1.65; }
ol.steps li, ul.steps li { margin: 6px 0; }

/* ── Setup overlay ── */
#setupOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 20, 0.38);
  backdrop-filter: blur(4px);
}
.setup-box {
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}
.setup-box h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-strong);
}
.setup-box p {
  color: var(--muted);
  font-size: .88rem;
  margin: 0 0 16px;
  line-height: 1.55;
}
.setup-box input {
  width: 100%;
  margin: 0 0 10px;
}
.setup-box button {
  width: 100%;
}

/* ── Toasts ── */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 260px;
  max-width: 400px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .88rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-lg);
  backdrop-filter: none;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .2s, transform .2s;
  border-left: 3px solid var(--accent);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.hide { opacity: 0; transform: translateX(20px); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .top-nav { padding: 10px 14px; gap: 10px; }
  .main-shell { padding: 20px 14px 40px; }
  .api-config-bar { flex-wrap: wrap; }
  #toastContainer { left: 10px; right: 10px; top: 12px; }
  .toast { min-width: auto; max-width: none; }
  .nav-pills { gap: 2px; }
  .nav-pills a, .nav-dropdown > .nav-btn { padding: 6px 10px; font-size: .8rem; }
}
