/* =============================================
   adaptive-table.css — styles for js/adaptive-table.js
   (priority columns + expandable row detail cards)

   Applies only to tables that opted in with `data-adaptive`, so every other
   table on the dashboard keeps its current behaviour.
   ============================================= */

/* No horizontal scrolling — ever. Columns that do not fit are hidden and
   move into the row's detail panel instead. */
.table-container.at-container {
    overflow-x: hidden !important;
}

:is(.table,.cf-table)[data-adaptive] {
    width: 100%;
    table-layout: auto;
}

:is(.table,.cf-table)[data-adaptive] .at-col-hidden {
    display: none !important;
}

/* ── Un-pin the frozen columns ──
   The contact tables pin checkbox/name/mobile with hard-coded `left:` offsets
   (0 / 50 / 250px) that assume the original column widths. With adaptive
   widths those offsets no longer line up, so a pinned cell slides over its
   neighbour and paints its opaque background across that column's text.
   Freezing is pointless anyway once the table can never scroll sideways —
   only the vertical header stickiness is kept. */
:is(.table,.cf-table)[data-adaptive] thead th.col-sticky,
:is(.table,.cf-table)[data-adaptive] thead th.col-sticky-right {
    position: sticky;
    top: 0;
    left: auto;
    right: auto;
    box-shadow: none;
}
:is(.table,.cf-table)[data-adaptive] tbody td.col-sticky,
:is(.table,.cf-table)[data-adaptive] tbody td.col-sticky-right {
    position: static;
    left: auto;
    right: auto;
    box-shadow: none;
}

/* ── The "..." toggle column ── */
:is(.table,.cf-table)[data-adaptive] .at-toggle-col {
    display: none;
}
:is(.table,.cf-table)[data-adaptive].at-collapsed .at-toggle-col {
    display: table-cell;
    width: 46px;
    min-width: 46px;
    max-width: 46px;
    padding-left: 4px !important;
    padding-right: 8px !important;
    text-align: right;
    white-space: nowrap;
}

.at-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 30px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--tertiary);
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    transition: all .15s ease;
}
.at-toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
:is(.table,.cf-table)[data-adaptive] tr.at-row-open .at-toggle-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Tight mode: squeeze the columns before dropping any ──
   Content that used to rely on horizontal scrolling now wraps instead.
   `at-tight` is applied whenever the table needed extra room; `at-collapsed`
   only when a column actually had to move into the detail panel. */
:is(.table,.cf-table)[data-adaptive].at-tight th,
:is(.table,.cf-table)[data-adaptive].at-tight td {
    padding-left: 10px;
    padding-right: 10px;
}
/* Cells wrap instead of forcing a scrollbar. `break-word`, never `anywhere`:
   `anywhere` drops a column's min-content width to a single character, which
   shreds the text into one letter per line and makes the fit test believe
   everything fits. */
:is(.table,.cf-table)[data-adaptive].at-tight td:not(.col-sticky-right):not(.at-toggle-col) {
    white-space: normal !important;
    overflow-wrap: break-word;
    word-break: normal;
}
/* Headers wrap at spaces only — a column is never squeezed narrower than the
   longest word of its own label, so "КОМПАНИЯ" can't come out as "КОМ/ПАНИЯ". */
:is(.table,.cf-table)[data-adaptive].at-tight th:not(.col-sticky-right):not(.at-toggle-col) {
    white-space: normal !important;
    overflow-wrap: normal;
    word-break: keep-all;
}
:is(.table,.cf-table)[data-adaptive].at-tight th.col-sticky-name,
:is(.table,.cf-table)[data-adaptive].at-tight td.col-sticky-name {
    min-width: 120px !important;
    max-width: none !important;
}
/* 130px was the pinned width of the mobile column; without pinning it only
   forces a useful column out in favour of a narrower, emptier one. */
