/* ==========================================================
   Training document — athletes table

   This file is the single visual owner of the athletes grid.
   The table keeps the generic .data-table class only for the ERP
   column-resizer/colgroup behavior; ui-components.css explicitly
   excludes this table from generic .data-table visual rules.
   ========================================================== */

.training-athletes-table-card {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--ui-border-soft);
  border-radius: var(--ui-card-radius);
  background: var(--ui-surface);
  box-shadow: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.training-athletes-table {
  --training-table-font-size: 13px;
  --training-table-line-height: 16px;
  --training-table-head-height: 30px;
  --training-table-row-height: 30px;
  --training-table-cell-padding-x: 8px;

  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  color: var(--ui-text);
  font-size: var(--training-table-font-size);
  line-height: var(--training-table-line-height);
}

.training-athletes-table th,
.training-athletes-table td {
  box-sizing: border-box;
  vertical-align: middle;
  font-size: var(--training-table-font-size);
  line-height: var(--training-table-line-height);
}

.training-athletes-table th {
  height: var(--training-table-head-height);
  padding: 3px var(--training-table-cell-padding-x);
  background: var(--ui-header-bg);
  border-bottom: 1px solid var(--ui-border);
  color: #4b5563;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.training-athletes-table td {
  height: var(--training-table-row-height);
  padding: 2px var(--training-table-cell-padding-x);
  background: #fff;
  border-bottom: 1px solid var(--ui-border-soft);
}

.training-athletes-table tbody tr:last-child td {
  border-bottom: 0;
}

.training-athletes-table tbody tr:hover td {
  background: var(--ui-row-hover);
}

/* Initial widths before erpTables.js creates the persistent <colgroup>. */
.training-athletes-table th:first-child,
.training-athletes-table td:first-child {
  min-width: 260px;
}

.training-athletes-table th:nth-child(2),
.training-athletes-table td:nth-child(2) {
  min-width: 360px;
}

.training-athletes-table th:nth-child(3),
.training-athletes-table td:nth-child(3) {
  width: 82px;
  min-width: 82px;
  text-align: center;
}

.training-athletes-table th:nth-child(4),
.training-athletes-table td:nth-child(4),
.training-athletes-table th:nth-child(5),
.training-athletes-table td:nth-child(5) {
  width: 96px;
  min-width: 96px;
  text-align: center;
}

/* Compact business-action columns. Default widths may differ, but every
   resizable training column follows the shared 50 px minimum. */
.training-athletes-table .training-sales-heading,
.training-athletes-table .training-athlete-sales-cell {
  width: 84px;
  min-width: 50px;
  white-space: nowrap;
}

.training-athletes-table .training-payments-heading,
.training-athletes-table .training-athlete-payments-cell {
  width: 132px;
  min-width: 50px;
  white-space: nowrap;
}

.training-athletes-table .training-actions-heading,
.training-athletes-table .training-athlete-actions-cell {
  width: 88px;
  min-width: 50px;
  white-space: nowrap;
}

.training-athletes-table .training-athlete-sales-cell,
.training-athletes-table .training-athlete-actions-cell {
  text-align: center;
}

.training-athletes-table .training-athlete-payments-cell {
  text-align: left;
}

/* Once ERP columns are initialized, <col> owns the width. */
.erp-columns-ready.training-athletes-table .training-sales-heading,
.erp-columns-ready.training-athletes-table .training-athlete-sales-cell,
.erp-columns-ready.training-athletes-table .training-payments-heading,
.erp-columns-ready.training-athletes-table .training-athlete-payments-cell,
.erp-columns-ready.training-athletes-table .training-actions-heading,
.erp-columns-ready.training-athletes-table .training-athlete-actions-cell {
  min-width: 0 !important;
}

.data-table.erp-columns-ready.training-athletes-table td.training-athlete-sales-cell,
.data-table.erp-columns-ready.training-athletes-table td.training-athlete-payments-cell,
.data-table.erp-columns-ready.training-athletes-table td.training-athlete-actions-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table.erp-columns-ready.training-athletes-table td.training-athlete-sales-cell,
.data-table.erp-columns-ready.training-athletes-table td.training-athlete-actions-cell {
  text-align: center;
}

.data-table.erp-columns-ready.training-athletes-table td.training-athlete-payments-cell {
  text-align: left;
}

/* Athlete name */
.training-athletes-table .training-athlete-open,
.training-athletes-table .table-link {
  padding: 0;
  min-height: 0;
  color: #244fc4;
  font-size: inherit;
  line-height: inherit;
  font-weight: 500;
  text-align: left;
  vertical-align: baseline;
}

.training-athletes-table .table-link:hover {
  text-decoration: underline;
}

/* Billing preview */
.training-athletes-table .training-billing-cell {
  white-space: nowrap;
}

