*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e0e3ea;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99,102,241,.08);
    --success: #16a34a;
    --success-light: rgba(22,163,74,.08);
    --warning: #d97706;
    --warning-light: rgba(245,158,11,.12);
    --danger: #dc2626;
    --danger-light: rgba(220,38,38,.08);
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --radius-lg: 12px;
    --input-bg: #f8fafc;
    --bg-secondary: #eef1f6;
    --bg-tertiary: #f1f4f8;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --primary-light: rgba(99,102,241,.12);
    --success: #22c55e;
    --success-light: rgba(34,197,94,.1);
    --warning: #fbbf24;
    --warning-light: rgba(245,158,11,.15);
    --danger: #ef4444;
    --danger-light: rgba(239,68,68,.1);
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --input-bg: #0f1117;
    --bg-secondary: #141823;
    --bg-tertiary: #232734;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; min-width: 0; }

/* ==================== ANIMATIONS ==================== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
.animate-in {
    animation: fadeInUp .4s ease both;
}

/* ==================== HEADER ==================== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}
.header .container { display: flex; align-items: center; justify-content: space-between; }
.header__logo {
    display: flex; align-items: center; gap: 8px;
    font-size: 17px; font-weight: 700; color: var(--primary); text-decoration: none;
}
.header__logo svg { flex-shrink: 0; }
.header__nav { display: flex; gap: 8px; align-items: center; }
.header__user { color: var(--text-muted); font-size: 13px; margin-right: 4px; }
.role-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11px;
    line-height: 1.4;
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 18px; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500;
    cursor: pointer; text-decoration: none; transition: all .15s; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(99,102,241,.3); }
.btn--ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--lg { width: 100%; padding: 12px 24px; font-size: 15px; }
.btn--danger { background: var(--danger); color: #fff; }

.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border: none; border-radius: var(--radius);
    background: transparent; color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary); }
.btn-icon--danger:hover { background: var(--danger-light); color: var(--danger); }

/* ==================== CARDS ==================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin: 24px 0;
    box-shadow: var(--shadow-sm);
}
.card__header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.card__title { font-size: 20px; font-weight: 600; flex-shrink: 0; }
.card__actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.selection-count { color: var(--text-muted); font-size: 13px; margin-right: 2px; white-space: nowrap; font-weight: 600; }

/* Floating bulk-action bar — slides down from top, doesn't push layout */
.bulk-bar-floating {
    position: fixed;
    top: 72px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 150;
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 12px 36px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.08);
    opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .25s cubic-bezier(.2,.9,.3,1.1);
    max-width: calc(100vw - 40px);
    white-space: nowrap;
    overflow-x: auto;
}
.bulk-bar-floating--visible {
    opacity: 1; pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.bulk-bar-floating .selection-count {
    background: var(--primary); color: #fff;
    padding: 4px 10px; border-radius: 999px;
    font-weight: 700;
}
.bulk-bar-floating__sep {
    width: 1px; height: 20px; background: var(--border);
    flex-shrink: 0;
}
.bulk-bar-floating .form-control { min-width: 120px; }
.bulk-bar-floating .btn { flex-shrink: 0; }
@media (max-width: 768px) {
    .bulk-bar-floating {
        top: auto; bottom: 90px;
        border-radius: 14px;
        max-width: calc(100vw - 20px);
    }
    .bulk-bar-floating--visible { transform: translateX(-50%) translateY(0); }
}

/* ==================== VIEW TOGGLE ==================== */
.view-toggle {
    display: flex; background: var(--input-bg); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.view-toggle__btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 30px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.view-toggle__btn.active { background: var(--primary); color: #fff; }
.view-toggle__btn:hover:not(.active) { color: var(--primary); }

/* ==================== FORMS ==================== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
    margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px;
}
.form-group label .req { color: var(--danger); margin-left: 2px; }
.form-control {
    width: 100%; padding: 10px 14px; background: var(--input-bg);
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-control::placeholder { color: var(--text-muted); opacity: .6; }
select.form-control { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.file-input {
    border: 2px dashed var(--border); border-radius: var(--radius-lg);
    padding: 36px 20px; text-align: center; cursor: pointer;
    transition: border-color .2s, background .2s; position: relative;
}
.file-input:hover { border-color: var(--primary); background: var(--primary-light); }
.file-input input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-input__label { color: var(--text-muted); font-size: 14px; }
.file-input__label strong { color: var(--primary); }
.file-input--small { padding: 16px; }

.form-section {
    font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .5px; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ==================== PAGINATION ==================== */
.pagination {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
    flex-wrap: wrap; gap: 12px;
}
.pagination__info { color: var(--text-muted); font-size: 13px; }
.pagination__sep { margin: 0 6px; opacity: .5; }
.pagination__nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pagination__ellipsis { color: var(--text-muted); padding: 0 4px; }

/* ==================== BULK / INLINE STATUS ==================== */
.bulk-bar {
    display: flex; gap: 6px; align-items: center;
    background: var(--primary-light); border-radius: var(--radius);
    padding: 4px 8px; margin-right: 6px;
}
.bulk-bar .selection-count { font-size: 12px; font-weight: 600; color: var(--primary); }
.status-inline {
    border: none; cursor: pointer; padding: 4px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .5px; -webkit-appearance: none; -moz-appearance: none; appearance: none;
    background-image: none; padding-right: 8px;
}
.status-inline:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--primary); }

/* ==================== FILTERS ==================== */
.filter-row {
    display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center;
    padding: 12px; background: var(--input-bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
    max-width: 100%; min-width: 0;
}
.filter-row__date { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); white-space: nowrap; flex: 0 1 auto; min-width: 0; }
.filter-row__date span { font-weight: 600; }
.filter-row__date input[type="date"] { min-width: 130px; width: 130px; flex: 0 0 auto; }
.filter-row__search { position: relative; flex: 2 1 220px; min-width: 180px; }
.filter-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); pointer-events: none;
}
.form-control--sm { padding: 8px 10px; font-size: 13px; width: auto; min-width: 110px; flex: 1 1 110px; }
.filter-row select.form-control--sm { max-width: 220px; min-width: 0; flex: 0 1 auto; }
.form-control--icon { padding-left: 32px; }
.filter-row > .btn { flex: 0 0 auto; }

