:root {
  --bg: #0c0d10;
  --surface: #14161b;
  --surface2: #1b1e25;
  --surface3: #252932;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f4f5f7;
  --muted: #9aa1ad;
  --accent1: #f6a83c;
  --accent2: #e8912d;
  --accent-soft: rgba(246, 168, 60, 0.14);
  --blue: #6db3f2;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ---------- brand ---------- */
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #1c1204; letter-spacing: 0.2px;
  flex: none; text-align: center; line-height: 1.05;
}
.logo-word {
  font-weight: 800; font-size: 21px; letter-spacing: -0.4px; line-height: 1;
  color: var(--text); white-space: nowrap;
}
.logo-word .ai {
  color: var(--accent1);
  text-shadow: 0 0 14px rgba(246, 168, 60, 0.55), 0 0 34px rgba(246, 168, 60, 0.25);
  margin-left: 3px;
}

button {
  font-family: inherit; font-size: 14px; border: none; cursor: pointer;
  border-radius: 10px; transition: opacity .15s, transform .05s, background .15s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  color: #221503; padding: 11px 20px; font-weight: 700;
  box-shadow: 0 4px 18px rgba(246, 168, 60, 0.18);
}
.btn-primary:hover { opacity: .92; }

.btn-ghost { background: var(--surface3); color: var(--text); padding: 9px 16px; font-weight: 500; border: 1px solid var(--border); }
.btn-ghost:hover { background: #2e333f; }
.btn-danger { background: rgba(248,113,113,.13); color: var(--red); padding: 9px 16px; font-weight: 500; }
.btn-green { background: rgba(74,222,128,.13); color: var(--green); padding: 9px 16px; font-weight: 500; }

input, textarea, select {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 14px; width: 100%;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(246, 168, 60, 0.65);
  box-shadow: 0 0 0 3px rgba(246, 168, 60, 0.12);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(640px 420px at 22% 8%, rgba(246, 168, 60, .10), transparent),
    radial-gradient(560px 400px at 85% 92%, rgba(232, 145, 45, .07), transparent),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 40px 36px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.login-card .head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-card h1 { font-size: 20px; font-weight: 700; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
.error-box {
  display: none; margin-top: 14px; padding: 10px 14px; border-radius: 10px;
  background: rgba(248,113,113,.12); color: var(--red); font-size: 13.5px;
}

/* ---------- app layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 244px; flex: none; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 22px 14px 18px;
}
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 20px; }
.sidebar .brand .name { font-weight: 700; font-size: 16px; }
.sidebar .brand .tag { font-size: 10.5px; color: var(--muted); letter-spacing: 1.6px; text-transform: uppercase; margin-top: 3px; }

.nav-sec {
  font-size: 10px; font-weight: 700; letter-spacing: 1.4px; color: var(--muted);
  opacity: .75; padding: 12px 12px 6px; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: var(--muted); font-weight: 500; cursor: pointer;
  margin-bottom: 2px; font-size: 14.5px; border: 1px solid transparent;
  transition: background .12s, color .12s;
}
.nav-item svg { flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft); color: #ffd79a;
  border-color: rgba(246, 168, 60, 0.22);
}
.nav-item.active svg { opacity: 1; }

.sidebar .spacer { flex: 1; }

.account-card {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
}
.account-card .row { display: flex; align-items: center; gap: 8px; }
.account-card .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.account-card .dot.off { background: var(--red); }
.account-card .uname { font-weight: 600; font-size: 14px; word-break: break-all; }
.account-card .meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; word-break: break-all; }

/* ---------- inbox ---------- */
.inbox { flex: 1; display: flex; min-width: 0; }

.conv-list {
  width: 300px; flex: none; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; background: rgba(20, 22, 27, .55);
}
.conv-list .head {
  padding: 18px 18px 12px; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: space-between;
}
.conv-list .items { overflow-y: auto; flex: 1; }
.conv-item {
  padding: 13px 16px; display: flex; gap: 11px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: var(--surface3); }
.conv-item .avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--surface3); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: var(--muted); text-transform: uppercase;
}
.conv-item .info { min-width: 0; flex: 1; }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; }
.conv-item .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .time { color: var(--muted); font-size: 11.5px; flex: none; }
.conv-item .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; letter-spacing: .3px;
}
.badge.human { background: rgba(109,179,242,.14); color: var(--blue); }
.badge.ai { background: var(--accent-soft); color: #ffc97a; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat .head {
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.chat .head .who { font-weight: 700; }
.chat .head .sub { color: var(--muted); font-size: 12px; }
.chat .head .actions { margin-left: auto; display: flex; gap: 8px; }

.state-banner {
  display: none; padding: 9px 22px; font-size: 13px; font-weight: 500;
  align-items: center; gap: 10px;
}
.state-banner.ai { background: var(--accent-soft); color: #ffc97a; }
.state-banner.human { background: rgba(109,179,242,.10); color: var(--blue); }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 62%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; font-size: 14.5px; position: relative; word-wrap: break-word; }
.msg .meta { font-size: 10.5px; color: rgba(255,255,255,.55); margin-top: 5px; display: flex; gap: 6px; align-items: center; }
.msg.in { align-self: flex-start; background: var(--surface2); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 6px; }
.msg.out.ai { background: linear-gradient(135deg, #f0a548, #dd8a2a); color: #241604; }
.msg.out.ai .meta { color: rgba(36, 22, 4, .6); }
.msg.out.human { background: #274a63; }

.composer { padding: 14px 22px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.composer input { flex: 1; }
.composer .btn-primary { padding: 11px 26px; flex: none; }

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

/* ---------- pages ---------- */
.page { flex: 1; overflow-y: auto; padding: 34px 44px; display: none; }
.page.visible { display: block; }
.page h2 { font-size: 23px; margin-bottom: 4px; letter-spacing: -0.3px; }
.page .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 20px; max-width: 760px;
  transition: border-color .15s;
}
.card:hover { border-color: rgba(255,255,255,.11); }
.card h3 { font-size: 16px; margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: 13px; margin-bottom: 10px; line-height: 1.5; }

.services-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.services-table th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 8px; }
.services-table td { padding: 5px 4px; }
.services-table input { padding: 9px 12px; }
.services-table .rm { background: none; color: var(--red); font-size: 17px; padding: 6px 10px; }

.row-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.save-note { color: var(--green); font-size: 13px; display: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 14px; display: none; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}

/* ---------- dashboard ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 20px; max-width: 980px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-num {
  font-size: 27px; font-weight: 800;
  background: linear-gradient(135deg, #ffd794, var(--accent1));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 500; }

.pipeline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.pipe-step {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 18px; border-radius: 12px; min-width: 92px;
  background: var(--surface2); border: 1px solid var(--border);
}
.pipe-step b { font-size: 20px; }
.pipe-step span { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.pipe-arrow { color: var(--muted); font-size: 16px; }
.pipe-step.st-new { border-color: rgba(154,161,173,.35); }
.pipe-step.st-replied { border-color: rgba(109,179,242,.5); }
.pipe-step.st-qualified { border-color: rgba(246,168,60,.55); }
.pipe-step.st-booked { border-color: rgba(74,222,128,.5); }
.pipe-step.st-disqualified { border-color: rgba(248,113,113,.4); opacity: .85; }

.topic-list { display: flex; flex-direction: column; gap: 6px; }
.topic-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface2); border-radius: 10px; padding: 9px 14px; font-size: 13.5px;
}
.topic-row b { color: #ffc97a; }

.activity-list { display: flex; flex-direction: column; gap: 4px; max-width: 980px; }
.activity-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: 10px; font-size: 13px; background: var(--surface2);
}
.act-ico { flex: none; }
.act-who { font-weight: 600; flex: none; }
.act-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.act-time { color: var(--muted); font-size: 11.5px; flex: none; }

.empty-mini { color: var(--muted); font-size: 13px; padding: 8px 2px; }
.mini-note { color: var(--muted); font-size: 11.5px; font-weight: 400; }

/* ---------- lead status ---------- */
.lead-select {
  width: auto; padding: 8px 10px; font-size: 13px; border-radius: 10px;
  background: var(--surface2);
}
.chat .head .actions { align-items: center; }
#chatActions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.badge.st-new { background: rgba(154,161,173,.16); color: var(--muted); }
.badge.st-replied { background: rgba(109,179,242,.16); color: var(--blue); }
.badge.st-qualified { background: var(--accent-soft); color: #ffc97a; }
.badge.st-booked { background: rgba(74,222,128,.16); color: var(--green); }
.badge.st-disqualified { background: rgba(248,113,113,.14); color: var(--red); }

/* ---------- test chat ---------- */
.ig-chat { display: flex; flex-direction: column; height: 560px; }
.ig-chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.ig-chat-head .avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
  color: #221503;
}
.ig-chat-head .who { font-weight: 700; font-size: 14.5px; }
.ig-chat-body {
  flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px;
}

/* ---------- demo bots ---------- */
.demo-list { display: flex; flex-direction: column; gap: 10px; }
.demo-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 16px; flex-wrap: wrap;
}
.demo-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.demo-link { color: #ffc97a; font-size: 12.5px; word-break: break-all; }
.demo-actions { display: flex; gap: 8px; flex: none; align-items: center; }
.btn-mini { padding: 7px 12px; font-size: 12.5px; text-decoration: none; display: inline-block; }
a.btn-mini { line-height: 1; }

.scan-card { border-color: rgba(246,168,60,.4); }

/* ---------- switch toggle ---------- */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface3);
  border: 1px solid var(--border); transition: background .15s; cursor: pointer;
}
.switch span::before {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); top: 2px; left: 2px; transition: transform .15s, background .15s;
}
.switch input:checked + span { background: rgba(246,168,60,.5); }
.switch input:checked + span::before { transform: translateX(20px); background: #fff; }

/* ===== admin console ===== */
.imp-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(90deg, rgba(246,168,60,.20), rgba(232,145,45,.14));
  border-bottom: 1px solid rgba(246,168,60,.35);
  color: var(--text); font-size: 13px; padding: 8px 16px;
  position: sticky; top: 0; z-index: 50;
}
.imp-banner b { color: #ffd794; }
.imp-banner .btn-ghost { padding: 4px 12px; font-size: 12.5px; }

.admin-chip {
  display: inline-block; font-size: 9.5px; font-weight: 800; letter-spacing: .6px;
  background: linear-gradient(135deg, var(--accent1), var(--accent2)); color: #221503;
  border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: 1px;
}
.nav-admin { margin-top: 4px; border-top: 1px dashed var(--border); padding-top: 12px; }

#view-admin .card { max-width: 1140px; }
.admin-stats { max-width: 1140px; }

.admin-table { font-size: 13.5px; }
.admin-table th {
  white-space: nowrap; border-bottom: 1px solid var(--border);
  padding: 8px; text-transform: uppercase; letter-spacing: .4px; font-size: 11px;
}
.admin-table td { vertical-align: middle; white-space: nowrap; padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,.04); }
.admin-table tr:hover td { background: rgba(255,255,255,.02); }
.admin-actions { display: flex; gap: 6px; }
.admin-actions .btn-ghost { padding: 5px 10px; font-size: 12.5px; }
#acNote { display: none; margin-top: 10px; font-size: 13px; color: var(--green);
  background: rgba(74,222,128,.08); border: 1px solid rgba(74,222,128,.25);
  border-radius: 10px; padding: 10px 12px; user-select: all; }