.training-athletes-table .training-billing-main {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
  white-space: nowrap;
  font-size: inherit;
  line-height: inherit;
}

.training-athletes-table .training-billing-cell .muted {
  display: inline;
  margin-top: 0;
}

.training-athletes-table .training-billing-inline-detail,
.training-athletes-table .training-billing-inline-balance,
.training-athletes-table .training-billing-hint {
  font-size: inherit;
  line-height: inherit;
}

.training-athletes-table .training-billing-inline-balance {
  font-weight: 600;
}

.training-athletes-table .training-billing-inline-balance.debt {
  color: #9b2c2c;
}

.training-athletes-table .training-billing-inline-balance.advance {
  color: #24713b;
}

.training-athletes-table .training-billing-inline-balance.zero {
  color: #5e6877;
}

/* Badges use the same text height as every other cell. */
.training-athletes-table .billing-badge,
.training-athletes-table .training-shoe-state-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: inherit;
  line-height: inherit;
  font-weight: 600;
  white-space: nowrap;
}

.training-athletes-table .training-billing-type-badge {
  box-sizing: border-box;

  width: 112px;
  min-width: 112px;
  max-width: 112px;

  justify-content: center;
  text-align: center;
}

.training-athletes-table .billing-badge.subscription {
  background: #e8f7ed;
  color: #24713b;
}

.training-athletes-table .billing-badge.casual {
  background: #fff4df;
  color: #8a5a00;
}

/* Default / exceptional shoe state */
.training-athletes-table .training-shoe-state-cell,
.training-athletes-table .training-shoe-flag-cell {
  text-align: center;
}

.training-athletes-table .training-shoe-state-badge.own {
  background: #f1f3f6;
  color: #4f5b6b;
}

.training-athletes-table .training-shoe-state-badge.rental {
  background: #eaf2ff;
  color: #315f9f;
}

.training-athletes-table .training-shoe-state-badge.pending {
  background: #f7f8fa;
  color: #8a94a3;
}

.training-athletes-table .training-shoe-checkbox-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}

.training-athletes-table .training-shoe-checkbox-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.training-athletes-table .training-shoe-checkbox-wrap input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.training-athletes-table .training-shoe-checkbox-wrap:has(input:disabled) {
  cursor: not-allowed;
  opacity: .55;
}

.training-athletes-table .training-shoe-checkbox-caption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Row actions: one visual language, semantic color by column. */
.training-athletes-table .training-athlete-sales-cell .button,
.training-athletes-table .training-athlete-payments-cell .button {
  height: 24px;
  min-height: 24px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: inherit;
  line-height: inherit;
  font-weight: 500;
  vertical-align: middle;
}

.training-athletes-table .training-athlete-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
}

.training-athletes-table .training-athlete-action-icon + .training-athlete-action-icon {
  margin-left: 4px;
}

/* Sales = green. */
.training-athletes-table .training-athlete-sales-cell .training-athlete-action-icon {
  border-color: #86d293;
  background: #f0fbf2;
  color: #187a32;
}

.training-athletes-table .training-athlete-sales-cell .training-athlete-action-icon:hover {
  border-color: #55b86b;
  background: #e2f7e6;
  color: #116527;
}

/* Payments = orange. */
.training-athletes-table .training-athlete-payments-cell .training-athlete-action-icon {
  border-color: #f3b56b;
  background: #fff7ed;
  color: #c65a0a;
}

.training-athletes-table .training-athlete-payments-cell .training-athlete-action-icon:hover {
  border-color: #e89437;
  background: #ffedd5;
  color: #a84708;
}

.training-action-svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.training-action-plus-one {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  font-size: 12px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.5px;
  pointer-events: none;
}

.training-athletes-table .training-athlete-payments-cell .training-athlete-payment-document-link {
  width: auto;
  max-width: 100%;
  padding: 0 9px 0 4px;
  gap: 3px;
  text-decoration: none;
}

.training-athletes-table .training-athlete-payment-amount {
  display: inline-block;
  min-width: 4ch;
  text-align: right;
  font-size: 12px;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ==========================================================
   Inline athlete adding / row removal
   ========================================================== */

.training-athletes-table .training-athlete-add-row td {
  height: var(--training-table-row-height);
  padding: 2px var(--training-table-cell-padding-x);
  background: #f7f8fa;
  border-bottom: 0;
}

.training-athletes-table .training-athlete-add-row:hover td {
  background: #f2f4f7;
}

.training-athletes-table .training-athlete-add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  height: 24px;
  min-height: 24px;
  padding: 0 8px;

  border: 1px solid #cfd5dd;
  border-radius: 4px;

  background: #fff;
  color: #344054;

  font: inherit;
  line-height: inherit;
  font-weight: 500;

  cursor: pointer;
}

