:root {
  color-scheme: light dark;
  --bg: #f6f7f5; --panel: #fff; --side: #eef2ec; --line: #e2e6e1; --ink: #1f2a24; --ink-2: #4c5a52; --ink-3: #7a877f;
  --brand: #2f6b4f; --brand-2: #dcefe3; --code: #f0f2ef; --err-bg: #fff3f0; --err-line: #f0c9c0; --err: #8a2f1f;
  --chip: #fff; --chip-line: #cfd6cf; --strip: rgba(246,247,245,.7);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --panel: #1a201c; --side: #161b18; --line: #2a322d; --ink: #e6ebe7; --ink-2: #b7c1ba; --ink-3: #7f8a83;
    --brand: #6cc59a; --brand-2: #1f3a2c; --code: #232b26; --err-bg: #2b1c18; --err-line: #5a2e26; --err: #f0a89a;
    --chip: #1a201c; --chip-line: #3a443d; --strip: rgba(18,22,20,.7);
  }
}
html, body { margin: 0; height: 100%; background: var(--bg); font-family: -apple-system, "Segoe UI", Inter, Roboto, sans-serif; color: var(--ink); }
.app { display: flex; height: 100vh; height: 100dvh; }
.side { width: 260px; flex: 0 0 260px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px; }
.btn-new { border: 1px solid var(--brand); background: var(--panel); color: var(--brand); border-radius: 10px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.chats { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1 1 auto; min-height: 80px; }
/* панель гостя (08.09): карточки под историей — погода, темы, дневник, приглашение */
.panel { padding: 0 8px; overflow-y: auto; flex: 0 1 auto; max-height: 55%; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 6px 0; background: var(--panel); font-size: 12px; line-height: 1.45; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 4px; font-size: 13px; }
details.card > summary { list-style: none; cursor: pointer; margin-bottom: 0; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary b::before { content: "▸ "; color: var(--ink-3); }
details.card[open] > summary b::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: 4px; }
#p-register-btn { display: block; margin-top: 6px; }
.reg { margin-top: 6px; }
.reg-tabs { margin-bottom: 4px; }
.reg .muted { font-size: 11px; margin-top: 2px; }
.card-b { color: var(--ink-2); }
.card .muted { color: var(--ink-3); }
.mini { border: 0; background: none; color: var(--brand); font: inherit; font-size: 11px; cursor: pointer; padding: 0; }
.chip-s { display: inline-block; border: 1px solid var(--chip-line); background: var(--chip); color: var(--ink-2); border-radius: 999px; padding: 2px 9px; margin: 2px 4px 2px 0; font: inherit; font-size: 12px; cursor: pointer; }
.chip-s.on { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.j-o { margin: 4px 0 2px; font-weight: 600; color: var(--ink); }
.j-e { display: flex; gap: 6px; align-items: baseline; margin: 2px 0; }
.j-e span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.j-e small { color: var(--ink-3); font-size: 11px; }
.j-e button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 13px; padding: 0; }
.j-e button:hover { color: #b03a2e; }
.p-in { display: flex; gap: 6px; margin: 4px 0; }
.p-in input { flex: 1; min-width: 0; border: 1px solid var(--chip-line); border-radius: 8px; padding: 4px 8px; font: inherit; font-size: 12px; background: var(--panel); color: var(--ink); }
.p-in button { width: auto; height: auto; border: 1px solid var(--brand); background: var(--panel); color: var(--brand); border-radius: 8px; padding: 4px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.jform { display: flex; gap: 6px; margin: 2px 0 8px; max-width: 460px; }
.jform input, .jform select { flex: 1; min-width: 0; border: 1px solid var(--chip-line); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; background: var(--panel); color: var(--ink); }
.jform button { width: auto; height: auto; border: 1px solid var(--brand); background: var(--panel); color: var(--brand); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; cursor: pointer; }
.jform button.x { border-color: var(--chip-line); color: var(--ink-3); }
#p-invite-n { display: block; margin-top: 4px; word-break: break-all; }
#p-weather-body div { margin-top: 2px; }
.chats li { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.chats li:hover { background: var(--line); }
.chats li.active { background: var(--panel); border: 1px solid var(--line); }
.chats li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats li small { color: var(--ink-3); font-size: 11px; }
.chats li button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 14px; }
.chats li button:hover { color: #b03a2e; }
.side-note { padding: 10px 12px; font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.side-note .btn-link { display: block; margin: 6px 0 2px; border: 1px solid var(--chip-line); background: var(--chip); color: var(--ink-2); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.side-note .btn-link:hover { border-color: var(--brand); color: var(--brand); }
.actions button.on { color: var(--brand); font-weight: 600; }
.wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
header { padding: 12px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
header a { color: var(--brand); text-decoration: none; font-size: 14px; }
header a.tg { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
header .logout { display: inline-flex; align-items: center; padding: 4px; border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: 6px; }
header .logout:hover { color: var(--brand); background: var(--brand-2); }
header b { font-size: 17px; display: flex; align-items: center; gap: 8px; }
/* логотип с названием — ссылка на сайт (владелец 08.09: текст-ссылку убрать, логотип кликабельный) */
header a.brand { font-size: 17px; font-weight: 700; color: inherit; display: flex; align-items: center; gap: 8px; }
header a.brand:hover { opacity: .85; }
header img { width: 26px; height: 26px; border-radius: 7px; }
header .hello { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.toggle { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; padding: 0 4px; color: var(--ink); }
.stage { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
main { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--ink-3); font-size: 14px; text-align: center; margin: auto; max-width: 520px; line-height: 1.5; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; font-size: 15px; white-space: pre-wrap; word-wrap: break-word; animation: pop .18s ease-out; }
.msg.user { align-self: flex-end; background: var(--brand-2); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; max-width: 92%; }
.msg.bot b { font-weight: 600; }
.msg.bot code { background: var(--code); padding: 0 4px; border-radius: 4px; }
.msg.bot a { color: var(--brand); word-break: break-all; }
.msg.err { align-self: flex-start; background: var(--err-bg); border: 1px solid var(--err-line); color: var(--err); }
.msg.err button { margin-left: 8px; border: 1px solid var(--err-line); background: transparent; color: inherit; border-radius: 8px; padding: 2px 8px; font: inherit; font-size: 13px; cursor: pointer; }
/* схема как карточки: подразделы сворачиваются */
.msg.bot details.sec { margin: 6px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); white-space: pre-wrap; }
.msg.bot details.sec summary { cursor: pointer; padding: 8px 12px; font-weight: 600; list-style: none; }
.msg.bot details.sec summary::before { content: "▸ "; color: var(--ink-3); }
.msg.bot details.sec[open] summary::before { content: "▾ "; }
.msg.bot details.sec .sec-body { padding: 0 12px 10px; }
.msg.bot table { border-collapse: collapse; margin: 6px 0; font-size: 14px; white-space: normal; display: block; overflow-x: auto; }
.msg.bot th, .msg.bot td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.msg.bot th { background: var(--code); }
.actions { display: flex; gap: 10px; margin: -4px 0 4px 6px; font-size: 12px; align-self: flex-start; }
.actions.user { display: flex; justify-content: flex-end; align-self: flex-end; margin-top: -4px; }
.actions.user button { font-size: 17px; line-height: 1; padding: 2px 8px; display: inline-flex; align-items: center; }
.actions.user button .sq { display: inline-block; width: 11px; height: 11px; border: 2px solid var(--ink-3); border-radius: 2px; box-sizing: border-box; }
.actions.user button.stop:hover .sq { border-color: var(--brand); }
.actions button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font: inherit; font-size: 12px; padding: 2px 4px; }
.actions button:hover { color: var(--brand); }
.actions button.copy { display: inline-flex; align-items: center; padding: 2px 4px; }
.actions button.copy.done { color: var(--brand); }
.actions.user button.copy { font-size: 12px; padding: 2px 6px; }
form.lead { align-self: flex-start; width: min(420px, 92%); background: var(--panel); border: 1px solid var(--brand); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; align-items: stretch; gap: 8px; animation: pop .18s ease-out; }
.lead input, .lead select { width: 100%; box-sizing: border-box; }
.lead-title { font-weight: 600; font-size: 14px; }
.lead input, .lead select { border: 1px solid var(--chip-line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; background: var(--panel); color: var(--ink); }
.lead-consent { font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: flex-start; line-height: 1.4; }
.lead-consent input { width: auto; flex: none; margin: 2px 0 0; }
.lead-row { display: flex; gap: 8px; align-items: center; }
.lead-row button { width: auto; height: auto; border: 0; border-radius: 10px; padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer; background: var(--brand); color: #fff; }
.lead-row button.lead-skip { background: transparent; color: var(--ink-3); }
.lead-note { font-size: 12px; color: var(--ink-3); min-height: 1em; }
.typing { align-self: flex-start; color: var(--ink-3); font-size: 14px; padding: 6px 14px; }
.typing .typing-more { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.typing .typing-line { display: flex; align-items: center; gap: 8px; }
@keyframes fade-deep { 0%, 100% { opacity: 1; } 50% { opacity: .08; } }
.typing .typing-logo { width: 22px; height: 22px; border-radius: 6px; animation: fade-deep 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .typing .typing-logo { animation: none; } }
.chips { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 16px; pointer-events: none; background: var(--strip); }
.chips:empty { display: none; }
/* полоса подсказок лежит поверх низа переписки; подложка полосы — фон на 70% (владелец 08.09), кнопки сплошные */
.chip { pointer-events: auto; border: 1px solid var(--chip-line); background: var(--chip); color: var(--ink-2); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; animation: pop .18s ease-out; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
form { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
textarea { flex: 1; resize: none; border: 1px solid var(--chip-line); border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; outline: none; max-height: 160px; background: var(--panel); color: var(--ink); }
textarea:focus { border-color: var(--brand); }
form button { width: 48px; height: 46px; border: 0; border-radius: 12px; background: var(--brand); color: #fff; font-size: 20px; cursor: pointer; }
form button:disabled { background: #b9c7be; cursor: default; }
form button.mic { background: var(--code); color: var(--ink); font-size: 18px; }
form button.mic.on { background: #e05a4f; color: #fff; animation: pulse 1s infinite; }
.note { padding: 6px 16px 10px; font-size: 11px; color: var(--ink-3); text-align: center; background: var(--panel); }
.note a { color: inherit; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .msg, .chip { animation: none; } }
@media (max-width: 760px) {
  .side { position: fixed; inset: 0 30% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .toggle { display: block; }
  .msg { max-width: 92%; }
}
@media print {
  .side, header, form, .note, .chips, .actions, .typing { display: none !important; }
  .app, .wrap, main { display: block; height: auto; overflow: visible; }
  body.print-one .msg:not(.printing) { display: none; }
  .msg { max-width: 100%; border: 0; box-shadow: none; }
  .msg.bot details.sec { break-inside: avoid; }
  .msg.bot details.sec:not([open]) .sec-body { display: block; }
}

/* дневник — кабинет фермера поверх чата (08.09) */
[hidden] { display: none !important; }
.diary { position: absolute; inset: 0; overflow: auto; padding: 16px 20px 24px; background: var(--bg); z-index: 6; }
.diary-head { display: flex; align-items: center; justify-content: space-between; font-size: 17px; margin-bottom: 10px; }
.diary-body { font-size: 14px; line-height: 1.45; }
.diary-body table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.diary-body td, .diary-body th { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; font-size: 13px; vertical-align: top; }
.diary-body th { color: var(--ink-3); font-weight: 500; }
.diary-body input, .diary-body select { border: 1px solid var(--chip-line); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; background: var(--panel); color: var(--ink); min-width: 0; }
.diary-body .row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; align-items: center; }
.diary-body .row input { flex: 1 1 120px; }
.diary-body button.act { border: 1px solid var(--brand); background: var(--panel); color: var(--brand); border-radius: 8px; padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.diary-body button.x { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 14px; }
.diary-body button.x:hover { color: #b03a2e; }
.diary-body .muted { color: var(--ink-3); font-size: 12px; }
.diary-body .rep { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
@media (max-width: 760px) { .diary { padding: 12px; } }

/* совместный чат (08.09): панель комнаты над перепиской, подписи авторов, приглашение с QR */
.roombar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; margin: -6px 0 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 13px; }
.roombar b { font-size: 14px; }
.roombar .muted { color: var(--ink-3); }
.roombar .mini { margin-left: 4px; }
.invite { width: 100%; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 12px; }
.invite code { user-select: all; word-break: break-all; }
.invite svg { display: block; margin: 6px 0; max-width: 160px; height: auto; }
.author { font-size: 11px; color: var(--ink-3); margin: 6px 0 -6px; align-self: flex-end; }
.msg.user.other { background: var(--code); }

/* карточки под замком для незарегистрированных (08.09) и уведомление */
.card.locked { cursor: pointer; opacity: .8; }
.card.locked:hover { border-color: var(--brand); opacity: 1; }
.card.locked .mini, .card.locked .chip-s { display: none; }
.card.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--brand); } 100% { box-shadow: 0 0 0 0 transparent; } }
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(8px); background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90%; text-align: center; }
#toast.on { opacity: .95; transform: translateX(-50%); }

/* кнопки разделов дневника в левой панели (владелец 09.09) */
.j-nav button { display: block; width: 100%; text-align: left; border: 1px solid var(--chip-line); background: var(--chip); color: var(--ink-2); border-radius: 8px; padding: 5px 9px; margin: 4px 0; font: inherit; font-size: 12px; cursor: pointer; }
.j-nav button.on { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.j-nav .mini { margin-top: 4px; }
/* открыт раздел дневника: поле ввода и подпись под ним скрыты, страница отдана разделу */
body.diary-open #form, body.diary-open .note { display: none; }
/* обращения к представителю (10.09) */
.tickets { margin-top: 16px; max-width: 640px; }
.tform { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 12px; }
.tform input, .tform textarea { border: 1px solid var(--chip-line); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; background: var(--panel); color: var(--ink); resize: vertical; }
.tform button.act { align-self: flex-start; }
.tlist { margin-top: 8px; }
.ticket { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 6px 0; cursor: pointer; background: var(--panel); }
.ticket.unread { border-color: var(--brand); }
.t-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.t-subj { font-weight: 600; }
.t-st { font-size: 12px; color: var(--ink-3); } .t-st.answered { color: var(--brand); }
.t-msg { border-radius: 10px; padding: 8px 10px; margin: 6px 0; max-width: 90%; white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line); }
.t-msg.guest { margin-left: auto; background: var(--brand-2); border-color: transparent; }
.t-who { font-size: 11px; color: var(--ink-3); margin-bottom: 3px; }
.t-img { display: block; max-width: 240px; max-height: 240px; border-radius: 8px; margin-top: 6px; }
.j-nav .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
/* карта полей (11.09) */
.map-wrap { margin-top: 10px; }
.map { height: 460px; border-radius: 12px; border: 1px solid var(--line); background: #223; }
.map-hint { margin: 4px 0 6px; }
.map-panel { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.field-label { background: rgba(0,0,0,.45); color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.map .ol-attribution { font-size: 10px; }
.ndvi-series .bars { display: flex; align-items: flex-end; gap: 3px; height: 100px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.ndvi-series .bar { width: 14px; background: var(--brand); border-radius: 3px 3px 0 0; opacity: .85; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photos .photo { width: 140px; font-size: 11px; position: relative; }
.photos .photo img { width: 140px; height: 105px; object-fit: cover; border-radius: 8px; display: block; background: var(--code); }
.photos .photo button.x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.5); color: #fff; border: 0; border-radius: 6px; }
@media (max-width: 760px) { .map { height: 62vh; } }
.jform input.bad, .row input.bad { border-color: var(--err); background: var(--err-bg); }
.crop-pick { display: inline-flex; gap: 4px; }
.field-history { margin-top: 8px; }
.timeline { margin: 4px 0 0 18px; padding: 0; font-size: 13px; line-height: 1.5; }
