/* ============================================================
   V2 — Registry table (Pattern 01)
   ============================================================
   Велика таблиця реєстру: sticky thead, hover/selected рядки,
   inline-edit клітинки, row-actions on hover, footer з pager.

   Структура:
     <div class="v2-tablewrap">
       <table class="v2-tbl">
         <thead>
           <tr>
             <th class="v2-col-checkbox"><input type="checkbox"></th>
             <th>№ договору</th>
             <th>Здобувач</th>
             …
           </tr>
         </thead>
         <tbody>
           <tr>
             <td class="v2-col-checkbox"><input type="checkbox"></td>
             <td class="v2-col-num">253/О</td>
             <td>
               <div class="v2-cell-name-primary">Ковальчук Софія</div>
               <div class="v2-cell-name-sub">SGE · 3-А</div>
             </td>
             …
             <td class="v2-col-actions">
               <div class="v2-row-actions">
                 <button class="v2-btn v2-btn-icon v2-btn-sm">…</button>
               </div>
             </td>
           </tr>
         </tbody>
       </table>
       <footer class="v2-tablefoot">
         <span>Рядки 1–50 з 619</span>
         <nav class="v2-pager">…</nav>
       </footer>
     </div>
   ============================================================ */

/* box-sizing reset */
.v2-tablewrap,
.v2-tablewrap *,
.v2-tablewrap *::before,
.v2-tablewrap *::after {
    box-sizing: border-box;
}

/* ============================================================
   WRAPPER (card)
   ============================================================ */
