/* BAO admin — дизайн-система.
   Формула: тёмный sidebar (#0D1117) + светлый workspace (#F5F6F8) + красный
   акцент BAO (#C92525). Компактный внутренний инструмент, не SaaS-плакат. */

:root {
  --side-bg: #0D1117;
  --side-text: #9AA4B2;
  --side-active: #C92525;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --text: #151922;
  --muted: #667085;
  --border: #E6E8EC;
  --red: #C92525;
  --red-hover: #B72020;
  --radius: 12px;
  --side-w: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45;
}
a { color: inherit; }
h1 { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; }

/* ---------- каркас ---------- */
.shell { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; margin-left: var(--side-w); }
.content { max-width: 1500px; margin: 0 auto; padding: 32px; }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w);
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; padding: 22px 14px 16px; z-index: 50;
}
.side-logo { display: flex; align-items: center; gap: 9px; padding: 0 10px 22px; }
.side-logo .mark { color: #fff; font-weight: 800; font-size: 21px; letter-spacing: .06em; }
.side-logo .yl {
  background: var(--red); color: #fff; font-size: 12px; font-weight: 600;
  padding: 2px 7px; border-radius: 5px;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: 9px; text-decoration: none; color: var(--side-text);
  font-weight: 500; font-size: 13.5px; transition: background .15s, color .15s;
}
.side-nav a svg { width: 17px; height: 17px; flex: none; stroke: currentColor; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #E6EAF0; }
.side-nav a.active { background: var(--side-active); color: #fff; }

.side-user {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px 0;
  border-top: 1px solid rgba(255,255,255,.08); margin-top: 12px;
}
.side-user .ava {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: center; font-size: 17px; flex: none;
}
.side-user .who { min-width: 0; flex: 1; }
.side-user .who b { display: block; color: #E6EAF0; font-size: 13px; font-weight: 600;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .who span { font-size: 11.5px; color: var(--side-text); }
.side-user .exit { color: var(--side-text); display: flex; padding: 6px; border-radius: 7px;
                   transition: background .15s, color .15s; }
.side-user .exit:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-user .exit svg { width: 16px; height: 16px; stroke: currentColor; }

/* ---------- страница ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between;
             gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-sub { color: var(--muted); margin: 5px 0 0; font-size: 13.5px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.flash {
  background: #FFF8E6; border: 1px solid #F2D791; color: #7A5A00;
  padding: 9px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 13.5px;
}

/* ---------- карточки ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between;
             padding: 15px 20px 0; }
.card.flush .card-head { padding: 15px 20px 12px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.card-head .more { font-size: 13px; color: var(--muted); text-decoration: none; }
.card-head .more:hover { color: var(--text); }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--border);
       border-radius: var(--radius); padding: 16px 18px; }
.kpi .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 11.5px; margin-top: 7px; }

.kpi-grid.kpi-mini { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi-mini .kpi { padding: 12px 16px; }
.kpi-mini .num { font-size: 22px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* распределение статусов */
.status-dist { display: flex; height: 8px; border-radius: 4px; overflow: hidden;
               background: #EDEFF2; margin: 4px 0 10px; }
.status-dist span { display: block; height: 100%; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px;
               color: var(--muted); }
.dist-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
                    margin-right: 5px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); padding: 10px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid #F0F1F4;
                vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
tr.rowlink { cursor: pointer; transition: background .12s; }
tr.rowlink:hover { background: #F7F8FA; }

.cell-num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.cell-ellipsis { max-width: 340px; overflow: hidden; text-overflow: ellipsis;
                 white-space: nowrap; color: var(--muted); }

/* клиентская ячейка */
.who-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ava-i {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: #EEF0F3; color: #5B6472; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.who-cell .nm { min-width: 0; }
.who-cell .nm b { display: block; font-weight: 600; font-size: 13.5px;
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-cell .nm span { color: var(--muted); font-size: 12px; }

.thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; display: block; }
.goods-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.goods-cell .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
                 max-width: 300px; }

/* ---------- бейджи ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
  background: #F1F2F4; color: #5B6472; text-decoration: none;
}
a.badge { transition: filter .15s; } a.badge:hover { filter: brightness(.96); }
.badge.active { box-shadow: 0 0 0 2px #15192226 inset; }
.st-new       { background: #EDF3FF; color: #2F5AC7; }
.st-accepted  { background: #F3EFFE; color: #6D4AC7; }
.st-purchased { background: #FFF3E0; color: #B45C00; }
.st-shipped   { background: #E4F6FA; color: #0E7490; }
.st-warehouse { background: #E3F5EE; color: #0B7A55; }
.st-delivered { background: #E5F6E8; color: #15803D; }
.st-cancelled { background: #F1F2F4; color: #82909F; }
.b-admin  { background: #F3EFFE; color: #6D4AC7; }
.b-ok     { background: #E5F6E8; color: #15803D; }
.b-wait   { background: #FFF3E0; color: #B45C00; }

.dot-new{background:#2F5AC7}.dot-accepted{background:#6D4AC7}
.dot-purchased{background:#B45C00}.dot-shipped{background:#0E7490}
.dot-warehouse{background:#0B7A55}.dot-delivered{background:#15803D}
.dot-cancelled{background:#9AA4B2}

/* ---------- формы ---------- */
label { display: block; margin: 12px 0; font-size: 13px; font-weight: 500; }
input, textarea, select {
  width: 100%; padding: 8px 11px; margin-top: 5px; font: inherit; font-size: 13.5px;
  border: 1px solid #D6DAE0; border-radius: 9px; background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--red); box-shadow: 0 0 0 3px #C9252519;
}
button, .btn {
  display: inline-flex; align-items: center; gap: 7px; background: var(--red);
  color: #fff; border: 0; padding: 8px 16px; border-radius: 9px; font: inherit;
  font-size: 13.5px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .15s, transform .1s;
}
button:hover, .btn:hover { background: var(--red-hover); }
button:active, .btn:active { transform: translateY(1px); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid #D6DAE0; }
.btn-ghost:hover { background: #F5F6F8; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }

.search input { width: 240px; margin-top: 0; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form label { display: flex; align-items: center; gap: 6px; margin: 0;
                     font-weight: 400; }
.inline-form select, .inline-form input[type=checkbox] { width: auto; margin-top: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }

/* ---------- заказы: панель и группировка по клиентам ---------- */
.orders-bar { display: flex; align-items: flex-start; justify-content: space-between;
              gap: 14px; flex-wrap: wrap; }
.orders-bar .filters { margin-bottom: 12px; flex: 1; }
.seg { display: inline-flex; background: #EDEFF2; border-radius: 9px; padding: 3px;
       flex: none; }
.seg button { background: none; color: var(--muted); border: 0; border-radius: 7px;
              padding: 6px 14px; font-size: 13px; font-weight: 600;
              transition: background .15s, color .15s; }
.seg button:hover { background: rgba(255,255,255,.6); color: var(--text); }
.seg button.on { background: #fff; color: var(--red);
                 box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.cgroup { margin-bottom: 12px; }
.cg-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px;
           background: #FAFBFC; cursor: pointer; border-radius: var(--radius);
           transition: background .12s; }
.cg-head:hover { background: #F5F6F8; }
.cgroup:not(.folded) .cg-head { border-bottom: 1px solid var(--border);
                                border-radius: var(--radius) var(--radius) 0 0; }
.cg-who { min-width: 0; }
.cg-who b { display: block; font-size: 14px; font-weight: 600; }
.cg-who .muted { font-size: 12px; }
.cg-sum { margin-left: auto; text-align: right; font-size: 12.5px; }
.cg-sum b { display: block; font-size: 13px; }
.cg-chat { flex: none; }
.chev { color: var(--muted); transition: transform .18s; flex: none; }
.cgroup.folded .chev { transform: rotate(-90deg); }
.cgroup.folded .cg-body { display: none; }
table.data.compact td { padding: 9px 14px; }
.row-act { text-decoration: none; font-size: 15px; opacity: .55;
           transition: opacity .15s; }
.row-act:hover { opacity: 1; }

/* ---------- переписки: двухпанельный экран ---------- */
.conv-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr);
               gap: 16px; height: calc(100vh - 64px); min-height: 480px; }
.conv-list, .conv-main { display: flex; flex-direction: column; min-height: 0; }

.conv-list-head { padding: 16px 16px 0; }
.conv-title { font-size: 22px; }
.conv-search { margin: 12px 0 10px; }
.conv-search input { margin-top: 0; }
.conv-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border);
             margin: 0 -16px; padding: 0 16px; }
.conv-tabs button {
  background: none; color: var(--muted); border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 10px; font-size: 13px; font-weight: 600;
  transition: color .15s, border-color .15s;
}
.conv-tabs button:hover { background: none; color: var(--text); }
.conv-tabs button.on { color: var(--red); border-bottom-color: var(--red); }
.conv-tabs .cnt { background: var(--red); color: #fff; border-radius: 999px;
                  font-size: 10.5px; padding: 1px 6px; margin-left: 3px; }

.conv-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.conv-item {
  display: flex; gap: 10px; padding: 11px 14px; text-decoration: none;
  border-bottom: 1px solid #F0F1F4; transition: background .12s; position: relative;
}
.conv-item:hover { background: #F7F8FA; }
.conv-item.sel { background: #F5F6F8; box-shadow: inset 2px 0 0 var(--red); }
.conv-item .ava-i { margin-top: 2px; }
.ci-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ci-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ci-top b { font-size: 13.5px; font-weight: 600; overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; }
.ci-top time { color: var(--muted); font-size: 11.5px; flex: none; }
.ci-user { color: var(--muted); font-size: 12px; }
.ci-last { color: var(--muted); font-size: 12.5px; overflow: hidden;
           text-overflow: ellipsis; white-space: nowrap; }
.ci-badge { margin-top: 4px; }
.conv-foot { padding: 9px 16px; border-top: 1px solid var(--border);
             color: var(--muted); font-size: 12px; }

.conv-head { display: flex; align-items: center; gap: 12px;
             padding: 13px 18px; border-bottom: 1px solid var(--border); }
.conv-back { display: none; text-decoration: none; color: var(--muted);
             font-size: 18px; padding: 4px 8px; }
.conv-head .ava-i { width: 40px; height: 40px; font-size: 15px; }
.ch-body { flex: 1; min-width: 0; }
.ch-name { font-size: 16px; font-weight: 700; display: flex; align-items: center;
           gap: 8px; flex-wrap: wrap; }
.ch-user { color: var(--muted); font-weight: 400; font-size: 13px; }
.ch-orders { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.ch-stats { display: flex; gap: 16px; color: var(--muted); font-size: 12px;
            text-align: center; flex: none; }
.ch-stats b { display: block; color: var(--text); font-size: 15px; }

.conv-scroll.msgs { background: #FAFBFC; padding: 14px 18px; }
.msgs-col { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; }
.date-sep { text-align: center; margin: 12px 0 6px; }
.date-sep span { background: #EDEFF2; color: var(--muted); font-size: 11.5px;
                 padding: 3px 11px; border-radius: 999px; }
.bubble {
  max-width: 68%; padding: 9px 13px; margin-top: 14px;
  white-space: pre-wrap; overflow-wrap: break-word; background: #F1F3F5;
  border-radius: 14px 14px 14px 4px; align-self: flex-start; font-size: 13.5px;
}
.bubble.bot { background: #FFF7F6; border: 1px solid #F3D3CF;
              border-radius: 14px 14px 4px 14px; align-self: flex-end; max-width: 72%; }
.bubble.grouped { margin-top: 6px; }
.bubble .when { display: block; font-size: 11px; color: #9AA4B2; margin-top: 4px; }
.chat-photo { display: block; max-width: 320px; max-height: 300px; object-fit: cover;
              border-radius: 10px; margin-bottom: 6px; cursor: zoom-in; }
.conv-empty { margin: auto; }

.composer { display: flex; gap: 10px; align-items: flex-end;
            padding: 12px 18px 4px; border-top: 1px solid var(--border); }
.composer textarea { resize: none; margin-top: 0; max-height: 120px; }
.composer button { flex: none; width: 38px; height: 38px; padding: 0;
                   justify-content: center; border-radius: 10px; }
.composer-hint { color: var(--muted); font-size: 11.5px; padding: 4px 18px 12px; }

#lightbox { position: fixed; inset: 0; background: rgba(13,17,23,.82); z-index: 200;
            display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 12px; }

.order-chips { display: flex; flex-wrap: wrap; gap: 7px; }

/* карточка заказа */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
.photo { max-width: 100%; border-radius: 10px; margin: 6px 0; display: block; }
.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: 8px 0; border-bottom: 1px solid #F0F1F4; font-size: 13px; }
.events li:last-child { border-bottom: none; }
.events .muted { display: block; font-size: 11.5px; }
.raw { white-space: pre-wrap; background: #F7F8FA; border-radius: 9px;
       padding: 11px 13px; font-size: 13px; }

/* ---------- пустые состояния ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ico { font-size: 40px; margin-bottom: 10px; }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.muted { color: var(--muted); }
.mt0 { margin-top: 0; }

/* ---------- вход ---------- */
body.plain { background: var(--bg); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
              padding: 20px; }
.login-box { width: 360px; background: var(--card); border: 1px solid var(--border);
             border-radius: 16px; padding: 30px 28px; text-align: center; }
.login-box .side-logo { justify-content: center; padding-bottom: 6px; }
.login-box .side-logo .mark { color: var(--text); font-size: 26px; }
.login-box .tagline { color: var(--muted); font-style: italic; font-size: 13px;
                      margin: 0 0 18px; }
.login-box input { text-align: left; }
.login-box button { width: 100%; justify-content: center; margin-top: 14px; }
.login-box .backlink { display: inline-block; margin-top: 16px; font-size: 12.5px;
                       color: var(--muted); }
code { background: #F0F1F4; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }

/* ---------- адаптив ---------- */
@media (max-width: 1024px) {
  :root { --side-w: 62px; }
  .sidebar { padding: 18px 9px 12px; }
  .side-logo { justify-content: center; padding-bottom: 16px; }
  .side-logo .mark, .side-user .who { display: none; }
  .side-nav a { justify-content: center; padding: 11px; }
  .side-nav a .txt { display: none; }
  .side-user { justify-content: center; }
  .side-user .exit { display: none; }
  .content { padding: 20px 16px; }
}
@media (max-width: 900px) {
  .conv-layout { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 120px); }
  .conv-layout.has-open .conv-list { display: none; }
  .conv-layout:not(.has-open) .conv-main { display: none; }
  .conv-back { display: inline-block; }
  .conv-scroll { overflow-y: visible; }
  .conv-scroll.msgs { overflow-y: auto; max-height: 60vh; }
}
@media (max-width: 640px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; width: auto; flex-direction: row; align-items: center;
             padding: 10px 12px; }
  .side-nav { flex-direction: row; flex: 1; justify-content: center; }
  .side-user { border: 0; margin: 0; padding: 0; }
  .side-user .ava { width: 28px; height: 28px; font-size: 14px; }
  .main { margin-left: 0; }
  .bubble { max-width: 88%; }
  h1 { font-size: 22px; }
  .search input { width: 100%; }
}
