/* Bazaar – бот-консультант + CRM заявок.
   Стиль: тёмная «операторская» с янтарным акцентом; слева – телеграм-чат. */

:root {
  --bg: #12161b;
  --panel: #191f26;
  --panel-2: #1f2730;
  --line: #2a333d;
  --line-2: #36424e;
  --text: #e7edf3;
  --muted: #8d9bab;
  --amber: #ff9f43;
  --amber-2: #ffb86b;
  --tg: #5288c1;
  --tg-deep: #3e6e9e;
  --green: #4fb477;
  --blue: #4a90d9;
  --purple: #9b6dd6;
  --red: #e0644a;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 30;
}
.logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--amber), #ff7a3d);
  color: #1a1207; display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.topbar .ttl b { font-size: 15px; }
.topbar .ttl span { display: block; font-size: 11.5px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px;
}
.chip b { color: var(--text); }
.chip .ping { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(79,180,119,.5); animation: ping 2s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(79,180,119,.45);} 70%{box-shadow:0 0 0 7px rgba(79,180,119,0);} 100%{box-shadow:0 0 0 0 rgba(79,180,119,0);} }
.tlink { color: var(--amber); text-decoration: none; font-size: 12.5px; }
.tlink:hover { text-decoration: underline; }

/* ---------- Workspace ---------- */
.workspace {
  display: grid; grid-template-columns: 392px 1fr;
  gap: 0; height: calc(100vh - 59px);
}

