/* CRM Net-Core — внутренний интерфейс (CRM-10). Бренд: ночь, көк, бумага. Одна сетка отступов
   (8 · 12 · 16 · 20), одна высота полей и кнопок (40), телефон от 320 px без горизонтальной
   прокрутки страницы: таблица заявок на узком экране — карточки. */
:root {
  --night: #0E1B26;
  --night-2: #16293A;
  --night-3: #1D3446;
  --kok: #1796C0;
  --kok-ink: #0B6A8E; /* көк для текста и кнопок: 6:1 к белому (көк — 3,4:1, только акценты) */
  --paper: #F4F6F8;
  --ink: #14212C;
  --muted: #5B6B78;
  --line: #DDE4EA;
  --white: #FFFFFF;
  --err: #B3261E;
  --ok: #1E7A45;
  --warn: #8A5200;
  --radius: 10px;
  --field: 40px;
}
* { box-sizing: border-box; }
html { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--paper); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-width: 320px; }
a { color: var(--kok-ink); }
a:hover { color: var(--night); }
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; line-height: 1.3; margin: 0 0 12px; font-weight: 650; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.wrap-any { overflow-wrap: anywhere; }

/* Шапка */
.top { background: var(--night); color: #E8EEF2; position: sticky; top: 0; z-index: 10; }
.top-in { display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { display: inline-flex; align-items: baseline; gap: 8px; color: var(--white); text-decoration: none; font-weight: 700; letter-spacing: .04em; flex: 0 0 auto; }
.brand:hover { color: var(--white); }
.brand .mark b { color: var(--kok); font-weight: 700; }
.brand .sub { font-weight: 600; font-size: .72rem; letter-spacing: .1em; color: #9FB2C0; text-transform: uppercase; }
.nav { display: flex; gap: 4px; min-width: 0; }
.nav a { display: inline-flex; align-items: center; white-space: nowrap; color: #C9D5DD; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .95rem; }
.nav a.on, .nav a:hover { background: var(--night-3); color: var(--white); }
.nav .count { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: var(--kok); color: var(--white); font-size: .75rem; font-weight: 700; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.who { display: flex; align-items: center; gap: 12px; margin-left: auto; min-width: 0; }
.who .user { color: #9FB2C0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.who form { margin: 0; }

/* Лента: просмотры сайта и заявки (CRM-09); на телефоне листается в одну строку */
.strip { background: var(--night-2); border-top: 1px solid #213547; }
.strip-in { display: flex; align-items: center; gap: 8px; height: 44px; line-height: 1; overflow-x: auto; white-space: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.strip-in::-webkit-scrollbar { display: none; }
.strip .lbl { color: #8FA4B3; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; flex: 0 0 auto; }
.strip .sep { width: 1px; height: 20px; background: #2C4558; flex: 0 0 auto; margin: 0 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; line-height: 1; border-radius: 999px; background: var(--night-3); color: #C9D5DD; font-size: .84rem; text-decoration: none; flex: 0 0 auto; }
.chip b { color: var(--white); font-weight: 650; font-variant-numeric: tabular-nums; }
a.chip:hover { background: #26425A; color: var(--white); }
.chip.warn { background: #4A2E12; color: #F3D2A8; }
.chip.warn b { color: #FFE2BD; }

main { padding: 20px 0 48px; }

/* Сообщения */
.msg { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; }
.msg.err { background: #FBEAEA; color: var(--err); border: 1px solid #F0C4C1; }
.msg.ok { background: #E8F5EC; color: var(--ok); border: 1px solid #BFE3CB; }
.msg.warn { background: #FFF6E5; color: var(--warn); border: 1px solid #F1D9A8; }
.card > .msg:last-child { margin-bottom: 0; }

/* Карточки */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h1, .card-head h2 { margin: 0; }
.hint { color: var(--muted); font-size: .88rem; margin: 12px 0 0; }

/* Поля и кнопки — одна высота */
.f { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); min-width: 0; margin: 0; }
input, select, textarea { width: 100%; min-height: var(--field); font: inherit; font-size: .95rem; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); min-width: 0; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--kok); outline-offset: 0; border-color: var(--kok); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--field); padding: 0 16px; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--kok-ink); color: var(--white); }
.btn.primary:hover { background: var(--night); color: var(--white); }
.btn.ghost { background: var(--white); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--kok-ink); color: var(--kok-ink); }
.top .btn.ghost { background: transparent; border-color: #2C4558; color: #E8EEF2; }
.top .btn.ghost:hover { border-color: #4A6A82; color: var(--white); }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: .85rem; }

/* Фильтры списка */
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.filters .actions { display: flex; gap: 8px; align-items: center; }

/* Этапы */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: #E4F2F8; color: #0B4F69; white-space: nowrap; }
.badge.s-new { background: #DCEFFA; color: #0B4F69; }
.badge.s-proposal_sent, .badge.s-negotiation { background: #FFF1DB; color: var(--warn); }
.badge.s-won { background: #E3F3E8; color: var(--ok); }
.badge.s-lost { background: #EEF0F2; color: var(--muted); }
.badge.unread { background: #FFF1DB; color: var(--warn); }
.badge.read { background: #E3F3E8; color: var(--ok); }

/* Список заявок: таблица на широком экране */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
.list th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tbody tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: #F7FAFC; }
.list .num a { font-weight: 650; text-decoration: none; }
.list .sub { color: var(--muted); font-size: .85rem; }
.list .step { max-width: 280px; }
.empty { color: var(--muted); margin: 0; }
.more { margin: 16px 0 0; }

/* Почта (CRM-11): непрочитанное — жирным */
.seg { display: inline-flex; gap: 6px; }
.list tr.unread td, .cards li.unread .name { font-weight: 650; }
.list.mail .subj { max-width: 420px; overflow-wrap: anywhere; }
.list.mail .from { max-width: 260px; overflow-wrap: anywhere; }
.letter-text { font-size: .95rem; line-height: 1.55; overflow-wrap: anywhere; }
.files { list-style: none; margin: 0; padding: 0; }
.files li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }

/* Почта (CRM-13): папки слева, отбор и действия над списком, на телефоне — свайп карточки */
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.mailx { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.mfolders { position: sticky; top: 116px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mflist { display: flex; flex-direction: column; gap: 2px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.mf { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.mf:hover { background: var(--paper); color: var(--ink); }
.mf.on { background: #E4F2F8; color: #0B4F69; font-weight: 600; }
.mf b { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--kok-ink); color: #fff; font-size: .78rem; text-align: center; }
.mf i { font-style: normal; color: var(--muted); font-size: .82rem; }
.mfnew { display: flex; gap: 6px; min-width: 0; }
.mfnew input { flex: 1 1 auto; width: auto; min-width: 0; min-height: 34px; padding: 6px 8px; font-size: .88rem; }
.mfedit { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: .88rem; }
.mfedit summary { cursor: pointer; color: var(--muted); }
.mfedit form { margin-top: 8px; }
.mmain { min-width: 0; }
.mhead .card-head { margin-bottom: 12px; }
.mfilter, .mbulk { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.mfilter input[type="search"] { flex: 1 1 220px; width: auto; min-width: 0; min-height: 36px; }
.mfilter select, .mbulk select { width: auto; min-height: 34px; padding: 4px 8px; font-size: .88rem; }
.mbulk { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.mmove { display: inline-flex; gap: 6px; align-items: center; min-width: 0; max-width: 100%; }
.mmove select { min-width: 0; max-width: 60vw; }
.js .nojs { display: none; }
.list.mail .ck { width: 28px; padding-right: 0; }
.list.mail .ck input, .mck { width: 18px; height: 18px; min-height: 18px; }
.list.mail .mno { font-weight: 650; text-decoration: none; }
.lactions { display: flex; flex-wrap: wrap; gap: 8px; }
.pager { display: flex; gap: 8px; }
.only-touch { display: none; }
.mcard { position: relative; overflow: hidden; padding: 0 !important; }
.mswipe { display: none; }
.mcard-body { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 0 0 0 12px; background: var(--white); border-radius: var(--radius); transition: transform .2s ease; touch-action: pan-y; }
.mcard-body .mck { margin-top: 16px; flex: 0 0 auto; }
.mcard-body .lead-link { flex: 1 1 auto; min-width: 0; padding-left: 0; }
.mcard .r1 .no { color: var(--ink); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard .r1 .when { color: var(--muted); font-size: .8rem; flex: 0 0 auto; }
.mcard:not(.unread) .name { font-weight: 500; }
.unread-dot { color: var(--warn); font-weight: 650; }
.js .mswipe { display: flex; position: absolute; top: 0; right: 0; bottom: 0; }
.mswipe button { border: 0; color: #fff; font: inherit; font-size: .82rem; font-weight: 600; padding: 0 12px; min-width: 76px; cursor: pointer; }
.sw-read { background: var(--kok-ink); }
.sw-move { background: #5B6B78; }
.sw-del { background: var(--err); }
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(14, 27, 38, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-in { width: 100%; max-width: 480px; background: var(--white); border-radius: 14px 14px 0 0; padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.sheet-title { margin: 0 0 4px; font-weight: 650; }
.sheet-in .btn { width: 100%; justify-content: flex-start; }

/* Паспорт объекта (CRM-12): сетка полей по 4 колонки, строки точек и пользователей */
h3 { font-size: .9rem; margin: 16px 0 8px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.passport .card h2 { margin-bottom: 14px; }
.pgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.pgrid .wide2 { grid-column: span 2; }
.pgrid .wide4, .wide-all { grid-column: 1 / -1; }
.wide-all { margin-top: 12px; }
.f small { color: #8796a3; font-size: .78rem; }
.f.bad input, .f.bad select, .f.bad textarea { border-color: var(--err); background: #FFF8F7; }
.ferr { color: var(--err); font-size: .8rem; line-height: 1.35; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; min-height: var(--field); color: var(--ink); }
.check input { width: 18px; min-height: 18px; height: 18px; }
.check.bad { color: var(--err); }
.radios { border: 0; padding: 0; margin: 0; }
.radios legend { padding: 0; margin-bottom: 6px; }
.radios label { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; min-height: 32px; color: var(--ink); font-size: .92rem; }
.radios input { width: 16px; min-height: 16px; height: 16px; }
.prows, .urows { display: flex; flex-direction: column; gap: 8px; }
.prow { display: grid; grid-template-columns: 24px 96px minmax(130px, 1.4fr) 92px 178px 94px 112px 62px 62px minmax(90px, 1fr); gap: 8px; align-items: end;
  padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #FBFCFD; }
.prow .f, .urow .f { font-size: .74rem; gap: 3px; }
.prow input, .prow select, .urow input, .urow select { min-height: 36px; padding: 6px 8px; font-size: .9rem; }
.pmeter input { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.pno { align-self: center; color: var(--muted); font-weight: 650; text-align: center; }
.urow { display: grid; grid-template-columns: minmax(200px, 1.5fr) minmax(160px, 1.2fr) 160px auto; gap: 10px; align-items: end;
  padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #FBFCFD; }
.form-actions.start { justify-content: flex-start; margin-top: 10px; }
.pactions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.connect { border-color: #BFD8E6; }
.problems { border-color: #F0C4C1; background: #FFF9F8; }
.problems h2 { color: var(--err); }
.warns { border-color: #F1D9A8; background: #FFFCF5; }
.warns h2 { color: var(--warn); }
.problems ul, .warns ul, .result ul { margin: 0; padding-left: 20px; }
.problems li, .warns li, .result li { margin: 3px 0; }
.result { border-color: #BFD8E6; }
.result.ok { border-color: #BFE3CB; background: #F7FCF9; }
.result h3 { margin-top: 14px; }
.links { list-style: none; padding: 0 !important; }
.links li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
.secret { display: inline-block; padding: 4px 8px; border-radius: 6px; background: var(--night); color: #fff; letter-spacing: .04em; user-select: all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; background: var(--paper); padding: 1px 5px; border-radius: 4px; }

/* Список заявок: карточки на телефоне */
.cards { list-style: none; margin: 0; padding: 0; display: none; }
.cards li { border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); margin-bottom: 10px; }
.cards a.lead-link { display: block; padding: 14px 16px; color: inherit; text-decoration: none; }
.cards .r1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cards .r1 .no { font-weight: 700; color: var(--kok-ink); }
.cards .name { margin-top: 6px; font-weight: 600; overflow-wrap: anywhere; }
.cards .meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.cards .next { margin-top: 10px; padding: 8px 10px; background: var(--paper); border-radius: 8px; font-size: .9rem; overflow-wrap: anywhere; }
.cards .next .when { font-weight: 600; }

/* Карточка заявки */
.back { margin: 0 0 12px; }
.back a { text-decoration: none; }
.lead-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lead-meta { color: var(--muted); font-size: .9rem; margin: 6px 0 16px; }
.lead-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 0 16px; align-items: start; }
dl.kv { display: grid; grid-template-columns: minmax(110px, 30%) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .9rem; }
dl.kv dd { margin: 0; min-height: 1.4em; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }

/* История — лента событий */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 18px; margin-left: 6px; border-left: 2px solid var(--line); }
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--kok); }
.timeline .when { font-size: .82rem; color: var(--muted); }
.timeline .what { margin-top: 2px; overflow-wrap: anywhere; }
.note { margin-top: 6px; padding: 8px 10px; background: var(--paper); border-left: 3px solid var(--kok); border-radius: 0 6px 6px 0; }

/* Вход */
.auth { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 24px 0; }
.auth .card { width: 100%; max-width: 400px; margin: 0; padding: 24px; }
.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.stack .btn { width: 100%; }

@media (max-width: 1120px) {
  .prow { grid-template-columns: 24px repeat(4, minmax(0, 1fr)); }
  .prow .pname, .prow .pnote { grid-column: span 2; }
  .prow .pmeter { grid-column: span 2; }
  .prow .pno { grid-row: span 3; }
}
@media (max-width: 900px) {
  .mailx { grid-template-columns: minmax(0, 1fr); }
  .mfolders { position: static; }
  .mflist { flex-direction: row; overflow-x: auto; scrollbar-width: none; padding: 4px; }
  .mflist::-webkit-scrollbar { display: none; }
  .mf { flex: 0 0 auto; white-space: nowrap; }
  .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .urow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .actions { grid-column: 1 / -1; }
  .filters .actions .btn { flex: 1; }
  .lead-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .js .only-touch { display: block; }
  .mfedit { display: none; }
  .mfnew input { flex: 1; }
  .only-wide { display: none; }
  .cards { display: block; }
  .card.list-card { padding: 0; background: none; border: 0; }
  /* Лента листается: у правого края — затухание, видно, что дальше есть ещё */
  .strip-in { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); padding-right: 32px; }
  .list-card > .empty { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 12px; }
  /* Шапка в две строки: знак и «Выйти», под ними разделы — три раздела в одну строку не входят. */
  .top-in { gap: 6px 12px; flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 6px; }
  .nav { order: 3; flex: 1 1 100%; gap: 2px; }
  .nav a { padding: 6px 10px; }
  .who .user { display: none; }
  main { padding-top: 16px; }
  .card { padding: 16px; }
  h1 { font-size: 1.2rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dt { margin-top: 10px; font-size: .82rem; }
  dl.kv dt:first-child { margin-top: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions .btn { width: 100%; }
  .filters .actions a.btn { flex: 0 0 auto; }
  .pgrid { grid-template-columns: 1fr; }
  .pgrid .wide2 { grid-column: auto; }
  .prow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .prow .pno { grid-row: auto; grid-column: 1 / -1; text-align: left; }
  .prow .pname, .prow .pnote, .prow .pmeter { grid-column: 1 / -1; }
  .urow { grid-template-columns: 1fr; }
  .pactions .btn { flex: 1 1 100%; }
}
@media (max-width: 420px) {
  .brand .sub { display: none; } /* шапка в одну строку: два раздела и «Выйти» */
}
