/* Echo Space responsive and protected-state fixes */
html.security-pending .deal-shell,
html.security-pending .form-backdrop,
html.security-pending .client-welcome {
  visibility: hidden !important;
}

body.modal-open {
  overflow: hidden !important;
  touch-action: none;
}

.security-gate {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.deal-dialog {
  position: relative;
}

.deal-dialog .deal-dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: #eef2f8;
  color: #34445e;
  font-size: 24px;
  line-height: 1;
}

.stage-is-completed > .section-caption,
.stage-is-completed > #actions {
  display: none;
}

.stage-is-completed .simple-stage-summary {
  margin-top: 28px;
}

@media (max-width: 800px) {
  .deal-shell {
    min-height: 100dvh;
    grid-template-rows: auto auto;
  }

  .deal-topbar {
    min-height: 64px;
    height: auto;
    padding-block: 10px;
    gap: 10px;
  }

  .deal-brand {
    min-width: 0;
  }

  .deal-brand strong {
    font-size: 15px;
  }

  .manager-identity-banner {
    display: none;
  }

  .deal-body {
    grid-template-columns: minmax(0, 1fr);
    padding: 8px;
  }

  .stage-nav {
    min-width: 0;
    overflow: hidden;
  }

  .stage-nav-head {
    padding: 14px 14px 8px;
  }

  .stage-scroll {
    width: 100%;
    padding: 4px 14px 12px;
    gap: 8px;
    scroll-padding-inline: 14px;
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .stage-scroll::-webkit-scrollbar {
    display: none;
  }

  .stage-scroll > button {
    flex: 0 0 min(76vw, 260px);
    min-width: 0;
    scroll-snap-align: start;
  }

  .stage-scroll > .show-all-stages {
    flex-basis: min(64vw, 220px);
  }

  .stage-utils {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    padding: 10px 12px 12px;
  }

  .stage-utils button {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    min-height: 58px;
    padding: 7px 5px;
    white-space: normal;
    text-align: center;
    font-size: 10px;
    line-height: 1.2;
  }

  .stage-utils button span {
    margin: 0;
  }

  .deal-content {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
  }

  .stage-card {
    min-width: 0;
    padding: 24px 17px;
  }

  .stage-card h1 {
    font-size: clamp(29px, 9vw, 36px);
    line-height: 1.04;
  }

  .curator-line {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .curator-line > button {
    grid-column: 1 / -1;
    width: 100%;
    margin-top: 4px;
  }

  .primary-action {
    padding: 20px 17px;
  }

  .primary-action > button,
  .primary-action .ask-curator-button {
    width: 100%;
    margin-left: 0;
  }

  .result-decision > div:last-child {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .result-decision button {
    width: 100%;
  }

  .chat-panel {
    min-height: 560px;
    max-height: none;
  }

  .composer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #fff;
  }

  .quick-actions {
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .quick-actions::-webkit-scrollbar {
    display: none;
  }

  .quick-actions button {
    flex: 0 0 auto;
    min-height: 38px;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .input-row textarea {
    min-height: 48px;
    font-size: 16px;
  }

  .input-row button {
    width: 48px;
    min-width: 48px;
    height: 48px;
  }

  .deal-switcher {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    width: 100%;
    gap: 6px;
  }

  .deal-switcher button {
    padding-inline: 10px;
    white-space: nowrap;
  }

  body[data-role="manager"] .deal-switcher .switcher-share-link {
    display: block;
    grid-column: 1 / -1;
    width: 100%;
    background: #355bd8;
    color: #fff;
  }

  .deal-switcher .switcher-share-link:disabled {
    opacity: .65;
  }

  .deal-switcher small {
    display: none;
  }

  .deal-switcher select {
    min-width: 0;
    width: 100%;
    font-size: 12px;
  }
}

@media (max-width: 600px) {
  .security-gate {
    place-items: end center;
    padding: 0;
  }

  .security-card {
    width: 100%;
    padding: 26px 20px max(24px, env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
  }

  .security-brand {
    margin-bottom: 24px;
  }

  .security-card h1 {
    font-size: 27px;
  }

  .deal-dialog-backdrop {
    place-items: end center;
    padding: 0;
  }

  .deal-dialog {
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    padding: 26px 18px max(20px, env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
  }

  .deals-dashboard {
    padding: 20px 12px max(24px, env(safe-area-inset-bottom));
  }

  .deals-dashboard header {
    gap: 18px;
    margin-bottom: 18px;
  }

  .deals-dashboard header > div:last-child {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .deals-table-wrap {
    overflow: visible;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .deals-dashboard table,
  .deals-dashboard tbody,
  .deals-dashboard tr,
  .deals-dashboard td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .deals-dashboard thead {
    display: none;
  }

  .deals-dashboard tbody {
    display: grid;
    gap: 10px;
  }

  .deals-dashboard tr[data-room] {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 10px;
    padding: 17px;
    border: 1px solid #dde4ee;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(29, 46, 75, .06);
  }

  .deals-dashboard td {
    padding: 0;
    border: 0;
    font-size: 12px;
  }

  .deals-dashboard td:nth-child(1),
  .deals-dashboard td:nth-child(2) {
    grid-column: 1 / -1;
  }

  .deals-dashboard td:nth-child(1) strong {
    font-size: 17px;
  }

  .deals-dashboard td:nth-child(2) {
    margin-top: -8px;
    color: #68768e;
  }

  .deals-dashboard td:nth-child(3)::before { content: "Этап"; }
  .deals-dashboard td:nth-child(4)::before { content: "Срок"; }
  .deals-dashboard td:nth-child(5)::before { content: "Сообщения"; }
  .deals-dashboard td:nth-child(6)::before { content: "Внимание"; }

  .deals-dashboard td:nth-child(n+3)::before {
    display: block;
    margin-bottom: 5px;
    color: #7a879b;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
  }

  .empty-row td {
    padding: 34px 18px;
    border-radius: 14px;
    background: #fff;
  }

  .deal-switcher {
    grid-template-columns: 1fr auto;
  }

  .deal-switcher .all-deals {
    grid-column: 1 / -1;
  }

  .stage-utils {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
    overflow-x: auto;
  }

  .stage-utils button {
    min-width: 92px;
  }

  .stage-card {
    padding-inline: 15px;
  }

  .action-list > button {
    min-height: 78px;
    padding: 13px;
  }

  .simple-stage-summary {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 16px 14px;
  }

  .next-stage {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .chat-panel header {
    padding-inline: 14px;
  }

  .chat-flow {
    padding-inline: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage-scroll,
  .quick-actions {
    scroll-behavior: auto;
  }
}