.v2-tablewrap {
    --v2-table-header-bg: color-mix(in srgb, var(--bg-subtle) 68%, var(--bg-card));
    --v2-table-separator: color-mix(in srgb, var(--border-subtle) 72%, transparent);
    --v2-table-frame-border: color-mix(in srgb, var(--border-light) 86%, transparent);

    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-color: var(--v2-table-frame-border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-xs-v2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Attached to a toolbar: keep a compact gap and rounded visible table corners. */
.v2-tablewrap-attached-top {
    margin-top: var(--s-2);
    border-top-color: var(--v2-table-frame-border);
    border-top-left-radius: var(--r-md);
    border-top-right-radius: var(--r-md);
}

/* Внутрішній скрол-контейнер для sticky thead */
.v2-tablewrap-scroll {
    flex: 1;
    overflow: auto;
    /* тонкий scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border-default) transparent;
}
.v2-tablewrap-scroll::-webkit-scrollbar { height: 8px; width: 8px; }
.v2-tablewrap-scroll::-webkit-scrollbar-track { background: transparent; }
.v2-tablewrap-scroll::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: var(--r-pill); }

/* Registry screens use a fixed viewport: the page itself should not scroll,
   only the inner table list scrolls between toolbar and footer. */
.v2-registry-page {
    height: calc(100vh - var(--v2-topbar-height));
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.v2-registry-page > * {
    flex-shrink: 0;
}
/* Тільки прямий нащадок: `flex: 1 1 0` має сенс у флекс-колонці сторінки, а
   в будь-якому іншому місці базис 0 просто складає таблицю в нуль. Саме так
   зникали врізки в панелях і таблиця, загорнута у <form>: у DOM рядки є, а
   висота нульова. */
.v2-registry-page > .v2-tablewrap {
    flex: 1 1 0;
    min-height: 0;
}
.v2-registry-page > .v2-tablewrap > .v2-tablewrap-scroll {
    flex: 1 1 0;
    min-height: 0;
    /* stylelint-disable-next-line declaration-no-important -- скидає інлайновий max-height з попап-режиму колонок */
    max-height: none !important;
}
.v2-registry-page .v2-tablefoot {
    flex-shrink: 0;
}

/* ============================================================
   TABLE
   ============================================================ */
.v2-tbl {
    width: 100%;
    /* min-width: дозволяє таблиці БУТИ ширшою за свого батька і отримувати
       горизонтальний скрол через .v2-tablewrap-scroll, замість стискатися
       нижче min-content і ламати wrap у вузьких колонках. */
    min-width: 880px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-md);
    color: var(--text-primary);
}

/* === thead (sticky) === */
.v2-tbl thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: left;
    padding: var(--s-3) var(--row-padding-x);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: var(--weight-semibold);
    color: var(--text-tertiary);
    background: var(--v2-table-header-bg);
    border-bottom: 1px solid var(--v2-table-separator);
    white-space: nowrap;
    user-select: none;
}

.v2-tablewrap-attached-top .v2-tbl thead th:first-child {
    border-top-left-radius: var(--r-md);
}

.v2-tablewrap-attached-top .v2-tbl thead th:last-child {
    border-top-right-radius: var(--r-md);
}

.v2-tbl thead th.is-sortable {
    cursor: pointer;
    transition: color 0.12s, background 0.12s;
}
.v2-tbl thead th.is-sortable:hover {
    color: var(--text-primary);
    background: var(--bg-muted);
}
.v2-tbl thead th .sort-arrow {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0.6;
}
.v2-tbl thead th.is-sorted .sort-arrow { opacity: 1; }

/* === tbody === */
.v2-tbl tbody tr {
    transition: background 0.08s;
}
.v2-tbl tbody tr:hover {
    background: var(--bg-hover);
}
.v2-tbl tbody tr.is-selected {
    background: var(--accent-bg);
}
.v2-tbl tbody tr.is-selected:hover {
    background: var(--accent-bg-strong);
}

.v2-tbl tbody td {
    padding: var(--row-padding-y) var(--row-padding-x);
    /* vertical-align: top — щоб одно-рядкові значення (Клас, money, статус)
       не "плавали" по центру коли сусідні клітинки мають 2 рядки (name+sub).
       Усе вирівнюється до верху → візуально читається як одна "стрічка" даних. */
    vertical-align: top;
    border-bottom: 1px solid var(--v2-table-separator);
    height: var(--row-height);
}

.v2-tbl tbody tr:last-child td {
    border-bottom: 0;
}

/* Зебра (опційно через .v2-tbl-zebra) */
.v2-tbl-zebra tbody tr:nth-child(even):not(.is-selected) {
    background: var(--bg-zebra);
}

/* ============================================================
   COLUMN TYPES
   ============================================================ */
.v2-col-checkbox {
    width: 32px;
    padding-left: var(--s-5);
    padding-right: 0;
    text-align: center;
}
.v2-col-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
    vertical-align: middle;
}

.v2-col-num {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    white-space: nowrap;
}

.v2-col-money {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
/* Заголовок грошової колонки має стояти над числом, а не ліворуч від нього:
   `.v2-tbl thead th` вирівнює вліво і за специфічністю перебиває .v2-col-money. */
.v2-tbl thead th.v2-col-money {
    text-align: right;
}
.v2-col-money.is-dim {
    color: var(--text-muted);
}

.v2-col-actions {
    width: 96px;
    text-align: right;
    padding-right: var(--s-5);
    white-space: nowrap;
}

/* Утиліта "стиснути до контенту" — для коротких колонок (клас, статус, рік),
   які за замовчуванням забирають частку auto-layout і виглядають заширокими.
   Трюк width:1% + white-space:nowrap змушує table-layout стиснути колонку
   до природної ширини контенту. */
.v2-col-shrink {
    width: 1%;
    white-space: nowrap;
}

/* ============================================================
   CELL CONTENT (двохрядкові клітинки, money, status)
   ============================================================ */
.v2-cell-name-primary {
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    line-height: var(--leading-tight);
    /* Compact rows: довгі ПІБ обмежуємо 2 рядками з трикрапкою замість 3+,
       щоб рядок реєстру не роздувався до ~80px. Повне ім'я — за кліком (це <a>). */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Кликабельний варіант — `.v2-cell-name-primary` як <a>. Без підкреслення.
   Підказку про клікабельність даємо через колір на hover і cursor: pointer. */
a.v2-cell-name-primary {
    text-decoration: none;
    color: var(--text-primary);
    cursor: pointer;
    display: -webkit-box;
    transition: color 0.12s ease;
}
a.v2-cell-name-primary:hover {
    color: var(--accent);
}
a.v2-cell-name-primary:focus-visible {
    outline: none;
    color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-bg);
    border-radius: var(--r-xs);
}

.v2-cell-name-sub {
    margin-top: 2px;
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    line-height: var(--leading-tight);
}

/* Money em-dash для null значень */
.v2-cell-money-empty::before {
    content: "—";
    color: var(--text-muted);
}

/* ============================================================
   INLINE-EDIT cells
   ============================================================ */
.v2-cell-editable {
    display: inline-block;
    border-radius: var(--r-xs);
    padding: 1px 4px;
    margin: -1px -4px;
    cursor: text;
    /* Короткі labels (клас, рік, статус) не переносяться між рядків при
       стисненні колонки — крім того, hover-bg має лишатись цілою смугою. */
    white-space: nowrap;
    transition: background 0.12s, box-shadow 0.12s;
}
.v2-cell-editable:hover {
    background: var(--bg-muted);
    box-shadow: inset 0 0 0 1px var(--border-default);
}

.v2-cell-edit {
    display: inline-block;
}
.v2-cell-edit input {
    width: 100%;
    min-width: 0;
    padding: 3px 6px;
    border: 1px solid var(--accent);
    border-radius: var(--r-xs);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-md);
    box-shadow: var(--focus-ring);
    outline: none;
}

/* Errored cell */
.v2-cell-edit.is-error input {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(164, 50, 50, 0.18);
}

/* ============================================================
   ROW ACTIONS (видимі на hover)
   ============================================================ */
.v2-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.1s;
}
.v2-tbl tbody tr:hover .v2-row-actions,
.v2-tbl tbody tr.is-selected .v2-row-actions,
.v2-tbl tbody tr:focus-within .v2-row-actions {
    opacity: 1;
}

