.form-actions__primary {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.form-actions__primary #save-btn {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
}

.form-actions__primary .field-notes-trigger {
  width: auto;
  flex: 0 0 auto;
}

.field-notes-trigger {
  min-width: 48px;
  padding-inline: 13px;
  border: 1px solid rgba(197, 160, 89, 0.5);
  color: var(--brass-light);
  background: linear-gradient(180deg, #28211a, #15110e);
  box-shadow: var(--inset-shadow);
}

.field-notes-trigger .field-notes-trigger__label {
  margin-left: 7px;
  font-size: 0.72rem;
}

.field-notes-popover {
  position: fixed;
  z-index: 1000;
  width: min(360px, calc(100vw - 24px));
  max-height: min(440px, calc(100vh - 24px));
  overflow: auto;
  padding: 16px 18px;
  border: 1px solid rgba(197, 160, 89, 0.72);
  color: var(--parchment-soft);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 36%),
    linear-gradient(180deg, #25201a, #11100e);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.72), var(--inset-shadow);
}

.field-notes-popover[hidden] {
  display: none;
}

.field-notes-popover h3 {
  margin: 2px 0 8px;
  color: var(--parchment);
  font-family: "Almendra", Baskerville, Georgia, serif;
  font-size: 1.35rem;
  line-height: 1.05;
}

.field-notes-popover p {
  margin: 0;
}

.field-notes-popover__kicker {
  display: block;
  color: var(--brass);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.legend-section + .legend-section {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid rgba(197, 160, 89, 0.2);
}

.legend-section h3 {
  margin: 0 0 8px;
  color: var(--brass-light);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.legend-section p {
  margin: 0;
  color: var(--parchment-dim);
  font-size: 0.93rem;
}

.legend-rules {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.legend-rules li {
  position: relative;
  padding-left: 15px;
  color: var(--parchment-soft);
  font-size: 0.91rem;
}

.legend-rules li::before {
  content: "✦";
  position: absolute;
  left: 0;
  top: 0.12em;
  color: var(--brass-dark);
  font-size: 0.62rem;
}

.trade-chat-panel {
  min-width: 0;
  padding: 18px;
  margin-block: 24px;
}

.trade-chat-panel[hidden],
.trade-chat-panel [hidden] { display: none; }

.trade-chat-panel .panel-heading {
  align-items: center;
}

.trade-chat-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.trade-chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 4px 8px;
  border: 1px solid rgba(197, 160, 89, 0.4);
  background: #17140f;
  color: var(--parchment-soft);
  font: 600 .8rem "Cinzel", Georgia, serif;
  cursor: pointer;
}
.trade-chat-toggle__track { width: 34px; padding: 3px; border: 1px solid #807257; border-radius: 14px; background: #29251f; }
.trade-chat-toggle__track::before { content: ""; display: block; width: 12px; height: 12px; border-radius: 50%; background: #a99d8d; }
.trade-chat-toggle[aria-checked="true"] .trade-chat-toggle__track { background: #57421e; border-color: #d6b568; }
.trade-chat-toggle[aria-checked="true"] .trade-chat-toggle__track::before { margin-left: auto; background: #f4dfac; }
.trade-chat-toggle:focus-visible, .trade-chat-refresh:focus-visible { outline: 2px solid #f4dfac; outline-offset: 3px; }
.trade-chat-panel .trade-chat-hint { margin: 0; color: var(--parchment-dim); font-size: .9rem; }
#trade-chat-content { margin-top: 12px; }

.trade-chat-refresh {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid rgba(197, 160, 89, 0.4);
  color: var(--brass-light);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.67rem;
  background: linear-gradient(180deg, #28231d, #15120f);
}

.trade-chat-refresh:disabled {
  cursor: wait;
  opacity: 0.58;
}

.trade-chat-state {
  min-height: 1.5em;
  margin: 0 0 10px;
  color: var(--parchment-dim);
  font-size: 0.88rem;
}

.trade-chat-state[data-kind="success"] {
  color: var(--success-light);
}

.trade-chat-state[data-kind="warning"] {
  color: var(--brass-light);
}

.trade-chat-state[data-kind="error"] {
  color: #d78f87;
}

.trade-chat-feed {
  display: grid;
  gap: 9px;
  max-height: min(54vh, 540px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 4px;
}

.trade-chat-message {
  min-width: 0;
  padding: 10px 11px;
  border-left: 2px solid rgba(197, 160, 89, 0.58);
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 1px rgba(197, 160, 89, 0.09);
}

.trade-chat-message header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.trade-chat-message__sender {
  min-width: 0;
  overflow: hidden;
  color: var(--brass-light);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trade-chat-message__time {
  flex: 0 0 auto;
  color: var(--tertiary);
  font-size: 0.73rem;
}

.trade-chat-message__body {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: var(--parchment-soft);
  font-size: 0.92rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.trade-chat-item-trigger {
  appearance: none;
  display: inline;
  padding: 0;
  border: 0;
  border-bottom: 1px dotted currentColor;
  background: transparent;
  color: var(--tooltip-rarity, #e9d6a0);
  cursor: help;
  font: inherit;
  font-weight: 600;
}

.trade-chat-item-trigger:hover,
.trade-chat-item-trigger:focus-visible {
  border-bottom-style: solid;
  color: var(--tooltip-rarity, #e9d6a0);
  outline: 0;
}

@media (max-width: 880px) {
  .hub-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .side-column {
    position: static;
  }

  .trade-chat-feed {
    max-height: 460px;
  }
}

@media (max-width: 560px) {
  .form-actions__primary {
    width: 100%;
  }

  .form-actions__primary #save-btn {
    min-width: 0;
    flex: 1 1 auto;
  }

  .field-notes-trigger {
    flex: 0 0 auto;
  }

  .field-notes-trigger .field-notes-trigger__label {
    display: none;
  }

  .trade-chat-panel {
    padding: 15px;
  }

  .trade-chat-panel .panel-heading {
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
  }

  .trade-chat-message header {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .field-notes-popover,
  .trade-chat-message {
    scroll-behavior: auto;
    transition: none;
  }
}

/* Future item-gated attribute filters need more breathing room. Keep the
   controls aligned, let the attribute search use the unused row width, and
   reserve enough height so lower actions are pushed down instead of crowding. */
.alert-form .stats-container {
  min-height: 112px;
  align-content: start;
}

@media (min-width: 760px) {
  .alert-form .stat-filter-row,
  .alert-form .stat-filter-row.is-empty-socket {
    box-sizing: border-box;
    width: 100%;
    grid-template-columns:
      minmax(300px, 1fr)
      88px
      50px
      88px
      40px;
    justify-content: stretch;
  }
}