.training-athletes-table .training-athlete-add-button:hover {
  background: #f9fafb;
  border-color: #b8c0cc;
  color: #202936;
  text-decoration: none;
}

.training-athletes-table .training-athlete-add-button:active {
  background: #f2f4f7;
}

.training-athletes-table .training-athlete-add-button:disabled {
  background: #f2f4f7;
  border-color: #e1e5ea;
  color: #98a2b3;
  cursor: default;
  opacity: 1;
}

.training-athletes-table .training-athlete-draft-row td {
  background: #fff;
}

.training-athletes-table .training-athlete-search-cell {
  overflow: visible !important;
}

.training-athletes-table .training-athlete-inline-search-wrap {
  position: relative;
  width: 170px;
  max-width: 170px;
  margin: 0;
}

.training-athletes-table .training-athlete-inline-search {
  width: 100%;
  height: 24px;
  min-height: 24px;
  padding: 2px 6px;
  border: 1px solid #cfd5dd;
  border-radius: 4px;
  background: #fff;
  color: var(--ui-text);
  font: inherit;
  line-height: inherit;
  outline: none;
}

.training-athletes-table .training-athlete-inline-search:focus {
  border-color: #3157d5;
  box-shadow: 0 0 0 2px rgba(49, 87, 213, .10);
}

.training-athletes-table .training-athlete-search-results {
  top: calc(100% + 2px);
  max-height: 280px;
  font-size: var(--training-table-font-size);
  line-height: var(--training-table-line-height);
}

.training-athletes-table .training-athlete-search-result {
  min-height: 32px;
  padding: 5px 8px;
  font-size: inherit;
  line-height: inherit;
}

.training-athletes-table .training-athlete-draft-empty {
  color: transparent;
}

.training-athletes-table .training-athlete-remove-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border: 1px solid #efa09a;
  border-radius: 4px;
  background: #fff5f4;
  color: #d92d20;
  font-family: inherit;
  font-size: 18px;
  line-height: 18px;
  font-weight: 500;
  cursor: pointer;
  vertical-align: middle;
}

.training-athletes-table .training-athlete-remove-icon:hover {
  border-color: #df746b;
  background: #ffe9e7;
  color: #b42318;
}

/* ===== TRAINER HEADER COMPACT START ===== */

/*
   Trainer row is a self-contained component.
   Legacy trainer-header rules were removed from app.css/ui-components.css.
*/
.training-trainer-group-header {
  box-sizing: border-box;

  display: grid;
  grid-template-columns:
    24px
    240px
    minmax(0, 1fr)
    auto;

  align-items: center;
  gap: 6px;

  height: 34px;
  min-height: 34px;
  max-height: 34px;

  padding: 2px 8px;

  background: var(--ui-header-bg);
  border-radius:
    var(--ui-card-radius)
    var(--ui-card-radius)
    0
    0;
}

.training-trainer-group-header .training-group-toggle {
  box-sizing: border-box;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;

  padding: 0;
  margin: 0;

  border: 0;
  border-radius: 4px;

  background: transparent;
  color: #526070;

  cursor: pointer;

  font-size: 13px;
  line-height: 16px;
}

.training-trainer-group-header .training-group-toggle:hover {
  background: #eef2f6;
}

.training-trainer-group-header
.training-group-trainer-control {
  display: flex;
  align-items: center;

  min-width: 0;
  min-height: 0;

  gap: 6px;
}

.training-trainer-group-header
.training-group-caption {
  flex: 0 0 auto;

  margin: 0;

  color: var(--ui-muted);

  font-size: 13px;
  line-height: 16px;
  font-weight: 500;

  text-transform: none;
  white-space: nowrap;
}

.training-trainer-group-header
.training-group-trainer-select {
  box-sizing: border-box;

  width: 100%;
  max-width: none;

  height: 28px;
  min-height: 28px;

  margin: 0;
  padding: 0 28px 0 8px;

  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;

  background: #fff;
  color: var(--ui-text);

  font-size: 13px;
  line-height: 16px;
}

.training-trainer-group-header
.training-group-trainer-name {
  margin: 0;

  font-size: 13px;
  line-height: 16px;
  font-weight: 500;

  white-space: nowrap;
}

.training-trainer-group-header
.training-group-summary {
  display: flex;
  align-items: center;
  justify-content: flex-end;

  gap: 6px;

  width: auto;
  min-width: 0;
  min-height: 0;

  justify-self: end;
  white-space: nowrap;
}

.training-trainer-group-header
.training-group-count,
.training-trainer-group-header
.training-trainer-money-summary {
  margin: 0;

  font-size: 13px;
  line-height: 16px;

  white-space: nowrap;
}

.training-trainer-group-header
.training-group-count {
  flex: 0 0 auto;

  color: #526070;
  font-weight: 600;
}

