/**
 * Client List Item Component
 * 
 * Consolidated styles for client name cell, including:
 * - Avatar
 * - Name & Legal Entity
 * - Status Badges (VAT, Invoice, etc.)
 * - Relations (Partners, etc.)
 * - Responsive behaviors
 * 
 * Replaces:
 * - client-name.css
 * - client-name-cell.css
 * - client-name-ui-overrides.css
 * 
 * @version 3.0.0
 * @date 2026-03-16
 */

/* ==========================================================================
   1. Main Wrapper & Layout
   ========================================================================== */
.client-name-wrapper-v2,
.tp-client-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 8px 0;
    direction: rtl;
    text-align: right;
    position: relative;
}

/* Fix for tables forcing width */
#posts-table tbody td.client-name-cell .client-name-wrapper-v2,
#tasks-table tbody td.client-name-cell .client-name-wrapper-v2 {
    width: 100%;
    min-width: 250px;
    white-space: normal;
}

/* ==========================================================================
   2. Avatar
   ========================================================================== */
.client-avatar-container {
    flex-shrink: 0;
}

.client-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0; /* slate-200 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 700;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.client-avatar:hover {
    transform: scale(1.05);
    border-color: #3b82f6; /* blue-500 */
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.client-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* ==========================================================================
   3. Info Container
   ========================================================================== */
.client-info-container {
    flex: 1;
    min-width: 0; /* Important for flex child truncation */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ==========================================================================
   4. Name Line
   ========================================================================== */
.client-name-line {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    align-items: center;
    gap: 8px;
    line-height: 1.4;
}

.client-name-main {
    font-weight: 600;
    font-size: 16px;
    color: #1e293b; /* slate-800 */
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    letter-spacing: -0.02em;
}

.client-name-link {
    color: #0f172a;
    text-decoration: none;
    font-family: 'Cairo', 'IBM Plex Sans Arabic', 'Tajawal', 'Segoe UI', sans-serif;
    font-weight: 700;
    line-height: 1.5;
    transition: color 0.15s;
}

.client-name-link:hover {
    color: #2563eb; /* blue-600 */
    text-decoration: underline;
}

/* Legal Entity Badge (Consolidated) */
.tp-legal-entity-badge,
.legal-entity-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    background: #f1f5f9; /* slate-100 */
    color: #475569; /* slate-600 */
    border: 1px solid transparent;
    white-space: nowrap;
}

/* Legal Entity Variants */
.tp-legal-entity-badge--company {
    background: #fff1f2; /* rose-50 */
    color: #be123c; /* rose-700 */
    border-color: #fecdd3; /* rose-200 */
}

.tp-legal-entity-badge--individual {
    background: #f0fdf4; /* green-50 */
    color: #15803d; /* green-700 */
    border-color: #bbf7d0; /* green-200 */
}

.tp-legal-entity-badge__edit {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.tp-legal-entity-badge:hover .tp-legal-entity-badge__edit {
    opacity: 1;
}

/* ==========================================================================
   5. Meta Line (Age, Gender)
   ========================================================================== */
.age-gender-line {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #64748b; /* slate-500 */
    gap: 10px;
}

.age-display, .gender-display {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ==========================================================================
   6. System Badges (VAT, Invoice, etc.)
   ========================================================================== */
.client-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.client-badge, .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #475569;
    white-space: nowrap;
    transition: all 0.15s;
}

/* Active States */
.client-badge.active, 
.badge.active {
    border-color: transparent;
    color: white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.badge.vat-badge.active { background: #6366f1; } /* indigo-500 */
.badge.law6-badge.active { background: #f59e0b; } /* amber-500 */
.badge.inv-badge.active { background: #db2777; } /* pink-600 */
.badge.social-insurance-badge.active { background: #0ea5e9; } /* sky-500 */

/* ==========================================================================
   7. Relations & Partners (The problematic part fixed)
   ========================================================================== */
.tp-client-relations-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    margin-top: 6px;
    background: #f0f9ff; /* sky-50 */
    border: 1px solid #bae6fd; /* sky-200 */
    border-radius: 6px;
    color: #0369a1; /* sky-700 */
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    width: fit-content;
}

.tp-client-relations-trigger:hover {
    background: #e0f2fe;
    border-color: #7dd3fc;
}

.tp-client-relations-group__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.tp-client-relations-chip, 
.tp-partner-chip {
    display: inline-flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 10px;
    background: rgba(248, 250, 252, 0.92);
    border: 1px solid rgba(203, 213, 225, 0.88);
    border-radius: 16px;
    font-size: 11px;
    color: #334155;
    max-width: 100%; /* Ensure it doesn't overflow */
}

.tp-partner-chip {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    text-align: right;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    min-height: 72px;
    padding: 10px 12px 12px;
    border-color: rgba(125, 211, 252, 0.3);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.99) 0%, rgba(248, 252, 255, 0.98) 44%, rgba(239, 246, 255, 0.95) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88), 0 12px 24px rgba(15, 23, 42, 0.08);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.tp-partner-chip::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.08), rgba(59, 130, 246, 0.02) 38%, rgba(255, 255, 255, 0) 72%);
    pointer-events: none;
    z-index: -1;
}

.tp-partner-chip::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg, rgba(14, 165, 233, 0.92), rgba(59, 130, 246, 0.8), rgba(99, 102, 241, 0.72));
    border-radius: 16px 0 0 16px;
    opacity: 0.92;
    pointer-events: none;
}

