:root {
  --blue: #1B3F8B;
  --blue-dark: #142f69;
  --blue-soft: #e8edf7;
  --red: #E30613;
  --red-soft: #fde7e8;
  --white: #fff;
  --bg: #f4f6fa;
  --text: #1c2333;
  --muted: #6b7486;
  --line: #dde2ec;
  --radius: 10px;
  --chat-in: #ffffff;
  --chat-out: #dbe6fb;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }

/* шапка */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--blue); color: var(--white); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: baseline; gap: 8px; color: var(--white); }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 800; letter-spacing: .04em; font-size: 18px; }
.brand-name.big { font-size: 34px; color: var(--blue); }
.brand-pro { color: var(--red); background: var(--white); padding: 0 5px; border-radius: 4px; }
.brand-name.big .brand-pro { color: var(--white); background: var(--red); }
.brand-sub { font-size: 12px; opacity: .75; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--white); padding: 6px 12px; border-radius: 6px; opacity: .85; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.15); opacity: 1; text-decoration: none; }
.nav a.warn b { background: var(--red); padding: 0 6px; border-radius: 8px; }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.who form { margin: 0; }
.role { background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 10px; }
.role-admin { background: var(--red); }
button.link { background: none; border: 0; color: var(--white); cursor: pointer; text-decoration: underline; font: inherit; padding: 0; }
.envbar { background: #fff4c2; color: #6a5400; text-align: center; font-size: 12px; padding: 3px; }

.container { max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; letter-spacing: .05em; }
.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.back { font-size: 14px; }

/* элементы */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--white); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--blue); }
.btn.primary { background: var(--blue); color: var(--white); border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-dark); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); }
.pill.red { background: var(--red-soft); color: var(--red); }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card.narrow { max-width: 480px; }
.error { color: var(--red); font-size: 13px; display: block; }
.alert { background: var(--red-soft); color: #8a0710; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.flash div { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; background: var(--blue-soft); }
.flash-error { background: var(--red-soft) !important; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
input[type=text], input[type=password], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--text); background: var(--white);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }

/* этапы */
.stage { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.stage-new { background: var(--red-soft); color: var(--red); }
.stage-payment { background: #fff1d6; color: #8a5a00; }
.stage-delivery { background: #e3f4ea; color: #1d6b3a; }
.stage-closed { background: #eceef2; color: var(--muted); }

/* вход */
.login { max-width: 380px; margin: 50px auto; }
.login-brand { text-align: center; margin-bottom: 20px; }
.slogan { color: var(--muted); letter-spacing: .25em; font-size: 12px; margin-top: 6px; }
.login h1 { margin-bottom: 16px; }

/* фильтры */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin: 0; min-width: 150px; }
.filters input[name=q] { flex: 1; min-width: 200px; }

/* таблица */
.table { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #f8faff; }
.num { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 14px; }

/* воронка */
.board { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 10px; }
.col { background: #e9edf4; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 300px; }
.col.over { outline: 2px dashed var(--blue); }
.col-head { display: flex; justify-content: space-between; gap: 6px; padding: 10px 12px; font-weight: 600; font-size: 13px; border-radius: var(--radius) var(--radius) 0 0; }
.col-meta { font-weight: 400; font-size: 12px; white-space: nowrap; }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.col-empty { color: var(--muted); text-align: center; padding: 10px; }
.bcard { display: flex; flex-direction: column; gap: 3px; background: var(--white); border-radius: 8px; padding: 10px; color: var(--text); border-left: 3px solid var(--blue); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.bcard:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(27,63,139,.15); }
.bcard.unassigned { border-left-color: var(--red); }
.bcard[draggable=true] { cursor: grab; }
.bcard.dragging { opacity: .5; }
.amount { font-weight: 600; color: var(--blue); }

/* карточка */
.detail { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 0 0 16px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.quote { background: var(--bg); padding: 6px 8px; border-radius: 6px; }
.ad { background: var(--red-soft); padding: 6px 8px; border-radius: 6px; }
.editform { border-top: 1px solid var(--line); padding-top: 14px; }
.plain { padding-left: 18px; margin: 0; }

.chat { background: #eef1f6; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.chat-head { display: flex; gap: 10px; align-items: baseline; padding: 12px 16px; background: var(--white); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--white); padding: 2px 10px; border-radius: 10px; margin: 8px 0; }
.msg { max-width: 75%; padding: 8px 10px 4px; border-radius: 10px; background: var(--chat-in); box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.msg.in { align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--chat-out); border-top-right-radius: 2px; }
.msg-text { white-space: normal; overflow-wrap: anywhere; }
.msg-meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.att { margin-top: 4px; }
.att img { max-width: 240px; max-height: 240px; border-radius: 6px; display: block; }
.att-off { font-size: 13px; color: var(--muted); }

/* сводки */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stats > div { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; }
.stats b { font-size: 22px; color: var(--blue); }
.stats span { font-size: 12px; color: var(--muted); }
.stats .bad b { color: var(--red); }
.table.compact td, .table.compact th { padding: 7px 10px; }
.table.compact tbody tr { cursor: default; }
.row-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.nav b.dot { background: var(--red); padding: 0 6px; border-radius: 8px; font-size: 12px; }
input[type=file] { display: block; margin-top: 6px; }

/* телефон */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .who-name { display: none; }
  .container { padding: 14px 12px 30px; }
  .hide-mobile { display: none; }
  .detail { grid-template-columns: 1fr; }
  .chat { height: 70vh; }
  .msg { max-width: 88%; }
  .filters input, .filters select { min-width: 0; flex: 1 1 45%; }
  .filters input[name=q] { flex-basis: 100%; }
  .board { grid-template-columns: repeat(6, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }

  /* таблица → карточки */
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table { border: 0; background: transparent; }
  .table thead { display: none; }
  .table tr { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  .table td:first-child { display: block; text-align: left; font-size: 16px; }
  .table td:first-child::before { content: none; }
  .table td.empty::before { content: none; }
}
