/**
 * Shared phone card-stack for wide tables.
 * One place for mentee docs, practice, BSL ref, portal, legal, HH sheets.
 * Load after site-tokens / domain CSS. Version via TABLE_CARDS_CSS_VERSION.
 */

@media (max-width: 640px) {
  /* --- wraps: drop desktop scroll chrome when rows become cards --- */
  .mentee-doc-table-wrap,
  .guide-lab-theory > .mentee-doc-table-wrap,
  .guide-lab-theory .guide-lab-theme > .mentee-doc-table-wrap,
  .practice-markdown-table-wrap,
  .public-legal .offer-table-wrap,
  .coa-table-wrap {
    overflow-x: visible;
    border: none;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  /* --- core card table family --- */
  .mentee-doc-table,
  .bsl-ref-page .bsl-ref-table,
  .bsl-ref-embed .bsl-ref-table,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table,
  .practice-markdown-table,
  .practice-download-kbd-table,
  .public-legal .offer-table:not(.offer-table--inner),
  .hh-sheet,
  .portal-guide-keymap,
  .portal-crm-pay-table,
  .podpis-sum-table,
  .coa-table {
    min-width: 0;
    width: 100%;
    display: block;
    font-size: 0.9375rem;
    line-height: 1.5;
  }

  .coa-table,
  .portal-guide-keymap,
  .portal-crm-pay-table,
  .podpis-sum-table {
    font-size: 0.92rem;
    line-height: 1.45;
  }

  .public-legal .offer-table:not(.offer-table--inner) {
    font-size: 0.95rem;
  }

  .mentee-doc-table thead,
  .bsl-ref-page .bsl-ref-table thead,
  .bsl-ref-embed .bsl-ref-table thead,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table thead,
  .practice-markdown-table thead,
  .practice-download-kbd-table thead,
  .public-legal .offer-table:not(.offer-table--inner) thead,
  .hh-sheet thead,
  .portal-guide-keymap thead,
  .portal-crm-pay-table thead,
  .podpis-sum-table thead,
  .coa-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .mentee-doc-table tbody,
  .bsl-ref-page .bsl-ref-table tbody,
  .bsl-ref-embed .bsl-ref-table tbody,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table tbody,
  .practice-markdown-table tbody,
  .practice-download-kbd-table tbody,
  .public-legal .offer-table:not(.offer-table--inner) tbody,
  .hh-sheet tbody,
  .portal-guide-keymap tbody,
  .portal-crm-pay-table tbody,
  .podpis-sum-table tbody,
  .coa-table tbody {
    display: block;
  }

  .mentee-doc-table tr,
  .bsl-ref-page .bsl-ref-table tr,
  .bsl-ref-embed .bsl-ref-table tr,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table tr,
  .practice-markdown-table tr,
  .practice-download-kbd-table tr,
  .public-legal .offer-table:not(.offer-table--inner) tr,
  .hh-sheet tr,
  .portal-guide-keymap tr,
  .portal-crm-pay-table tr,
  .podpis-sum-table tr,
  .coa-table tr {
    display: block;
    margin: 0 0 0.7rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid color-mix(in srgb, var(--color-text, #132033) 14%, var(--color-border, #d5dbe3));
    border-radius: var(--radius-md, 0.65rem);
    background: var(--color-surface, #fff);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
  }

  .portal-guide-keymap tr,
  .portal-crm-pay-table tr,
  .podpis-sum-table tr {
    border-color: var(--portal-line, var(--color-border, #d5dbe3));
    border-radius: 10px;
    background: var(--portal-card, var(--color-surface, #fff));
    box-shadow: none;
    margin-bottom: 0.65rem;
    padding: 0.65rem 0.75rem;
  }

  .mentee-doc-table tbody tr:nth-child(even),
  .mentee-doc-table tbody tr:nth-child(odd),
  .mentee-doc-table tbody tr:hover,
  .practice-markdown-table tbody tr:nth-child(even) td,
  .practice-markdown-table tbody tr:nth-child(odd) td {
    background: var(--color-surface, #fff);
  }

  .practice-markdown-table tbody tr:nth-child(even) td,
  .practice-markdown-table tbody tr:nth-child(odd) td {
    background: transparent;
  }

  .mentee-doc-table th,
  .mentee-doc-table td,
  .bsl-ref-page .bsl-ref-table th,
  .bsl-ref-page .bsl-ref-table td,
  .bsl-ref-embed .bsl-ref-table th,
  .bsl-ref-embed .bsl-ref-table td,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table th,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table td,
  .practice-markdown-table th,
  .practice-markdown-table td,
  .practice-download-kbd-table th,
  .practice-download-kbd-table td,
  .public-legal .offer-table:not(.offer-table--inner) th,
  .public-legal .offer-table:not(.offer-table--inner) td,
  .hh-sheet th,
  .hh-sheet td,
  .portal-guide-keymap th,
  .portal-guide-keymap td,
  .portal-crm-pay-table th,
  .portal-crm-pay-table td,
  .coa-table th,
  .coa-table td {
    display: block;
    width: auto !important;
    min-width: 0 !important;
    border: none !important;
    padding: 0.18rem 0;
    white-space: normal !important;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .podpis-sum-table th,
  .podpis-sum-table td {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    width: auto;
    border: none;
    padding: 0.15rem 0;
    white-space: normal;
    word-break: break-word;
    color: var(--color-text);
  }

  .mentee-doc-table td:first-child,
  .mentee-doc-table th:first-child,
  .bsl-ref-page .bsl-ref-table td:first-child,
  .bsl-ref-page .bsl-ref-table th:first-child,
  .bsl-ref-embed .bsl-ref-table td:first-child,
  .bsl-ref-embed .bsl-ref-table th:first-child,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table td:first-child,
  main.mentee-guide-main article.mentee-doc .bsl-ref-embed .bsl-ref-table th:first-child,
  .practice-markdown-table td:first-child,
  .practice-markdown-table th:first-child,
  .practice-download-kbd-table td:first-child,
  .practice-download-kbd-table th:first-child,
  .hh-sheet td:first-child,
  .portal-guide-keymap:not(.portal-guide-sum-table) td:first-child,
  .portal-guide-keymap:not(.portal-guide-sum-table) th:first-child,
  .portal-crm-pay-table td:first-child,
  .portal-crm-pay-table th:first-child {
    font-weight: 650;
    margin-bottom: 0.15rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid color-mix(in srgb, var(--color-text, #132033) 12%, var(--color-border, #d5dbe3)) !important;
  }

  .public-legal .offer-table:not(.offer-table--inner) th {
    font-weight: 700;
    margin-bottom: 0.15rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--color-border, #d5dbe3) !important;
  }

  .mentee-doc-table.mentee-doc-num-table {
    min-width: 0;
  }

  /* --- installment grids: restore column names after thead hide --- */
  .portal-guide-sum-table td {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
  }

  .portal-guide-sum-table td::before,
  .podpis-sum-table td::before {
    flex: 0 0 5.75rem;
    font-weight: 650;
    color: var(--portal-muted, var(--color-text-muted, #5b6b6b));
  }

  .portal-guide-sum-table td:nth-child(1)::before,
  .podpis-sum-table td:nth-child(1)::before {
    content: "Месяцев";
  }

  .portal-guide-sum-table td:nth-child(2)::before,
  .podpis-sum-table td:nth-child(2)::before {
    content: "Наценка";
  }

  .portal-guide-sum-table td:nth-child(3)::before,
  .podpis-sum-table td:nth-child(3)::before {
    content: "Сумма";
  }

  .portal-guide-sum-table td:nth-child(4)::before,
  .podpis-sum-table td:nth-child(4)::before {
    content: "В месяц";
  }

  /* --- COA extras --- */
  .coa-table {
    font-size: 0.9rem;
  }

  .coa-table tr.coa-section-row {
    padding: 0.55rem 0.8rem;
    background: var(--color-surface-offset);
    box-shadow: none;
  }

  .coa-section-row th {
    text-align: left;
    padding: 0;
  }

  .coa-num {
    width: auto;
    text-align: left;
    font-size: 1rem;
    margin-bottom: 0.1rem;
  }

  .coa-title {
    font-weight: 650;
    margin-bottom: 0.25rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid color-mix(in srgb, var(--color-text) 12%, var(--color-border));
  }

  .coa-type {
    width: auto;
    color: var(--color-text-muted);
    white-space: normal;
  }

  .coa-subs-cell {
    min-width: 0;
    margin-top: 0.35rem;
    padding: 0;
  }

  .coa-subs-table {
    display: table;
    width: 100%;
  }

  .coa-subs-table tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .coa-subs-table td {
    display: table-cell;
    padding: 0.35rem 0.45rem;
    border-bottom: 1px solid var(--color-border);
    width: auto !important;
  }

  /* --- legal signature block --- */
  .public-legal .dogovor-sign {
    display: block;
    width: 100%;
    font-size: 0.95rem;
    line-height: 1.5;
  }

  .public-legal .dogovor-sign tbody {
    display: block;
  }

  .public-legal .dogovor-sign tr {
    display: block;
  }

  .public-legal .dogovor-sign th,
  .public-legal .dogovor-sign td {
    display: block;
    width: 100% !important;
    box-sizing: border-box;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 0.65rem);
    margin: 0 0 0.65rem;
    padding: 0.7rem 0.8rem;
    white-space: normal;
    word-break: break-word;
  }

  .public-legal .dogovor-sign tr:first-child th {
    font-weight: 700;
    background: var(--color-surface-offset);
  }

  /* --- intentional scroll leftovers --- */
  .public-legal .offer-table--inner {
    font-size: 0.9rem;
  }

  .public-legal .offer-table-wrap:has(.offer-table--inner) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .practice-query-result-table {
    font-size: 0.9rem;
  }
}