.tp-partner-chip:hover,
.tp-partner-chip:focus-visible {
    transform: translateY(-2px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.94), 0 18px 34px rgba(14, 165, 233, 0.14);
    border-color: rgba(14, 165, 233, 0.42);
    background: linear-gradient(145deg, rgba(255, 255, 255, 1) 0%, rgba(240, 249, 255, 0.98) 48%, rgba(224, 242, 254, 0.96) 100%);
}

.tp-partner-chip__identity {
    min-width: 0;
    flex: 1 1 auto;
}

.tp-partner-chip__title-line {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px 10px;
    flex-wrap: wrap;
    min-width: 0;
}

/* Name truncation inside chips */
.tp-client-relations-chip__name,
.tp-partner-chip__name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Reasonable limit */
}

.tp-partner-chip__name {
    font-weight: 800;
    font-size: 13.5px;
    line-height: 1.55;
    letter-spacing: -0.01em;
}

.tp-partner-chip__share {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 4px 11px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(240, 249, 255, 0.98), rgba(224, 242, 254, 0.92));
    border: 1px solid var(--tp-partner-share-border, rgba(148, 163, 184, 0.24));
    color: #075985;
    font-size: 11.5px;
    font-weight: 900;
    letter-spacing: 0.01em;
    overflow: hidden;
    isolation: isolate;
    box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.1), 0 6px 16px rgba(14, 165, 233, 0.08);
}

.tp-partner-chip__share--empty {
    background: linear-gradient(135deg, rgba(248, 250, 252, 0.98), rgba(226, 232, 240, 0.9));
    color: #64748b;
    opacity: 1;
}

.tp-partner-chip__share-fill {
    position: absolute;
    inset: 0;
    width: var(--tp-partner-share, 0%);
    background: linear-gradient(90deg, color-mix(in srgb, var(--tp-partner-share-color, #475569) 22%, white), var(--tp-partner-share-color, #475569));
    opacity: 0.16;
    border-radius: inherit;
    z-index: 0;
}

.tp-partner-chip__share-text {
    position: relative;
    z-index: 1;
    letter-spacing: -0.01em;
}

.tp-partner-chip__related-files {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    max-width: 100%;
    margin-top: 2px;
}

.tp-partner-related-file {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    white-space: nowrap;
    border: 1px solid transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.76);
    letter-spacing: -0.01em;
}

.tp-partner-related-file--individual {
    background: linear-gradient(135deg, rgba(240, 249, 255, 0.98), rgba(224, 242, 254, 0.92));
    color: #075985;
    border-color: rgba(14, 165, 233, 0.18);
}

.tp-partner-related-file--partner {
    background: linear-gradient(135deg, rgba(245, 243, 255, 0.98), rgba(237, 233, 254, 0.92));
    color: #6d28d9;
    border-color: rgba(124, 58, 237, 0.16);
}

.tp-partner-chip__edit {
    width: 20px;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.14);
    color: #475569;
    font-size: 10px;
    margin-top: 1px;
}

/* ==========================================================================
   8. Responsive Behavior
   ========================================================================== */
@media (max-width: 768px) {
    .client-name-wrapper-v2 {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .client-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .tp-client-relations-chip__name,
    .tp-partner-chip__name {
        max-width: 140px;
        font-size: 13px;
    }
}

/* ==========================================================================
   9. Row Highlighting (Legal Entity)
   ========================================================================== */
/* Keep the row neutral and use only a vertical divider between file number and client name. */
#posts-table tbody tr.client-legal-entity-individual > td,
#tasks-table tbody tr.client-legal-entity-individual > td,
#posts-table tbody tr.client-legal-entity-company > td,
#tasks-table tbody tr.client-legal-entity-company > td,
#posts-table tbody tr.client-legal-entity-individual:hover > td,
#tasks-table tbody tr.client-legal-entity-individual:hover > td,
#posts-table tbody tr.client-legal-entity-company:hover > td,
#tasks-table tbody tr.client-legal-entity-company:hover > td {
    background: #ffffff !important;
    background-image: none !important;
    box-shadow: none !important;
}

#posts-table tbody tr.client-legal-entity-individual > td.client-name-cell,
#tasks-table tbody tr.client-legal-entity-individual > td.client-name-cell,
#posts-table tbody tr.client-legal-entity-individual > .sorting_1.client-name-cell,
#posts-table tbody tr.client-legal-entity-individual > .sorting_2.client-name-cell,
#posts-table tbody tr.client-legal-entity-individual > .sorting_3.client-name-cell,
#tasks-table tbody tr.client-legal-entity-individual > .sorting_1.client-name-cell,
#tasks-table tbody tr.client-legal-entity-individual > .sorting_2.client-name-cell,
#tasks-table tbody tr.client-legal-entity-individual > .sorting_3.client-name-cell {
    border-inline-start: 4px solid rgba(22, 163, 74, 0.72) !important;
}

