:root {
    --crm-dt-brand: #0d9488;
    --crm-dt-brand-dark: #0f766e;
    --crm-dt-brand-light: #ecfdf5;
    --crm-dt-border: #e2e8f0;
    --crm-dt-muted: #64748b;
    --crm-dt-text: #0f172a;
    --crm-dt-radius: 0.875rem;
    --crm-dt-shadow: 0 4px 6px -1px rgb(15 23 42 / 0.05), 0 12px 32px -8px rgb(15 23 42 / 0.08);
}

/* ── Table card shell ── */
.crm-table-card {
    overflow: hidden;
    border: 1px solid rgb(226 232 240 / 0.9) !important;
    box-shadow: var(--crm-dt-shadow) !important;
    border-radius: 1.125rem !important;
}

.crm-table-card .table-responsive {
    overflow: visible;
}

.crm-dt-enhanced {
    padding: 0 !important;
    background: #fff;
}

/* ── Card header (title + live count) ── */
.crm-dt-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, #f0fdfa 0%, #fff 55%, #f8fafc 100%);
    border-bottom: 1px solid var(--crm-dt-border);
}

.crm-dt-card-header__main {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-width: 0;
}

.crm-dt-card-header__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, #14b8a6, #0d9488);
    color: #fff;
    box-shadow: 0 4px 12px rgb(13 148 136 / 0.3);
    flex-shrink: 0;
}

.crm-dt-card-header__icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.crm-dt-card-header__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #134e4a;
    line-height: 1.2;
}

.crm-dt-card-header__subtitle {
    margin: 0.125rem 0 0;
    font-size: 0.75rem;
    color: var(--crm-dt-muted);
}

.crm-dt-card-header__count {
    flex-shrink: 0;
    padding: 0.375rem 0.875rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--crm-dt-brand-dark);
    background: var(--crm-dt-brand-light);
    border: 1px solid #99f6e4;
    border-radius: 9999px;
    white-space: nowrap;
}

/* ── Toolbar ── */
.crm-dt-toolbar {
    margin: 0 !important;
    padding: 1rem 1.5rem !important;
    background: #fafbfc !important;
    border-bottom: 1px solid var(--crm-dt-border) !important;
    gap: 1rem !important;
}

.crm-dt-toolbar .dt-layout-cell {
    display: flex;
    align-items: center;
}

.crm-dt-toolbar .dt-layout-end {
    justify-content: flex-end;
}

.crm-dt-length {
    display: flex;
    align-items: center;
}

.crm-dt-length__label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.375rem 0.75rem 0.375rem 0.875rem;
    background: #fff;
    border: 1px solid var(--crm-dt-border);
    border-radius: var(--crm-dt-radius);
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.crm-dt-length__text {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--crm-dt-muted);
    white-space: nowrap;
}

.crm-dt-length__select {
    appearance: none;
    min-width: 3.25rem;
    padding: 0.25rem 1.75rem 0.25rem 0.375rem;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--crm-dt-text);
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%230d9488'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E") no-repeat right 0 center / 1rem;
    border: none;
    cursor: pointer;
}

.crm-dt-length__select:focus {
    outline: none;
}

/* ── Search ── */
.crm-dt-search {
    position: relative;
    width: 100%;
    max-width: 22rem;
}

.crm-dt-search::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.125rem;
    height: 1.125rem;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%230d9488'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z'/%3E%3C/svg%3E") center / contain no-repeat;
    pointer-events: none;
    z-index: 1;
    opacity: 0.7;
}

.crm-dt-search__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.crm-dt-search__input {
    width: 100%;
    padding: 0.6875rem 2.5rem 0.6875rem 2.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--crm-dt-text);
    background: #fff;
    border: 1px solid var(--crm-dt-border);
    border-radius: var(--crm-dt-radius);
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04), inset 0 1px 0 rgb(255 255 255 / 0.8);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.crm-dt-search__input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.crm-dt-search__input:hover {
    border-color: #94a3b8;
}

.crm-dt-search__input:focus {
    outline: none;
    border-color: var(--crm-dt-brand);
    box-shadow: 0 0 0 4px rgb(13 148 136 / 0.12), 0 1px 2px rgb(15 23 42 / 0.04);
}

.crm-dt-search__clear {
    position: absolute;
    right: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    background: #e2e8f0;
    color: #475569;
    font-size: 0.625rem;
    font-weight: 700;
    cursor: pointer;
    z-index: 2;
    transition: background 0.15s, color 0.15s;
}

.crm-dt-search__clear.is-visible {
    display: flex;
}

.crm-dt-search__clear:hover {
    background: #fecaca;
    color: #b91c1c;
}

/* ── Table body ── */
.crm-dt-enhanced .dt-layout-table {
    padding: 0;
}

