:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --line: #e6e8ee;
  --text: #16203a;
  --muted: #6b7280;
  --accent: #2456e6;
  --accent-2: #1d49c4;
  --accent-soft: #eef2ff;
  --green: #0a8f4f;
  --green-soft: #e9f7ef;
  --amber-bg: #fff7ed;
  --amber-line: #f5c97f;
  --amber-text: #b45309;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-md: 0 4px 10px rgba(16,24,40,.05), 0 14px 30px rgba(16,24,40,.07);
  --shadow-lg: 0 18px 50px rgba(36,86,230,.20);
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { letter-spacing: -0.02em; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 40px 24px 96px; }

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px); z-index: 30;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 800; font-size: 19px; }
.brand .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; align-self: center; }
.brand .sub { font-weight: 500; font-size: 13px; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a { padding: 8px 14px; color: var(--muted); font-size: 14px; font-weight: 500; border-radius: 8px; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

/* hero */
.hero { padding: 24px 0 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent-soft); color: var(--accent);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; margin-bottom: 20px;
}
.hero h1 { font-size: 46px; line-height: 1.08; margin: 0 0 16px; font-weight: 800; }
.hero p { color: var(--muted); font-size: 18px; max-width: 600px; margin: 0; }

/* feature grid */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-top: 40px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-sm); transition: transform .18s, box-shadow .18s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.card .ic {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft);
  display: grid; place-items: center; color: var(--accent); margin-bottom: 16px;
}
.card .ic svg { width: 22px; height: 22px; }
.card h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

/* chat widget */
.chat-fab {
  position: fixed; right: 28px; bottom: 28px; width: 60px; height: 60px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer; color: #fff;
  display: grid; place-items: center; box-shadow: var(--shadow-lg); z-index: 40; transition: transform .15s, background .15s;
}
.chat-fab:hover { background: var(--accent-2); transform: scale(1.05); }
.chat-fab svg { width: 26px; height: 26px; }