/* ==================== STATS ==================== */
.stats-row { display: flex; gap: 14px; margin-bottom: 20px; }
.stat-box {
    flex: 1; background: var(--input-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px; text-align: center;
    transition: transform .15s, box-shadow .15s;
}
.stat-box:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-box__num { font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat-box__label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

/* ==================== TABLE ==================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
    text-align: left; padding: 10px 12px; color: var(--text-muted);
    font-weight: 600; font-size: 11px; text-transform: uppercase;
    letter-spacing: .5px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
th.sortable:hover { color: var(--primary); }
th .sort-arrow { display: inline-block; width: 0; margin-left: 4px; }
th.sort-asc .sort-arrow::after { content: ' \u25B2'; font-size: 9px; }
th.sort-desc .sort-arrow::after { content: ' \u25BC'; font-size: 9px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr { transition: opacity .3s, background .15s; }
tr:hover td { background: var(--primary-light); }

/* ---- Creatives table polish: zebra rows, quiet actions, framed thumbs ---- */
#creativesTable tbody tr:nth-child(even):not(.group-header) td { background: rgba(127,127,127,.035); }
#creativesTable tbody tr:hover td { background: var(--primary-light); }
#creativesTable td, #creativesTable th { border-bottom-color: color-mix(in srgb, var(--border) 60%, transparent); }
#creativesTable .likes-num { font-weight: 600; }
/* Action icons stay quiet until you hover the row (declutters dense tables). */
#creativesTable .actions-cell .btn-icon { opacity: .4; transition: opacity .12s, background .12s, color .12s; }
#creativesTable tbody tr:hover .actions-cell .btn-icon,
#creativesTable .actions-cell .btn-icon:focus-visible { opacity: 1; }
/* Uniform, softly framed preview thumbnails. */
#creativesTable .img-thumb { border: 1px solid var(--border); background: var(--bg-tertiary); }
/* On touch devices (no hover) keep action icons fully visible. */
@media (hover: none) { #creativesTable .actions-cell .btn-icon { opacity: 1; } }

/* Merged media column: video + preland + screen as one compact gallery. */
.media-cell { white-space: nowrap; }
.media-gallery { display: inline-flex; align-items: center; gap: 5px; }
.media-gallery__video { width: 84px !important; height: 50px !important; flex: 0 0 auto; border-radius: 6px; }
.media-gallery__video .video-thumb__play svg { width: 16px; height: 16px; }
.media-gallery__img {
    width: 38px !important; height: 50px !important;
    max-width: none !important; max-height: none !important;
    object-fit: cover; flex: 0 0 auto; border-radius: 6px;
}
.media-none { color: var(--text-muted); }
#creativesTable .likes-cell { min-width: 76px; }
.nowrap { white-space: nowrap; }
.actions-cell { white-space: nowrap; text-align: right; }
.sel-item { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* Creatives table fits within the content column without horizontal scroll at
   common widths. Scoped to the comfortable (default) density so the compact /
   spacious presets keep their own paddings. id-scoped to beat density specificity. */
[data-density="comfortable"] #creativesTable td,
[data-density="comfortable"] #creativesTable th { padding: 8px 7px; }
#creativesTable .actions-cell { white-space: nowrap; }
#creativesTable .actions-cell .btn-icon { padding: 4px; }
#creativesTable .actions-cell .btn-icon svg { width: 13px; height: 13px; }

/* ==================== BADGES ==================== */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
/* No-video highlight */
tr.no-video td { background: rgba(234,179,8,.08); }
tr.no-video { border-left: 3px solid #eab308; }

.badge--new { background: var(--primary-light); color: var(--primary); }
.badge--used { background: var(--success-light); color: var(--success); }
.badge--archived { background: rgba(100,116,139,.1); color: var(--text-muted); }

/* ==================== THUMBNAILS / VIDEO ==================== */
.img-thumb {
    max-width: 44px; max-height: 30px; border-radius: 4px; object-fit: cover;
}
.img-clickable { cursor: pointer; transition: opacity .15s, transform .15s; }
.img-clickable:hover { opacity: .85; transform: scale(1.05); }
.video-inline {
    width: 110px; height: 65px; border-radius: 6px; background: #000; object-fit: cover;
}

/* ==================== GRID VIEW ==================== */
.grid-view {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px;
}
.cr-card {
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; overflow: hidden;
    box-shadow: 0 1px 2px rgba(15,23,42,.04);
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.cr-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px -10px rgba(15,23,42,.28); border-color: transparent; }
.cr-card__media {
    position: relative; aspect-ratio: 4/5; overflow: hidden;
    background: linear-gradient(160deg, #1e2230, #0f1117);
}
.cr-card__media::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 42%;
    background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
    pointer-events: none; z-index: 2;
}
.cr-card__media img { transition: transform .4s ease; }
.cr-card:hover .cr-card__media img { transform: scale(1.04); }
.cr-card .cr-card__media .video-thumb { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; border: 0; }
.cr-card__media:has(.video-thumb--playing)::after,
.cr-card__media:has(.video-thumb--playing) .cr-card__ov--bottom { display: none; }
.cr-card__ov {
    position: absolute; left: 10px; right: 10px; z-index: 3;
    display: flex; align-items: center; gap: 6px; pointer-events: none;
}
.cr-card__ov a { pointer-events: auto; }
.cr-card__ov--top { top: 10px; right: 44px; }
.cr-card__ov--bottom { bottom: 10px; }
.cr-chip {
    display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
    border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .4px;
    background: rgba(15,17,23,.62); color: #fff;
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.cr-chip--warn { background: rgba(234,179,8,.9); color: #1f1300; font-weight: 600; letter-spacing: 0; }
.cr-card__likes-big {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 17px; font-weight: 800; color: #fff; line-height: 1;
    text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.cr-card__likes-big svg { color: #ff5a7a; }
.cr-card__delta {
    font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 999px;
}
.cr-card__delta--up   { background: rgba(34,197,94,.9); color: #fff; }
.cr-card__delta--down { background: rgba(239,68,68,.9); color: #fff; }
.cr-card__ov .copy-badge {
    margin-left: auto; height: 22px; padding: 0 8px; font-size: 11px;
    background: rgba(245,158,11,.92); color: #1f1300;
}
.cr-card__ov .copy-badge:hover { background: #f59e0b; }
.cr-card__media .ai-dot--card { top: 16px; right: 40px; z-index: 3; box-shadow: 0 0 0 2px rgba(0,0,0,.35); }
.cr-card__check {
    position: absolute;
    z-index: 3;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: rgba(255,255,255,.9);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .cr-card__check { background: rgba(26,29,39,.9); }
.cr-card__media video, .cr-card__media img {
    width: 100%; height: 100%; object-fit: cover;
}
.cr-card__placeholder {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); opacity: .4;
}
.cr-card__body { padding: 12px 14px 6px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.cr-card__row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.cr-card__vert {
    font-size: 13.5px; font-weight: 650; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cr-card__vert--none { color: var(--text-muted); font-weight: 500; font-style: italic; }
.cr-card__date { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.cr-card__title {
    font-size: 12.5px; color: var(--text-muted); line-height: 1.35;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cr-card__footer {
    display: flex; align-items: center; gap: 2px;
    padding: 6px 10px 10px 14px;
}
.cr-card__spacer { flex: 1; }
.cr-card__footer .status-inline { padding: 3px 9px; font-size: 10px; }
.cr-card__footer .btn-icon { opacity: .45; transition: opacity .15s, background .15s, color .15s; }
.cr-card:hover .cr-card__footer .btn-icon, .cr-card__footer .btn-icon:focus-visible { opacity: 1; }
@media (hover: none) { .cr-card__footer .btn-icon { opacity: 1; } }

/* ==================== MODALS ==================== */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
    z-index: 100; align-items: center; justify-content: center;
    backdrop-filter: blur(4px); animation: fadeIn .2s ease;
}
.modal-overlay.active { display: flex; }
.modal-content {
    position: relative; max-width: 90vw; max-height: 90vh;
}
.modal-content img {
    max-width: 90vw; max-height: 85vh; border-radius: 8px; display: block;
}
.modal-close {
    position: absolute; top: -12px; right: -12px;
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-md); transition: all .15s;
}
.modal-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.modal-panel {
    background: var(--surface); border-radius: 16px; width: 680px; max-width: 92vw;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
    animation: slideInRight .3s ease;
}
.modal-panel--sm { width: 480px; }
.modal-panel__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-panel__title { font-size: 17px; font-weight: 600; }
.modal-panel__header .modal-close {
    position: static; width: 28px; height: 28px; font-size: 16px;
}
.modal-panel__body { padding: 24px; }

/* Detail modal content */
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 20px; }
.detail-video video {
    width: 100%; max-height: 320px; border-radius: var(--radius-lg);
    background: #000; object-fit: contain;
}
.detail-video--empty {
    min-height: 160px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.detail-images { display: flex; gap: 12px; flex-wrap: wrap; }
.detail-images--two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-img-wrap { text-align: center; }
.detail-img-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; }
.detail-img-wrap img {
    width: 100%;
    max-height: 200px;
    min-height: 140px;
    border-radius: var(--radius);
    object-fit: cover;
}
.detail-img-wrap--empty {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 8px;
}
.detail-img-placeholder {
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}
.detail-info { border-top: 1px solid var(--border); padding-top: 16px; }
.detail-row {
    display: flex; padding: 8px 0; border-bottom: 1px solid var(--border);
    font-size: 13px; align-items: baseline;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 120px; flex-shrink: 0; color: var(--text-muted); font-weight: 500; }
.detail-value { flex: 1; word-break: break-all; }
.detail-value a { color: var(--primary); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }

/* ==================== TOASTS ==================== */
.toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 200;
    display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px; border-radius: var(--radius-lg);
    background: var(--surface); border: 1px solid var(--border);
    box-shadow: var(--shadow-lg); font-size: 14px;
    transform: translateX(120%); opacity: 0;
    transition: all .3s cubic-bezier(.4,0,.2,1);
}
.toast--visible { transform: translateX(0); opacity: 1; }
.toast--out { transform: translateX(120%); opacity: 0; }
.toast__icon { display: flex; flex-shrink: 0; }
.toast--success { border-left: 3px solid var(--success); }
.toast--success .toast__icon { color: var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--error .toast__icon { color: var(--danger); }
.toast--info { border-left: 3px solid var(--primary); }
.toast--info .toast__icon { color: var(--primary); }
.toast--warning { border-left: 3px solid var(--warning); }
.toast--warning .toast__icon { color: var(--warning); }

/* ==================== ALERTS ==================== */
.alert {
    padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 14px;
}
.alert--success { background: var(--success-light); color: var(--success); border: 1px solid rgba(22,163,74,.2); }
.alert--error { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(220,38,38,.2); }
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

/* ==================== EMPTY STATE ==================== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state__icon { margin-bottom: 12px; opacity: .4; }
.empty-state__text { font-size: 15px; }
.empty-state__text a { color: var(--primary); text-decoration: none; font-weight: 600; }
.empty-state__text a:hover { text-decoration: underline; }

/* ==================== PROGRESS BAR ==================== */
.progress-wrap { margin: 16px 0 8px; }
.progress-bar {
    width: 100%; height: 6px; background: var(--border);
    border-radius: 6px; overflow: hidden;
}
.progress-bar__fill {
    height: 100%; width: 0; background: var(--primary);
    border-radius: 6px; transition: width .2s ease;
}
.progress-text { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* ==================== URL CHECK ==================== */
.url-check { margin-top: 6px; min-height: 20px; }
.url-check--loading { font-size: 12px; color: var(--text-muted); }
.url-check--ok {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 13px; font-weight: 500; color: var(--success);
}
.url-check--dup {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 13px; font-weight: 600; color: var(--danger);
}

/* ==================== DRAG & DROP ==================== */
.drop-zone--active { border-color: var(--primary) !important; background: var(--primary-light) !important; }

/* ==================== EDIT DROP ZONES ==================== */
.edit-drop {
    border: 2px dashed var(--border); border-radius: var(--radius);
    position: relative; cursor: pointer; transition: border-color .2s, background .2s;
    overflow: hidden;
}
.edit-drop:hover { border-color: var(--primary); background: var(--primary-light); }
.edit-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }
.edit-drop__inner {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px;
    min-height: 48px;
}
.edit-drop--img .edit-drop__inner { padding: 10px; flex-direction: column; gap: 6px; text-align: center; min-height: 80px; justify-content: center; }
.edit-drop__icon { color: var(--text-muted); display: flex; flex-shrink: 0; }
.edit-drop__text { color: var(--text-muted); font-size: 13px; }
.edit-drop__preview { max-height: 60px; max-width: 100%; border-radius: 4px; display: none; }
.edit-drop--has { border-color: var(--primary); border-style: solid; background: var(--primary-light); }

/* ==================== UPLOAD PREVIEW ==================== */
.upload-preview-img {
    display: none; max-width: 200px; max-height: 150px; margin-top: 8px; border-radius: 4px;
}

/* ==================== LOGIN ==================== */
.login-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    min-height: 100vh;
}
[data-theme="dark"] .login-body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.login-wrap {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 20px;
}
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 44px 40px; width: 100%; max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
[data-theme="dark"] .login-card { box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-card__logo {
    text-align: center; margin-bottom: 8px; color: var(--primary);
}
.login-card__title {
    text-align: center; font-size: 26px; font-weight: 700; margin-bottom: 6px;
}
.login-card__sub {
    text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 28px;
}
.login-footer {
    margin-top: 24px; font-size: 12px; color: rgba(255,255,255,.5); letter-spacing: .5px;
}
[data-theme="dark"] .login-footer { color: rgba(255,255,255,.3); }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .header__nav { gap: 6px; }
    .header__user { display: none; }
    .card { padding: 20px; }
    .modal-panel { width: 96vw; }
}
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
    .stats-row { flex-direction: column; }
    .filter-row { flex-direction: column; }
    .form-control--sm { width: 100%; }
    .video-inline { width: 80px; height: 50px; }
    .grid-view { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; }
    .detail-images--two { grid-template-columns: 1fr; }
}

/* ======= PHASE 1 ADDITIONS ======= */

/* Video thumb (instead of heavy <video>) */
.video-thumb {
    position: relative;
    width: 104px; height: 62px;
    border-radius: 8px;
    background: linear-gradient(135deg, #1a1f2e, #0f131d);
    overflow: hidden;
    cursor: pointer;
    display: inline-block;
    transition: transform .15s, box-shadow .15s;
    border: 1px solid rgba(255,255,255,.06);
}
.video-thumb:hover { transform: scale(1.04); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.video-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .8; }
.video-thumb__play {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; pointer-events: none;
    text-shadow: 0 2px 8px rgba(0,0,0,.7);
    background: radial-gradient(circle at center, rgba(0,0,0,.25), transparent 60%);
}
.video-thumb__play svg { filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); }
.video-thumb--big { width: 100%; aspect-ratio: 16/10; height: auto; }
.video-thumb--playing { cursor: default; }
.video-thumb--playing:hover { transform: none; }
.video-thumb__playing { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }

/* Mini player modal (table view) */
.mini-player {
    position: fixed; inset: 0; z-index: 1200;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 12, 18, .55);
    animation: miniPlayerIn .12s ease-out;
}
.mini-player__box {
    position: relative; display: flex; flex-direction: column; gap: 8px;
    padding: 10px; border-radius: 12px;
    background: var(--surface); box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.mini-player__box video {
    display: block; width: auto; height: auto;
    max-width: min(420px, 90vw); max-height: 72vh; min-width: 240px;
    border-radius: 8px; background: #000;
}
.mini-player__bar { display: flex; gap: 6px; justify-content: flex-end; }
.mini-player__bar:empty { display: none; }
.mini-player__x {
    position: absolute; top: -12px; right: -12px; z-index: 1;
    width: 28px; height: 28px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--surface); color: var(--text); font-size: 18px; line-height: 28px;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
@keyframes miniPlayerIn { from { opacity: 0; } to { opacity: 1; } }

/* Date chips */
.date-chips {
    display: flex; flex-wrap: wrap; gap: 6px;
    align-items: center;
    margin: 12px 0 8px;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.date-chips__label { font-size: 12px; color: var(--text-muted); margin-right: 4px; font-weight: 600; }
.date-chips__sep { flex: 0 0 1px; height: 20px; background: var(--border); margin: 0 4px; }
.chip {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    font-weight: 500;
}
.chip:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.chip--active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.chip--active:hover { background: var(--primary-hover); color: #fff; }
.chip:active { transform: translateY(0); }
.chip--ghost { background: transparent; color: var(--text-muted); }
.chip--ghost:hover { color: var(--primary); }

/* Undo toasts */
.undo-host {
    position: fixed; bottom: 20px; left: 50%;
    transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 8px;
    z-index: 2100; pointer-events: none;
}
.undo-toast {
    pointer-events: auto;
    min-width: 320px;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    background: #1a1f2e;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    color: #e0e6f0;
    font-size: 13px;
    position: relative;
    overflow: hidden;
    animation: undo-in .25s ease-out;
}
.undo-toast.hide { animation: undo-out .25s ease-in forwards; }
@keyframes undo-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes undo-out { to { opacity: 0; transform: translateY(10px); } }
.undo-toast__msg { flex: 1; }
.undo-toast__btn {
    background: transparent;
    color: #ffd166;
    border: 1px solid rgba(255,209,102,.3);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    font-family: inherit;
}
.undo-toast__btn:hover { background: rgba(255,209,102,.12); }
.undo-toast__bar {
    position: absolute; left: 0; bottom: 0; right: 0; height: 2px;
    background: rgba(255,255,255,.04);
}
.undo-toast__bar > span {
    display: block; height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ffd166, #ef476f);
}
.pending-delete { opacity: .4; filter: grayscale(.5); transition: opacity .2s; }

/* Keyboard focus */
.kbd-focus {
    outline: 2px solid var(--primary) !important;
    outline-offset: -2px;
    box-shadow: 0 0 0 4px var(--primary-light);
}
tr.kbd-focus { background: var(--primary-light) !important; }

/* Shared keyboard focus ring for custom interactive controls */
.chip:focus-visible, .nav-item:focus-visible, .seg-btn:focus-visible,
.icon-btn:focus-visible, .view-toggle__btn:focus-visible, .facet-item:focus-visible,
.gr-axis:focus-visible, .gr-group:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Detail actions */
.detail-actions {
    display: flex; gap: 8px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.06);
}

/* Inline editing */
.inline-cell { cursor: cell; position: relative; transition: background .15s; }
.inline-cell:hover { background: rgba(99,102,241,.06); }
.inline-cell--editing { background: rgba(99,102,241,.12); padding: 2px 4px !important; }
.inline-cell--saving { opacity: .5; }
.inline-cell--saved { background: rgba(46,204,113,.18) !important; animation: cell-flash .8s ease-out; }
@keyframes cell-flash { from { background: rgba(46,204,113,.5); } to { background: rgba(46,204,113,.0); } }
.inline-cell__input {
    width: 100%;
    padding: 4px 6px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--primary);
    border-radius: 4px;
    font: inherit;
    outline: none;
}

/* Diff preview in edit modal */
.diff-preview {
    margin-top: 14px; padding: 12px;
    background: rgba(255,209,102,.06);
    border: 1px dashed rgba(255,209,102,.3);
    border-radius: 8px;
    font-size: 12px;
}
.diff-title { font-weight: 600; color: #ffd166; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px; }
.diff-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.diff-field { min-width: 110px; color: rgba(255,255,255,.6); font-size: 11px; text-transform: uppercase; }
.diff-old { color: rgba(239,71,111,.8); text-decoration: line-through; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-arrow { color: rgba(255,255,255,.3); }
.diff-new { color: #52de97; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ======= PHASE 3: Tags / Comments / Activity ======= */

.detail-section {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,.06);
}
.detail-section__title {
    font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
    color: rgba(255,255,255,.6);
    margin-bottom: 10px;
}

/* Tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag-empty { font-size: 12px; color: rgba(255,255,255,.35); font-style: italic; }
.tag-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 4px 3px 10px;
    background: linear-gradient(135deg, rgba(99,102,241,.25), rgba(139,92,246,.18));
    border: 1px solid rgba(99,102,241,.3);
    border-radius: 999px;
    font-size: 12px; font-weight: 500;
}
.tag-chip__name { color: inherit; text-decoration: none; }
.tag-chip__name:hover { text-decoration: underline; }
.tag-chip__rm {
    background: rgba(0,0,0,.3); color: #fff; border: none;
    width: 18px; height: 18px; border-radius: 50%;
    cursor: pointer; font-size: 14px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0;
}
.tag-chip__rm:hover { background: #ef476f; }
.tag-add-form { display: flex; gap: 6px; align-items: center; }
.tag-add-form input { flex: 1; }

/* Row-tag (inline mini-chip) */
.row-tags { display: inline-flex; gap: 3px; margin-left: 6px; }
.row-tag {
    font-size: 10px; padding: 1px 6px;
    background: var(--primary-light);
    color: var(--primary); text-decoration: none;
    border-radius: 999px;
    white-space: nowrap;
}
.row-tag:hover { background: var(--primary); color: #fff; }
.row-tag--more { background: var(--bg-tertiary); color: var(--text-muted); pointer-events: none; }
.row-cmts { font-size: 10px; margin-left: 6px; color: var(--text-muted); }
.active-tag-filter {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.active-tag-filter a { color: inherit; text-decoration: none; margin-left: 4px; font-size: 16px; line-height: 1; }

/* Comments */
.cmt-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; max-height: 280px; overflow-y: auto; }
.cmt-item {
    padding: 8px 10px;
    background: rgba(255,255,255,.03);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 8px;
    font-size: 13px;
}
.cmt-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.cmt-user { font-weight: 600; color: #a5b4fc; font-size: 12px; }
.cmt-date { font-size: 11px; color: rgba(255,255,255,.35); }
.cmt-del { margin-left: auto; background: transparent; color: rgba(239,71,111,.7); border: none; cursor: pointer; font-size: 16px; line-height: 1; }
.cmt-del:hover { color: #ef476f; }
.cmt-body { color: rgba(255,255,255,.85); white-space: pre-wrap; }
.cmt-empty, .cmt-loading { text-align: center; color: rgba(255,255,255,.35); padding: 12px; font-size: 12px; font-style: italic; }
.cmt-add-form { display: flex; flex-direction: column; gap: 6px; }
.cmt-add-form button { align-self: flex-end; }

/* Activity log */
.activity-action { white-space: nowrap; }
.activity-details code {
    background: rgba(255,255,255,.06);
    padding: 1px 6px; border-radius: 4px;
    font-size: 11px;
    color: #ffd166;
}

/* ======= PHASE 4: Charts / Groups / Duplicates / User stats ======= */

/* Bar chart (30 days) */
.chart-section { margin: 20px 0 24px; }
.chart-section__title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: rgba(255,255,255,.5); margin-bottom: 12px; }
.bar-chart {
    display: flex; align-items: flex-end; gap: 3px;
    height: 160px;
    padding: 8px 12px 0;
    background: linear-gradient(180deg, rgba(99,102,241,.04), transparent);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.04);
}
.bar-chart__col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 8px; }
.bar-chart__bar {
    width: 100%;
    background: linear-gradient(180deg, #6366f1, #4338ca);
    border-radius: 4px 4px 0 0;
    transition: all .2s;
    position: relative;
    margin-top: auto;
    min-height: 2px;
}
.bar-chart__col:hover .bar-chart__bar { background: linear-gradient(180deg, #a5b4fc, #6366f1); transform: scaleY(1.03); transform-origin: bottom; }
.bar-chart__val {
    position: absolute;
    top: -18px;
    left: 50%; transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255,255,255,.7);
    white-space: nowrap;
}
.bar-chart__label { font-size: 10px; color: rgba(255,255,255,.4); margin-top: 4px; }

/* H-bars for top groups */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 8px;
}
.chart-box {
    padding: 14px;
    background: rgba(255,255,255,.02);
    border: 1px solid rgba(255,255,255,.05);
    border-radius: 10px;
}
.chart-box__title { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: rgba(255,255,255,.9); }
.chart-empty { font-size: 12px; color: rgba(255,255,255,.3); text-align: center; padding: 16px; }
.hbar {
    display: grid; grid-template-columns: 80px 1fr 40px;
    gap: 8px; align-items: center;
    padding: 5px 0;
    text-decoration: none;
    color: inherit;
    font-size: 12px;
}
.hbar:hover { color: #a5b4fc; }
.hbar__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar__track { background: rgba(255,255,255,.05); height: 8px; border-radius: 4px; overflow: hidden; }
.hbar__fill { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width .3s; }
.hbar__fill--purple { background: linear-gradient(90deg, #a855f7, #d946ef); }
.hbar__fill--amber { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.hbar__val { text-align: right; font-weight: 600; color: rgba(255,255,255,.9); }

/* Group headers in table/grid */
tr.group-header td {
    background: linear-gradient(90deg, rgba(99,102,241,.1), transparent);
    font-weight: 700;
    font-size: 13px;
    color: #a5b4fc;
    padding: 10px 12px;
    text-transform: none;
    letter-spacing: 0;
    border-top: 1px solid rgba(99,102,241,.2);
}
.grid-group-header {
    grid-column: 1 / -1;
    font-weight: 700;
    font-size: 13px;
    color: #a5b4fc;
    padding: 10px 0 4px;
    border-bottom: 1px solid rgba(99,102,241,.2);
}
#btnGroupToggle.active { background: rgba(99,102,241,.2); border-color: rgba(99,102,241,.4); color: #a5b4fc; }

/* Duplicates page */
.dup-group {
    margin-bottom: 14px;
    padding: 12px;
    background: rgba(239,71,111,.05);
    border: 1px solid rgba(239,71,111,.15);
    border-radius: 10px;
}
.dup-group__head {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.dup-group__url {
    color: #a5b4fc;
    font-size: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1; min-width: 0;
}
.dup-group__items { display: flex; flex-direction: column; gap: 6px; }
.dup-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    background: rgba(255,255,255,.02);
    border-radius: 6px;
    font-size: 13px;
}
.dup-item__id { font-weight: 700; color: #fff; min-width: 60px; }
.dup-item__orig { font-size: 10px; padding: 2px 6px; background: rgba(46,204,113,.2); color: #52de97; border-radius: 999px; }
.dup-item__date { color: rgba(255,255,255,.5); font-size: 12px; min-width: 110px; }
.dup-item__meta { color: rgba(255,255,255,.7); flex: 1; }
.dup-item__owner { color: rgba(255,255,255,.6); min-width: 80px; }

/* User stats cells */
.user-stat { display: inline-block; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.user-stat--hot { background: linear-gradient(135deg, #ef4444, #f59e0b); color: #fff; }

/* ======= PHASE 5: Mobile / Profile / DnD / Duplicate badge ======= */

/* Clickable username */
.header__user {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background .15s;
}
.header__user:hover { background: rgba(255,255,255,.06); }

/* Profile page */
.profile-block {
    padding: 16px;
    background: rgba(255,255,255,.02);
    border: 1px solid rgba(255,255,255,.05);
    border-radius: 10px;
    margin-bottom: 20px;
}
.profile-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.profile-row:last-child { border-bottom: none; }
.profile-label { color: var(--text-muted); font-size: 13px; }
.profile-value { font-size: 14px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert--success { background: var(--success-light); border: 1px solid var(--success); color: var(--success); }
.alert--error { background: var(--danger-light); border: 1px solid var(--danger); color: var(--danger); }

/* Duplicate inline badge */
.dup-badge {
    display: inline-flex; align-items: center;
    padding: 1px 6px;
    background: rgba(239,71,111,.2);
    color: #ef476f;
    border-radius: 999px;
    font-size: 10px; font-weight: 700;
    text-decoration: none;
    margin-left: 4px;
    gap: 2px;
}
.dup-badge:hover { background: rgba(239,71,111,.35); }
.copy-badge {
    display: inline-flex; align-items: center;
    padding: 1px 6px; margin-left: 4px;
    background: rgba(245,158,11,.16); color: #d97706;
    border-radius: 999px;
    font-size: 10.5px; font-weight: 700; white-space: nowrap;
    text-decoration: none;
}
.copy-badge:hover { background: rgba(245,158,11,.3); }
/* ---------- Advertiser pill (per-creative cluster badge in feed) ---------- */
.adv-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 11px; font-weight: 600; line-height: 1.4;
    text-decoration: none;
    max-width: 100%;
    white-space: nowrap; overflow: hidden;
    transition: background .12s, border-color .12s, transform .12s;
}
.adv-pill:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.adv-pill__emoji { font-size: 13px; line-height: 1; }
.adv-pill__name  { overflow: hidden; text-overflow: ellipsis; }
.adv-pill--none {
    color: var(--text-muted); background: transparent; border-color: transparent; cursor: default;
    padding: 2px 0; font-weight: 400;
}
.adv-pill--card {
    margin-top: 4px;
    align-self: flex-start;
}
.adv-cell { white-space: nowrap; }

/* "Свой / чужой рекламодатель" segmented filter pill */
.own-toggle {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--input-bg, var(--surface));
    height: 30px;
    align-self: center;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
}
.own-toggle__btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 8px;
    font-size: 12px; font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-right: 1px solid var(--border);
    transition: background .12s, color .12s;
    white-space: nowrap;
    min-width: 0;
}
.own-toggle__btn:last-child { border-right: none; }
.own-toggle__btn:hover { background: var(--bg); color: var(--text); }
.own-toggle__btn.is-active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}
.own-toggle__btn--mine.is-active   { background: linear-gradient(135deg, #f59e0b, #f97316); }
.own-toggle__btn--others.is-active { background: linear-gradient(135deg, #64748b, #475569); }

/* "Свой" pill on advertiser badge in cards/detail modal */
.adv-pill--own {
    background: linear-gradient(135deg, #f59e0b, #f97316);
    color: #fff !important;
    border-color: transparent !important;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(245,158,11,.35);
}
.adv-pill--own:hover { opacity: .92; }

/* Confidence chip in stats panel of detail modal */
.stats-conf {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px; font-weight: 600;
    margin: 8px 0 4px;
    border: 1px solid;
}
.stats-conf--high { background: rgba(34,197,94,.12);  border-color: rgba(34,197,94,.35);  color: #16a34a; }
.stats-conf--med  { background: rgba(234,179,8,.12);  border-color: rgba(234,179,8,.35);  color: #b58400; }
.stats-conf--low  { background: rgba(239,68,68,.12);  border-color: rgba(239,68,68,.35);  color: #dc2626; }

/* Quick-action button inside detail modal pointing to advertiser cluster */
.btn--adv {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: var(--primary-light); color: var(--primary);
    border: 1px solid transparent; border-radius: 6px;
    font-size: 12px; font-weight: 600;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn--adv:hover { background: var(--primary); color: #fff; }

/* DnD overlay */
.dnd-overlay {
    position: fixed; inset: 0;
    background: rgba(99,102,241,.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
}
.dnd-overlay.active { opacity: 1; pointer-events: auto; }
.dnd-overlay__inner {
    padding: 40px 60px;
    background: rgba(20,24,36,.95);
    border: 3px dashed rgba(99,102,241,.6);
    border-radius: 20px;
    text-align: center;
    color: #a5b4fc;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.dnd-overlay__title { font-size: 22px; font-weight: 700; margin-top: 14px; color: #fff; }
.dnd-overlay__sub { font-size: 13px; opacity: .7; margin-top: 6px; }

/* Mobile polish */
@media (max-width: 768px) {
    .header .container { flex-direction: column; align-items: flex-start; gap: 8px; }
    .header__nav { flex-wrap: wrap; gap: 4px; }
    .header__nav .btn--sm { padding: 6px 10px; font-size: 12px; }
    .date-chips { gap: 4px; padding: 8px; overflow-x: auto; flex-wrap: nowrap; }
    .chip { white-space: nowrap; }
    .bar-chart { height: 120px; }
    .bar-chart__label { display: none; }
    .chart-grid { grid-template-columns: 1fr; }
    .stats-row .stat-box__num { font-size: 22px; }
    .video-thumb { width: 96px; height: 60px; }
    .dup-item { flex-wrap: wrap; }
    .detail-images--two { grid-template-columns: 1fr; }
    .detail-video video { max-height: 50vh; }
    .btn-icon { min-width: 36px; min-height: 36px; }
    .table-wrap { font-size: 12px; }
    .undo-toast { min-width: 260px; }
    .card { padding: 12px; }
    .modal-panel { width: 96vw !important; max-height: 90vh; }
}

/* Tap-friendly targets */
@media (hover: none) and (pointer: coarse) {
    .btn, .btn-icon { min-height: 40px; }
    .sel-item { transform: scale(1.3); }
}

/* Page load time footer */
.page-timing {
    text-align: center;
    font-size: 11px;
    color: rgba(255,255,255,.25);
    padding: 8px 0;
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
}

/* ============================================================ */
/* ========== LIGHT-THEME FIXES for Phase 1-5 styles ========== */
/* ============================================================ */
/* Previously many elements used rgba(255,255,255,.XX) which is invisible on light background. */
:root:not([data-theme="dark"]) .video-thumb {
    border-color: var(--border);
    background: linear-gradient(135deg, #e9edf4, #dde2ec);
}
:root:not([data-theme="dark"]) .undo-toast {
    background: var(--surface); color: var(--text);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}
:root:not([data-theme="dark"]) .undo-toast__bar { background: var(--border); }
:root:not([data-theme="dark"]) .detail-actions { border-top-color: var(--border); }
:root:not([data-theme="dark"]) .diff-field { color: var(--text-muted); }
:root:not([data-theme="dark"]) .diff-arrow { color: var(--text-muted); opacity: .5; }
:root:not([data-theme="dark"]) .detail-section { border-top-color: var(--border); }
:root:not([data-theme="dark"]) .detail-section__title { color: var(--text-muted); }
:root:not([data-theme="dark"]) .tag-empty { color: var(--text-muted); }
:root:not([data-theme="dark"]) .row-tag--more { background: rgba(0,0,0,.06); color: var(--text-muted); }
:root:not([data-theme="dark"]) .row-cmts { color: var(--text-muted); }
:root:not([data-theme="dark"]) .cmt-item {
    background: var(--input-bg);
    border-color: var(--border);
}
:root:not([data-theme="dark"]) .cmt-date { color: var(--text-muted); }
:root:not([data-theme="dark"]) .cmt-body { color: var(--text); }
:root:not([data-theme="dark"]) .cmt-empty,
:root:not([data-theme="dark"]) .cmt-loading { color: var(--text-muted); }
:root:not([data-theme="dark"]) .activity-details code { background: var(--input-bg); color: var(--primary); }
:root:not([data-theme="dark"]) .chart-section__title { color: var(--text-muted); }
:root:not([data-theme="dark"]) .bar-chart {
    background: linear-gradient(180deg, var(--primary-light), transparent);
    border-color: var(--border);
}
:root:not([data-theme="dark"]) .bar-chart__val { color: var(--text); }
:root:not([data-theme="dark"]) .bar-chart__label { color: var(--text-muted); }
:root:not([data-theme="dark"]) .chart-box {
    background: var(--input-bg);
    border-color: var(--border);
}
:root:not([data-theme="dark"]) .chart-box__title { color: var(--text); }
:root:not([data-theme="dark"]) .chart-empty { color: var(--text-muted); }
:root:not([data-theme="dark"]) .hbar__track { background: var(--border); }
:root:not([data-theme="dark"]) .hbar__val { color: var(--text); }
:root:not([data-theme="dark"]) .dup-group__head { border-bottom-color: var(--border); }
:root:not([data-theme="dark"]) .dup-item { background: var(--input-bg); }
:root:not([data-theme="dark"]) .dup-item__id { color: var(--text); }
:root:not([data-theme="dark"]) .dup-item__date { color: var(--text-muted); }
:root:not([data-theme="dark"]) .dup-item__meta { color: var(--text); }
:root:not([data-theme="dark"]) .dup-item__owner { color: var(--text-muted); }
:root:not([data-theme="dark"]) .dup-group__url { color: var(--primary); }
:root:not([data-theme="dark"]) .header__user:hover { background: var(--primary-light); }
:root:not([data-theme="dark"]) .profile-block {
    background: var(--input-bg);
    border-color: var(--border);
}
:root:not([data-theme="dark"]) .profile-row { border-bottom-color: var(--border); }
:root:not([data-theme="dark"]) .profile-label { color: var(--text-muted); }
:root:not([data-theme="dark"]) tr.group-header td {
    background: linear-gradient(90deg, var(--primary-light), transparent);
    color: var(--primary);
    border-top-color: var(--border);
}
:root:not([data-theme="dark"]) .grid-group-header {
    color: var(--primary);
    border-bottom-color: var(--border);
}
:root:not([data-theme="dark"]) .page-timing { color: var(--text-muted); opacity: .6; }
:root:not([data-theme="dark"]) .dnd-overlay__inner {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--primary);
}
:root:not([data-theme="dark"]) .dnd-overlay__title { color: var(--text); }

/* ============================================================ */
/* ==================== PHASE 6: «ДЕСЯТКА» ==================== */
/* ============================================================ */

/* --- Accent themes (swap --primary / --primary-hover) --- */
[data-accent="indigo"] { --primary:#6366f1; --primary-hover:#4f46e5; --primary-light:rgba(99,102,241,.1); }
[data-accent="purple"] { --primary:#8b5cf6; --primary-hover:#7c3aed; --primary-light:rgba(139,92,246,.12); }
[data-accent="teal"]   { --primary:#14b8a6; --primary-hover:#0d9488; --primary-light:rgba(20,184,166,.12); }
[data-accent="amber"]  { --primary:#f59e0b; --primary-hover:#d97706; --primary-light:rgba(245,158,11,.12); }
[data-accent="rose"]   { --primary:#f43f5e; --primary-hover:#e11d48; --primary-light:rgba(244,63,94,.12); }
[data-accent="emerald"]{ --primary:#10b981; --primary-hover:#059669; --primary-light:rgba(16,185,129,.12); }
[data-accent="sky"]    { --primary:#0ea5e9; --primary-hover:#0284c7; --primary-light:rgba(14,165,233,.12); }
[data-accent="pink"]   { --primary:#ec4899; --primary-hover:#db2777; --primary-light:rgba(236,72,153,.12); }

/* --- Density (compact / comfortable / spacious) --- */
[data-density="compact"]   { --tbl-py: 4px;  --tbl-px: 8px;  --tbl-font: 12px; --row-h: 28px; --card-gap: 10px; }
[data-density="comfortable"] { --tbl-py: 10px; --tbl-px: 12px; --tbl-font: 13px; --row-h: 40px; --card-gap: 16px; }
[data-density="spacious"]  { --tbl-py: 14px; --tbl-px: 16px; --tbl-font: 14px; --row-h: 54px; --card-gap: 22px; }

[data-density] td, [data-density] th { padding: var(--tbl-py) var(--tbl-px); font-size: var(--tbl-font); }
[data-density] .grid-view { gap: var(--card-gap); }
[data-density="compact"] .video-thumb { width: 96px; height: 58px; }
[data-density="compact"] .img-thumb { max-width: 40px; max-height: 28px; }
[data-density="compact"] .btn-icon { width: 26px; height: 26px; }
[data-density="compact"] .cr-card__body { padding: 10px; }
[data-density="spacious"] .video-thumb { width: 180px; height: 108px; }
[data-density="spacious"] .img-thumb { max-width: 72px; max-height: 48px; }
[data-density="spacious"] .cr-card__body { padding: 18px; }

/* --- Settings popover (density / accent / etc.) --- */
.settings-btn {
    background: transparent; border: 1px solid var(--border); color: var(--text-muted);
    width: 32px; height: 30px; border-radius: var(--radius);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.settings-btn:hover { border-color: var(--primary); color: var(--primary); }
.settings-pop {
    display: none;
    position: absolute; top: 56px; right: 20px; z-index: 1200;
    min-width: 300px;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0,0,0,.3);
    padding: 16px; animation: fadeIn .15s;
}
.settings-pop.active { display: block; }
.settings-pop__section { margin-bottom: 14px; }
.settings-pop__section:last-child { margin-bottom: 0; }
.settings-pop__label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); font-weight: 600;
    margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;
}
.density-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.density-btn {
    padding: 7px 6px; font-size: 12px; border-radius: 8px;
    background: transparent; color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: pointer; font-family: inherit; transition: all .15s;
}
.density-btn:hover { border-color: var(--primary); color: var(--primary); }
.density-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.accent-row { display: flex; gap: 7px; flex-wrap: wrap; }
.accent-swatch {
    width: 26px; height: 26px; border-radius: 50%;
    cursor: pointer; border: 2px solid transparent; position: relative;
    transition: transform .15s;
}
.accent-swatch:hover { transform: scale(1.15); }
.accent-swatch.active { border-color: var(--text); }
.accent-swatch.active::after {
    content: '✓'; color: #fff; font-size: 14px; font-weight: bold;
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

/* --- Ctrl+K command palette --- */
.cmdk-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
    z-index: 2500; align-items: flex-start; justify-content: center;
    padding-top: 15vh; animation: fadeIn .12s;
}
.cmdk-overlay.active { display: flex; }
.cmdk-box {
    width: 640px; max-width: 92vw;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 24px 80px rgba(0,0,0,.6);
    overflow: hidden;
    animation: cmdk-slide .18s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes cmdk-slide { from { opacity: 0; transform: translateY(-14px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.cmdk-input {
    width: 100%; padding: 16px 20px;
    font-size: 16px; background: transparent; border: none; color: var(--text);
    outline: none; border-bottom: 1px solid var(--border);
    font-family: inherit;
}
.cmdk-list { max-height: 52vh; overflow-y: auto; padding: 6px; }
.cmdk-section-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); padding: 10px 12px 4px; font-weight: 700;
}
.cmdk-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 8px;
    cursor: pointer; font-size: 14px; color: var(--text);
    transition: background .1s;
}
.cmdk-item:hover, .cmdk-item.active { background: var(--primary-light); }
.cmdk-item.active { color: var(--primary); }
.cmdk-item__icon { width: 22px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.cmdk-item.active .cmdk-item__icon { color: var(--primary); }
.cmdk-item__text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item__hint { font-size: 11px; color: var(--text-muted); text-transform: none; }
.cmdk-kbd {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; padding: 2px 5px; font-size: 10px; font-family: ui-monospace, Consolas, monospace;
    background: var(--input-bg); border: 1px solid var(--border); border-radius: 4px;
    color: var(--text-muted);
}
.cmdk-empty { padding: 30px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.cmdk-footer {
    display: flex; gap: 12px; align-items: center;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    font-size: 11px; color: var(--text-muted);
}

/* --- Hover-preview video on grid --- */
.cr-card__media { transition: box-shadow .2s; }
.cr-card__preview-video {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover;
    background: #000;
    opacity: 0;
    transition: opacity .25s;
    pointer-events: none;
    z-index: 2;
}
.cr-card__preview-video.playing { opacity: 1; }
.cr-card__preview-hint {
    position: absolute; top: 44px; left: 10px;
    display: flex; align-items: center; gap: 4px;
    padding: 3px 7px;
    font-size: 10px; font-weight: 600;
    background: rgba(0,0,0,.75); color: #fff;
    border-radius: 999px;
    opacity: 0; transition: opacity .2s;
    pointer-events: none; z-index: 3;
}
.cr-card:hover .cr-card__preview-hint { opacity: 1; }
.cr-card__preview-hint::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%; background: #ef4444;
    animation: rec-pulse 1.2s infinite;
}
@keyframes rec-pulse { 0%,100% { opacity: 1; } 50% { opacity: .2; } }

/* --- Column visibility / reorder / resize --- */
.col-btn {
    padding: 6px 10px; font-size: 12px; border-radius: 6px;
    background: transparent; border: 1px solid var(--border); color: var(--text-muted);
    cursor: pointer; font-family: inherit;
}
.col-btn:hover { border-color: var(--primary); color: var(--primary); }
.col-pop {
    display: none;
    position: absolute; z-index: 1100;
    min-width: 260px; max-height: 70vh; overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 8px;
    box-shadow: 0 12px 32px rgba(0,0,0,.25);
}
.col-pop.active { display: block; }
.col-pop__label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 6px 10px 4px; }
.col-pop__item {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px; border-radius: 6px; cursor: grab;
    font-size: 13px; user-select: none;
}
.col-pop__item:hover { background: var(--primary-light); }
.col-pop__item.dragging { opacity: .4; }
.col-pop__item.drag-over { box-shadow: inset 0 2px 0 var(--primary); }
.col-pop__handle { color: var(--text-muted); cursor: grab; font-size: 16px; line-height: 1; }
.col-pop__chk { accent-color: var(--primary); }
.col-pop__name { flex: 1; }
.col-pop__actions { display: flex; gap: 6px; padding: 8px 10px 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.col-pop__actions button { flex: 1; font-size: 11px; padding: 5px; border-radius: 6px; background: transparent; border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; }
.col-pop__actions button:hover { border-color: var(--primary); color: var(--primary); }

th { position: relative; }
th.col-resizer::after {
    content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 5px;
    cursor: col-resize; background: transparent; transition: background .15s;
}
th.col-resizer:hover::after { background: var(--primary); opacity: .5; }
th.col-resizing::after { background: var(--primary); }
.col-hidden { display: none !important; }
th.col-dragging { opacity: .3; }
th.col-drop-target { box-shadow: inset 3px 0 0 var(--primary); }

/* --- Facet sidebar --- */
.layout-with-facets {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 16px;
    align-items: flex-start;
}
/* Collapsed state (desktop): hide the facet sidebar so the table gets full width. */
.layout-with-facets.facets-collapsed { grid-template-columns: 1fr; }
.layout-with-facets.facets-collapsed > .facet-sidebar { display: none; }
/* Grid items default to min-width: auto, which lets a wide table inside push
   the 1fr column past the viewport. Forcing min-width: 0 makes the column
   stay within its grid track and lets .table-wrap's own overflow-x:auto
   produce a horizontal scrollbar INSIDE the card (instead of on <body>). */
.layout-with-facets > * { min-width: 0; }
.facet-sidebar {
    position: sticky; top: 72px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    font-size: 13px;
}
.facet-section { margin-bottom: 16px; }
.facet-section:last-child { margin-bottom: 0; }
.facet-section__title {
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); font-weight: 700;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; user-select: none;
}
.facet-section__title::after {
    content: '▼'; font-size: 8px; transition: transform .2s; color: var(--text-muted);
}
.facet-section.collapsed .facet-section__title::after { transform: rotate(-90deg); }
.facet-section.collapsed .facet-section__body { display: none; }
.facet-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 8px; border-radius: 6px;
    text-decoration: none; color: var(--text);
    cursor: pointer; transition: background .12s;
    font-size: 12px;
}
.facet-item:hover { background: var(--primary-light); }
.facet-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.facet-item__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.facet-item__count {
    font-size: 10px; padding: 1px 7px;
    background: var(--input-bg); border-radius: 999px;
    color: var(--text-muted); font-variant-numeric: tabular-nums;
    margin-left: 6px; flex-shrink: 0;
}
.facet-item.active .facet-item__count { background: var(--primary); color: #fff; }

/* Show more / collapse toggle inside long facet sections (e.g. Темы with 13+ items) */
.facet-item--more { display: none; }
.facet-section__body.is-expanded .facet-item--more { display: flex; }
.facet-show-more {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 5px 8px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background .12s, color .12s, border-color .12s;
}
.facet-show-more:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    border-style: solid;
}
.facet-show-more__collapse { display: none; }
.facet-section__body.is-expanded .facet-show-more__expand { display: none; }
.facet-section__body.is-expanded .facet-show-more__collapse { display: inline; }
.facet-toggle {
    display: none;
    padding: 6px 10px; border-radius: 6px;
    font-size: 12px; border: 1px solid var(--border); background: transparent;
    color: var(--text-muted); cursor: pointer; font-family: inherit;
}
.facet-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* --- Split view --- */
body.split-view-active .layout-with-facets {
    grid-template-columns: 220px 1fr 420px;
}
.split-pane {
    display: none;
    position: sticky; top: 72px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    animation: fadeIn .2s;
}
body.split-view-active .split-pane { display: block; }
.split-pane__empty { text-align: center; padding: 40px 10px; color: var(--text-muted); font-size: 13px; }
.split-pane__media {
    width: 100%;
    aspect-ratio: 16/10;
    border-radius: var(--radius);
    background: #000;
    overflow: hidden;
    margin-bottom: 12px;
}
.split-pane__media video, .split-pane__media img {
    width: 100%; height: 100%; object-fit: contain; background: #000;
}
.split-pane__title { font-size: 14px; font-weight: 600; margin-bottom: 6px; word-break: break-word; }
.split-pane__meta { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.split-pane__row {
    display: flex; justify-content: space-between; gap: 8px;
    font-size: 12px; padding: 4px 0;
    border-bottom: 1px solid var(--border);
}
.split-pane__row:last-child { border-bottom: none; }
.split-pane__row b { color: var(--text-muted); font-weight: 500; }
.split-pane__row span { text-align: right; word-break: break-all; max-width: 60%; }
.split-pane__actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

tr.row-active-preview td { background: var(--primary-light) !important; }
.cr-card.card-active-preview { box-shadow: 0 0 0 2px var(--primary); }

/* --- Drag-to-select + shift-click --- */
.selection-rect {
    position: fixed; z-index: 1500;
    border: 1.5px solid var(--primary);
    background: rgba(99,102,241,.1);
    pointer-events: none;
    border-radius: 2px;
    display: none;
}
.selection-rect.active { display: block; }
tr.sel-candidate td, .cr-card.sel-candidate { background: var(--primary-light) !important; }

/* --- Mini sparkline --- */
.sparkline {
    display: inline-block;
    vertical-align: middle;
    height: 16px;
    margin-left: 6px;
}
.sparkline__path { fill: none; stroke: var(--primary); stroke-width: 1.5; }
.sparkline__area { fill: var(--primary); opacity: .15; }
.sparkline__dot { fill: var(--primary); }
/* NOTE: .likes-cell is a <td>; it must stay a normal table-cell. The inner
   .likes-wrap handles the inline-flex layout of number + delta. */
.likes-cell { vertical-align: middle; white-space: nowrap; }

/* --- View Transitions API (for supported browsers) --- */
@supports (view-transition-name: auto) {
    ::view-transition-old(root),
    ::view-transition-new(root) { animation-duration: 0.25s; }
    ::view-transition-old(thumb-viewer), ::view-transition-new(thumb-viewer) {
        animation-duration: .32s; animation-timing-function: cubic-bezier(.2,.9,.3,1.1);
    }
}
.vt-thumb { view-transition-name: thumb-viewer; }

/* --- Mobile bottom nav + FAB --- */
.mobile-bottom-nav {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 900;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,.1);
    backdrop-filter: blur(12px);
}
.mobile-bottom-nav__row { display: flex; justify-content: space-around; align-items: center; }
.mobile-bottom-nav__item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 4px;
    text-decoration: none;
    color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .3px;
    transition: color .15s;
    border-radius: 8px;
}
.mobile-bottom-nav__item.active, .mobile-bottom-nav__item:hover { color: var(--primary); }
.mobile-bottom-nav__item.active { background: var(--primary-light); }
.mobile-bottom-nav__item svg { flex-shrink: 0; }

.fab {
    display: none;
    position: fixed; right: 20px; bottom: 72px; z-index: 910;
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--primary); color: #fff;
    border: none; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,.3), 0 0 0 0 var(--primary-light);
    align-items: center; justify-content: center;
    transition: transform .15s, box-shadow .25s;
    text-decoration: none;
}
.fab:hover { transform: scale(1.05) rotate(5deg); }
.fab:active { transform: scale(.95); }
.fab-menu {
    display: none;
    position: fixed; right: 20px; bottom: 140px; z-index: 910;
    flex-direction: column; gap: 10px;
    animation: fab-menu-in .2s;
}
.fab-menu.active { display: flex; }
@keyframes fab-menu-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fab-menu__item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; padding-right: 18px;
    background: var(--surface); color: var(--text);
    border-radius: 999px; text-decoration: none;
    border: 1px solid var(--border);
    font-size: 13px; font-weight: 500;
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
}

@media (max-width: 768px) {
    .mobile-bottom-nav { display: block; }
    .fab { display: inline-flex; }
    body { padding-bottom: 80px; }
    .layout-with-facets { grid-template-columns: 1fr; }
    .facet-sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        width: 80vw; max-width: 300px;
        z-index: 1100;
        transform: translateX(-100%);
        transition: transform .25s;
        max-height: 100vh; border-radius: 0;
        overflow-y: auto;
    }
    .facet-sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }
    .facet-toggle { display: inline-flex; }
    body.split-view-active .layout-with-facets { grid-template-columns: 1fr; }
    body.split-view-active .split-pane {
        position: fixed; inset: auto 0 0 0;
        max-height: 70vh; border-radius: 16px 16px 0 0;
    }
}

/* --- Subtle scroll-to-top button --- */
.scroll-top {
    position: fixed; right: 20px; bottom: 20px; z-index: 800;
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--surface); color: var(--text-muted);
    border: 1px solid var(--border);
    display: none; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-md);
    transition: all .15s;
}
.scroll-top.visible { display: inline-flex; }
.scroll-top:hover { color: var(--primary); border-color: var(--primary); }
@media (max-width: 768px) { .scroll-top { bottom: 140px; } }


/* === AI transcription & analysis === */

/* === AI transcription & analysis === */

/* Dot badge on video thumb */
.video-thumb { position: relative; }
.ai-dot {
    position: absolute; top: 4px; right: 4px;
    width: 10px; height: 10px; border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(0,0,0,.35);
    pointer-events: none; z-index: 2;
}
.ai-dot--card { top: 6px; right: 6px; width: 11px; height: 11px; }
.ai-dot--done       { background: #22c55e; }
.ai-dot--processing { background: #3b82f6; animation: ai-pulse 1.2s ease-in-out infinite; }
.ai-dot--pending    { background: #eab308; }
.ai-dot--error      { background: #ef4444; }
.ai-dot--none       { background: #64748b; opacity: .6; }
@keyframes ai-pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(1.3); } }

/* AI section inside detail modal */
.ai-section { }
.ai-status-inline { margin-left: 8px; font-size: 12px; font-weight: 400; }
.ai-badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 500; letter-spacing: .2px;
}
.ai-badge--ok   { background: rgba(34,197,94,.15);  color: #22c55e; }
.ai-badge--proc { background: rgba(59,130,246,.15); color: #3b82f6; }
.ai-badge--pend { background: rgba(234,179,8,.15);  color: #eab308; }
.ai-badge--err  { background: rgba(239,68,68,.15);  color: #ef4444; }
.ai-badge--skip { background: rgba(100,116,139,.15); color: #64748b; }
.ai-badge--none { background: rgba(100,116,139,.15); color: #64748b; }

.ai-body { margin-top: 6px; }
.ai-loading, .ai-proc, .ai-err, .ai-empty {
    padding: 10px 12px; border-radius: 8px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: 13px; color: var(--text-muted);
}
.ai-proc { background: rgba(59,130,246,.08); border-color: rgba(59,130,246,.3); color: var(--text); }
.ai-err  { background: rgba(239,68,68,.08);  border-color: rgba(239,68,68,.3);  color: var(--text); }
.ai-empty b { color: var(--text); }
.ai-empty code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.ai-grid {
    display: grid; gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    margin-bottom: 10px;
}
.ai-block {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 10px;
}
.ai-block--wide { grid-column: 1 / -1; }
.ai-block__label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.ai-block__val { font-size: 13px; line-height: 1.5; color: var(--text); }

.ai-topics { display: flex; flex-wrap: wrap; gap: 4px; }
.ai-topic {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 11px; background: rgba(99,102,241,.12); color: #818cf8;
    border: 1px solid rgba(99,102,241,.25);
}

.ai-transcript { margin-top: 8px; }
.ai-transcript summary {
    cursor: pointer; padding: 8px 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; font-size: 13px; user-select: none;
}
.ai-transcript summary:hover { background: var(--surface-hover, var(--bg)); }
.ai-transcript__body {
    margin-top: 6px; padding: 12px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; font-size: 13px; line-height: 1.6;
    max-height: 320px; overflow-y: auto;
    white-space: pre-wrap; word-break: break-word;
    color: var(--text);
}

.ai-meta {
    margin-top: 8px; font-size: 11px; color: var(--text-muted);
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.ai-retry { margin-top: 6px; }

/* === AI queue popover === */
.ai-queue-btn { position: relative; }
.ai-queue-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    margin-left: 4px;
    background: var(--primary); color: #fff;
    border-radius: 9px; font-size: 10px; font-weight: 700; line-height: 1;
}
.ai-queue-btn:has(.ai-queue-badge.has-err) .ai-queue-badge,
.ai-queue-badge.has-err { background: #ef4444; }

.ai-queue-pop {
    position: fixed; top: 60px; right: 20px; z-index: 900;
    width: 420px; max-width: calc(100vw - 40px);
    max-height: calc(100vh - 80px); overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow-lg, 0 20px 50px rgba(0,0,0,.4));
    padding: 0;
    display: none;
    animation: ai-q-in .16s ease-out;
}
.ai-queue-pop.active { display: block; }
@keyframes ai-q-in { from { opacity: 0; transform: translateY(-6px); } }
.ai-queue-pop__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.ai-queue-pop__title { font-weight: 600; font-size: 14px; }
.ai-queue-pop__actions { display: flex; gap: 6px; }
.ai-queue-pop__body { padding: 12px 14px; }
.ai-queue-loading { padding: 30px; text-align: center; color: var(--text-muted); font-size: 13px; }

.ai-q-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    margin-bottom: 14px;
}
.ai-q-stat {
    display: block; padding: 8px 10px; border-radius: 8px;
    background: var(--bg); border: 1px solid var(--border);
    text-decoration: none; color: var(--text);
    transition: all .1s;
}
.ai-q-stat:hover { border-color: var(--primary); transform: translateY(-1px); }
.ai-q-stat__n { font-size: 20px; font-weight: 700; line-height: 1.2; }
.ai-q-stat__l { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }
.ai-q-stat--ok   .ai-q-stat__n { color: #22c55e; }
.ai-q-stat--proc .ai-q-stat__n { color: #3b82f6; }
.ai-q-stat--pend .ai-q-stat__n { color: #eab308; }
.ai-q-stat--err  .ai-q-stat__n { color: #ef4444; }

.ai-q-section { margin-bottom: 14px; }
.ai-q-section__title {
    font-size: 11px; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .5px; margin-bottom: 6px; font-weight: 600;
}
.ai-q-list { list-style: none; padding: 0; margin: 0; }
.ai-q-list li {
    padding: 6px 8px; border-radius: 6px; margin-bottom: 3px;
    background: var(--bg); border: 1px solid var(--border);
    font-size: 12px;
}
.ai-q-list li:hover { border-color: var(--primary); }
.ai-q-item { display: flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; }
.ai-q-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ai-q-geo { font-weight: 600; }
.ai-q-lang { color: var(--text-muted); font-size: 10px; }
.ai-q-attempts { color: #ef4444; margin-left: auto; font-size: 10px; }
.ai-q-err { font-size: 11px; color: #ef4444; margin-top: 3px; word-break: break-word; opacity: .85; }
.ai-q-summary { font-size: 11px; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }

.ai-q-foot {
    display: flex; flex-wrap: wrap; gap: 4px;
    padding-top: 10px; border-top: 1px solid var(--border);
}

.ai-q-backoff {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #b45309;
    padding: 8px 10px; border-radius: 8px;
    font-size: 12px; line-height: 1.5; margin-bottom: 10px;
}
[data-theme="dark"] .ai-q-backoff { color: #fcd34d; background: rgba(245, 158, 11, 0.1); }

.ai-queue-btn.has-backoff::after {
    content: '⏸'; position: absolute; right: -6px; bottom: -6px;
    background: #f59e0b; color: #fff; font-size: 10px; line-height: 1;
    width: 16px; height: 16px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2px var(--bg-secondary);
}

@media (max-width: 640px) {
    .ai-queue-pop { left: 10px; right: 10px; width: auto; top: 70px; }
    .ai-q-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ============ Likes history (stats tracker) ============ */
.likes-cell { min-width: 104px; }
.likes-wrap { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.likes-num { font-variant-numeric: tabular-nums; }
.likes-delta {
    display: inline-flex; align-items: center; gap: 1px;
    font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px;
    font-variant-numeric: tabular-nums;
}
.likes-delta--up   { color: #16a34a; background: rgba(34, 197, 94, 0.12); }
.likes-delta--down { color: #dc2626; background: rgba(239, 68, 68, 0.12); }
.likes-delta--flat { color: var(--text-muted); background: transparent; padding: 0 2px; }
[data-theme="dark"] .likes-delta--up   { color: #4ade80; background: rgba(34, 197, 94, 0.15); }
[data-theme="dark"] .likes-delta--down { color: #f87171; background: rgba(239, 68, 68, 0.15); }

/* Benchmark percentile badge */
.bench-badge {
    display: inline-flex; align-items: center; gap: 2px;
    font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 10px;
    background: rgba(37, 99, 235, .12); color: #1d4ed8; white-space: nowrap;
}
.bench-badge--gold   { background: linear-gradient(135deg, rgba(250,204,21,.25), rgba(245,158,11,.2)); color: #b45309; }
.bench-badge--silver { background: rgba(148,163,184,.2); color: #475569; }
.bench-badge--weak   { background: rgba(148,163,184,.12); color: var(--text-muted); opacity: .7; }
[data-theme="dark"] .bench-badge { color: #60a5fa; }
[data-theme="dark"] .bench-badge--gold { color: #fbbf24; }
[data-theme="dark"] .bench-badge--silver { color: #cbd5e1; }

.likes-spark { display: inline-block; min-width: 48px; height: 18px; opacity: .85; line-height: 0; }
.likes-spark:hover { opacity: 1; }
.likes-spark:empty { background: linear-gradient(90deg, transparent 0%, var(--bg-tertiary) 50%, transparent 100%); background-size: 200% 100%; border-radius: 3px; }

/* th sort sub-options */
/* Queue-count badge on the top-level "Транскрипция" nav item */
.nav-ai-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px;
    font-size: 10px; font-weight: 700; line-height: 1;
    color: #fff; background: var(--primary);
    border-radius: 999px;
}
.nav-ai-badge--err { background: var(--danger); }
.nav-health-dot {
    width: 8px; height: 8px; margin-left: 5px; border-radius: 50%;
    background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent);
}

/* System-health banner (admins) */
.health-banner {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 8px 16px; font-size: 13px; line-height: 1.4;
    background: color-mix(in srgb, var(--danger) 12%, var(--surface, #fff));
    border-bottom: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
    color: var(--text);
}
.health-banner--warn {
    background: color-mix(in srgb, #f59e0b 14%, var(--surface, #fff));
    border-bottom-color: color-mix(in srgb, #f59e0b 40%, transparent);
}
.health-banner a { font-weight: 600; }
.health-banner__x { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--text-muted); font-size: 16px; }

/* Transcript-match snippet shown when search hit the video transcript. */
.row-transcript {
    display: flex; align-items: flex-start; gap: 5px;
    margin-top: 5px; padding: 4px 8px;
    background: var(--primary-light); border-left: 2px solid var(--primary);
    border-radius: 4px; font-size: 11px; line-height: 1.4; color: var(--text-muted);
    max-width: 420px;
}
.row-transcript__ico { flex: 0 0 auto; }
.row-transcript__txt { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-transcript--card { max-width: none; margin-bottom: 6px; }

.th-sort-alt { font-size: 10px; font-weight: normal; color: var(--text-muted); margin-left: 4px; white-space: nowrap; }
.th-sort-alt a { color: var(--text-muted); }
.th-sort-alt a:hover { color: var(--primary); }

/* Detail modal: stats section */
.stats-section .stats-actions { float: right; font-weight: normal; }
.stats-kpis {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px;
}
.stats-kpi {
    background: var(--bg-tertiary); border: 1px solid var(--border);
    padding: 10px; border-radius: 8px; text-align: center;
}
.stats-kpi__n { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-kpi__l { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.stats-kpi--up   .stats-kpi__n { color: #16a34a; }
.stats-kpi--down .stats-kpi__n { color: #dc2626; }
.stats-kpi--flat .stats-kpi__n { color: var(--text); }
[data-theme="dark"] .stats-kpi--up   .stats-kpi__n { color: #4ade80; }
[data-theme="dark"] .stats-kpi--down .stats-kpi__n { color: #f87171; }

.stats-chart { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-bottom: 10px; }
.stats-svg { display: block; width: 100%; height: auto; }
.stats-empty { padding: 12px; background: var(--bg-tertiary); border-radius: 8px; color: var(--text-muted); font-size: 12px; text-align: center; }
.stats-err { padding: 10px; color: #ef4444; font-size: 12px; }
.stats-loading { padding: 12px; color: var(--text-muted); font-size: 12px; }
.stats-meta { margin-top: 8px; color: var(--text-muted); font-size: 11px; }

.stats-details { margin-top: 8px; }
.stats-details summary { cursor: pointer; font-size: 12px; color: var(--text-muted); padding: 4px; }
.stats-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.stats-table th, .stats-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.stats-table .d-up   { color: #16a34a; }
.stats-table .d-down { color: #dc2626; }
.stats-table .d-flat { color: var(--text-muted); }
[data-theme="dark"] .stats-table .d-up   { color: #4ade80; }
[data-theme="dark"] .stats-table .d-down { color: #f87171; }

/* Update timeline (used in detail modal — replaces hidden stats-details table) */
.ut {
    margin-top: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.ut-head {
    padding: 8px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 12px; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.ut-cols {
    display: grid;
    grid-template-columns: 110px 1fr 1fr 90px;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 10px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
.ut-list {
    max-height: 360px;
    overflow-y: auto;
}
.ut-row {
    display: grid;
    grid-template-columns: 110px 1fr 1fr 90px;
    gap: 8px;
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    align-items: center;
    transition: background .12s;
}
.ut-row:last-child { border-bottom: none; }
.ut-row:hover { background: var(--bg); }
.ut-row--up   { border-left: 3px solid rgba(34,197,94,.5); }
.ut-row--down { border-left: 3px solid rgba(239,68,68,.5); }
.ut-row--flat { border-left: 3px solid transparent; }
.ut-date { color: var(--text-muted); font-size: 12px; }
.ut-likes { font-weight: 600; color: var(--text); }
.ut-delta { font-weight: 600; }
.ut-row--up   .ut-delta { color: #16a34a; }
.ut-row--down .ut-delta { color: #dc2626; }
.ut-row--flat .ut-delta { color: var(--text-muted); }
[data-theme="dark"] .ut-row--up   .ut-delta { color: #4ade80; }
[data-theme="dark"] .ut-row--down .ut-delta { color: #f87171; }
.ut-pct-cell { text-align: right; }
.ut-pct {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 600;
}
.ut-pct--up    { background: rgba(34,197,94,.13);  color: #16a34a; }
.ut-pct--down  { background: rgba(239,68,68,.13);  color: #dc2626; }
.ut-pct--flat  { background: rgba(148,163,184,.18); color: #64748b; }
.ut-pct--first { background: rgba(99,102,241,.15);  color: #6366f1; }
[data-theme="dark"] .ut-pct--up   { color: #4ade80; }
[data-theme="dark"] .ut-pct--down { color: #f87171; }

@media (max-width: 640px) {
    .stats-kpis { grid-template-columns: repeat(2, 1fr); }
    .th-sort-alt { display: none; }
    .ut-cols, .ut-row { grid-template-columns: 90px 1fr 80px 70px; gap: 4px; padding-left: 8px; padding-right: 8px; }
}

/* ===== Shared alias: new analytics pages use --bg-card/--bg-panel/--accent/--text  but app uses --surface/--input-bg/--primary. Remap so themes work. ===== */
.trends-page, .digest-page, .cmp-page, .ins-page {
    --bg-card: var(--surface);
    --bg-panel: var(--input-bg);
    --accent: var(--primary);
}
/* Card surfaces need a subtle contrast from page bg in light mode. */
.trends-page .trend-card,
.trends-page .tr-row,
.digest-page .dg-kpi, .digest-page .dg-card, .digest-page .dg-activity, .digest-page .dg-table,
.cmp-page .cmp-card, .cmp-page .cmp-chart-wrap, .cmp-page .cmp-empty,
.ins-page .ins-stat, .ins-page .ins-tagcloud, .ins-page .ins-table-wrap, .ins-page .ins-filters, .ins-page .ins-empty,
.trends-page .trends-toolbar, .trends-page .trends-kpis .kpi,
.trends-page .trends-empty, .trends-page .trends-loading,
.digest-page .dg-empty,
.cmp-page .cmp-search input,
.trends-page .seg, .cmp-page .seg, .digest-page .seg, .ins-page .seg {
    box-shadow: var(--shadow-sm);
}

/* Page headings — use themed text colors */
.trends-page .trends-title, .digest-page .dg-title, .cmp-page .cmp-title, .ins-page .ins-title { color: var(--text); }
.trends-page .trends-sub, .digest-page .dg-sub, .cmp-page .cmp-sub, .ins-page .ins-sub,
.trends-page .trends-kpis .kpi-l, .digest-page .dg-k-l,
.digest-page .dg-date, .ins-page .ins-stat, .ins-page .f-in, .trends-page .f-in { color: var(--text-muted); }

/* KPI numbers need strong contrast */
.trends-page .trends-kpis .kpi-n,
.digest-page .dg-k-n { color: var(--text); }

/* Active segment button */
.trends-page .seg-btn.is-active, .digest-page .seg-btn.is-active, .cmp-page .seg-btn.is-active, .ins-page .seg-btn.is-active {
    background: var(--primary); color: #fff;
}
.trends-page .seg-btn, .digest-page .seg-btn, .cmp-page .seg-btn, .ins-page .seg-btn { color: var(--text); }

/* Activity heatmap — use primary accent, not hardcoded blue */
.digest-page .dg-a-cell.l0 { background: var(--input-bg); }
.digest-page .dg-a-cell.l1 { background: color-mix(in srgb, var(--primary) 25%, transparent); }
.digest-page .dg-a-cell.l2 { background: color-mix(in srgb, var(--primary) 50%, transparent); }
.digest-page .dg-a-cell.l3 { background: color-mix(in srgb, var(--primary) 75%, transparent); }
.digest-page .dg-a-cell.l4 { background: var(--primary); }

/* Insights tag cloud tiles */
.ins-page .ins-tag { background: var(--primary-light); color: var(--text); }
.ins-page .ins-tag:hover { background: color-mix(in srgb, var(--primary) 25%, transparent); }

/* Light theme: make sure secondary text & numbers above ok contrast */
.trends-page .tr-likes, .trends-page .tr-title,
.digest-page .dg-title, .cmp-page .cmp-card .c-title,
.ins-page .ins-word { color: var(--text); }

/* Delta pills — reuse standard success/danger palette */
.trends-page .tr-delta.up, .trends-page .t-delta.up, .digest-page .dg-delta.up, .digest-page .dg-k-n.up { color: var(--success); }
.trends-page .tr-delta.down, .trends-page .t-delta.down, .digest-page .dg-delta.down, .digest-page .dg-k-n.down { color: var(--danger); }
.trends-page .t-delta { background: rgba(0,0,0,.5); }
[data-theme="dark"] .trends-page .t-delta { background: rgba(0,0,0,.8); }

/* ==================== HEADER v2 (clean grouped navigation) ==================== */
.header { padding: 10px 0; }
.header__inner {
    display: flex; align-items: center; gap: 16px;
    min-height: 48px;
}

/* ---- Brand ---- */
.brand {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 700; letter-spacing: .02em;
    color: var(--text); text-decoration: none;
    padding: 4px 6px; border-radius: 8px;
    transition: color .15s;
}
.brand:hover { color: var(--primary); }
.brand__mark { color: var(--primary); flex-shrink: 0; }
.brand__text { line-height: 1; }

/* ---- Primary nav (flex-1 between brand and actions) ---- */
.primary-nav {
    display: flex; align-items: center; gap: 2px;
    flex: 1; min-width: 0; margin-left: 8px;
}
.nav-item {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 11px; border-radius: 8px;
    color: var(--text-muted); text-decoration: none;
    font-size: 13.5px; font-weight: 500; line-height: 1;
    background: transparent; border: 0; cursor: pointer; white-space: nowrap;
    transition: background .15s, color .15s;
}
.nav-item { flex: 0 0 auto; }
.nav-item svg { flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: var(--primary-light); color: var(--text); }
/* Compact the nav on mid-width screens so it never overflows into the actions. */
@media (max-width: 1280px) {
    .header__inner { gap: 10px; }
    .primary-nav { gap: 0; margin-left: 4px; }
    .nav-item { padding: 7px 8px; gap: 5px; font-size: 13px; }
}
@media (max-width: 1120px) {
    .nav-item { padding: 6px 7px; font-size: 12.5px; }
    .nav-item svg { width: 15px; height: 15px; }
}
.nav-item:hover svg { opacity: 1; }
.nav-item.is-active {
    color: var(--primary);
    background: var(--primary-light);
}
.nav-item.is-active svg { opacity: 1; }
.nav-item--dd .dd-caret { margin-left: -2px; opacity: .6; transition: transform .18s; }
.nav-dd.is-open .nav-item--dd,
.nav-dd.is-open .user-btn { background: var(--primary-light); color: var(--text); }
.nav-dd.is-open .dd-caret { transform: rotate(180deg); }

/* ---- Dropdown menu ---- */
.nav-dd { position: relative; }
.nav-menu {
    position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 60;
    opacity: 0; transform: translateY(-6px) scale(.98);
    pointer-events: none;
    transition: opacity .15s, transform .15s;
}
.nav-menu--right { left: auto; right: 0; }
.nav-dd.is-open .nav-menu {
    opacity: 1; transform: translateY(0) scale(1); pointer-events: auto;
}
.nav-menu__item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 9px 10px; border-radius: 8px;
    color: var(--text); text-decoration: none;
    font-size: 13.5px; line-height: 1.3;
    background: transparent; border: 0; cursor: pointer; text-align: left;
    transition: background .12s;
}
.nav-menu__item:hover { background: var(--primary-light); }
.nav-menu__item.is-active { background: var(--primary-light); color: var(--primary); }
.nav-menu__item.is-active .nav-menu__t { color: var(--primary); }
.nav-menu__ico {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; flex-shrink: 0;
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-muted);
}
.nav-menu__item:hover .nav-menu__ico { background: color-mix(in srgb, var(--primary) 15%, var(--input-bg)); color: var(--primary); }
.nav-menu__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nav-menu__t { font-weight: 600; color: var(--text); }
.nav-menu__d { font-size: 11.5px; color: var(--text-muted); line-height: 1.25; }
.nav-menu__sep { height: 1px; background: var(--border); margin: 4px 2px; }
.nav-menu__item--danger .nav-menu__t { color: var(--danger); }
.nav-menu__item--danger:hover { background: var(--danger-light); }
.nav-menu__item--danger:hover .nav-menu__ico { background: color-mix(in srgb, var(--danger) 15%, var(--input-bg)); color: var(--danger); }

/* ---- Right cluster (actions) ---- */
.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.icon-btn {
    position: relative;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 10px; border-radius: 8px;
    background: transparent; color: var(--text-muted); border: 1px solid var(--border);
    cursor: pointer; line-height: 1;
    transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--primary-light); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }
.icon-btn svg { flex-shrink: 0; opacity: .9; }
.kbd-hint {
    font: 11px ui-monospace, Menlo, Consolas, monospace;
    padding: 1px 5px; border-radius: 4px;
    background: var(--input-bg); color: var(--text-muted);
    border: 1px solid var(--border);
}

/* AI queue badge sits on the icon-btn instead of pushing layout */
.icon-btn .ai-queue-badge {
    position: absolute; top: -4px; right: -4px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px;
    background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
    border: 2px solid var(--surface);
}

.upload-btn {
    gap: 6px; padding: 7px 14px; font-size: 13.5px; font-weight: 600;
    border-radius: 8px;
}
.upload-btn svg { flex-shrink: 0; }

/* ---- User avatar button & card ---- */
.user-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 8px 3px 3px; border-radius: 999px;
    background: transparent; color: var(--text-muted); border: 1px solid var(--border);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.user-btn:hover { background: var(--primary-light); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }
.user-btn .dd-caret { opacity: .55; transition: transform .18s; }
.nav-dd.is-open .user-btn .dd-caret { transform: rotate(180deg); }

.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 60%, #000));
    color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .02em;
    text-transform: uppercase; flex-shrink: 0;
}
.avatar--lg { width: 40px; height: 40px; font-size: 14px; }

.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px 10px;
}
.user-card__info { min-width: 0; }
.user-card__name { font-weight: 600; font-size: 13.5px; color: var(--text); line-height: 1.2; }
.user-card__role { margin-top: 4px; }

/* ---- Make obsolete classes defensive (in case cached page uses them) ---- */
.header__nav { display: none; }
.header__user { display: none; }
.settings-btn { display: none; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1100px) {
    .nav-item span { display: none; } /* icons-only for primary nav */
    .nav-item--dd .dd-caret { display: none; }
    .nav-item { padding: 8px 9px; }
    .primary-nav { gap: 0; }
}
@media (max-width: 820px) {
    .upload-btn__label { display: none; }
    .upload-btn { padding: 8px 10px; }
    .icon-btn .kbd-hint { display: none; }
    .icon-btn { padding: 7px 9px; }
}
@media (max-width: 640px) {
    .header { padding: 8px 0; }
    .brand__text { display: none; }
    /* On small screens we rely on bottom-nav + cmdk + avatar menu */
    .primary-nav { display: none; }
    .header__inner { gap: 8px; }
}

/* ==================== TIGHT DENSITY ==================== */
[data-density="compact"] .header { padding: 6px 0; }
[data-density="compact"] .nav-item { padding: 6px 9px; font-size: 13px; }
[data-density="compact"] .upload-btn { padding: 6px 11px; font-size: 13px; }
[data-density="compact"] .avatar { width: 24px; height: 24px; font-size: 10px; }
[data-density="spacious"] .header { padding: 14px 0; }
[data-density="spacious"] .nav-item { padding: 9px 13px; }

/* ---- Make sure popovers (settings-pop, ai-queue-pop) don't get hidden by the new z-index ---- */
.settings-pop, .ai-queue-pop { z-index: 65; }

/* ==================== SHARED PAGE HEAD (all tool/admin pages) ==================== */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 16px 0 20px; flex-wrap: wrap; }
.page-head__title { margin: 0; font-size: 22px; font-weight: 700; color: var(--text); }
.page-head__subtitle { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==================== SKELETON LOADERS ==================== */
@keyframes skel-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
}
.skel-row { height: 64px; margin-bottom: 8px; }
.skel-card { aspect-ratio: 16/10; }
.skel-line { height: 12px; margin: 6px 0; }
.skel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

/* Active state for ghost toolbar buttons (Фасеты/Split/Группы share this) */
.btn--ghost.is-active { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* Compact inline stats line (replaces the tall 4-box stats row on the feed) */
.stats-line {
    display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
    padding: 9px 14px; margin-bottom: 12px;
    background: var(--input-bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
    font-size: 13px; color: var(--text-muted);
}
.stats-line b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.stats-line__item { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stats-line__item--accent b { color: var(--primary); }

/* Overflow "more tools" dropdown in card header */
.tools-dd { position: relative; }
.tools-dd__menu {
    display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 70;
    min-width: 210px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.tools-dd.is-open .tools-dd__menu { display: block; }
.tools-dd__item {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 10px; border: 0; background: transparent;
    color: var(--text); font-size: 13px; text-align: left;
    border-radius: 6px; cursor: pointer; text-decoration: none;
}
.tools-dd__item:hover { background: var(--primary-light); color: var(--primary); }
.tools-dd__item.is-active { color: var(--primary); font-weight: 600; }

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