.crm-dt-enhanced table.crm-dt-table {
    width: 100% !important;
    margin: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
}

.crm-dt-enhanced table.crm-dt-table thead th {
    padding: 0.875rem 1.25rem;
    font-size: 0.6875rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--crm-dt-brand-dark);
    background: linear-gradient(to bottom, #f0fdfa, #f8fafc);
    border-bottom: 2px solid #5eead4;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.crm-dt-enhanced table.crm-dt-table tbody td {
    padding: 1rem 1.25rem;
    font-size: 0.875rem;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    transition: background 0.12s ease;
}

.crm-dt-enhanced table.crm-dt-table tbody tr:nth-child(even) td {
    background: #fafbfc;
}

.crm-dt-enhanced table.crm-dt-table tbody tr:hover td {
    background: #ecfdf5 !important;
}

.crm-dt-enhanced table.crm-dt-table tbody tr:last-child td {
    border-bottom: none;
}

.crm-dt-enhanced table.crm-dt-table thead th.dt-ordering-asc,
.crm-dt-enhanced table.crm-dt-table thead th.dt-ordering-desc {
    color: var(--crm-dt-brand);
    background: linear-gradient(to bottom, #d1fae5, #ecfdf5);
}

.crm-dt-enhanced table.crm-dt-table .btn-sm {
    border-radius: 0.5rem;
    font-weight: 600;
    padding: 0.3125rem 0.625rem;
    font-size: 0.6875rem;
    letter-spacing: 0.01em;
}

/* ── Footer ── */
.crm-dt-enhanced .dt-layout-row:last-child {
    margin: 0 !important;
    padding: 1rem 1.5rem !important;
    background: linear-gradient(to top, #f8fafc, #fff) !important;
    border-top: 1px solid var(--crm-dt-border) !important;
    gap: 1rem !important;
}

.crm-dt-info {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--crm-dt-muted);
    background: #fff;
    border: 1px solid var(--crm-dt-border);
    border-radius: var(--crm-dt-radius);
}

.crm-dt-info strong {
    color: var(--crm-dt-text);
    font-weight: 800;
}

.crm-dt-info__label,
.crm-dt-info__of {
    color: #94a3b8;
}

.crm-dt-info__empty {
    color: #94a3b8;
    font-style: italic;
}

/* ── Pagination ── */
.crm-dt-paging nav,
.crm-dt-paging {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 0.25rem;
    background: #fff;
    border: 1px solid var(--crm-dt-border);
    border-radius: var(--crm-dt-radius);
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.crm-dt-paging .dt-paging-button,
.crm-dt-paging .paginate_button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 2.125rem;
    height: 2.125rem;
    padding: 0 0.5rem !important;
    margin: 0 !important;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    color: #475569 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0.5rem !important;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: none !important;
}

.crm-dt-paging .dt-paging-button:hover:not(.disabled):not(.current),
.crm-dt-paging .paginate_button:hover:not(.disabled):not(.current) {
    color: var(--crm-dt-brand-dark) !important;
    background: var(--crm-dt-brand-light) !important;
}

.crm-dt-paging .dt-paging-button.current,
.crm-dt-paging .paginate_button.current {
    color: #fff !important;
    background: linear-gradient(135deg, #14b8a6, #0d9488) !important;
    box-shadow: 0 2px 8px rgb(13 148 136 / 0.4) !important;
}

.crm-dt-paging .dt-paging-button.disabled,
.crm-dt-paging .paginate_button.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.crm-dt-paging .dt-paging-button.first,
.crm-dt-paging .dt-paging-button.last,
.crm-dt-paging .paginate_button.first,
.crm-dt-paging .paginate_button.last {
    font-size: 0.6875rem !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0 0.625rem !important;
}

/* Empty state row */
.crm-dt-enhanced .dt-empty {
    padding: 3rem 1.5rem !important;
    text-align: center;
    font-size: 0.9375rem;
    color: #94a3b8;
    background: linear-gradient(to bottom, #fafbfc, #fff);
}

/* ── Page header ── */
.crm-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.crm-page-header__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--crm-dt-brand-dark);
    background: var(--crm-dt-brand-light);
    border-radius: 9999px;
}

.crm-page-header__title {
    margin: 0;
    font-size: 1.625rem;
    font-weight: 800;
    color: var(--crm-dt-text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.crm-page-header__desc {
    margin: 0.375rem 0 0;
    font-size: 0.9375rem;
    color: var(--crm-dt-muted);
    max-width: 36rem;
}

.crm-page-header__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.crm-page-header__actions .btn {
    box-shadow: 0 2px 8px rgb(13 148 136 / 0.2);
}

/* ── Filter bar ── */
.crm-filter-bar {
    border-radius: 1.125rem;
    border: 1px solid rgb(226 232 240 / 0.95);
    background: #fff;
    box-shadow: var(--crm-dt-shadow);
    margin-bottom: 1.25rem;
    overflow: hidden;
}

.crm-filter-bar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg, #ecfdf5 0%, #fff 100%);
    border-bottom: 1px solid var(--crm-dt-border);
    cursor: pointer;
    user-select: none;
}

.crm-filter-bar__title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    color: #134e4a;
}

.crm-filter-bar__title-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    background: linear-gradient(135deg, #14b8a6, #0d9488);
    color: #fff;
}

.crm-filter-bar__title-icon svg {
    width: 1rem;
    height: 1rem;
}

.crm-filter-bar__toggle {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--crm-dt-muted);
}