:is(.table,.cf-table)[data-adaptive].at-tight th.col-sticky-mobile,
:is(.table,.cf-table)[data-adaptive].at-tight td.col-sticky-mobile {
    min-width: 0 !important;
    max-width: none !important;
}
:is(.table,.cf-table)[data-adaptive].at-tight th.col-sticky-cb,
:is(.table,.cf-table)[data-adaptive].at-tight td.col-sticky-cb {
    min-width: 38px !important;
    max-width: 38px !important;
    width: 38px !important;
    padding-left: 6px !important;
    padding-right: 0 !important;
}
:is(.table,.cf-table)[data-adaptive].at-collapsed tbody tr:not(.at-detail-row) {
    cursor: pointer;
}
/* The pinned cells set their own background with !important, so the open-row
   tint has to out-shout them or the highlight stops halfway across the row. */
:is(.table,.cf-table)[data-adaptive] tr.at-row-open > td,
:is(.table,.cf-table)[data-adaptive] tr.at-row-open > td.col-sticky,
:is(.table,.cf-table)[data-adaptive] tr.at-row-open > td.col-sticky-right,
:is(.table,.cf-table)[data-adaptive] tbody tr.at-row-open:hover > td.col-sticky,
:is(.table,.cf-table)[data-adaptive] tbody tr.at-row-open:hover > td.col-sticky-right {
    background: var(--tertiary) !important;
    border-bottom-color: transparent;
}

/* The tablet "collapse the actions cell into a floating menu" treatment
   (js/table-actions-menu.js) is replaced by the detail panel here. */
:is(.table,.cf-table)[data-adaptive] td.col-sticky-right::before,
:is(.table,.cf-table)[data-adaptive] th.col-sticky-right::before {
    content: none !important;
}
:is(.table,.cf-table)[data-adaptive] td.col-sticky-right .action-buttons {
    display: flex !important;
}
@media (max-width: 1100px) {
    :is(.table,.cf-table)[data-adaptive] td.col-sticky-right,
    :is(.table,.cf-table)[data-adaptive] th.col-sticky-right {
        width: auto;
        min-width: 0;
        max-width: none;
        text-align: left;
    }
    :is(.table,.cf-table)[data-adaptive] th.col-sticky-right { font-size: 12px; }
    :is(.table,.cf-table)[data-adaptive] th.col-sticky-name,
    :is(.table,.cf-table)[data-adaptive] td.col-sticky-name {
        min-width: 120px !important;
        max-width: none !important;
    }
}

/* ── The expanded detail row ──
   The panel cell is the row's :first-child, which the contacts pages style as
   the 50px centred checkbox column — reset that here. */
:is(.table,.cf-table)[data-adaptive] tr.at-detail-row > td {
    padding: 0 !important;
    width: auto !important;
    text-align: left !important;
    vertical-align: top !important;
    background: var(--tertiary);
    border-bottom: 1px solid var(--border);
}

.at-detail {
    padding: 14px 16px 16px;
    animation: atDetailIn .18s ease-out;
}

@keyframes atDetailIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.at-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.at-detail-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.at-detail-close {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--secondary);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
}
.at-detail-close:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.at-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}

.at-card {
    background: var(--secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    min-width: 0;
}
.at-card-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.at-card-value {
    font-size: 14px;
    color: var(--text);
    overflow-wrap: anywhere;
    line-height: 1.45;
}
.at-card-value .at-empty { color: var(--text-muted); }

/* Actions moved out of the (hidden) actions cell */
.at-detail-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}
.at-detail-actions .action-buttons {
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.at-detail-actions .action-buttons > *[style*="display:none"],
.at-detail-actions .action-buttons > *[style*="display: none"] {
    display: none !important;
}
/* Icon-only buttons get their tooltip as a visible label */
.at-detail-actions .action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 13px;
}
.at-detail-actions .action-btn[title]::after {
    content: attr(title);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}
.at-detail-actions .action-btn-text {
    height: 34px;
}

@media (max-width: 560px) {
    .at-detail-grid { grid-template-columns: 1fr 1fr; }
    .at-detail { padding: 12px; }
}
@media (max-width: 340px) {
    .at-detail-grid { grid-template-columns: 1fr; }
}
