/* Counterparty groups — counterparty-list.html (the Group column, the Groups
   section and the group dialog, always on).
   Every rule is scoped under body.counterparty-groups-era, the class
   counterparty-list.js adds to that page on load, so nothing here can reach
   another page even if this sheet were linked there.
   The section, the dialog and the chips reuse the page's own components
   (styles.css .top-holding-kpis tiles, .top-holding-modal/-dialog/-form,
   .top-holding-readonly-pill, .ghost-button), so this file is mostly layout.
   Buttons keep the page's classes; the few button properties set here carry
   !important because styles.css and button-system.css pin every button. */

/* ── Groups section: a full-width tile under the KPI tiles ──────────────── */
.counterparty-groups-era .counterparty-groups {
  margin: 0 0 18px;
  padding: 15px 16px 6px;
  border: 1px solid rgba(103, 232, 215, 0.18);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(18, 35, 52, 0.94), rgba(9, 18, 30, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.counterparty-groups-era .counterparty-groups-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
}

.counterparty-groups-era .counterparty-groups-head h2 {
  margin: 0;
  color: #f7fbff;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.counterparty-groups-era .counterparty-groups-head .card-sub {
  margin: 4px 0 0;
  max-width: 78ch;
}

.counterparty-groups-era #addCounterpartyGroup {
  flex: 0 0 auto;
}

.counterparty-groups-era .counterparty-group-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.counterparty-groups-era .counterparty-group-list[hidden],
.counterparty-groups-era .counterparty-groups-empty[hidden] {
  display: none;
}

.counterparty-groups-era .counterparty-group-item {
  display: grid;
  grid-template-columns: minmax(200px, 0.9fr) minmax(0, 2fr) auto;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.counterparty-groups-era .counterparty-group-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-width: 0;
}

.counterparty-groups-era .counterparty-group-name {
  color: #f7fbff;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.counterparty-groups-era .counterparty-group-limit {
  min-width: 0;
  padding: 4px 10px;
}

.counterparty-groups-era .counterparty-group-title small {
  color: rgba(223, 237, 245, 0.68);
  font-size: 0.78rem;
}

.counterparty-groups-era .counterparty-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.counterparty-groups-era .counterparty-group-chip {
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  color: #dfedf5;
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.counterparty-groups-era .counterparty-group-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.counterparty-groups-era .counterparty-groups-empty {
  margin: 0;
  padding: 10px 0 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(223, 237, 245, 0.68);
  font-size: 0.85rem;
}

/* ── Group column in the registry table (read-only) ─────────────────────── */
/* The registry table already fills a 1440px desktop. The Group column takes
   its room from the two code columns (codes are at most 12 characters; the
   page's own <=760px rule uses the same 120px), and a long label wraps
   between words rather than widening the table: "Tai Fung Holdings" over
   "· 12.5%" still fits the 38px row the inputs set. "· 12.5%" never splits. */
.counterparty-groups-era .counterparty-table [data-counterparty-field="alphadesk_code"],
.counterparty-groups-era .counterparty-table [data-counterparty-field="legacy_code"] {
  min-width: 120px;
}

/* The containing block of the absolutely positioned .visually-hidden "No
   group" text: without it that text escapes the table's horizontal scroller
   and widens the whole document on a phone. */
.counterparty-groups-era .counterparty-group-cell {
  position: relative;
}

.counterparty-groups-era .counterparty-group-static {
  display: inline-block;
  min-width: 7.5rem;
  max-width: 12rem;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.3;
}

.counterparty-groups-era .counterparty-group-static-limit {
  white-space: nowrap;
}

.counterparty-groups-era .counterparty-group-static.is-empty {
  color: var(--text-muted);
}

/* ── Group dialog (reuses .top-holding-modal / -dialog / -form) ─────────── */
.counterparty-groups-era .counterparty-group-dialog {
  width: min(600px, 100%);
}

.counterparty-groups-era .counterparty-group-fieldset {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.counterparty-groups-era .counterparty-group-fieldset legend {
  margin-bottom: 7px;
  padding: 0;
  color: rgba(223, 237, 245, 0.72);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.counterparty-groups-era .counterparty-group-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  max-height: min(320px, 42vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
}

/* (0,3,1) beats .top-holding-form label's grid/column/font rules. */
.counterparty-groups-era .top-holding-form label.counterparty-group-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 9px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.counterparty-groups-era .top-holding-form label.counterparty-group-option:has(input:checked) {
  border-color: rgba(103, 232, 215, 0.45);
  background: rgba(103, 232, 215, 0.08);
}

.counterparty-groups-era .top-holding-form label.counterparty-group-option:focus-within {
  border-color: rgba(103, 232, 215, 0.7);
  box-shadow: 0 0 0 3px rgba(103, 232, 215, 0.12);
}

.counterparty-groups-era .counterparty-group-option .counterparty-checkbox {
  margin: 0;
  accent-color: var(--c1);
}

.counterparty-groups-era .counterparty-group-option small {
  grid-column: 2;
  color: var(--text-muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.counterparty-groups-era .counterparty-group-options-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Narrow viewports: the same breakpoints the page's own rules use ────── */
@media (max-width: 900px) {
  .counterparty-groups-era .counterparty-group-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .counterparty-groups-era .counterparty-group-chips {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 700px) {
  .counterparty-groups-era .counterparty-groups-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  /* Mirrors C-5 for Add counterparty: a full-width, 44px touch target. */
  .counterparty-groups-era #addCounterpartyGroup {
    width: 100% !important;
    min-height: 44px !important;
  }
  .counterparty-groups-era .counterparty-group-item {
    grid-template-columns: minmax(0, 1fr);
  }
  .counterparty-groups-era .counterparty-group-chips {
    grid-row: auto;
  }
  .counterparty-groups-era .counterparty-group-actions {
    justify-content: stretch;
  }
  .counterparty-groups-era .counterparty-group-actions .ghost-button {
    flex: 1 1 0 !important;
    min-height: 44px !important;
  }
}

@media (max-width: 640px) {
  .counterparty-groups-era .counterparty-group-options {
    grid-template-columns: minmax(0, 1fr);
    max-height: none;
  }
  .counterparty-groups-era .top-holding-form label.counterparty-group-option {
    min-height: 44px;
  }
}
