/* Компоновка «история болезни сверху, машинерия в ящике»; режим боковой панели. */

.app {
  max-width: 1280px;
  padding: 14px 16px 40px;
  --app-sticky-below-header: 46px;
}
header.app-header {
  justify-content: space-between;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  padding: 4px 0 6px;
}

/* ---- подвкладки ---- */
.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0 0 10px;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--line);
}
.subtab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}
.subtab:hover { color: var(--ink); background: rgba(255, 255, 255, 0.6); }
.subtab.active { color: var(--accent); background: var(--accent-soft); }
.subpanel { display: none; }
.subpanel.active { display: block; }

/* ---- верхняя строка вкладки «Работа» ---- */
.work-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  position: sticky;
  top: var(--app-sticky-below-header, 46px);
  z-index: 30;
}
.work-topbar-left,
.work-topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
}
.work-ind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafb;
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: default;
}
button.work-ind { cursor: pointer; }
button.work-ind:hover { background: var(--accent-soft); border-color: var(--accent); }
button.work-ind[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.work-ind .autopilot-dot { width: 9px; height: 9px; box-shadow: 0 0 0 2px rgba(196, 92, 92, 0.18); }
.work-ind .autopilot-dot.on { box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22); }
.work-ind .autopilot-mode-icon { width: 22px; height: 22px; }
.work-ind .autopilot-mode-icon svg { width: 14px; height: 14px; }
.work-ind-label { line-height: 1; }
#workLlmInd .autopilot-dot.is-llm-ready {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
}
#workLlmInd .autopilot-dot.is-llm-busy {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
  animation: autopilot-dot-blink 1.1s ease-in-out infinite;
}
#workLlmInd .autopilot-dot.is-llm-error {
  background: #c45c5c;
  box-shadow: 0 0 0 2px rgba(196, 92, 92, 0.18);
}
#workLlmInd .autopilot-dot.is-llm-loading {
  background: #b8c0cc;
  box-shadow: 0 0 0 2px rgba(184, 192, 204, 0.35);
}
@media (prefers-reduced-motion: reduce) {
  #workLlmInd .autopilot-dot.is-llm-busy { animation: none; }
}
#workScreenBtn .autopilot-dot.is-screen-ready {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
}
#workScreenBtn .autopilot-dot.on {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
  animation: autopilot-dot-blink 1.1s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #workScreenBtn .autopilot-dot.on { animation: none; }
}
#workMicInd .autopilot-dot.is-mic-ready {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
}
#workMicInd .autopilot-dot.on {
  background: #1a9b6c;
  box-shadow: 0 0 0 2px rgba(26, 155, 108, 0.22);
  animation: autopilot-dot-blink 1.1s ease-in-out infinite;
}
#workMicInd .autopilot-dot.is-mic-error {
  background: #c45c5c;
  box-shadow: 0 0 0 2px rgba(196, 92, 92, 0.18);
}
@media (prefers-reduced-motion: reduce) {
  #workMicInd .autopilot-dot.on { animation: none; }
}
.field-card.is-inferred-fill .field-text {
  background: #fffbeb;
  box-shadow: inset 0 0 0 1px rgba(240, 216, 120, 0.55);
}
.field-text .glance-inferred-line {
  display: inline;
  background: #fffbeb;
  box-shadow: 0 0 0 1px rgba(240, 216, 120, 0.45);
  border-radius: 2px;
}
.work-topbar .autopilot-mode-badge { margin: 0; }
.work-topbar button.small { padding: 5px 10px; font-size: 0.82rem; }
#autopilotTplToScreen[hidden] { display: none; }

/* ---- живая речь одной строкой ---- */
.work-speech {
  position: relative;
  margin: 8px 0 10px;
  padding: 0;
  border: none;
  background: transparent;
}
.work-speech textarea#autopilotTranscript {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 8px 36px 8px 10px;
  font-family: var(--sans);
  font-size: 0.9rem;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.work-speech textarea#autopilotTranscript:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.work-speech-clear {
  position: absolute;
  right: 6px;
  top: 6px;
  padding: 2px 8px;
  font-size: 1rem;
  line-height: 1;
}

/* ---- история болезни ---- */
.autopilot-history-wrap { margin-top: 0; }
.work-status-line {
  min-height: 1.2em;
  margin: 8px 2px 0;
  font-size: 0.82rem;
}
.work-status-line:empty { display: none; }

/* ---- ящик с машинерией ---- */
.work-drawer { margin-top: 14px; }
.work-drawer[hidden] { display: none; }
.work-drawer .card.autopilot-layout { padding: 12px; }
.drawer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}
.drawer-cell { min-width: 0; }
.drawer-title {
  display: block;
  font-size: 0.86rem;
  margin: 0 0 6px;
}
.drawer-cell .autopilot-log { max-height: 220px; }
.drawer-cell .progress-wrap { margin-top: 10px; }
#autopilotFilm .autopilot-film-strip { max-height: 240px; }

