/* Operator affiliate console.
 *
 * Uses the same tokens, radii, type scale, and density as /styles.css and
 * /crm/crm.css — an operator moving between the CRM and this page should not
 * notice a change of hand. Nothing here redefines a token. */

.aff-shell { max-width: 1440px; }
.aff-shell [hidden],
.aff-dialog [hidden] { display: none !important; }
.aff-brand-link { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.aff-muted { color: var(--ink-soft); font-size: 10px; }

.aff-eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--acc-deep);
  font: 600 10px/1.2 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.aff-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}
.aff-header p { max-width: 700px; }
.aff-header-actions { display: flex; gap: 9px; flex: 0 0 auto; }

.aff-section-heading,
.aff-workspace-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}
.aff-section-heading h2,
.aff-workspace-top h2 {
  font: 600 18px/1.2 'Space Grotesk', sans-serif;
  letter-spacing: -.025em;
}
.aff-section-heading > p { color: var(--ink-soft); font-size: 11px; }
.aff-today { margin-bottom: 24px; }

.aff-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 11px;
  margin-top: 13px;
}
.aff-summary-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.aff-summary-card.is-eligible { border-color: var(--acc-dim); box-shadow: 0 0 0 3px var(--acc-soft); }
.aff-summary-card strong,
.aff-summary-card span,
.aff-summary-card small { display: block; }
.aff-summary-card strong { font: 600 25px/1 'Space Grotesk', sans-serif; }
.aff-summary-card.is-eligible strong { color: var(--acc-deep); }
.aff-summary-card span { margin-top: 9px; font-size: 12px; font-weight: 650; }
.aff-summary-card small { margin-top: 4px; color: var(--ink-soft); font-size: 10px; line-height: 1.45; }
.aff-summary-skeleton {
  min-height: 103px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(100deg, var(--surface) 25%, var(--line-soft) 38%, var(--surface) 52%);
  background-size: 200% 100%;
  animation: aff-shimmer 1.2s linear infinite;
}
@keyframes aff-shimmer { to { background-position-x: -200%; } }

.aff-workspace {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.aff-search-field { flex: 0 1 300px; gap: 4px; }
.aff-search-field label { font-size: 9px; }
.aff-search-field input { min-height: 38px; }
.aff-truncation {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--warning);
  border-radius: 10px;
  background: var(--warning-soft);
  color: #6f4b00;
  font-size: 11px;
  line-height: 1.5;
}

.aff-state,
.aff-detail-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 190px;
  padding: 28px;
  color: var(--ink-dim);
  font-size: 12px;
  text-align: center;
}
.aff-state.is-error,
.aff-detail-state.is-error { flex-direction: column; color: var(--negative); }
.aff-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: aff-spin .7s linear infinite;
}
@keyframes aff-spin { to { transform: rotate(360deg); } }
.aff-empty { padding: 48px 20px; text-align: center; }
.aff-empty h3 { font: 600 16px/1.2 'Space Grotesk', sans-serif; }
.aff-empty p { max-width: 460px; margin: 7px auto 0; color: var(--ink-dim); font-size: 12px; line-height: 1.55; }
.aff-empty code, .aff-detail-card code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--line-soft);
  font: 400 10px/1.4 'JetBrains Mono', ui-monospace, monospace;
}
.aff-empty-inline {
  padding: 13px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
  list-style: none;
}

/* === Tables === */
.aff-list-wrap { margin-top: 16px; overflow-x: auto; }
.aff-table { width: 100%; border-collapse: collapse; }
.aff-table th {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 9px;
  letter-spacing: .05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.aff-table td { padding: 12px 10px; border-bottom: 1px solid var(--line-soft); font-size: 11px; vertical-align: middle; }
.aff-table tr:last-child td { border-bottom: 0; }
.aff-table-compact td { padding: 9px 8px; }
.aff-amount-eligible { color: var(--acc-deep); font-weight: 650; }
.aff-amount-negative { color: var(--negative); font-weight: 650; }
.aff-record-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 650 12px/1.25 inherit;
  text-align: left;
  cursor: pointer;
}
.aff-record-button:hover { color: var(--acc-deep); }
.aff-record-button:focus-visible,
.aff-icon-button:focus-visible,
.aff-row-actions summary:focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; }
.aff-record-secondary { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 9px; }

