:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1c2733;
  --muted: #6b7785;
  --line: #e2e7ee;
  --brand: #0f3d5e;
  --accent: #c8102e;
  --primary: #1f6feb;
  --primary-dark: #1958c0;
  --ok: #1a7f37;
  --warn: #9a6700;
  --err: #cf222e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: .5rem 0; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn-text { color: var(--warn); }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  background: var(--brand); color: #fff; padding: .55rem 1.25rem;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 650; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a { color: rgba(255,255,255,.82); padding: .35rem .7rem; border-radius: 6px; }
.mainnav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.mainnav a.active { background: rgba(255,255,255,.16); color: #fff; }
.logout button { color: rgba(255,255,255,.8); }
.bottomnav { display: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }

/* --- элементы --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-head, .page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-head h1 { margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid > * { min-width: 0; }
.grid.stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; color: var(--text); margin: 0; }
.stat:hover { text-decoration: none; border-color: #c5d2e0; }
.stat b { font-size: 1.6rem; color: var(--brand); }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.attention b { color: var(--err); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: .5rem .9rem; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f0f3f7; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--err); border-color: #f0c4c8; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link.danger { color: var(--err); }

input, textarea, select {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid #cdd5df; border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid #b6d0fb; border-color: var(--primary); }
label { display: block; font-size: .9rem; color: #3b4652; }
label input, label textarea, label select { margin-top: .3rem; }
label.check { display: flex; align-items: center; gap: .5rem; }
label.check input { width: auto; margin: 0; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack.narrow { max-width: 460px; }
.row { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; }
.row input { flex: 1; }

.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #dafbe1; border-color: #aceebb; color: #116329; }
.flash.error { background: #ffebe9; border-color: #ffcecb; color: #a40e26; }
.flash.warn { background: #fff8c5; border-color: #f2e08a; color: #6c4b00; }
.flash.info { background: #ddf4ff; border-color: #b6e3ff; color: #0a3069; }

.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge.s-ready { background: #dafbe1; color: #116329; }
.badge.s-pending, .badge.s-processing { background: #ddf4ff; color: #0a3069; }
.badge.s-error, .badge.s-needs_ocr { background: #ffebe9; color: #a40e26; }
.badge.s-stored { background: #fff8c5; color: #6c4b00; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kind { display: inline-block; font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-right: .45rem; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table.small { font-size: .85rem; }
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; max-width: 460px; }

/* --- главная --- */
.ask-hero { background: linear-gradient(135deg, #0f3d5e, #1b5b86); color: #fff; border-radius: var(--radius); padding: 1.4rem 1.4rem 1.5rem; margin-bottom: 1rem; }
.ask-hero h1 { color: #fff; font-size: 1.35rem; margin: 0 0 .8rem; }
.ask-row { display: flex; gap: .5rem; }
.ask-row input { border: 0; }
.roadmap ul { margin: 0; padding-left: 1.2rem; }
.roadmap li { margin: .25rem 0; }
.checks li::marker { content: "✓  "; color: var(--ok); }
.todo li::marker { content: "○  "; color: var(--muted); }
.todo { color: var(--muted); }

/* --- документ --- */
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.rename { margin-top: .75rem; }
.preview { max-width: 100%; max-height: 480px; border-radius: 8px; border: 1px solid var(--line); }
.chunk { border-top: 1px solid var(--line); padding: .6rem 0; }
.chunk:target { background: #fff8c5; }
.chunk-loc { font-size: .78rem; color: var(--muted); margin-bottom: .2rem; }
.chunk-text { white-space: pre-wrap; word-break: break-word; }

/* --- входящие --- */
.upload { display: flex; flex-direction: column; gap: .8rem; }
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; gap: .25rem; border: 2px dashed #b9c6d4; border-radius: var(--radius); padding: 1.5rem 1rem; text-align: center; cursor: pointer; background: #fafcfe; color: var(--text); font-size: 1rem; }
.dropzone.over { border-color: var(--primary); background: #eef5ff; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dz-big { font-size: 2rem; color: var(--primary); line-height: 1; }
.camera-row { margin: 0; }
.picked { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.picked li { display: flex; justify-content: space-between; padding: .25rem 0; border-bottom: 1px dashed var(--line); }
.progress { height: 6px; background: #e6ebf1; border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.help ol { padding-left: 1.2rem; }
.help summary, .rename summary, .sources summary { cursor: pointer; color: var(--primary); }

/* --- поиск --- */
.search-row { max-width: 720px; }
.hit .snippet { margin-top: .35rem; color: #3b4652; white-space: pre-wrap; font-size: .92rem; }

/* --- чат --- */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; height: calc(100vh - 48px); max-width: 1300px; margin: 0 auto; }
.chat-layout > * { min-width: 0; }
.chat-side { border-right: 1px solid var(--line); padding: 1rem; overflow-y: auto; background: #fbfcfd; }
.conv-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.conv-list li a { display: block; padding: .4rem .55rem; border-radius: 6px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.conv-list li a:hover { background: #eef1f5; text-decoration: none; }
.conv-list li.active a { background: #e3ecf7; }
.chat-main { display: flex; flex-direction: column; min-height: 0; padding: 1rem 1.25rem .5rem; }
.chat-main > .flash { margin-bottom: .5rem; padding: .45rem .7rem; font-size: .88rem; }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-head h1 { font-size: 1.15rem; margin: 0 0 .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; padding: .5rem 0; display: flex; flex-direction: column; gap: .9rem; }
.msg { max-width: 860px; }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--primary); color: #fff; border-radius: 14px 14px 4px 14px; padding: .6rem .9rem; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: .75rem 1rem; box-shadow: var(--shadow); word-break: break-word; }
.bubble p { margin: .4rem 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .4rem 0; padding-left: 1.3rem; }
.bubble h3, .bubble h4 { margin: .7rem 0 .3rem; font-size: 1rem; }
.cite { font-size: .75em; vertical-align: super; background: #e3ecf7; color: var(--primary-dark); border-radius: 4px; padding: 0 4px; margin: 0 1px; }
.cite:hover { text-decoration: none; background: #cfe0f5; }
.ai-note { background: #fff8e6; border-left: 3px solid #e3b341; padding: 0 .5rem; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.sources { margin-top: .4rem; font-size: .88rem; }
.sources ol { padding-left: 1.4rem; margin: .4rem 0; }
.sources li { margin-bottom: .45rem; }
.sources .snippet { color: var(--muted); font-size: .82rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-error { color: var(--err); }
.msg-meta { color: var(--muted); font-size: .75rem; margin-top: .25rem; }
.composer { display: flex; gap: .5rem; align-items: flex-end; padding-top: .5rem; border-top: 1px solid var(--line); }
.composer textarea { resize: none; max-height: 200px; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { color: var(--muted); font-size: .78rem; margin: .35rem 0 0; }
.empty-chat { margin: auto; text-align: center; max-width: 560px; color: var(--muted); }
.suggestions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.suggestions button { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.suggestions button:hover { border-color: var(--primary); }

/* --- вход --- */
body.auth { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: linear-gradient(160deg, #0f3d5e, #1b5b86 60%, #2a7ab0); }
body.auth main { width: 100%; padding: 1rem; }
.auth-card { max-width: 380px; margin: 0 auto; background: #fff; border-radius: 14px; padding: 2rem 1.75rem; box-shadow: 0 10px 40px rgba(0,0,0,.25); text-align: center; }
.auth-card h1 { margin: .5rem 0 0; }
.auth-card form { text-align: left; margin-top: 1.25rem; }

/* --- телефон --- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .mainnav, .logout { display: none; }
  .topbar { padding: .5rem 1rem; }
  .container { padding: 1rem 1rem 5.5rem; }
  .grid.two { grid-template-columns: 1fr; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .card { padding: .85rem .9rem; }
  .ask-row { flex-direction: column; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: #fff; border-top: 1px solid var(--line);
    padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
  }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: .7rem; color: var(--muted); padding: .2rem 0; }
  .bottomnav a:hover { text-decoration: none; }
  .bottomnav a.active { color: var(--primary); }
  .bottomnav .ico { font-size: 1.25rem; line-height: 1.2; }
  .bottomnav a.add .ico { background: var(--primary); color: #fff; border-radius: 50%; width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center; }
  .chat-layout { grid-template-columns: 1fr; height: calc(100dvh - 44px - 62px); }
  .chat-side { display: none; }
  .chat-main { padding: .6rem .75rem .25rem; }
  .msg { max-width: 100%; }
  .hint { display: none; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
}

/* --- раздел «Сайт» --- */
.site-collect { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.site-collect h2 { margin-top: 0; }
.tabs-line { display: flex; gap: .4rem; align-items: center; border-bottom: 2px solid var(--line); margin: 1rem 0; flex-wrap: wrap; }
.tabs-line a { padding: .45rem .9rem; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs-line a.on { background: var(--surface); border: 1px solid var(--line); border-bottom-color: var(--surface); margin-bottom: -2px; color: var(--text); font-weight: 600; }
.tabs-line-right { margin-left: auto; }
.news-card h2 { margin: .2rem 0 .3rem; font-size: 1.1rem; }
.news-head { display: flex; gap: 1rem; align-items: flex-start; }
.news-photo { width: 200px; height: 130px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.news-photo.off { opacity: .35; }
.news-photo.big { width: 100%; max-width: 520px; height: auto; }
.lang-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; margin: .8rem 0; }
.lang-col { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; font-size: .92rem; min-width: 0; }
.lang-col p { margin: .35rem 0; }
.lang-tag { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .2rem; }
.note-ai { background: #fff8c5; padding: .4rem .5rem; border-radius: 6px; }
.grid.three-cols { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) {
  .site-collect, .news-head { flex-direction: column; }
  .news-photo { width: 100%; height: auto; }
  .lang-cols, .grid.three-cols { grid-template-columns: 1fr; }
}
.mt { margin-top: .6rem; }
.score { display: inline-block; font-weight: 700; padding: 0 6px; border-radius: 4px; margin-right: 4px; }
.score.ok { background: #dafbe1; color: #116329; }
.score.low { background: #ffebe9; color: #a40e26; }
.photo-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; max-height: 340px; overflow-y: auto; }
.photo-opt { display: flex; flex-direction: column; gap: 2px; border: 2px solid var(--line); border-radius: 8px; padding: 4px; cursor: pointer; font-size: .72rem; color: var(--muted); }
.photo-opt input { position: absolute; opacity: 0; }
.photo-opt img { width: 100%; height: 72px; object-fit: cover; border-radius: 4px; }
.photo-opt span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-opt:has(input:checked) { border-color: var(--primary); color: var(--text); }
.photo-none { display: flex; align-items: center; justify-content: center; height: 72px; }
/* --- CRM --- */
.grid.stats.crm-stats { grid-template-columns: repeat(3, 1fr); }
.crm-suggestions, .crm-mentions { list-style: none; margin: 0 0 .8rem; padding: 0; }
.crm-suggestions li, .crm-mentions li { padding: .55rem 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: .25rem; }
.crm-suggestions li:last-child, .crm-mentions li:last-child { border-bottom: 0; }
.list li > span:first-child { min-width: 0; }
.crm-doc-items { display: flex; flex-wrap: wrap; gap: .35rem .8rem; margin: .3rem 0 .6rem; }
.check.inline { display: inline-flex; margin: .2rem .7rem .2rem 0; }