.training-trainer-group-header
.training-trainer-money-summary {
  min-width: 0;
  max-width: none;

  overflow: visible;

  font-weight: 400;
  text-align: right;
}

.training-trainer-group-header
.training-group-count
+ .training-trainer-money-summary::before {
  content: "·";
  margin-right: 6px;
  color: var(--ui-muted);
}

.training-trainer-group-header
.training-group-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;

  gap: 4px;

  min-height: 0;

  justify-self: end;
  white-space: nowrap;
}

.training-trainer-group-header
.training-group-header-actions
.training-trainer-payment-button {
  box-sizing: border-box;

  height: 28px;
  min-height: 28px;

  width: 28px;
  min-width: 28px;

  padding: 0;

  border-radius: 4px;

  font-size: 13px;
  line-height: 16px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  border-color: #f3b56b;
  background: #fff7ed;
  color: #c65a0a;
}

.training-trainer-group-header
.training-group-header-actions
.training-trainer-payment-button:hover {
  border-color: #e89437;
  background: #ffedd5;
  color: #a84708;
}

.training-trainer-group-header
.training-group-remove-icon {
  box-sizing: border-box;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;

  padding: 0;
  margin: 0;

  border: 1px solid #efa09a;
  border-radius: 4px;

  background: #fff5f4;
  color: #d92d20;

  font-family: inherit;
  font-size: 18px;
  line-height: 18px;
  font-weight: 500;

  cursor: pointer;
}

.training-trainer-group-header
.training-group-remove-icon:hover {
  border-color: #df746b;
  background: #ffe9e7;
  color: #b42318;
}

/* ===== TRAINER HEADER COMPACT END ===== */

/* ===== TRAINING RESPONSIVE NARROW START ===== */

/*
   Узкий desktop / tablet.
   Строка тренера становится двухстрочной.
   Таблица спортсменов остаётся таблицей и прокручивается по горизонтали.
*/
@media (max-width: 1100px) {

  .training-trainer-group-header {
    grid-template-columns:
      24px
      minmax(0, 1fr)
      auto;

    grid-template-rows:
      28px
      auto;

    grid-template-areas:
      "toggle trainer actions"
      ". summary summary";

    height: auto;
    min-height: 58px;
    max-height: none;

    padding: 3px 8px;

    column-gap: 6px;
    row-gap: 2px;

    align-items: center;
  }

  .training-trainer-group-header
  .training-group-toggle {
    grid-area: toggle;
  }

  .training-trainer-group-header
  .training-group-trainer-control {
    grid-area: trainer;

    min-width: 0;
  }

  .training-trainer-group-header
  .training-group-trainer-select {
    width: 100%;
    max-width: 170px;
    min-width: 0;
  }

  .training-trainer-group-header
  .training-group-summary {
    grid-area: summary;

    width: 100%;
    min-width: 0;

    justify-self: stretch;
    justify-content: flex-end;

    overflow: visible;

    white-space: nowrap;
  }

  .training-trainer-group-header
  .training-group-header-actions {
    grid-area: actions;

    flex: 0 0 auto;
  }


  /*
     На узком экране первая колонка занимает четверть viewport и
     остаётся закреплённой. Её ручка скрыта: остальные колонки
     продолжают пользоваться общей сквозной сеткой.
  */
  .training-athletes-table th:first-child,
  .training-athletes-table td:first-child {
    width: 25vw !important;
    min-width: 25vw !important;
    max-width: 25vw !important;
  }

  .training-athletes-table
  th:first-child
  > .erp-column-resizer {
    display: none;
  }

  /*
     При горизонтальной прокрутке имя спортсмена
     остаётся перед глазами.
  */

  .training-athletes-table
  thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 4;

    background: var(--ui-header-bg);

    box-shadow:
      1px 0 0 var(--ui-border-soft);
  }

  .training-athletes-table
  tbody
  .training-athlete-row
  td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;

    background: #fff;

    box-shadow:
      1px 0 0 var(--ui-border-soft);
  }

  .training-athletes-table
  tbody
  .training-athlete-row:hover
  td:first-child {
    background: var(--ui-row-hover);
  }

  .training-athletes-table
  .training-athlete-open {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}


/*
   Пока это ещё не мобильная карточная версия.
   На совсем узком экране просто разрешаем финансовой
   строке тренера перенестись, чтобы ничего не пересекалось.
*/
@media (max-width: 700px) {

  .training-trainer-group-header {
    min-height: 64px;
  }

  .training-trainer-group-header
  .training-group-summary {
    flex-wrap: wrap;

    justify-content: flex-start;

    white-space: normal;

    column-gap: 6px;
    row-gap: 0;
  }

  .training-trainer-group-header
  .training-group-count,
  .training-trainer-group-header
  .training-trainer-money-summary {
    white-space: nowrap;
  }
}

/* ===== TRAINING RESPONSIVE NARROW END ===== */