/* === Chips === */
.aff-chip {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--acc-soft);
  color: var(--acc-deep);
  font-size: 9px;
  font-weight: 650;
  text-transform: capitalize;
}
.aff-chip.is-paid,
.aff-chip.is-active { background: var(--positive-soft); color: var(--positive); }
.aff-chip.is-held,
.aff-chip.is-paused { background: var(--warning-soft); color: var(--warning); }
.aff-chip.is-void,
.aff-chip.is-archived { background: var(--line-soft); color: var(--ink-soft); }

/* === Dialogs === */
.aff-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(880px, calc(100dvh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(15, 23, 42, .24);
}
.aff-detail-dialog { width: min(1180px, calc(100vw - 32px)); }
.aff-dialog::backdrop { background: rgba(13, 15, 20, .48); backdrop-filter: blur(3px); }
.aff-dialog > form,
.aff-dialog > .aff-dialog-header,
.aff-dialog > .aff-detail-state,
.aff-dialog > #partnerDetail { padding: 22px 24px; }
.aff-dialog > form > .aff-dialog-header { margin: -22px -24px 19px; padding: 22px 24px 17px; border-bottom: 1px solid var(--line); }
.aff-dialog > .aff-dialog-header {
  position: sticky;
  z-index: 3;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(14px);
}
.aff-dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.aff-dialog-header h2 { font: 600 21px/1.15 'Space Grotesk', sans-serif; letter-spacing: -.025em; }
.aff-dialog-header p { margin-top: 6px; color: var(--ink-dim); font-size: 11px; line-height: 1.45; }
.aff-icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-dim);
  font: 400 23px/1 sans-serif;
  cursor: pointer;
}
.aff-icon-button:hover { border-color: var(--ink-soft); color: var(--ink); }

.aff-fieldset {
  min-width: 0;
  margin-top: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.aff-fieldset legend {
  padding: 0 6px;
  color: var(--ink-dim);
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.aff-form-status { min-height: 18px; margin-top: 12px; color: var(--ink-dim); font-size: 11px; }
.aff-form-status.is-error { color: var(--negative); }
.aff-form-status.is-success { color: var(--positive); }

/* === Detail panel === */
.aff-detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .85fr); gap: 14px; align-items: start; }
.aff-detail-main,
.aff-detail-side { display: grid; gap: 12px; min-width: 0; }
.aff-detail-card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.aff-detail-card h3 { margin-bottom: 11px; font: 600 14px/1.2 'Space Grotesk', sans-serif; }
.aff-detail-card .hint { margin: -4px 0 12px; color: var(--ink-dim); font-size: 10px; line-height: 1.5; }
.aff-detail-card .helper { color: var(--ink-soft); font-size: 10px; line-height: 1.5; }

.aff-inline-form { display: grid; gap: 10px; }
.aff-inline-form .grid { gap: 9px; }
.aff-inline-form .field input,
.aff-inline-form .field select,
.aff-inline-form .field textarea { padding: 8px 10px; }
.aff-inline-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.aff-inline-actions .btn-primary,
.aff-inline-actions .btn-secondary { padding: 8px 12px; font-size: 11px; }
.aff-action-status { flex: 1; min-height: 16px; color: var(--ink-soft); font-size: 9px; line-height: 1.35; }

.aff-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 11px;
  list-style: none;
}
.aff-meta-row-wide { margin-top: 0; gap: 10px 26px; }
.aff-meta-row li { min-width: 84px; }
.aff-meta-row span { display: block; color: var(--ink-soft); font-size: 9px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.aff-meta-row strong { display: block; margin-top: 4px; font-size: 12px; }

/* === Codes === */
.aff-code-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line-soft);
}
.aff-code-card + .aff-code-card { margin-top: 9px; }
.aff-code-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.aff-code-head strong { font: 500 12px/1.2 'JetBrains Mono', ui-monospace, monospace; }
.aff-code-head span { display: block; margin-top: 4px; color: var(--ink-dim); font-size: 10px; }
.aff-share-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 11px; }
.aff-share-row input {
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-dim);
  font: 400 10px/1.4 'JetBrains Mono', ui-monospace, monospace;
}
.aff-share-row .btn-secondary { min-height: 36px; padding-inline: 12px; font-size: 11px; }