/* ---------- Chat side ---------- */
.chatside {
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  background: var(--panel); min-height: 0;
}
.chatside-h { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chatside-h .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.chatside-h p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

.phone {
  margin: 14px; flex: 1; min-height: 0; border-radius: 22px; overflow: hidden;
  border: 1px solid var(--line-2); display: flex; flex-direction: column;
  box-shadow: 0 16px 40px rgba(0,0,0,.4); background: #0e1216;
}
.tg-head {
  background: linear-gradient(180deg, #5b91c9, var(--tg)); color: #fff;
  display: flex; align-items: center; gap: 11px; padding: 10px 14px;
}
.tg-ava { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; font-weight: 700; }
.tg-head b { font-size: 14px; display: block; }
.tg-head span { font-size: 11.5px; opacity: .85; }

.tg-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px;
  background-color: #0e1216;
  background-image: radial-gradient(rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 22px 22px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg { max-width: 84%; padding: 8px 11px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; position: relative; white-space: pre-wrap; word-wrap: break-word; animation: msgin .22s ease; }
@keyframes msgin { from { transform: translateY(6px); opacity: 0; } }
.msg .t { display: block; font-size: 10px; opacity: .55; text-align: right; margin-top: 3px; }
.msg.bot { align-self: flex-start; background: #20262d; color: var(--text); border-bottom-left-radius: 5px; }
.msg.me { align-self: flex-end; background: #2b5278; color: #fff; border-bottom-right-radius: 5px; }
.msg.sys { align-self: center; background: rgba(255,255,255,.07); color: var(--muted); font-size: 11.5px; padding: 4px 12px; border-radius: 999px; }
.msg .prod { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 6px; font-size: 12.5px; }
.msg .prod .price { color: var(--amber-2); font-weight: 700; }
.msg .prod .stk { color: var(--green); }
.msg .prod .out { color: var(--red); }

.typing { align-self: flex-start; background: #20262d; padding: 11px 13px; border-radius: 14px; border-bottom-left-radius: 5px; display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #6f7d8c; animation: bounce 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .15s; } .typing i:nth-child(3){ animation-delay: .3s; }
@keyframes bounce { 0%,60%,100%{ transform: translateY(0); opacity:.5;} 30%{ transform: translateY(-5px); opacity:1;} }

.quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 9px 12px; border-top: 1px solid var(--line); background: #11161b; }
.quick button {
  background: rgba(82,136,193,.15); border: 1px solid rgba(82,136,193,.4); color: #9ec3ea;
  padding: 6px 11px; border-radius: 999px; font-size: 12px;
}
.quick button:hover { background: rgba(82,136,193,.3); color: #fff; }

.tg-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.tg-input input { flex: 1; background: #11161b; border: 1px solid var(--line-2); color: var(--text); border-radius: 999px; padding: 9px 14px; font-size: 13.5px; outline: none; }
.tg-input input:focus { border-color: var(--tg); }
.tg-input button { background: var(--tg); color: #fff; border: 0; width: 40px; border-radius: 50%; display: grid; place-items: center; }
.tg-input button:hover { background: var(--tg-deep); }

/* ---------- CRM side ---------- */
.crmside { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.crm-h { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.crm-h .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.crm-h h2 { margin: 2px 0 0; font-size: 16px; }
.crm-stat { display: flex; gap: 22px; margin-left: auto; }
.crm-stat .s b { font-size: 18px; display: block; color: var(--amber); }
.crm-stat .s span { font-size: 11px; color: var(--muted); }

.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 18px 20px; overflow: auto; flex: 1; min-height: 0; align-content: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-height: 120px; }
.col-h { padding: 11px 13px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.col-h .dot { width: 8px; height: 8px; border-radius: 50%; }
.col-h b { font-size: 13px; }
.col-h .cnt { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--panel-2); padding: 1px 8px; border-radius: 999px; }
.col-h .hint { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; }
.col-b { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.col-b.dragover { background: rgba(255,159,67,.06); border-radius: 8px; }

.col[data-stage="new"] .dot { background: var(--blue); }
.col[data-stage="work"] .dot { background: var(--amber); }
.col[data-stage="agreed"] .dot { background: var(--purple); }
.col[data-stage="done"] .dot { background: var(--green); }

.lead {
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 11px 12px;
  cursor: grab; transition: border-color .15s, transform .1s;
}
.lead:hover { border-color: var(--amber); }
.lead:active { cursor: grabbing; }
.lead.dragging { opacity: .5; }
.lead.flash { animation: flash 1.1s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(255,159,67,.6); border-color: var(--amber);} 100%{ box-shadow: 0 0 0 14px rgba(255,159,67,0);} }
.lead .lh { display: flex; align-items: center; gap: 8px; }
.lead .lh b { font-size: 13.5px; }
.lead .id { margin-left: auto; font-size: 10.5px; color: var(--muted); font-family: ui-monospace, monospace; }
.lead .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.lead .sum { color: var(--amber-2); font-weight: 700; margin-top: 7px; font-size: 13.5px; }
.lead .items { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.lead .src { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--tg); margin-top: 6px; }
.lead .acts { display: flex; gap: 6px; margin-top: 9px; }
.lead .acts button { flex: 1; font-size: 11px; padding: 5px; border-radius: 7px; border: 1px solid var(--line-2); background: #161c22; color: var(--muted); }
.lead .acts button:hover { color: var(--text); border-color: var(--amber); }
.lead .acts button.go { color: #1a1207; background: var(--amber); border-color: var(--amber); font-weight: 600; }

.empty-col { color: var(--muted); font-size: 11.5px; text-align: center; padding: 16px 6px; opacity: .6; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5,8,11,.6); display: none; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.overlay.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; width: 100%; max-width: 460px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-h .x { margin-left: auto; background: 0; border: 0; color: var(--muted); font-size: 22px; }
.modal-b { padding: 20px; }
.modal-b .row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.modal-b .row:last-child { border-bottom: 0; }
.modal-b .row span { color: var(--muted); }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.btn { border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 8px; font-size: 13px; }
.btn:hover { border-color: var(--amber); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1a1207; font-weight: 600; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text); padding: 11px 15px; border-radius: 10px; font-size: 13px; box-shadow: 0 12px 30px rgba(0,0,0,.4); display: flex; gap: 9px; align-items: center; animation: tin .25s ease; }
.toast .d { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Catalog drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: 380px; max-width: 92vw; background: var(--panel); border-left: 1px solid var(--line-2); transform: translateX(100%); transition: transform .25s ease; z-index: 50; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.drawer-h h3 { margin: 0; font-size: 15px; }
.drawer-h .x { margin-left: auto; background: 0; border: 0; color: var(--muted); font-size: 22px; }
.drawer-b { overflow-y: auto; padding: 14px 18px; }
.cat-row { padding: 11px 0; border-bottom: 1px solid var(--line); }
.cat-row b { font-size: 13.5px; }
.cat-row .cat { font-size: 11px; color: var(--muted); }
.cat-row .line { display: flex; justify-content: space-between; margin-top: 4px; font-size: 12.5px; }
.cat-row .price { color: var(--amber-2); font-weight: 600; }
.cat-row .stk { color: var(--green); } .cat-row .stk.low { color: var(--red); }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .chatside { border-right: 0; border-bottom: 1px solid var(--line); height: 620px; }
  .phone { height: auto; }
  .board { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  .board { grid-template-columns: 1fr; }
  .crm-stat { display: none; }
}