.chat-panel {
  position: fixed; right: 28px; bottom: 100px; width: 392px; max-width: calc(100vw - 36px);
  height: 580px; max-height: calc(100vh - 140px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  display: none; flex-direction: column; overflow: hidden; z-index: 40;
  box-shadow: var(--shadow-md);
}
.chat-panel.open { display: flex; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.chat-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.chat-head .av { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.chat-head .t { font-weight: 700; font-size: 15px; }
.chat-head .s { font-size: 12px; color: var(--green); display: flex; align-items: center; gap: 5px; }
.chat-head .s::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; }
.chat-head .x { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; border-radius: 8px; width: 32px; height: 32px; display: grid; place-items: center; }
.chat-head .x:hover { background: var(--panel-2); }

.chat-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.msg.bot { background: var(--panel); border: 1px solid var(--line); color: var(--text); align-self: flex-start; border-bottom-left-radius: 5px; box-shadow: var(--shadow-sm); }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.typing { color: var(--muted); font-style: italic; }
.msg.bot b { font-weight: 700; color: #0b1220; }
.msg.bot .who { font-size: 11px; color: var(--accent); font-weight: 700; margin-bottom: 3px; }
.msg.bot.op { border-color: var(--accent); }
.sys { align-self: center; color: var(--muted); font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; }
.consent { display: flex; gap: 7px; align-items: flex-start; margin-top: 8px; font-size: 12px; color: var(--muted); }
.consent input { margin-top: 2px; flex: none; }
.consent span { flex: 1; line-height: 1.4; }

.products { display: flex; flex-direction: column; gap: 8px; align-self: flex-start; width: 86%; }
.product {
  display: flex; gap: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.product:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.product img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--panel-2); flex: none; }
.product .pn { font-size: 13px; font-weight: 600; line-height: 1.3; }
.product .pc { font-size: 11px; color: var(--muted); margin-top: 3px; }
.product .pp { font-size: 14px; color: var(--green); font-weight: 700; margin-top: 4px; }
.product .pst { font-size: 11px; margin-top: 3px; font-weight: 600; }
.product .pst.in { color: var(--green); }
.product .pst.out { color: #c0392b; }

.rate { display: flex; gap: 6px; align-items: center; align-self: flex-start; }
.rate button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; cursor: pointer; font-size: 14px; line-height: 1; }
.rate button:hover { border-color: var(--accent); }
.rate .done { color: var(--muted); font-size: 12px; }

.handoff { align-self: flex-start; width: 86%; background: var(--accent-soft); border: 1px solid #c7d4fb; color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 13px; }

.chat-input { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--line); background: var(--panel); }
.chat-input input { flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; outline: none; transition: border-color .15s; }
.chat-input input::placeholder { color: var(--muted); }
.chat-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-input button { background: var(--accent); border: none; color: #fff; border-radius: var(--radius-sm); width: 44px; display: grid; place-items: center; cursor: pointer; transition: background .15s; }
.chat-input button:hover { background: var(--accent-2); }
.chat-input button svg { width: 18px; height: 18px; }

.suggest { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 14px 12px; background: var(--bg); }
.suggest button { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; cursor: pointer; transition: .15s; }
.suggest button:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* admin / analytics */
h1.page { font-size: 30px; margin: 8px 0 6px; }
.lead-sub { color: var(--muted); margin: 0 0 4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; margin-top: 22px; box-shadow: var(--shadow-sm); }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.btn { background: var(--accent); border: none; color: #fff; padding: 11px 20px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; font-size: 14px; transition: background .15s; }
.btn:hover { background: var(--accent-2); }
.btn.secondary { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.btn.secondary:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 11px 13px; border-radius: var(--radius-sm); width: 130px; font-size: 14px; outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 7px; font-weight: 500; }
.log { background: #0f1729; border: 1px solid #1e293b; border-radius: var(--radius-sm); padding: 16px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; color: #cbd5e1; height: 290px; overflow: auto; white-space: pre-wrap; margin-top: 18px; }
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.stat .v { font-size: 32px; font-weight: 800; letter-spacing: -0.03em; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 6px; }
.stat .v.green { color: var(--green); } .stat .v.orange { color: var(--accent); }
.pill { font-size: 11px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-top: 12px; background: var(--bg); }
.dialog .m { font-size: 13px; margin: 5px 0; }
.dialog .m b { color: var(--accent); }
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
td, th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.cfg-grid { display: grid; grid-template-columns: 1fr 320px; gap: 28px; margin-top: 8px; align-items: start; }
#pv { --pa: var(--accent); }
@media (max-width: 760px) { .cfg-grid { grid-template-columns: 1fr; } }
.warn { background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-text); padding: 14px 16px; border-radius: var(--radius-sm); margin-top: 16px; font-size: 13.5px; }
.warn code { background: rgba(0,0,0,.06); padding: 1px 6px; border-radius: 5px; }

/* анимированный индикатор «печатает» */
.dots { display: inline-flex; gap: 4px; align-items: center; padding: 3px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: dotpulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes dotpulse { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ===== адаптив ===== */
@media (max-width: 760px) {
  .wrap { padding: 26px 16px 84px; }
  .topbar { padding: 14px 16px; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .hero { padding: 14px 0 4px; }
  .hero h1 { font-size: 32px; }
  .hero p { font-size: 16px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 28px; }
  .card { padding: 18px; }
  .panel { padding: 18px; }
  h1.page { font-size: 24px; }
  .stat .v { font-size: 26px; }
  .stat { padding: 16px; }
  .row { gap: 12px; }
}

@media (max-width: 480px) {
  .brand .sub { display: none; }
  .hero h1 { font-size: 27px; }
  .grid { grid-template-columns: 1fr; }
  .field { width: 100%; }

  /* чат на весь экран */
  .chat-fab { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .chat-panel {
    right: 0; left: 0; top: 0; bottom: 0;
    width: 100%; max-width: none; height: 100dvh; max-height: none;
    border-radius: 0; border: none;
  }
  .chat-panel.open { animation: slideup .24s cubic-bezier(.22,.61,.36,1); }
  @keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .chat-head { padding-top: calc(16px + env(safe-area-inset-top)); }
  .chat-head .av { width: 44px; height: 44px; }
  .chat-head .x { width: 40px; height: 40px; }
  .chat-input { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .chat-input input { font-size: 16px; }   /* без авто-зума на iOS */
  .chat-input button { width: 48px; }
  .msg { max-width: 88%; font-size: 15px; }
  .suggest { padding-bottom: 12px; }
}

/* ============================================================
   Admin shell — единый SaaS-кабинет (сайдбар + контент)
   ============================================================ */
body.app { display: block; background: var(--bg); }

/* ----- сайдбар ----- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 236px; z-index: 80;
  background: #0e1526; color: #aab4c8;
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; }
.sb-brand .logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), #6d8dff);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px;
}
.sb-brand .nm { color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.sb-brand .nm small { display: block; font-weight: 500; font-size: 11px; color: #7c8aa5; letter-spacing: 0; }
.snav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.sgroup { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #5d6b87; font-weight: 700; padding: 16px 10px 7px; }
.snav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; margin: 1px 0; border-radius: 9px;
  color: #aab4c8; font-size: 13.5px; font-weight: 500;
  position: relative; transition: background .12s, color .12s;
}
.snav a svg { width: 17px; height: 17px; flex: none; opacity: .8; }
.snav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.snav a.active { background: rgba(63,103,233,.28); color: #fff; }
.snav a.active::before {
  content: ""; position: absolute; left: -12px; top: 7px; bottom: 7px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.snav .cnt {
  margin-left: auto; background: #e0a020; color: #1a2233; border-radius: 999px;
  font-size: 10.5px; font-weight: 800; min-width: 19px; height: 19px;
  display: grid; place-items: center; padding: 0 5px;
}
.sb-foot { padding: 14px 16px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12.5px; }
.sb-status { display: flex; align-items: center; gap: 8px; margin-bottom: 11px; color: #8c99b2; }
.sb-status i { width: 8px; height: 8px; border-radius: 50%; background: #34d27b; flex: none; box-shadow: 0 0 0 3px rgba(52,210,123,.15); }
.sb-status.warn i { background: #e0a020; box-shadow: 0 0 0 3px rgba(224,160,32,.15); }
.sb-foot .out {
  display: flex; align-items: center; gap: 9px; color: #aab4c8; cursor: pointer;
  background: none; border: none; font: inherit; padding: 6px 0; width: 100%;
}
.sb-foot .out:hover { color: #fff; }
.sb-foot .out svg { width: 15px; height: 15px; }

/* ----- контент ----- */
.main { margin-left: 236px; min-height: 100vh; }
.container { max-width: 1120px; margin: 0 auto; padding: 30px 34px 96px; }
.pagehead { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.pagehead h1 { font-size: 24px; margin: 0 0 4px; font-weight: 800; }
.pagehead .sub { color: var(--muted); font-size: 14px; margin: 0; }
.pagehead .actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* ----- мобильная шапка ----- */
.mtop {
  display: none; position: sticky; top: 0; z-index: 70;
  align-items: center; gap: 12px; padding: 12px 16px;
  background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.mtop .burger { background: none; border: 1px solid var(--line); border-radius: 9px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.mtop .t { font-weight: 800; font-size: 15px; }
.scrim { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 75; display: none; }
.scrim.show { display: block; }

/* ----- компоненты ----- */
.btn.danger { background: #c0392b; }
.btn.danger:hover { background: #a93226; }
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 8px; }
.btn .bicon { width: 15px; height: 15px; vertical-align: -2px; margin-right: 6px; }

.search { position: relative; flex: 1; min-width: 220px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding-left: 36px; }

.progress { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 14px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #6d8dff); border-radius: 999px; transition: width .5s ease; }
.progress.indet i { width: 30%; animation: indet 1.2s infinite ease-in-out; }
@keyframes indet { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

.steps { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.step { font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; display: inline-flex; align-items: center; gap: 6px; }
.step.on { color: var(--accent); background: var(--accent-soft); border-color: #c7d4fb; }
.step.done { color: var(--green); background: var(--green-soft); border-color: #bfe8d2; }

.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state svg { width: 38px; height: 38px; opacity: .45; margin-bottom: 10px; }
.empty-state .h { font-weight: 700; color: var(--text); font-size: 14.5px; margin-bottom: 4px; }
.empty-state p { font-size: 13px; margin: 0; }

.skel { background: linear-gradient(90deg, #eceef3 25%, #f6f7f9 50%, #eceef3 75%); background-size: 200% 100%; animation: skel 1.2s infinite; border-radius: 8px; color: transparent !important; }
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* тосты */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #0e1526; color: #e8edf6; border-radius: 12px; padding: 12px 16px 12px 14px;
  font-size: 13.5px; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 10px;
  border-left: 3px solid var(--green); animation: toastin .22s ease; max-width: 360px;
}
.toast.err { border-left-color: #e35d6a; }
.toast svg { width: 16px; height: 16px; flex: none; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }
.toast.hide { opacity: 0; transform: translateY(6px); transition: .25s; }

/* модальное подтверждение */
.ovl { position: fixed; inset: 0; background: rgba(16,24,40,.5); z-index: 110; display: flex; align-items: center; justify-content: center; padding: 20px; }
.cbox { background: var(--panel); border-radius: 16px; padding: 24px; width: 420px; max-width: 100%; box-shadow: var(--shadow-md); animation: pop .16s ease; }
.cbox h3 { margin: 0 0 8px; font-size: 17px; }
.cbox p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.cbox .bts { display: flex; gap: 10px; justify-content: flex-end; }

/* табы страницы */
.ptabs { display: flex; gap: 8px; margin: 18px 0 4px; flex-wrap: wrap; }
.ptabs button { background: var(--panel); border: 1px solid var(--line); color: var(--muted); padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 13.5px; font-weight: 600; transition: .12s; }
.ptabs button:hover { color: var(--text); }
.ptabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* таблицы кабинета */
table tr.trow { cursor: pointer; }
table tr.trow:hover { background: var(--panel-2); }

/* адаптив кабинета */
@media (max-width: 920px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.35); }
  .main { margin-left: 0; }
  .mtop { display: flex; }
  .container { padding: 20px 16px 80px; }
  .pagehead h1 { font-size: 20px; }
}