.aff-row-actions { margin-top: 11px; }
.aff-row-actions > summary {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-dim);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
}
.aff-row-actions > summary::-webkit-details-marker { display: none; }
.aff-row-actions > summary:hover { border-color: var(--ink-soft); color: var(--ink); }
.aff-row-actions[open] > summary { margin-bottom: 10px; border-color: var(--acc-dim); color: var(--acc-deep); background: var(--acc-soft); }

.aff-mini-form {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.aff-mini-form + .aff-mini-form { margin-top: 8px; }
.aff-mini-label { color: var(--ink-soft); font-size: 9px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.aff-mini-form input,
.aff-mini-form select {
  min-width: 0;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
}
.aff-mini-form input:focus,
.aff-mini-form select:focus { outline: 2px solid var(--acc); outline-offset: 1px; }
.aff-mini-form button { min-height: 34px; }
.aff-mini-form .aff-action-status { flex: none; }

/* === Members === */
.aff-member-list { display: grid; gap: 9px; list-style: none; }
.aff-member-row {
  display: grid;
  gap: 8px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--line-soft);
}
.aff-member-row strong { display: block; font-size: 11px; overflow-wrap: anywhere; }
.aff-member-row span { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 9px; }
.aff-member-form { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.aff-member-form .aff-action-status { grid-column: 1 / -1; }
.aff-member-add { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

.aff-preview-list { display: grid; gap: 5px; margin-top: 10px; list-style: none; }
.aff-preview-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--line-soft);
}
.aff-preview-list span { color: var(--ink-soft); font: 400 9px/1.5 'JetBrains Mono', ui-monospace, monospace; }
.aff-preview-list strong { font-size: 10px; text-align: right; overflow-wrap: anywhere; }

.aff-mini-list { display: grid; gap: 7px; list-style: none; }
.aff-mini-list li { padding: 10px; border-radius: 9px; background: var(--line-soft); }
.aff-mini-list strong,
.aff-mini-list span,
.aff-mini-list small { display: block; }
.aff-mini-list strong { font: 500 11px/1.2 'JetBrains Mono', ui-monospace, monospace; }
.aff-mini-list span { margin-top: 4px; color: var(--ink-dim); font-size: 10px; }
.aff-mini-list small { margin-top: 4px; color: var(--ink-soft); font-size: 9px; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media (max-width: 1180px) {
  .aff-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .aff-detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  .aff-header,
  .aff-section-heading,
  .aff-workspace-top { align-items: stretch; flex-direction: column; }
  .aff-header-actions button { width: 100%; min-height: 44px; }
  .aff-search-field { flex: 1 1 auto; }
  .aff-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .aff-workspace { margin-inline: -2px; padding: 15px 12px; border-radius: 14px; }
  .aff-list-wrap { overflow: visible; }
  .aff-table,
  .aff-table tbody,
  .aff-table tr,
  .aff-table td { display: block; width: 100%; }
  .aff-table thead { display: none; }
  .aff-table tr { padding: 13px; border: 1px solid var(--line); border-radius: 11px; }
  .aff-table tr + tr { margin-top: 8px; }
  .aff-table td { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border: 0; text-align: right; }
  .aff-table td::before { content: attr(data-label); flex: 0 0 auto; color: var(--ink-soft); font-size: 9px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
  .aff-table td:first-child { display: block; padding-bottom: 10px; text-align: left; }
  .aff-table td:first-child::before { display: none; }
  .aff-dialog,
  .aff-detail-dialog {
    width: 100vw;
    max-width: none;
    max-height: calc(100dvh - 10px);
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
  }
  .aff-dialog > form,
  .aff-dialog > .aff-dialog-header,
  .aff-dialog > .aff-detail-state,
  .aff-dialog > #partnerDetail { padding: 18px 15px; }
  .aff-dialog > form > .aff-dialog-header { margin: -18px -15px 17px; padding: 18px 15px 14px; }
  .aff-dialog .field input,
  .aff-dialog .field select,
  .aff-dialog .field textarea { min-height: 44px; font-size: 16px; }
  .aff-share-row { grid-template-columns: minmax(0, 1fr); }
  .aff-share-row .btn-secondary { min-height: 44px; }
  .aff-inline-actions { align-items: stretch; flex-direction: column; }
  .aff-inline-actions button { min-height: 44px; width: 100%; }
  .aff-member-form { grid-template-columns: minmax(0, 1fr); }
  .aff-member-form button { min-height: 44px; }
}
