/* Помощник и лента (agent.js). Телефон: строка над панелью разделов, лента — шторка снизу.
 * Компьютер: лента — панель справа, делит экран со страницей; без неё строка висит внизу по центру. */
:root { --ag-w: 380px; --ag-bar-h: 56px; --ag-bg: var(--plane, var(--surface)); --ag-card: var(--surface);
  --staff-soft: #EFE9FD; --staff-ink: #5B3BB5; --doc-soft: #E3F4F6; --doc-ink: #136B78; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) { --staff-soft: #2B2342; --staff-ink: #C7B5FF; --doc-soft: #17333A; --doc-ink: #8FD6E0; } }
:root[data-theme="dark"] { --staff-soft: #2B2342; --staff-ink: #C7B5FF; --doc-soft: #17333A; --doc-ink: #8FD6E0; }

.ag-bar {
  position: fixed; z-index: 60; left: 10px; right: 10px; bottom: calc(66px + var(--safe-bottom, 0px));
  display: flex; align-items: flex-end; gap: 6px; padding: 5px; margin: 0 auto; max-width: 720px;
  background: var(--glass, var(--surface)); backdrop-filter: blur(22px) saturate(1.7); -webkit-backdrop-filter: blur(22px) saturate(1.7);
  border: 1px solid var(--line-soft, var(--line)); border-radius: 24px; box-shadow: var(--shadow-1);
  transition: transform 240ms var(--ease, ease), opacity 240ms var(--ease, ease);
}
html.ag-on .view { padding-bottom: calc(var(--ag-bar-h) + 12px); }
/* На экране заявки внизу «Подать заявку»: строка уступает место. */
html.ag-order-view:not(.ag-sheet-open) body > .ag-bar { opacity: 0; transform: translateY(16px); pointer-events: none; }
html.ag-order-view .view#view-order { padding-bottom: 0; }

.ag-plus, .ag-send, .ag-mic {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; font: inherit;
  transition: background-color 150ms var(--ease, ease), color 150ms var(--ease, ease), transform 120ms var(--ease, ease);
}
.ag-plus { background: var(--accent); color: var(--on-accent, #fff); }
.ag-send { background: transparent; color: var(--ink-3); }
.ag-bar.typing .ag-send { background: var(--accent); color: var(--on-accent, #fff); }
.ag-plus:active, .ag-send:active, .ag-mic:active { transform: scale(.94); }

/* Микрофон и «отправить» — в одном месте: пустая строка — микрофон, есть текст — стрелка (смена значков 150 мс). */
.ag-act { position: relative; width: 38px; height: 38px; flex: none; }
.ag-act > button { position: absolute; inset: 0; transition: opacity 150ms var(--ease-out, ease), transform 150ms var(--ease-out, ease), background-color 150ms var(--ease, ease), color 150ms var(--ease, ease); }
.ag-mic { background: transparent; color: var(--ink-2); opacity: 0; transform: scale(.8); pointer-events: none; }
.ag-bar.voice:not(.typing) .ag-mic, .ag-bar.recording .ag-mic, .ag-bar.hearing .ag-mic { opacity: 1; transform: none; pointer-events: auto; }
.ag-bar.voice:not(.typing) .ag-send, .ag-bar.recording .ag-send, .ag-bar.hearing .ag-send { opacity: 0; transform: scale(.8); pointer-events: none; }
.ag-bar.recording .ag-mic { background: var(--critical, #D03B3B); color: #fff; }
.ag-bar.hearing .ag-mic { pointer-events: none; opacity: .5; }
.ag-bar.recording .ag-plus, .ag-bar.hearing .ag-plus { background: var(--surface-2); color: var(--ink-2); }

/* Запись: вместо поля — красная точка и время; поле прячется, но не теряет набранный текст. */
.ag-rec { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 4px; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.ag-rec[hidden] { display: none; }
.ag-bar.recording .ag-input, .ag-bar.hearing .ag-input { display: none; }
.ag-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--critical, #D03B3B); animation: ag-rec 1.2s ease-in-out infinite; }
.ag-bar.hearing .ag-dot { background: var(--ink-3); }
@keyframes ag-rec { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .ag-dot { animation: none; } .ag-act > button { transition: opacity 150ms ease; } }
.ag-input {
  flex: 1; min-width: 0; min-height: 38px; max-height: 120px; resize: none; border: 0; outline: 0; background: transparent;
  color: var(--ink); font: inherit; font-size: 16px; line-height: 22px; padding: 8px 4px;
}
.ag-input::placeholder { color: var(--ink-3); }
.ag-plus:focus-visible, .ag-send:focus-visible, .ag-ib:focus-visible, .ag-ev:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ——— лента ——— */
.ag-pane {
  position: fixed; z-index: 89; left: 0; right: 0; bottom: 0; top: calc(56px + var(--safe-top, 0px));
  display: flex; flex-direction: column; background: var(--plane, var(--surface));
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow-2);
  transform: translateY(102%); transition: transform 280ms var(--ease-drawer, cubic-bezier(.32, .72, 0, 1));
}
.ag-pane.open { transform: none; }
.ag-pane[hidden] { display: none; }
html.ag-sheet-open body { overflow: hidden; }
html.ag-on::after {
  content: ''; position: fixed; inset: 0; z-index: 88; background: rgb(11 11 11 / .28);
  opacity: 0; pointer-events: none; transition: opacity 280ms var(--ease-drawer, cubic-bezier(.32, .72, 0, 1));
}
html.ag-sheet-open::after { opacity: 1; pointer-events: auto; }
.ag-grip { display: none; }
.ag-pane.dragging { transition: none; user-select: none; }
.ag-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; flex: none; }
.ag-head { display: flex; align-items: center; gap: 8px; padding: 6px 12px 8px; flex: none; }
.ag-head b { font-size: 16px; }
.ag-seg { margin-left: auto; display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.ag-seg button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 12.5px; padding: 4px 9px; border-radius: 8px; cursor: pointer; }
.ag-seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.ag-ib { width: 34px; height: 34px; flex: none; border: 0; border-radius: 10px; display: inline-grid; place-items: center; background: transparent; color: var(--ink-2); cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .ag-ib:hover, .ag-seg button:not(.on):hover { background: var(--surface-2); } }
.ag-feed { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.ag-foot { flex: none; padding: 6px 8px calc(8px + var(--safe-bottom, 0px)); }
.ag-foot .ag-bar { position: static; margin: 0; max-width: none; box-shadow: none; }
.ag-empty, .ag-more { color: var(--ink-3); font-size: 13.5px; text-align: center; margin: 24px 12px; }
.ag-more { margin: 4px 0 8px; font-size: 12px; }
.ag-day { text-align: center; font-size: 11.5px; color: var(--ink-3); margin: 10px 0 4px; }

/* Лента v2 (вариант C, 06.11.2026): события на линии времени. Значок — точка на линии, у каждого вида свой
 * цвет (заявка — синий, после срока — оранжевый, от диспетчера — фиолетовый, ждёт решения — жёлтый,
 * согласовано — зелёный, отклонено и отмена — красный, документы — бирюзовый). */
.ag-tl { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; padding: 5px 0; }
.ag-tl::before { content: ''; position: absolute; left: 13.5px; top: 0; bottom: 0; width: 1px; background: var(--line); }
.ag-day + .ag-tl::before, .ag-more + .ag-tl::before, .ag-tl:first-child::before { top: 16px; }
.ag-tl:has(+ :not(.ag-tl))::before, .ag-tl:last-child::before { bottom: calc(100% - 20px); }
.ag-tl > .ic { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2); box-shadow: 0 0 0 4px var(--ag-bg); margin-top: 1px; }
.ag-tl > .ic.order { background: var(--accent-soft); color: var(--accent-ink); }
.ag-tl > .ic.late { background: var(--serious-soft); color: var(--serious-ink); }
.ag-tl > .ic.staff { background: var(--staff-soft); color: var(--staff-ink); }
.ag-tl > .ic.g { background: var(--good-soft); color: var(--good-ink); }
.ag-tl > .ic.w { background: var(--warning-soft); color: var(--warning-ink); }
.ag-tl > .ic.r { background: var(--critical-soft); color: var(--critical-ink); }
.ag-tl > .ic.doc { background: var(--doc-soft); color: var(--doc-ink); }
.ag-tb { min-width: 0; padding-top: 4px; }
.ag-ev { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: baseline; font-size: 13.5px; line-height: 18px; color: var(--ink); border-radius: 8px; }
.ag-ev[role="button"] { cursor: pointer; }
.ag-ev .x { min-width: 0; }
.ag-ev .x b, .ag-th b { font-weight: 600; }
.ag-co { cursor: pointer; text-decoration: underline transparent; text-underline-offset: 3px; transition: text-decoration-color 150ms var(--ease, ease); }
@media (hover: hover) and (pointer: fine) { .ag-co:hover { text-decoration-color: currentColor; } }
.ag-ev .tm, .ag-th .tm { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ag-sub { font-size: 12px; line-height: 17px; color: var(--ink-2); margin-top: 2px; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; gap: 0 10px; }
.ag-up { color: var(--good-ink); font-weight: 500; }
.ag-down { color: var(--critical-ink); font-weight: 500; }
.ag-same { color: var(--ink-3); }
.ag-diff s { color: var(--ink-3); text-decoration-thickness: 1px; }
.ag-diff b { font-weight: 600; }
.ag-tag { display: inline-flex; align-items: center; gap: 3px; height: 19px; padding: 0 7px; margin-left: 6px; border-radius: 10px; font-size: 11.5px; font-weight: 500; white-space: nowrap; vertical-align: 1px; }
.ag-tag.late { background: var(--serious-soft); color: var(--serious-ink); }
.ag-tag.warn { background: var(--warning-soft); color: var(--warning-ink); margin-left: 0; }

/* «Открыть заявку» — в строке заголовка, только у раскрытого события; у свёрнутого места не занимает. */
.ag-go { width: 0; height: 22px; opacity: 0; visibility: hidden; overflow: hidden; margin-left: -8px; align-self: center;
  transition: opacity 150ms var(--ease-out, ease), visibility 0s linear 150ms; }
.ag-evw.open .ag-go { width: 26px; margin-left: 0; opacity: 1; visibility: visible; transition: opacity 150ms var(--ease-out, ease); }
.ag-det { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows 200ms var(--ease-out, ease), opacity 200ms var(--ease-out, ease); }
.ag-evw.open .ag-det { grid-template-rows: 1fr; opacity: 1; }
.ag-det-in { min-height: 0; overflow: hidden; font-size: 12.5px; color: var(--ink-2); }
.ag-evw.open .ag-det-in { margin-top: 6px; padding: 2px 10px 6px; background: var(--ag-card); border-radius: 12px; box-shadow: var(--shadow-1); }
.ag-det .r { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line-soft, var(--line)); }
.ag-det .r:first-child { border-top: 0; }
.ag-note { margin: 4px 0 0; white-space: pre-wrap; }
.ag-by { color: var(--ink-3); font-size: 12px; }
@media (prefers-reduced-motion: reduce) { .ag-det { transition: opacity 150ms ease; } }

/* Просьба о правке: что меняется и кнопки решения прямо в ленте. */
.ag-call { margin-top: 7px; padding: 8px 10px; border-radius: 12px; background: var(--ag-card); box-shadow: var(--shadow-1); font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; }
.ag-call .btn .ph { margin-right: 4px; vertical-align: -2px; }

/* Пачка заявок на один день: компании, порции, изменение к прошлому дню и итог. */
.ag-th { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; line-height: 18px; }
.ag-pack { margin-top: 7px; background: var(--ag-card); border-radius: 12px; box-shadow: var(--shadow-1); overflow: hidden; }
.ag-pr { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 52px 74px; gap: 8px; align-items: baseline; padding: 6px 10px; border: 0; border-top: 1px solid var(--line-soft, var(--line));
  background: transparent; font: inherit; font-size: 12.5px; color: var(--ink); text-align: left; cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background-color 150ms var(--ease, ease); }
.ag-pr:first-child { border-top: 0; }
.ag-pr b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-pr .n { text-align: right; font-weight: 600; }
.ag-pr .d { text-align: right; white-space: nowrap; }
.ag-pr.tot { background: var(--surface-2); font-weight: 600; cursor: default; }
@media (hover: hover) and (pointer: fine) { button.ag-pr:hover { background: var(--surface-2); } }
.ag-pr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ag-miss { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 7px; font-size: 12px; color: var(--ink-2); }
.ag-link { border: 0; background: none; padding: 0; font: inherit; font-size: 12px; font-weight: 500; color: var(--accent); cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .ag-link:hover { text-decoration: underline; text-underline-offset: 3px; } }

/* Поиск — строка под заголовком, открывается лупой; ищет на сервере за 120 дней. */
.ag-search { display: flex; align-items: center; gap: 6px; margin: 0 12px 6px; padding: 0 2px 0 10px; height: 38px; border-radius: 12px; background: var(--surface-2); flex: none; }
.ag-search[hidden] { display: none; }
.ag-search-ic { color: var(--ink-3); display: grid; }
.ag-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 15px; color: var(--ink); }
.ag-search input::placeholder { color: var(--ink-3); }
.ag-search input::-webkit-search-cancel-button { display: none; }
.ag-search .ag-ib { width: 30px; height: 30px; }
.ag-ib.on { background: var(--accent-soft); color: var(--accent-ink); }
.ag-seg .ph { flex: none; }
.ag-seg button { display: inline-flex; align-items: center; gap: 4px; }
.ag-seg em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--warning-ink); font-variant-numeric: tabular-nums; }
.ag-seg em:empty { display: none; }
@media (max-width: 380px) { .ag-seg button span { display: none; } }

/* Порции по приёмам: подпись приглушённая, число жирное, между приёмами воздух. */
.ag-meals { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 12px; }
.ag-m { white-space: nowrap; color: var(--ink); font-variant-numeric: tabular-nums; }
.ag-m i { font-style: normal; color: var(--ink-3); }
.ag-m b { font-weight: 600; }

.ag-me, .ag-ai { font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.ag-me { margin: 6px 0 6px auto; max-width: 82%; width: fit-content; background: var(--accent); color: var(--on-accent, #fff); border-radius: 18px 18px 6px 18px; padding: 8px 12px; }
.ag-me.failed { opacity: .7; }
.ag-me small { display: block; font-size: 12px; opacity: .85; margin-top: 2px; }
.ag-ai { margin: 6px 0; max-width: 94%; background: var(--surface); border-radius: 18px 18px 18px 6px; padding: 9px 12px; box-shadow: var(--shadow-1); color: var(--ink); }
.ag-typing { display: inline-flex; gap: 4px; width: fit-content; }
.ag-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: ag-dot 1s infinite ease-in-out; }
.ag-typing i:nth-child(2) { animation-delay: .15s; } .ag-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ag-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ag-typing i { animation: none; opacity: .6; } .ag-pane, .ag-bar { transition: none; } }

.ag-card { white-space: normal; margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--plane, var(--surface)); }
.ag-card .h { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--ink-3); margin-bottom: 4px; }
.ag-card table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ag-card th { text-align: left; font-weight: 500; color: var(--ink-3); padding: 3px 6px 3px 0; }
.ag-card td { padding: 3px 6px 3px 0; border-top: 1px solid var(--line-soft, var(--line)); vertical-align: top; }
.ag-card td + td, .ag-card th { white-space: nowrap; }
.ag-draft td:last-child { white-space: normal; }
.ag-card td + td, .ag-card th + th { text-align: right; padding-right: 0; }
.ag-card tr:first-child td { border-top: 0; }
.ag-card em { font-style: normal; font-size: 11px; color: var(--ink-3); }
.ag-card em.late { color: var(--warning-ink); }
.ag-tw { overflow-x: auto; }
.ag-bar-row { display: grid; grid-template-columns: minmax(60px, 34%) 1fr auto; gap: 8px; align-items: center; font-size: 12px; margin: 4px 0; }
.ag-bar-row i { display: block; height: 8px; border-radius: 4px; background: var(--c1, var(--accent)); }
.ag-bar-row b { font-weight: 500; font-variant-numeric: tabular-nums; }
.ag-btns { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.ag-btns .ag-ib { margin-left: auto; }
.ag-state { margin-top: 6px; font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.ag-state.ok { color: var(--good-ink); }
.ag-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; white-space: normal; }
.ag-chip { border: 0; border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 13px; background: var(--accent-soft); color: var(--accent-ink); cursor: pointer; text-align: left; }
.ag-check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-top: 1px solid var(--line-soft, var(--line)); font-size: 13.5px; cursor: pointer; }
.ag-check:first-of-type { border-top: 0; }
.ag-check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.ag-check small { display: block; color: var(--ink-3); font-size: 12px; }
.ag-check.off { color: var(--ink-3); cursor: default; }

/* ——— компьютер ——— */
@media (min-width: 1040px) {
  .ag-bar { left: calc(236px + 24px); right: 24px; bottom: 16px; }
  html.ag-on .view { padding-bottom: 84px; }
  .ag-pane {
    top: 0; left: auto; width: var(--ag-w); border-radius: 0; z-index: 84; border-left: 1px solid var(--line);
    box-shadow: none; transform: translateX(102%); background: var(--surface);
  }
  .ag-pane.open { transform: none; }
  .ag-pane { --ag-bg: var(--surface); --ag-card: var(--plane, var(--surface-2)); }
  .ag-grab { display: none; }
  .ag-grip { display: block; position: absolute; left: -5px; top: 0; bottom: 0; width: 10px; cursor: col-resize; touch-action: none; z-index: 1; }
  .ag-grip::after { content: ''; position: absolute; left: 3px; top: 50%; width: 4px; height: 44px; margin-top: -22px; border-radius: 2px; background: var(--line); transition: background-color 140ms var(--ease, ease); }
  .ag-pane.dragging .ag-grip::after, .ag-grip:focus-visible::after { background: var(--accent); }
  .ag-grip:focus-visible { outline: none; }
  .ag-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line-soft, var(--line)); }
  .ag-foot { padding: 10px 12px 12px; border-top: 1px solid var(--line); background: var(--surface); }
  .ag-foot .ag-bar { background: var(--surface-2); border-color: var(--line); backdrop-filter: none; -webkit-backdrop-filter: none; }
  html.ag-dock:not(.sp-squeeze) .app { padding-right: var(--ag-w); box-sizing: border-box; }
  html.ag-dock .submit-dock { right: var(--ag-w); }
  html.ag-dock .view { padding-bottom: 0; }
  html.ag-on::after { display: none; }
  html.ag-dock .sp { right: var(--ag-w); }
  html.ag-dock.sp-squeeze .app { padding-right: calc(var(--sp-pad, var(--sp-w)) + var(--ag-w)); }
  html.ag-dock.sp-squeeze .submit-dock { right: calc(var(--sp-pad, var(--sp-w)) + var(--ag-w)); }
  @media (hover: hover) and (pointer: fine) { .ag-grip:hover::after { background: var(--accent); } }
}
