/* Extracted from ecosystem.css — Unified app surface primitives. */
/* Load after ecosystem.css and before existing ecosystem feature sheets; original order preserved. */

.ecosystem-workspace {
  min-width: 0;
}

.ui-responsive-grid {
  min-width: 0;
}

.ecosystem-card {
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}

.ecosystem-filter {
  align-items: end;
}

.ecosystem-form {
  display: grid;
  gap: 10px;
}

.ecosystem-field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ecosystem-grow-field {
  flex: 1 1 12rem;
  min-width: 0;
  font-size: 16px;
  /* Author chrome — never rely on UA color-scheme alone (Telegram dark + light app). */
  color: var(--tg-theme-text-color, #111);
  background: var(--tg-theme-bg-color, #fff);
  border: 1px solid var(--ui-border-strong, rgba(127, 127, 127, .38));
  border-radius: var(--ui-radius-xs, 8px);
  min-height: var(--ui-control-h, 38px);
  padding: 8px 10px;
  box-sizing: border-box;
  color-scheme: inherit;
}

.ecosystem-choice {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.ecosystem-choice legend {
  margin-bottom: 6px;
  color: var(--tg-theme-hint-color, #6d7582);
  font-size: 12px;
  font-weight: 700;
}

.ecosystem-choice .rk {
  margin: 0 4px 4px 0;
}

.ecosystem-action {
  min-height: 40px;
}

.ui-action.ecosystem-secondary,
.rk.ecosystem-secondary,
#nf-cancel,
#pm-cancel {
  color: var(--tg-theme-text-color, #18212f);
  border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color, #708090) 32%, transparent);
  background: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #eef2f7) 92%, #fff);
  box-shadow: none;
}

.ui-action.ecosystem-danger {
  color: var(--tg-theme-destructive-text-color, #d92d20);
  border-color: color-mix(in srgb, var(--tg-theme-destructive-text-color, #d92d20) 30%, transparent);
  background: color-mix(in srgb, var(--tg-theme-destructive-text-color, #d92d20) 9%, transparent);
  box-shadow: none;
}

.cat-review-copy,
.cat-description {
  white-space: normal;
}

.cat-description {
  margin: 4px 0;
}

.cat-subhead,
.cat-detail-actions {
  margin-top: 8px;
}

.po-actions {
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.rv-star {
  min-width: 40px;
  min-height: 40px;
  padding: 6px 9px;
}

.b2b-action,
.po-actions .ecosystem-action,
.ref-secondary-actions .ecosystem-action,
.cw-actions .ecosystem-action,
.pc-actions .ecosystem-action {
  flex: 0 1 auto;
}

body.pro .ui-responsive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 10px;
}

/* ref-card layout / lite ref forms → ecosystem_refs.css. */

body.lite .ui-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

body.lite .ui-actions > .ecosystem-action,
body.lite .ecosystem-grow-field {
  width: 100%;
}

body.lite #deal-form-modal .ecosystem-grow-field {
  flex: 0 0 auto;
}

@media (prefers-reduced-motion: reduce) {
  .ecosystem-action {
    transition: none;
  }
}

/* Unified application surfaces.
 Legacy renderers still emit compact semantic classes (`frow`, `fin`, `mini`, `rk`). Keeping
 their visual contract here gives every reachable sheet and modal the same system without
 duplicating layout code across Finance, Deals, references, Marketplace and admin workspaces. */
:where(#dash, #deals-command-bar, #form, #deal-bar, #grid-wrap, #refs-bar, #led-bar,
  #suppliers-bar, #settings-bar, #platform-bar, #docs-bar) {
  min-width: 0;
}

:where(.rcard, .collap, .card, .fin-card, .dash-sec) {
  border-color: var(--ui-border) !important;
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface-raised);
  box-shadow: 0 1px 2px rgb(0 0 0 / 3%), 0 8px 24px rgb(0 0 0 / 3%);
}

:where(.rk, .btn, .btn-primary, button.del, button.act) {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-xs);
  font-weight: 620;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

:where(.rk, .btn, .btn-primary, button.del, button.act):active:not(:disabled) {
  transform: scale(.985);
}

:where(.rk, .btn, button.act) {
  background: var(--ui-surface-muted);
}

:where(.btn-primary, .rk.active) {
  border-color: color-mix(in srgb, var(--tg-theme-button-color, #3390ec) 70%, transparent);
}

button.del {
  color: var(--ui-danger);
  border-color: color-mix(in srgb, var(--ui-danger) 20%, transparent);
  background: var(--ui-danger-soft);
}

input.cm, select.cm, textarea.cm, .frow > input, .frow > select, .frow > textarea,
.ecosystem-field-row > :is(input, select, textarea),
.ecosystem-grow-field,
#f-q, #docs-q, #ref-add {
  min-width: 0;
  min-height: var(--ui-control-h);
  padding: 8px 10px;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-xs);
  color: var(--tg-theme-text-color, #111);
  background: var(--tg-theme-bg-color, #fff);
  box-shadow: inset 0 1px 1px rgb(0 0 0 / 2%);
  color-scheme: inherit;
}

input.cm:focus, select.cm:focus, textarea.cm:focus, .frow > input:focus, .frow > select:focus, .frow > textarea:focus,
.ecosystem-field-row > :is(input, select, textarea):focus,
.ecosystem-grow-field:focus,
#f-q:focus, #docs-q:focus, #ref-add:focus {
  border-color: var(--tg-theme-button-color, #3390ec);
  outline: none;
  box-shadow: var(--ui-focus);
}

.frow {
  gap: var(--ui-space-2);
}

.frow > label {
  color: var(--tg-theme-hint-color, #6d7582);
  font-size: 11px;
  font-weight: 680;
}

:where(.mini, #grid) {
  border-color: var(--ui-border);
  background: var(--ui-surface-raised);
}

:where(.mini, #grid) th {
  color: var(--tg-theme-hint-color, #5f6875);
  border-color: var(--ui-border);
  background: var(--ui-surface-muted);
  font-weight: 700;
}

:where(.mini, #grid) td {
  border-color: var(--ui-border);
}

:where(.mini, #grid) tbody tr:hover > td {
  background: color-mix(in srgb, var(--tg-theme-button-color, #3390ec) 4%, transparent);
}

#deals-command-bar,
#deal-bar,
#led-sheets,
#led-balances,
#led-filters,
#ref-kinds,
#ref-context {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface-raised);
}

#deals-command-bar {
  gap: 8px;
  padding: 8px;
  box-shadow: var(--ui-shadow);
}

#deal-bar {
  padding: 6px 8px;
}

#led-sheets {
  padding: 8px;
  box-shadow: var(--ui-shadow);
}

#led-balances:not(:empty) {
  margin-bottom: 8px;
  padding: 8px;
}

#led-filters {
  margin: 0 0 8px;
  padding: 7px 8px;
}

#ref-kinds,
#ref-context:not(:empty) {
  padding: 6px 8px;
}

#grid-wrap {
  border-radius: var(--ui-radius-sm);
}

.modal {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg) !important;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #111);
  box-shadow: 0 24px 70px rgb(0 0 0 / 22%);
}

html[data-theme="dark"] .overlay .modal,
.overlay[data-theme="dark"] .modal {
  background: var(--tg-theme-bg-color, #17212b);
  color: var(--tg-theme-text-color, #f5f5f5);
  box-shadow: 0 24px 70px rgb(0 0 0 / 45%);
}

html[data-theme="dark"] .overlay .modal-head,
.overlay[data-theme="dark"] .modal-head {
  border-bottom-color: rgba(255, 255, 255, .12);
}

.cabinet-admin-tab.ecosystem-choice.active {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #fff);
  border-color: transparent;
}

.modal-head {
  border-bottom: 1px solid var(--ui-border);
}

.fin-empty,
.admin-state {
  border-radius: var(--ui-radius-sm);
}