.crm-filter-bar__body {
    padding: 1.25rem 1.5rem;
}

.crm-filter-bar__grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1rem;
    align-items: end;
}

.crm-filter-bar--leads .crm-filter-bar__header {
    cursor: default;
}

.crm-filter-bar__grid--leads {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.crm-filter-field label {
    display: block;
    margin-bottom: 0.4375rem;
    font-size: 0.6875rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #475569;
}

.crm-filter-field .form-control,
.crm-filter-field .form-select {
    border-radius: var(--crm-dt-radius);
    border: 1px solid var(--crm-dt-border);
    font-size: 0.875rem;
    padding: 0.5625rem 0.875rem;
    background: #fafbfc;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.crm-filter-field .form-control:focus,
.crm-filter-field .form-select:focus {
    background: #fff;
    border-color: var(--crm-dt-brand);
    box-shadow: 0 0 0 3px rgb(13 148 136 / 0.12);
    outline: none;
}

.crm-filter-bar__submit .btn-primary {
    padding: 0.5625rem 1.25rem;
    font-weight: 700;
    border-radius: var(--crm-dt-radius);
    box-shadow: 0 4px 12px rgb(13 148 136 / 0.25);
}

.crm-filter-bar__clear {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #64748b;
    text-decoration: none;
    padding: 0.4375rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--crm-dt-border);
    background: #fff;
    transition: all 0.15s;
}

.crm-filter-bar__clear:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.crm-filter-bar__badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 1.5rem 1rem;
}

.crm-filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3125rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--crm-dt-brand-dark);
    background: linear-gradient(to bottom, #ecfdf5, #d1fae5);
    border: 1px solid #99f6e4;
    border-radius: 9999px;
    box-shadow: 0 1px 2px rgb(13 148 136 / 0.1);
}

@media (max-width: 1200px) {
    .crm-filter-bar__grid,
    .crm-filter-bar__grid--leads {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .crm-page-header__title {
        font-size: 1.375rem;
    }

    .crm-filter-bar__grid,
    .crm-filter-bar__grid--leads {
        grid-template-columns: 1fr;
    }

    .crm-dt-search {
        max-width: none;
    }

    .crm-dt-toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }

    .crm-dt-toolbar .dt-layout-end {
        justify-content: stretch;
    }

    .crm-dt-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .crm-dt-enhanced table.crm-dt-table thead th,
    .crm-dt-enhanced table.crm-dt-table tbody td {
        padding: 0.75rem 1rem;
    }
}

/* Campaign analysis — status chip filter */
.crm-status-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.crm-status-filter__chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.crm-status-filter__chip:hover {
    border-color: #94a3b8;
    background: #fff;
    color: #0f172a;
}

.crm-status-filter__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: #94a3b8;
    flex-shrink: 0;
}

.crm-status-filter__chip--all .crm-status-filter__dot { background: #64748b; }
.crm-status-filter__chip--planning .crm-status-filter__dot { background: #3b82f6; }
.crm-status-filter__chip--active .crm-status-filter__dot { background: #10b981; }
.crm-status-filter__chip--inactive .crm-status-filter__dot { background: #f59e0b; }
.crm-status-filter__chip--complete .crm-status-filter__dot { background: #8b5cf6; }

.crm-status-filter__chip.is-active {
    border-color: transparent;
    color: #fff;
    box-shadow: 0 4px 12px rgb(15 23 42 / 0.12);
}

.crm-status-filter__chip--all.is-active {
    background: linear-gradient(135deg, #475569, #334155);
}
.crm-status-filter__chip--planning.is-active {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}
.crm-status-filter__chip--active.is-active {
    background: linear-gradient(135deg, #14b8a6, #0d9488);
}
.crm-status-filter__chip--inactive.is-active {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}
.crm-status-filter__chip--complete.is-active {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.crm-status-filter__chip.is-active .crm-status-filter__dot {
    background: rgba(255, 255, 255, 0.9);
}

.crm-status-filter__hint {
    font-size: 0.75rem;
    color: #94a3b8;
}