/* ============================================================
   STATUS PILL у клітинці — re-use .v2-badge без додаткових змін
   (вирівнюємо vertical-align щоб не зміщувало рядок)
   ============================================================ */
.v2-tbl td .v2-badge {
    vertical-align: middle;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.v2-tbl-empty {
    padding: var(--s-12) var(--s-7);
    text-align: center;
    color: var(--text-tertiary);
}
.v2-tbl-empty-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    margin-bottom: var(--s-3);
}
.v2-tbl-empty-hint,
.v2-tbl-empty-sub {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

/* ============================================================
   TABLE FOOTER
   ============================================================ */
.v2-tablefoot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-5);
    padding: var(--s-3) var(--s-5);
    border-top: 1px solid var(--v2-table-separator);
    background: var(--bg-card);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.v2-tablefoot-left,
.v2-tablefoot-right {
    display: inline-flex;
    align-items: center;
    gap: var(--s-4);
}

.v2-tablefoot-center {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
}

.v2-process-hints {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    max-width: min(720px, 100%);
    min-width: 0;
    overflow: hidden;
}

.v2-process-hint {
    display: inline-flex;
    align-items: center;
    max-width: 320px;
    height: 22px;
    padding: 0 var(--s-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-pill);
    background: var(--bg-app);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.v2-process-hint.success {
    border-color: var(--accent-soft);
    background: var(--accent-soft);
    color: var(--accent-text);
}

.v2-process-hint.error,
.v2-process-hint.danger {
    border-color: color-mix(in srgb, var(--danger) 22%, transparent);
    background: color-mix(in srgb, var(--danger) 10%, var(--bg-card));
    color: var(--danger);
}

.v2-process-hint.warning,
.v2-process-hint.warn {
    border-color: color-mix(in srgb, var(--warning) 28%, transparent);
    background: var(--warning-bg);
    color: var(--warning);
}

.v2-tablefoot select.v2-pagesize {
    padding: 3px 22px 3px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--r-sm);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%238a8a86' stroke-width='1.5' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

[data-v2-density="compact"] .v2-tablefoot {
    gap: var(--s-3);
    min-height: 38px;
    padding: var(--s-2) var(--s-4);
}

[data-v2-density="compact"] .v2-tablefoot-left,
[data-v2-density="compact"] .v2-tablefoot-right {
    gap: var(--s-3);
}

[data-v2-density="compact"] .v2-process-hint {
    height: 20px;
    padding: 0 var(--s-2);
    font-size: 11px;
}

@media (max-width: 900px) {
    .v2-tablefoot-center {
        flex-basis: 100%;
        justify-content: flex-start;
        order: 3;
    }

    .v2-process-hints {
        justify-content: flex-start;
    }
}

/* ============================================================
   PAGER
   ============================================================ */
.v2-pager {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.v2-pgbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: var(--r-xs);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.v2-pgbtn:hover:not(.is-disabled):not(.is-active) {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.v2-pgbtn.is-active {
    background: var(--accent-bg);
    color: var(--accent-text);
    font-weight: var(--weight-semibold);
}
.v2-pgbtn.is-disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: default;
}
.v2-pgbtn .v2-i {
    width: 13px;
    height: 13px;
}

.v2-pgbtn-ellipsis {
    color: var(--text-muted);
    padding: 0 4px;
    user-select: none;
}

/* ============================================================
   DENSITY
   ============================================================ */
[data-v2-density="compact"] .v2-tbl thead th {
    padding: var(--s-2) var(--row-padding-x);
    font-size: 9px;
}
[data-v2-density="compact"] .v2-tbl tbody td {
    font-size: var(--text-sm);
    line-height: 1.22;
}
[data-v2-density="compact"] .v2-cell-name-sub {
    margin-top: 1px;
    line-height: 1.15;
}
[data-v2-density="compact"] .v2-tablefoot {
    padding: var(--s-2) var(--s-4);
    font-size: var(--text-xs);
}

[data-v2-density="spacious"] .v2-tbl thead th {
    padding: var(--s-4) var(--row-padding-x);
}
[data-v2-density="spacious"] .v2-tablefoot {
    padding: var(--s-4) var(--s-6);
}

/* Таблиці поза .v2-tablewrap (секції карток осіб): ті самі ледь помітні лінії
   рядків і зовнішній каркас, що в реєстрах. Без цього змінна --v2-table-separator
   не визначена і межі рядків зникають зовсім. Погоджено власником 2026-07-15. */
.v2-profile-section-body .v2-tbl {
    --v2-table-separator: color-mix(in srgb, var(--border-subtle) 36%, transparent);
    border: 1px solid color-mix(in srgb, var(--border-subtle) 36%, transparent);
    border-radius: var(--r-sm);
}
