@font-face { font-family: "Golos Text"; font-weight: 400; font-display: swap;
  src: url(fonts/golos-text-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: "Golos Text"; font-weight: 400; font-display: swap;
  src: url(fonts/golos-text-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Golos Text"; font-weight: 500; font-display: swap;
  src: url(fonts/golos-text-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: "Golos Text"; font-weight: 500; font-display: swap;
  src: url(fonts/golos-text-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Golos Text"; font-weight: 600; font-display: swap;
  src: url(fonts/golos-text-cyrillic-600-normal.woff2) format("woff2"); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: "Golos Text"; font-weight: 600; font-display: swap;
  src: url(fonts/golos-text-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Golos Text"; font-weight: 700; font-display: swap;
  src: url(fonts/golos-text-cyrillic-700-normal.woff2) format("woff2"); unicode-range: U+0400-04FF, U+2116; }
@font-face { font-family: "Golos Text"; font-weight: 700; font-display: swap;
  src: url(fonts/golos-text-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --bg: #F4F6F5;
  --surface: #FFFFFF;
  --ink: #1D2A31;
  --muted: #5B6B73;
  --line: #D7DEDF;
  --line-soft: #E8EDEC;
  --steel: #1F5F7A;
  --steel-ink: #FFFFFF;
  --steel-soft: #E3EEF2;
  --red: #B3261E;
  --red-soft: #FBE9E7;
  --amber: #9A5B00;
  --amber-soft: #FDF1DC;
  --green: #2E6B47;
  --green-soft: #E3F1E8;
  --grey-soft: #ECEFEF;
  --focus: #1F5F7A;
  --side: #1D2A31;
  --side-ink: #C9D4D8;
  --side-active: #FFFFFF;
  --radius-s: 4px;
  --radius-m: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 15px/1.45 "Golos Text", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--steel); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.2; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; margin: 24px 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 16px 0; }
.brand { padding: 4px 20px 16px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--side-ink); margin-top: 2px; }
.nav { display: flex; flex-direction: column; }
.nav a { color: var(--side-ink); text-decoration: none; padding: 8px 20px; border-left: 3px solid transparent; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav a.active { color: var(--side-active); border-left-color: #7FB3C8; background: rgba(255,255,255,.08); font-weight: 500; }
.nav .group { padding: 16px 20px 4px; font-size: 12px; color: #8FA2AA; }
.side-foot { margin-top: auto; padding: 12px 20px 0; font-size: 13px; border-top: 1px solid rgba(255,255,255,.1); }
.side-foot a { color: var(--side-ink); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); }
.top .uk { display: flex; align-items: center; gap: 8px; }
.top .uk select { min-width: 260px; }
.top .who { margin-left: auto; color: var(--muted); font-size: 14px; }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.lead { color: var(--muted); max-width: 72ch; margin: -8px 0 16px; }

/* ---------- элементы управления ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-s); padding: 6px 12px; cursor: pointer; line-height: 1.3; white-space: nowrap; }
.btn:hover { border-color: #AEBBBE; }
.btn.primary { background: var(--steel); border-color: var(--steel); color: var(--steel-ink); }
.btn.primary:hover { background: #194E64; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.link { border: 0; background: none; padding: 0; color: var(--steel); text-decoration: underline; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=datetime-local], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; padding: 6px 9px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--steel); outline: none; box-shadow: 0 0 0 2px var(--steel-soft); }
label.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
label.field > span { font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { width: 260px; }
.toolbar select { width: auto; }

/* ---------- таблицы ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 500; font-size: 13px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F7FAFA; }
td.num { font-weight: 600; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* полоса срочности у заявок — главный визуальный сигнал */
tr.u-emergency td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.u-high td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
tr.u-normal td:first-child, tr.u-low td:first-child { box-shadow: inset 4px 0 0 transparent; }

.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 13px; white-space: nowrap; background: var(--grey-soft); }
.pill.new { background: var(--steel-soft); color: var(--steel); }
.pill.in_progress { background: var(--amber-soft); color: var(--amber); }
.pill.done { background: var(--green-soft); color: var(--green); }
.pill.rejected { background: var(--grey-soft); color: var(--muted); }
.pill.sent, .pill.ok { background: var(--green-soft); color: var(--green); }
.pill.failed, .pill.bad { background: var(--red-soft); color: var(--red); }
.pill.pending { background: var(--amber-soft); color: var(--amber); }
.pill.skipped { background: var(--grey-soft); color: var(--muted); }
.urg { font-size: 13px; }
.urg.emergency { color: var(--red); font-weight: 600; }
.urg.high { color: var(--amber); font-weight: 500; }

/* ---------- панели, карточка заявки ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 20px; margin-bottom: 16px; }
.drawer-back { position: fixed; inset: 0; background: rgba(29,42,49,.35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 21;
  overflow-y: auto; padding: 20px 24px 40px; border-left: 1px solid var(--line); animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer .close { position: absolute; top: 14px; right: 16px; }
.ticket-no { font-size: 40px; line-height: 1; font-weight: 700; letter-spacing: -0.02em; }
.ticket-no small { font-size: 15px; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-left: 8px; }
.ticket-head { display: flex; align-items: flex-end; gap: 12px; margin: 8px 0 12px; flex-wrap: wrap; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 8px; }
dl.kv dt { color: var(--muted); font-size: 14px; }
dl.kv dd { margin: 0; }
.desc { white-space: pre-wrap; background: var(--bg); border-radius: var(--radius-s); padding: 10px 12px; margin: 4px 0 12px; }
.history { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line-soft); }

.code-box { font-size: 28px; font-weight: 700; letter-spacing: .08em; padding: 8px 14px; background: var(--steel-soft);
  color: var(--steel); border-radius: var(--radius-s); display: inline-block; user-select: all; }

.modal-back { position: fixed; inset: 0; background: rgba(29,42,49,.35); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius-m); width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px 24px; }
.modal h2 { margin-top: 0; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-s); z-index: 40; max-width: 90vw; }
.toast.err { background: var(--red); }
.notice { border-left: 3px solid var(--amber); background: var(--amber-soft); padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius-s); }
.notice.info { border-color: var(--steel); background: var(--steel-soft); }

/* ---------- чаты домов ---------- */
.live { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #AEBBBE; }
.live.on { color: var(--green); }
.live.on::before { background: var(--green); }
.chats { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  display: flex; flex-direction: column; overflow-y: auto; }
.chat-view { display: flex; flex-direction: column; min-width: 0; }
.chat-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; text-align: left; border: 0;
  border-bottom: 1px solid var(--line-soft); background: none; padding: 10px 14px; cursor: pointer; }
.chat-item:last-child { border-bottom: 0; }
.chat-item:hover { background: #F7FAFA; }
.chat-item.active { background: var(--steel-soft); box-shadow: inset 3px 0 0 var(--steel); }
.chat-item .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .s { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.chat-item .badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 600;
  padding: 0 7px; line-height: 20px; align-self: start; }
.chat-view .toolbar input[type=search] { width: 240px; }
.legend { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 10px; height: 10px; border-radius: 2px; background: var(--red-soft); box-shadow: inset 3px 0 0 var(--red); }
.feed-wrap { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  display: flex; flex-direction: column; }
.feed-wrap .older { margin: 10px auto 0; }
.feed { height: 70vh; height: 70dvh; min-height: 320px; overflow-y: auto; padding: 8px 12px 12px; overscroll-behavior: contain; }
.feed .empty { padding: 48px 16px; }
.jump { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); box-shadow: 0 2px 8px rgba(29,42,49,.2); }
.msg { padding: 8px 12px; border-radius: var(--radius-s); margin-top: 4px; border-left: 3px solid transparent; }
.msg:hover { background: #F7FAFA; }
.msg header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.msg .who { font-weight: 600; font-size: 14px; }
.msg .house { color: var(--steel); }
.msg time { color: var(--muted); margin-left: auto; white-space: nowrap; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.msg .quote { font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 8px; margin: 4px 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 12px; border-radius: 999px; padding: 1px 8px; background: var(--grey-soft); color: var(--muted); }
.tag.red { background: #F6CFCB; color: var(--red); font-weight: 500; }
.tag.staff { background: var(--steel-soft); color: var(--steel); }
/* подсветка: жалобы и ключевые слова */
.msg.hl { background: var(--red-soft); border-left-color: var(--red); }
.msg.hl:hover { background: #F8DEDA; }
.msg.hl .text { color: #5E1612; }
.msg.emergency { border-left-width: 6px; }
.msg.removed .text { text-decoration: line-through; color: var(--muted); }
.msg.staff { border-left-color: var(--steel-soft); }
.msg.fresh { animation: arrive 1.2s ease-out; }
@keyframes arrive { from { box-shadow: 0 0 0 2px var(--steel-soft); } to { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .msg.fresh { animation: none; } }
@media (max-width: 860px) {
  .chats { grid-template-columns: minmax(0, 1fr); }
  .chat-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .chat-item { min-width: 180px; border-bottom: 0; border-right: 1px solid var(--line-soft); }
  .chat-view .toolbar input[type=search] { width: 100%; }
  .legend { margin-left: 0; }
}
/* На широком экране раздел чатов занимает ровно высоту окна: прокручиваются только список чатов и лента,
   страница целиком не прокручивается. На телефоне — обычная прокрутка страницы, у ленты своя высота. */
@media (min-width: 861px) {
  .shell.fill { height: 100vh; height: 100dvh; min-height: 0; }
  .shell.fill .side { overflow-y: auto; }
  .shell.fill .main { min-height: 0; overflow: hidden; }
  .content.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-bottom: 16px; }
  .content.fill .chats { flex: 1; min-height: 0; align-items: stretch; grid-template-rows: minmax(0, 1fr); }
  .content.fill .chat-view { min-height: 0; }
  .content.fill .feed-wrap { flex: 1; min-height: 0; }
  .content.fill .feed { flex: 1; height: auto; min-height: 0; }
}

/* ---------- промпты ИИ ---------- */
.prompt-kind, .prompt-full, .modal .prompt-edit { font-variant-ligatures: none; } /* «<<<» не склеивается в кавычку */
.prompt-kind-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.prompt-kind-head h2 { margin: 0; font-size: 18px; }
.prompt-kind-head .btn { margin-left: auto; }
.prompt-model { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.prompt-model code { font-size: 13px; background: var(--bg); padding: 2px 6px; border-radius: var(--radius-s); overflow-wrap: anywhere; }
input.model-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.prompt-list { border: 1px solid var(--line); border-radius: var(--radius-s); }
.prompt-row { display: flex; gap: 16px; align-items: flex-start; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.prompt-row:last-child { border-bottom: 0; }
.prompt-row.active { box-shadow: inset 3px 0 0 var(--green); background: #F7FBF8; }
.prompt-info { flex: 1; min-width: 0; }
.prompt-preview { margin: 4px 0 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.prompt-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.prompt-full { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border-radius: var(--radius-s);
  padding: 10px 12px; font-size: 13px; max-height: 40vh; overflow-y: auto; margin: 4px 0 12px; }
textarea.prompt-edit { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.45; }
.prompt-test { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 12px; margin: 4px 0 12px; }
.prompt-test summary { cursor: pointer; color: var(--steel); }
.prompt-test[open] summary { margin-bottom: 8px; }
.prompt-test-out { margin-top: 10px; }
@media (max-width: 860px) {
  .prompt-row { flex-direction: column; gap: 8px; }
  .prompt-actions { justify-content: flex-start; }
}

/* ---------- фото ---------- */
.thumb { display: block; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--grey-soft);
  cursor: zoom-in; margin: 6px 0 2px; overflow: hidden; max-width: min(320px, 100%); }
.thumb img { display: block; max-width: 100%; max-height: 240px; object-fit: contain; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs .thumb { margin: 0; max-width: 150px; }
.thumbs .thumb img { max-height: 110px; }
.thumb-missing { display: inline-block; margin: 6px 0; }
.photo-full img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto; border-radius: var(--radius-s); }
.ai-note { font-size: 13px; margin-top: 4px; padding: 4px 8px; border-radius: var(--radius-s); background: var(--steel-soft); color: #173F50; }
.msg.hl .ai-note { background: #fff; }

/* ---------- журнал решений ---------- */
.why-btn { font-size: 13px; }
.trace { margin-top: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 10px; }
.trace ol { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.trace li { display: grid; grid-template-columns: 16px 130px minmax(0, 1fr); gap: 6px; padding: 3px 0; border-bottom: 1px solid var(--line-soft); }
.trace li:last-child { border-bottom: 0; }
.trace .mark { color: var(--muted); text-align: center; }
.trace .step { color: var(--muted); }
.trace .why { overflow-wrap: anywhere; }
.trace li.yes .mark { color: var(--green); font-weight: 700; }
.trace li.no .mark { color: var(--red); font-weight: 700; }
.trace li.s-result { font-weight: 500; }
.trace li.s-settings .why { color: var(--muted); }
.trace-actions { margin-top: 8px; display: flex; gap: 8px; }
@media (max-width: 860px) { .trace li { grid-template-columns: 16px minmax(0, 1fr); } .trace .step { grid-column: 2; } .trace .why { grid-column: 2; } }

/* ---------- вкладки мессенджеров ---------- */
.tabs { display: flex; gap: 4px; margin: -4px 0 16px; border-bottom: 1px solid var(--line); }
.tab { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 8px 14px; cursor: pointer;
  font-weight: 500; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--steel); }
.tab .tab-count { font-size: 12px; font-weight: 500; background: var(--grey-soft); color: var(--muted); border-radius: 999px;
  padding: 0 7px; line-height: 20px; }
.tab .badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 600; padding: 0 7px; line-height: 20px; }
.chat-pills { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); }
.login .brand-big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { padding: 8px 0; min-width: 0; }
  .brand { padding-bottom: 8px; }
  .nav { -webkit-overflow-scrolling: touch; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav .group, .side-foot { display: none; }
  .nav a { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; padding: 8px 12px; }
  .nav a.active { border-bottom-color: #7FB3C8; }
  .content, .top { padding-left: 16px; padding-right: 16px; }
  .top { flex-wrap: wrap; }
  .top .uk select { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type=search] { width: 100%; }
}
