/**
 * User List V2 - Clean Card-Based Design
 * Bigger cards, smart icons with status dots, clear hierarchy
 */

/* ============================================
   Users Hub - Tabs Navigation
   ============================================ */

.hub-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-gray-200);
    margin-bottom: 24px;
    background: var(--color-white);
    padding: 0 4px;
}

.hub-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-gray-500);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.hub-tab:hover {
    color: var(--color-gray-700);
    background: var(--color-gray-50);
}

.hub-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.hub-tab-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hub-tab-icon svg {
    width: 18px;
    height: 18px;
}

.hub-content {
    min-height: 400px;
}

.hub-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--color-gray-500);
}

.hub-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-gray-200);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.hub-loading p {
    margin-top: 16px;
    font-size: 14px;
}

.hub-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--color-gray-500);
}

.hub-error p {
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive hub tabs */
@media (max-width: 768px) {
    .hub-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .hub-tab {
        padding: 12px 16px;
        font-size: 13px;
    }
    
    .hub-tab-label {
        display: none;
    }
    
    .hub-tab-icon {
        width: 20px;
        height: 20px;
    }
}

/* ============================================
   User Card Container
   ============================================ */

.user-card {
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray-100);
    transition: all 0.2s ease;
}

.user-card:hover {
    background: var(--color-gray-50);
}

.user-card.selected {
    background: rgba(59, 130, 246, 0.04);
    border-left: 3px solid var(--color-primary);
}

.user-card.expired {
    /* Removed opacity - the EXPIRED badge is clear enough */
}