/* ---- пилюля «расширение подключено» ---- */
.bridge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid #a6f4c5;
}
.bridge-pill::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}
.bridge-pill[hidden] { display: none; }
.bridge-pill { cursor: pointer; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bridge-pill.is-off { background: #f1f3f5; color: var(--muted); border-color: var(--line); }
.bridge-pill.is-off::before { background: #b9c2cc; }
.bridge-pill.is-matched { background: #e6eefc; color: #1d4ed8; border-color: #bfd3fb; }
.bridge-pill.is-matched::before { background: #2f6fed; }

/* поле ЕМИАС под курсором — подсветка карточки */
.field-card.is-emias-focus {
  outline: 2px solid #2f6fed;
  outline-offset: 2px;
}
.field-card .field-emias-insert {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #fff;
  background: #2f6fed;
  border: 1px solid #2f6fed;
  border-radius: 6px;
  cursor: pointer;
}
.field-card .field-emias-insert:hover { background: #1d4ed8; }
.field-card .field-emias-insert:disabled { opacity: 0.5; }

/* ---- последовательное заполнение ---- */
.seq-banner.active {
  display: block;
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.84rem;
}
.seq-banner:not(.active) { display: none; }

/* ---- схема тела ---- */
.bodymap-card { padding: 12px; }
.bodymap-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
}
.bodymap-figure-wrap { min-width: 0; }
.bodymap-view-tog {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f6f8;
  margin-bottom: 8px;
}
.bodymap-view-tog button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 10px;
  font-size: 0.82rem;
  border-radius: 6px;
}
.bodymap-view-tog button.is-active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.bodymap-figure {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 6px;
}
.bodymap-figure svg {
  width: 100%;
  height: auto;
  display: block;
  max-height: 640px;
}
.bodymap-figure .bm-region {
  fill: #e7ecf1;
  stroke: #9db0c0;
  stroke-width: 1.2;
  cursor: pointer;
  transition: fill 0.12s ease;
}
.bodymap-figure .bm-region:hover { fill: #cfe8dd; }
.bodymap-figure .bm-region.is-selected { fill: #0b6e4f; stroke: #064e37; }
.bodymap-figure .bm-region.is-active { stroke: #2f6fed; stroke-width: 2.4; }
.bodymap-figure .bm-region.has-tpl { stroke: #0b6e4f; }
.bodymap-figure .bm-outline { fill: none; stroke: #b7c4d0; stroke-width: 1; pointer-events: none; }
.bodymap-figure .bm-label {
  font-family: var(--sans);
  font-size: 9px;
  fill: #5c6b7a;
  pointer-events: none;
  user-select: none;
}
.bodymap-figure .bm-side-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  fill: #8b93a1;
  pointer-events: none;
}
.bodymap-hint { margin: 6px 0 0; }

.bodymap-side { min-width: 0; }
.bodymap-picker-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
}
.bodymap-picker-head h3 { margin: 0; font-size: 1rem; }
.bodymap-picker-head .bm-side-tag {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
}
.bm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}
.bm-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.bm-chip:hover { border-color: var(--accent); }
.bm-chip.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.bm-chip.is-empty { opacity: 0.45; }
.bm-codes {
  display: grid;
  gap: 4px;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: #fbfcfd;
}
.bm-code {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.bm-code:hover { border-color: var(--accent); }
.bm-code.is-picked { background: var(--accent-soft); border-color: var(--accent); }
.bm-code .code { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.bm-code .meta { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }

.bodymap-selection { margin-top: 12px; }
.bm-sel-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--surface);
}
.bm-sel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}
.bm-sel-head strong { color: var(--accent); font-family: var(--mono); }
.bm-sel-head .ghost { padding: 2px 8px; }
.bm-sel-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 6px;
  align-items: start;
}
.bm-sel-body input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 0.84rem;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.bm-ao {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}
.bm-ao select {
  width: auto;
  max-width: 100%;
  flex: 0 1 auto;
  font: inherit;
  font-size: 0.8rem;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.bm-ao a { color: #2f6fed; font-weight: 600; white-space: nowrap; }
.bm-ao-code { font-family: var(--mono); font-weight: 700; color: var(--ink); }
.bm-chip-n { opacity: 0.7; font-weight: 500; }
.bm-inset {
  width: 100%;
  max-width: 220px;
  height: auto;
  display: block;
  margin: 0 auto 8px;
}
.bm-inset .bm-inset-outline { fill: #f4f6f8; stroke: #c3ced8; stroke-width: 1; }
.bm-inset .bm-detail {
  fill: #e7ecf1;
  stroke: #9db0c0;
  stroke-width: 1;
  cursor: pointer;
}
.bm-inset .bm-detail:hover { fill: #cfe8dd; }
.bm-inset .bm-detail.is-active { fill: #0b6e4f; stroke: #064e37; }
.bm-inset .bm-label { font-size: 8px; fill: #8b93a1; }
.bm-sel-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px 12px;
  margin: 0 0 8px;
  font-size: 0.86rem;
}
.bm-ped-tog, .bm-open-tog {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.bm-sel-name { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.bm-ao { margin-top: 6px; }
.bm-ao .bm-ao-manual {
  width: 110px;
  font: inherit;
  font-size: 0.78rem;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.bm-sel-preview {
  font-size: 0.84rem;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
}
.bm-sel-preview .muted { color: var(--muted); }
.bodymap-actions { margin: 10px 0 0; }
.bodymap-actions[hidden] { display: none; }

/* ---- узкое окно (боковая панель рядом с ЕМИАС) ---- */
@media (max-width: 760px) {
  .app { padding: 8px 8px 32px; }
  header.app-header { gap: 4px; }
  .tab { padding: 6px 8px; font-size: 0.86rem; }
  .work-topbar { top: 40px; padding: 6px 8px; }
  .work-ind-label { display: none; }
  .drawer-row { grid-template-columns: 1fr; }
  .autopilot-glance.is-split { grid-template-columns: 1fr; }
  .autopilot-film-row { grid-template-columns: 1fr; }
  .bodymap-layout { grid-template-columns: 1fr; }
  .mkb-layout { grid-template-columns: 1fr; }
  .field-compare { grid-template-columns: 1fr; }
  .ib-header-main { flex-wrap: wrap; }
}
