/* ========================================================================
   Component: Tables — Clean minimal table design
   ======================================================================== */

.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }

thead th {
    position: sticky; top: 0; z-index: var(--z-base);
    text-align: left;
    font-size: var(--text-xs); font-weight: var(--weight-bold);
    letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

th.sortable { cursor: pointer; user-select: none; transition: color var(--duration-fast); }
th.sortable:hover { color: var(--brand); }
th.sortable.sorted { color: var(--brand); }
th.sortable .sort-indicator { display: inline-block; margin-left: var(--space-1); font-size: var(--text-xs); }

tbody td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand) 4%, transparent); }
tbody tr:nth-child(even) td { background: rgba(0,0,0,0.012); }
[data-theme="dark"] tbody tr:nth-child(even) td { background: rgba(255,255,255,0.012); }
tbody tr.updated { animation: rowHighlight 1.5s ease-out; }

tfoot td {
    padding: var(--space-2) var(--space-3);
    border-top: 2px solid var(--border);
    background: var(--bg-secondary);
    font-weight: var(--weight-bold);
}

/* ── Column sizing ── */
.col-checkbox { width: 36px; text-align: center; }
.col-toggle { width: 50px; text-align: center; }
.col-id { width: 80px; }
.col-avito { width: 60px; text-align: center; }
.col-title { min-width: clamp(140px, 20vw, 260px); max-width: 400px; }

.col-impressions, .col-views, .col-contacts, .col-conv, .col-diff,
.col-cpa, .col-spend, .col-bid, .col-next-bid, .col-rec, .col-limit {
    text-align: right;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

.col-last-bid { width: 120px; text-align: center; }
.col-priority { width: 100px; text-align: center; }
.col-action { width: 110px; text-align: left; }
.col-link { width: 44px; text-align: center; }

/* ── Metrics with diff ── */
.metric-with-diff {
    display: inline-flex; align-items: center; justify-content: flex-end;
    gap: var(--space-2); min-width: 94px;
}
.metric-main-value { font-weight: var(--weight-semibold); min-width: 44px; text-align: right; }
.metric-diff {
    font-size: var(--text-xs); line-height: 1; font-weight: var(--weight-semibold);
    opacity: 0.85; display: inline-block; min-width: 28px; text-align: left;
}
.metric-diff-pos, .diff-positive { color: var(--success); font-weight: var(--weight-semibold); }
.metric-diff-neg, .diff-negative { color: var(--danger); font-weight: var(--weight-semibold); }
.metric-diff-zero, .diff-zero { color: var(--text-muted); }
.metric-diff-empty { color: transparent; opacity: 0; }

/* ── Item cells ── */
.item-id-text { color: var(--text-muted); font-size: var(--text-xs); font-family: var(--font-mono); }
.item-title {
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: var(--weight-medium); font-size: var(--text-sm);
}
.item-title a { color: inherit; text-decoration: none; }
.item-title a:hover { color: var(--brand); }
.item-id { font-size: var(--text-sm); color: var(--text-muted); }

.next-bid-hint {
    display: block; margin-top: 2px;
    font-size: 0.64rem; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.item-thumb {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    object-fit: cover; border: 1px solid var(--border);
    background: var(--bg-tertiary); flex-shrink: 0;
}

/* ── Link button ── */
.link-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: var(--bg-tertiary); color: var(--text-secondary);
    text-decoration: none; font-size: var(--text-base); transition: all var(--duration-fast);
}
.link-btn:hover { background: var(--brand); color: var(--text-inverse); }

.link-muted { color: var(--text-secondary); text-decoration: none; border-bottom: 1px dashed var(--text-muted); }
.link-muted:hover { color: var(--text-primary); border-bottom-color: var(--brand); }

/* ── Metric cells ── */
.metric-value { font-weight: var(--weight-semibold); font-size: var(--text-md); }
.metric-cell { text-align: right; font-variant-numeric: tabular-nums; }
.metric-cell .main { font-weight: var(--weight-semibold); color: var(--text-primary); }
.actions-cell { white-space: nowrap; display: flex; gap: 0.25rem; align-items: center; }
.actions-cell .btn { margin-left: 0; }
@media (max-width: 768px) {
    .actions-cell { flex-wrap: wrap; white-space: normal; }
}

/* ── Pagination ── */
.items-pagination {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-3); padding: var(--space-3) var(--space-3);
    border-top: 1px solid var(--border-light);
}
.items-pagination__left, .items-pagination__right { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.items-pagination__label { color: var(--text-secondary); font-weight: var(--weight-bold); font-size: var(--text-base); }
.items-pagination__meta { color: var(--text-muted); font-size: var(--text-base); }
.items-pagination__page { color: var(--text-secondary); font-weight: var(--weight-extrabold); font-size: var(--text-base); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .items-pagination { flex-direction: column; align-items: stretch; gap: var(--space-2); }
    .items-pagination__left, .items-pagination__right { width: 100%; justify-content: space-between; }
}