.user-card.expanded {
    background: var(--color-gray-50);
    border-radius: 8px;
    margin: 8px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ============================================
   Main Card Layout - V2.2 Redesigned
   ============================================ */

.user-card-main {
    display: grid;
    /* Checkbox | User Info | Integrations (WA+Stripe) | Status | Actions */
    grid-template-columns: 40px 1fr 120px 140px 120px;
    align-items: center;
    padding: 18px 20px;
    gap: 16px;
    cursor: pointer;
    min-height: 88px;
}

@media (max-width: 1400px) {
    .user-card-main {
        grid-template-columns: 40px 1fr 110px 130px 100px;
        padding: 16px;
        gap: 14px;
    }
}

@media (max-width: 1200px) {
    .user-card-main {
        grid-template-columns: 36px 1fr 100px 120px 90px;
        padding: 14px;
        gap: 12px;
    }
}

/* ============================================
   Checkbox
   ============================================ */

.user-card-select {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   User Info Section
   ============================================ */

.user-card-info {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.user-card-avatar {
    position: relative;
    flex-shrink: 0;
}

.user-card-avatar .avatar {
    width: 48px;
    height: 48px;
    font-size: 16px;
}

.user-card-avatar .avatar-lg {
    width: 48px;
    height: 48px;
}

.avatar-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #10b981;
    border: 2px solid white;
    border-radius: 50%;
}

/* Avatar with gravatar support */
.user-card-avatar .avatar {
    position: relative;
    overflow: hidden;
}

.user-card-avatar .avatar-initials {
    position: relative;
    z-index: 1;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.user-card-avatar .avatar-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 2;
    border-radius: 50%;
}

.user-card-details {
    min-width: 0;
    flex: 1;
}

.user-card-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-gray-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.micro-badges {
    display: inline-flex;
    gap: 3px;
    flex-shrink: 0;
}

.micro-badge {
    font-size: 12px;
    line-height: 1;
}

.user-card-email {
    font-size: 13px;
    color: var(--color-gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.user-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-gray-400);
}

/* Old meta styles - kept for compatibility */
.meta-package {
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 11px;
}

.meta-package.trial {
    background: #fef3c7;
    color: #92400e;
}

.meta-package.paid {
    background: #dbeafe;
    color: #1e40af;
}

.meta-dot {
    color: var(--color-gray-300);
}

.meta-login.inactive {
    color: var(--color-gray-400);
    font-style: italic;
}

/* ============================================
   New Meta Row - V2.2 Chip-based Design
   ============================================ */

.user-card-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

/* Package chip */
.meta-chip.package {
    font-weight: 600;
}

.meta-chip.package.trial {
    background: #fef3c7;
    color: #92400e;
}

.meta-chip.package.paid {
    background: #dbeafe;
    color: #1e40af;
}

/* Timeline chip (account age) */
.meta-chip.timeline {
    background: var(--color-gray-100);
    color: var(--color-gray-600);
}

.meta-chip.timeline svg {
    color: var(--color-gray-400);
}

/* Activity chip (last login) */
.meta-chip.activity {
    background: var(--color-gray-100);
    color: var(--color-gray-600);
}

.meta-chip.activity .activity-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Recently active - green dot */
.meta-chip.activity.recent {
    background: #dcfce7;
    color: #166534;
}

.meta-chip.activity.recent .activity-dot {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* Past activity - gray dot */
.meta-chip.activity.past .activity-dot {
    background: #9ca3af;
}

/* Never logged in - hollow dot */
.meta-chip.activity.never {
    color: var(--color-gray-400);
    font-style: italic;
}

.meta-chip.activity.never .activity-dot {
    background: transparent;
    border: 1.5px solid var(--color-gray-300);
}

/* ============================================
   Status Chip - V2.2 Compact Design
   ============================================ */

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-chip-label {
    font-weight: 600;
}

.status-chip-time {
    font-weight: 400;
    opacity: 0.85;
    font-size: 11px;
}

/* Active - Green */
.status-chip.active {
    background: #dcfce7;
    color: #166534;
}

.status-chip.active .status-chip-dot {
    background: #22c55e;
}

/* Expiring Soon - Orange/Amber */
.status-chip.expiring {
    background: #fef3c7;
    color: #92400e;
    animation: subtle-pulse 2s ease-in-out infinite;
}

.status-chip.expiring .status-chip-dot {
    background: #f59e0b;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

/* Expired - Red */
.status-chip.expired {
    background: #fee2e2;
    color: #991b1b;
}

.status-chip.expired .status-chip-dot {
    background: #ef4444;
}

/* Trialing - Blue/Cyan (distinct from active green) */
.status-chip.trialing {
    background: #e0f2fe;
    color: #0369a1;
}

.status-chip.trialing .status-chip-dot {
    background: #0ea5e9;
}

@keyframes subtle-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* ============================================
   Combined Integrations - WA + Stripe together
   ============================================ */

.user-card-integrations-combined {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

/* Slightly smaller icons when combined */
.user-card-integrations-combined .app-icon-badge {
    width: 38px;
    height: 38px;
}

/* ============================================
   Usage Stats Section
   ============================================ */

.user-card-usage {
    display: flex;
    align-items: center;
    gap: 16px;
}

.usage-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.usage-stat-icon {
    width: 18px;
    height: 18px;
    color: var(--color-gray-400);
    display: flex;
    align-items: center;
    justify-content: center;
}

.usage-stat-icon svg {
    width: 16px;
    height: 16px;
}

.usage-stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-gray-700);
    min-width: 20px;
}

/* ============================================
   App Icon Badges (WhatsApp, Stripe, Cal)
   ============================================ */

.app-icon-badge {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.app-icon-badge:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.app-icon-img {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

/* WhatsApp Icon */
.app-icon-badge.whatsapp .app-icon-img {
    background: #25D366;
    color: white;
}

.app-icon-badge.whatsapp.disconnected .app-icon-img {
    background: var(--color-gray-300);
    color: var(--color-gray-500);
}

.app-icon-badge.whatsapp .app-icon-img svg {
    width: 24px;
    height: 24px;
}

/* Stripe Icon */
.app-icon-badge.stripe .app-icon-img.stripe-logo {
    background: #635BFF;
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 22px;
    font-weight: 700;
}

.app-icon-badge.stripe.inactive .app-icon-img.stripe-logo {
    background: var(--color-gray-300);
    color: var(--color-gray-500);
}

/* Cal.com Icon */
.app-icon-badge.cal .app-icon-img.cal-logo {
    background: #292929;
    color: white;
}

.app-icon-badge.cal.inactive .app-icon-img.cal-logo {
    background: var(--color-gray-300);
    color: var(--color-gray-500);
}

.app-icon-badge.cal .app-icon-img svg {
    width: 20px;
    height: 20px;
}

/* Count Badge (legacy - keep for other uses) */
.app-icon-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* WhatsApp dual badges */
.wa-badge {
    position: absolute;
    height: 18px;
    padding: 0 5px 0 3px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    gap: 2px;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    white-space: nowrap;
}

.wa-badge svg {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

/* Subscribers badge - red, top-left */
.wa-badge.subscribers {
    top: -6px;
    left: -10px;
    background: #ef4444;
    color: white;
}

/* Messages badge - gold, bottom-right */
.wa-badge.messages {
    bottom: -6px;
    right: -10px;
    background: #fef3c7;
    color: #b45309;
}

/* LTV Badge (bottom-right for Stripe) */
.app-icon-ltv {
    position: absolute;
    bottom: -4px;
    right: -8px;
    padding: 2px 6px;
    background: #059669;
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: 8px;
    border: 2px solid white;
    white-space: nowrap;
}

/* Status Dot (top-right small indicator) */
.app-icon-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
}

.app-icon-dot.healthy {
    background: #10b981;
}

.app-icon-dot.warning {
    background: #f59e0b;
    animation: pulse-dot 2s infinite;
}

.app-icon-dot.inactive-sub {
    background: #6b7280;
}

.app-icon-dot.churned {
    background: #ef4444;
}

.app-icon-dot.one-time {
    background: #9ca3af;
}

.app-icon-dot.upcoming {
    background: #3b82f6;
    animation: pulse-dot 1.5s infinite;
}

/* Loading state for icons */
.app-icon-badge.loading {
    opacity: 0.6;
    pointer-events: none;
}

.app-icon-badge.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Messages - subtle when zero */
.usage-stat.messages:not(.has-value) .usage-stat-icon,
.usage-stat.messages:not(.has-value) .usage-stat-value {
    color: var(--color-gray-400);
}

.usage-stat.messages.has-value .usage-stat-icon {
    color: var(--color-primary);
}

/* Subscriber bar - hidden since count shown on WhatsApp badge */
.usage-stat.subscribers {
    display: none;
}

.usage-stat-bar {
    width: 50px;
    height: 5px;
    background: var(--color-gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.usage-stat-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--color-success);
    transition: width 0.3s ease;
}

.usage-stat-bar-fill.warning {
    background: var(--color-warning);
}

.usage-stat-bar-fill.danger {
    background: var(--color-danger);
}

.usage-stat-text {
    font-size: 11px;
    color: var(--color-gray-500);
    white-space: nowrap;
}

/* ============================================
   Integration Icons Container (Legacy)
   ============================================ */

.user-card-integrations {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

/* Hide old usage section - now integrated */
.user-card-usage {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

/* ============================================
   Status Badge - V2.2 Updated
   ============================================ */

.user-card-status {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* Legacy status badge wrap - kept for compatibility */
.status-badge-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.status-badge-wrap.active .status-badge {
    background: #dcfce7;
    color: #166534;
}

.status-badge-wrap.expiring .status-badge {
    background: #fef3c7;
    color: #92400e;
}

.status-badge-wrap.expired .status-badge {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge-wrap.lifetime .status-badge {
    background: #e0e7ff;
    color: #3730a3;
}

.status-detail {
    font-size: 11px;
    color: var(--color-gray-500);
}

/* ============================================
   Actions
   ============================================ */

.user-card-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.btn-icon-action {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-gray-500);
    transition: all 0.15s ease;
}

.btn-icon-action:hover {
    background: var(--color-gray-200);
    color: var(--color-gray-700);
}

.btn-icon-action svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   Hover-reveal Expand Hint Chip
   ============================================ */

.card-expand-hint {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--color-gray-700);
    color: white;
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.card-expand-hint svg {
    opacity: 0.8;
}

.card-expand-hint:hover {
    background: var(--color-gray-800);
    transform: translateX(-50%) translateY(50%) scale(1.05);
}

/* Show on card hover */
.user-card:hover .card-expand-hint:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

/* Hide when expanded */
.card-expand-hint.hidden {
    display: none;
}

/* User card needs relative positioning */
.user-card {
    position: relative;
}

/* Collapse button in expanded footer */
.card-collapse-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: var(--color-gray-100);
    border: none;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-gray-600);
    cursor: pointer;
    transition: all 0.15s ease;
}

.card-collapse-btn:hover {
    background: var(--color-gray-200);
    color: var(--color-gray-800);
}

.card-collapse-btn svg {
    opacity: 0.7;
}

/* ============================================
   Expanded Section
   ============================================ */

.user-card-expanded {
    max-height: 0;
    overflow: hidden;
    background: white;
    border-top: 1px solid var(--color-gray-100);
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.user-card-expanded.visible {
    max-height: 400px;
    padding: 0;
}

.expanded-loading,
.expanded-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: var(--color-gray-500);
}

.expanded-error {
    color: var(--color-danger);
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-gray-200);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Expanded sections grid */
.expanded-sections {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--color-gray-100);
    padding: 1px;
}

@media (max-width: 1000px) {
    .expanded-sections {
        grid-template-columns: 1fr;
    }
}

.expanded-section {
    background: white;
    padding: 16px 20px;
}

.expanded-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-gray-100);
}

.section-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-icon svg {
    width: 16px;
    height: 16px;
}

.section-icon.whatchimp {
    color: #059669;
}

.section-icon.stripe {
    color: #7c3aed;
}

.section-icon.cal {
    color: #2563eb;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-gray-700);
}

.section-link {
    margin-left: auto;
    font-size: 12px;
    color: var(--color-primary);
    text-decoration: none;
}

.section-link:hover {
    text-decoration: underline;
}

/* Info grid inside sections */
.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 16px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.info-item.highlight {
    grid-column: span 2;
    background: var(--color-gray-50);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.info-item.upcoming {
    background: #dbeafe;
    padding: 6px 10px;
    border-radius: 4px;
}

.info-label {
    color: var(--color-gray-500);
}

.info-value {
    font-weight: 500;
    color: var(--color-gray-800);
}

.info-value.large {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-gray-900);
}

.info-value.active {
    color: #059669;
}

.info-value .danger {
    color: #dc2626;
}

/* Empty state */
.section-empty {
    text-align: center;
    padding: 20px;
}

.empty-text {
    color: var(--color-gray-400);
    font-size: 13px;
}

/* Expanded footer */
.expanded-footer {
    display: flex;
    justify-content: center;
    padding: 12px;
    background: var(--color-gray-50);
    border-top: 1px solid var(--color-gray-100);
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 1200px) {
    .user-card-avatar .avatar,
    .user-card-avatar .avatar-lg {
        width: 40px;
        height: 40px;
    }
    
    .user-card-name {
        font-size: 14px;
    }
    
    .usage-stat-bar {
        width: 50px;
    }
    
    .integration-icon {
        width: 32px;
        height: 32px;
    }
    
    .integration-icon svg {
        width: 16px;
        height: 16px;
    }
}

/* ============================================
   Dark Mode (if supported)
   ============================================ */

[data-theme="dark"] .user-card {
    background: var(--color-gray-800);
    border-color: var(--color-gray-700);
}

[data-theme="dark"] .user-card:hover {
    background: var(--color-gray-750);
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .user-card-expanded,
    .user-card-actions,
    .user-card-select {
        display: none !important;
    }
}