#posts-table tbody tr.client-legal-entity-company > td.client-name-cell,
#tasks-table tbody tr.client-legal-entity-company > td.client-name-cell,
#posts-table tbody tr.client-legal-entity-company > .sorting_1.client-name-cell,
#posts-table tbody tr.client-legal-entity-company > .sorting_2.client-name-cell,
#posts-table tbody tr.client-legal-entity-company > .sorting_3.client-name-cell,
#tasks-table tbody tr.client-legal-entity-company > .sorting_1.client-name-cell,
#tasks-table tbody tr.client-legal-entity-company > .sorting_2.client-name-cell,
#tasks-table tbody tr.client-legal-entity-company > .sorting_3.client-name-cell {
    border-inline-start: 4px solid rgba(220, 38, 38, 0.72) !important;
}

#posts-table tbody tr.client-legal-entity-individual td.client-name-cell .client-name-wrapper-v2,
#tasks-table tbody tr.client-legal-entity-individual td.client-name-cell .client-name-wrapper-v2,
#posts-table tbody tr.client-legal-entity-company td.client-name-cell .client-name-wrapper-v2,
#tasks-table tbody tr.client-legal-entity-company td.client-name-cell .client-name-wrapper-v2 {
    width: 100%;
    padding: 10px 12px;
    border-radius: 20px;
    background: transparent !important;
}

.tp-legal-entity-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 5px 12px;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.02em;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(12px) saturate(1.15);
    -webkit-backdrop-filter: blur(12px) saturate(1.15);
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.tp-legal-entity-badge::before {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 100%);
    pointer-events: none;
}

.tp-legal-entity-badge > * {
    position: relative;
    z-index: 1;
}

.tp-legal-entity-badge i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 9999px;
    font-size: 10px;
    opacity: 0.95;
    background: rgba(255, 255, 255, 0.62);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42), 0 1px 2px rgba(15, 23, 42, 0.06);
}

.tp-legal-entity-badge--interactive {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    text-decoration: none;
    outline: none;
    border-width: 1px;
    border-style: solid;
}

.tp-legal-entity-badge--interactive:hover,
.tp-legal-entity-badge--interactive:focus-visible {
    transform: translateY(-1px) scale(1.01);
    box-shadow: 0 16px 30px rgba(15, 23, 42, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.58);
    filter: saturate(1.1) brightness(1.01);
}

.tp-legal-entity-badge--interactive:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.28);
    outline-offset: 2px;
}

.tp-legal-entity-badge--individual {
    background: linear-gradient(135deg, rgba(247, 255, 249, 0.92) 0%, rgba(220, 252, 231, 0.88) 55%, rgba(187, 247, 208, 0.84) 100%);
    color: #166534;
    border-color: rgba(34, 197, 94, 0.22);
}

.tp-legal-entity-badge--company {
    background: linear-gradient(135deg, rgba(255, 251, 235, 0.94) 0%, rgba(254, 243, 199, 0.9) 52%, rgba(253, 230, 138, 0.84) 100%);
    color: #92400e;
    border-color: rgba(245, 158, 11, 0.24);
}
