<script setup lang="ts">
definePageMeta({ ssr: false })
usePageTitle('Colectivos · Operations')

const {
  accounts,
  activeAccounts,
  onboardingAccounts,
  totalMembers,
  totalDependents,
  totalPremium,
  urgentIssuesCount
} = useColectivos()

const search = ref('')
const viewMode = ref<'card' | 'list'>('card')
const statusFilter = ref<'all' | 'active' | 'onboarding' | 'renewal_due' | 'suspended'>('all')
const lobFilter = ref<'all' | 'health' | 'life' | 'disability'>('all')
const expandedGroupId = ref<string | null>(null)

const statusTabs = [
  { label: 'All', value: 'all' },
  { label: 'Active', value: 'active' },
  { label: 'Onboarding', value: 'onboarding' },
  { label: 'Renewal Due', value: 'renewal_due' },
  { label: 'Suspended', value: 'suspended' }
] as const

const lobOptions = [
  { label: 'All Lines', value: 'all' },
  { label: 'Health', value: 'health' },
  { label: 'Life', value: 'life' },
  { label: 'Disability', value: 'disability' }
] as const

const filteredAccounts = computed(() => {
  let rows = accounts.value
  if (statusFilter.value !== 'all') {
    rows = rows.filter((a) => a.status === statusFilter.value)
  }
  if (lobFilter.value !== 'all') {
    rows = rows.filter((a) => a.lob?.toLowerCase() === lobFilter.value)
  }
  const t = search.value.trim().toLowerCase()
  if (t) {
    rows = rows.filter(
      (a) =>
        a.name.toLowerCase().includes(t) ||
        a.carrier?.toLowerCase().includes(t) ||
        a.id.toLowerCase().includes(t) ||
        a.ruc?.toLowerCase().includes(t)
    )
  }
  return rows
})

const pendingEnrollmentTotal = computed(() =>
  accounts.value.reduce((sum, a) => sum + (a.pendingEnrollment || 0), 0)
)

function toggleExpand(id: string) {
  expandedGroupId.value = expandedGroupId.value === id ? null : id
}

function statusDotClass(status: string) {
  switch (status) {
    case 'active': return 'gc-dot--active'
    case 'onboarding': return 'gc-dot--onboarding'
    case 'renewal_due': return 'gc-dot--renewal'
    case 'suspended': case 'cancelled': return 'gc-dot--suspended'
    default: return 'gc-dot--default'
  }
}

function lobBadgeClass(lob: string) {
  switch (lob?.toLowerCase()) {
    case 'health': return 'gc-lob--health'
    case 'life': return 'gc-lob--life'
    case 'disability': return 'gc-lob--disability'
    default: return 'gc-lob--default'
  }
}

function renewalClass(dateStr: string) {
  if (!dateStr) return ''
  const days = Math.floor((new Date(dateStr).getTime() - Date.now()) / 86400000)
  if (days < 30) return 'gc-renewal--urgent'
  if (days < 60) return 'gc-renewal--warning'
  return ''
}

function fmtCurrency(value: number) {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 0,
    maximumFractionDigits: 0
  }).format(value)
}

function fmtDate(d: string) {
  if (!d) return '--'
  return new Date(d).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })
}

function fmtShortDate(d: string) {
  if (!d) return '--'
  return new Date(d).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
}

function billingStatusLabel(account: any) {
  const cycles = account.billingCycles
  if (!cycles || cycles.length === 0) return 'No billing data'
  return cycles[cycles.length - 1].status || 'Unknown'
}

function enrollmentPct(account: any) {
  if (!account.totalMembers || account.totalMembers === 0) return 100
  const enrolled = account.totalMembers - (account.pendingEnrollment || 0)
  return Math.round((enrolled / account.totalMembers) * 100)
}

const quickActions = [
  { label: 'New Inclusion', icon: 'i-heroicons-user-plus', route: '#', countKey: 'inclusion' },
  { label: 'New Exclusion', icon: 'i-heroicons-user-minus', route: '#', countKey: 'exclusion' },
  { label: 'File Claim', icon: 'i-heroicons-document-text', route: '#', countKey: 'claim' },
  { label: 'View Billing', icon: 'i-heroicons-banknotes', route: '#', countKey: 'billing' },
  { label: 'Generate Certificate', icon: 'i-heroicons-document-check', route: '#', countKey: 'certificate' },
  { label: 'Upload Document', icon: 'i-heroicons-arrow-up-tray', route: '#', countKey: 'document' }
]

const quickActionCounts = computed(() => {
  const counts: Record<string, number> = {
    inclusion: 0,
    exclusion: 0,
    claim: 0,
    billing: 0,
    certificate: 0,
    document: 0
  }
  for (const a of accounts.value) {
    if (a.serviceRequests) {
      for (const sr of a.serviceRequests) {
        if (sr.status !== 'resolved' && sr.status !== 'closed') {
          const t = sr.type?.toLowerCase()
          if (t && t in counts) counts[t]++
        }
      }
    }
    if (a.outstandingClaims) counts.claim += a.outstandingClaims
    if (a.pendingEnrollment) counts.inclusion += a.pendingEnrollment
  }
  return counts
})
</script>

<template>
  <div class="gc-page">
    <!-- Header -->
    <div class="gc-header">
      <div class="gc-header__text">
        <h1 class="gc-header__title">Colectivos</h1>
        <p class="gc-header__subtitle">Group account management &amp; operations</p>
      </div>
      <div style="display: flex; align-items: center; gap: 10px;">
        <span class="gc-count-badge">{{ filteredAccounts.length }} groups</span>
        <NuxtLink to="/support/collectivos/new">
          <UButton icon="i-heroicons-plus" color="primary">New Group</UButton>
        </NuxtLink>
      </div>
    </div>

    <!-- Filter Bar -->
    <div class="gc-filters">
      <div class="gc-filters__search">
        <UInput
          v-model="search"
          icon="i-heroicons-magnifying-glass"
          placeholder="Search group name, carrier, or ID..."
          class="gc-filters__search-input"
        />
      </div>
      <div class="gc-filters__tabs">
        <button
          v-for="tab in statusTabs"
          :key="tab.value"
          type="button"
          class="gc-filters__tab"
          :class="{ 'gc-filters__tab--active': statusFilter === tab.value }"
          @click="statusFilter = tab.value"
        >
          {{ tab.label }}
        </button>
      </div>
      <div class="gc-filters__lob">
        <select v-model="lobFilter" class="gc-filters__lob-select">
          <option v-for="opt in lobOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
        </select>
      </div>
      <div class="gc-view-toggle">
        <button type="button" :class="['gc-view-toggle-btn', viewMode === 'card' && 'gc-view-toggle-btn--active']" title="Card view" @click="viewMode = 'card'">
          <UIcon name="i-heroicons-squares-2x2" style="width: 16px; height: 16px;" />
        </button>
        <button type="button" :class="['gc-view-toggle-btn', viewMode === 'list' && 'gc-view-toggle-btn--active']" title="List view" @click="viewMode = 'list'">
          <UIcon name="i-heroicons-bars-3" style="width: 16px; height: 16px;" />
        </button>
      </div>
    </div>

    <!-- ═══ Card View ═══ -->
    <div v-if="viewMode === 'card'" class="gc-card-grid">
      <NuxtLink
        v-for="account in filteredAccounts"
        :key="account.id"
        :to="`/support/collectivos/${account.id}`"
        class="gc-card"
      >
        <div class="gc-card__top">
          <span class="gc-card__dot" :class="statusDotClass(account.status)" />
          <span class="gc-card__name">{{ account.name }}</span>
          <span class="gc-card__lob" :class="lobBadgeClass(account.lob)">{{ account.lob }}</span>
        </div>
        <div class="gc-card__body">
          <div class="gc-card__field">
            <span class="gc-card__field-label">Carrier</span>
            <span class="gc-card__field-value">{{ account.carrier }}</span>
          </div>
          <div class="gc-card__field">
            <span class="gc-card__field-label">Members</span>
            <span class="gc-card__field-value">{{ account.activeMembersCount ?? account.totalMembers }}</span>
          </div>
          <div class="gc-card__field">
            <span class="gc-card__field-label">Premium</span>
            <span class="gc-card__field-value">{{ fmtCurrency(account.monthlyPremium || 0) }}/mo</span>
          </div>
          <div class="gc-card__field">
            <span class="gc-card__field-label">Renewal</span>
            <span class="gc-card__field-value" :class="renewalClass(account.renewalDate)">{{ fmtShortDate(account.renewalDate) }}</span>
          </div>
          <div class="gc-card__field">
            <span class="gc-card__field-label">Agent</span>
            <span class="gc-card__field-value">{{ account.agent }}</span>
          </div>
        </div>
        <div v-if="account.hasUrgentIssues" class="gc-card__urgent">
          <UIcon name="i-heroicons-exclamation-triangle" style="width: 12px; height: 12px;" />
          Urgent issues
        </div>
        <div v-if="account.status === 'renewal_due' || renewalClass(account.renewalDate)" class="gc-card__renewal-cta" @click.prevent>
          <NuxtLink :to="`/renewals?group=${account.id}`" class="gc-renewal-btn">
            <UIcon name="i-heroicons-arrow-path" style="width: 13px; height: 13px;" />
            Start Renewal
          </NuxtLink>
        </div>
      </NuxtLink>
      <div v-if="filteredAccounts.length === 0" class="gc-empty" style="grid-column: 1 / -1;">
        <UIcon name="i-heroicons-building-office-2" class="gc-empty__icon" />
        <p class="gc-empty__text">No group accounts match your filters.</p>
      </div>
    </div>

    <!-- ═══ List View ═══ -->
    <div v-else class="gc-list">
      <div
        v-for="account in filteredAccounts"
        :key="account.id"
        class="gc-list__item"
        :class="{ 'gc-list__item--expanded': expandedGroupId === account.id }"
      >
        <!-- Collapsed Row -->
        <div class="gc-row" @click="toggleExpand(account.id)">
          <span class="gc-row__dot" :class="statusDotClass(account.status)" />
          <NuxtLink
            :to="`/support/collectivos/${account.id}`"
            class="gc-row__name"
            @click.stop
          >
            {{ account.name }}
          </NuxtLink>
          <span class="gc-row__lob" :class="lobBadgeClass(account.lob)">{{ account.lob }}</span>
          <span class="gc-row__carrier">{{ account.carrier }}</span>
          <span class="gc-row__members">
            <UIcon name="i-heroicons-users" class="gc-row__members-icon" />
            {{ account.activeMembersCount ?? account.totalMembers }}
          </span>
          <span class="gc-row__premium">{{ fmtCurrency(account.monthlyPremium || 0) }}/mo</span>
          <span class="gc-row__renewal" :class="renewalClass(account.renewalDate)">
            {{ fmtShortDate(account.renewalDate) }}
          </span>
          <span v-if="account.hasUrgentIssues" class="gc-row__urgent-dot" title="Urgent issues" />
          <span class="gc-row__agent">{{ account.agent }}</span>
          <UIcon
            name="i-heroicons-chevron-down"
            class="gc-row__chevron"
            :class="{ 'gc-row__chevron--open': expandedGroupId === account.id }"
          />
        </div>

        <!-- Expanded Quick-View -->
        <Transition name="gc-expand">
          <div v-if="expandedGroupId === account.id" class="gc-quickview">
            <div class="gc-quickview__grid">
              <!-- Column 1: Account Overview -->
              <div class="gc-quickview__col">
                <h4 class="gc-quickview__col-title">Account Overview</h4>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Contact</span>
                  <span class="gc-quickview__field-value">{{ account.contactName || '--' }}</span>
                  <span v-if="account.contactEmail" class="gc-quickview__field-sub">{{ account.contactEmail }}</span>
                  <span v-if="account.contactPhone" class="gc-quickview__field-sub">{{ account.contactPhone }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">HR Contact</span>
                  <span class="gc-quickview__field-value">{{ account.hrContactName || '--' }}</span>
                  <span v-if="account.hrContactEmail" class="gc-quickview__field-sub">{{ account.hrContactEmail }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Product</span>
                  <span class="gc-quickview__field-value">{{ account.product || '--' }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Effective Date</span>
                  <span class="gc-quickview__field-value">{{ fmtDate(account.effectiveDate) }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Commission</span>
                  <span class="gc-quickview__field-value">{{ account.commissionPct != null ? account.commissionPct + '%' : '--' }}</span>
                </div>
              </div>

              <!-- Column 2: Current Status -->
              <div class="gc-quickview__col">
                <h4 class="gc-quickview__col-title">Current Status</h4>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Outstanding Claims</span>
                  <span class="gc-quickview__field-value">{{ account.outstandingClaims ?? 0 }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Pending Tasks</span>
                  <span class="gc-quickview__field-value">{{ account.pendingTasks ?? 0 }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Pending Enrollment</span>
                  <div class="gc-quickview__enrollment">
                    <span class="gc-quickview__field-value">{{ account.pendingEnrollment ?? 0 }} of {{ account.totalMembers }}</span>
                    <div class="gc-quickview__progress-bar">
                      <div class="gc-quickview__progress-fill" :style="{ width: enrollmentPct(account) + '%' }" />
                    </div>
                    <span class="gc-quickview__progress-label">{{ enrollmentPct(account) }}% enrolled</span>
                  </div>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Billing Status</span>
                  <span class="gc-quickview__field-value">{{ billingStatusLabel(account) }}</span>
                </div>
                <div class="gc-quickview__field">
                  <span class="gc-quickview__field-label">Documents</span>
                  <span class="gc-quickview__field-value">{{ account.documents?.length ?? 0 }}</span>
                </div>
              </div>

              <!-- Column 3: Recent Activity -->
              <div class="gc-quickview__col">
                <h4 class="gc-quickview__col-title">Recent Activity</h4>
                <div v-if="account.recentActivity && account.recentActivity.length > 0" class="gc-quickview__activity">
                  <div
                    v-for="(entry, idx) in account.recentActivity.slice(0, 4)"
                    :key="idx"
                    class="gc-quickview__activity-item"
                  >
                    <span class="gc-quickview__activity-date">{{ fmtShortDate(entry.date) }}</span>
                    <span class="gc-quickview__activity-text">{{ entry.text }}</span>
                    <span v-if="entry.actor" class="gc-quickview__activity-actor">{{ entry.actor }}</span>
                  </div>
                </div>
                <p v-else class="gc-quickview__empty">No recent activity</p>

                <div class="gc-quickview__actions">
                  <NuxtLink
                    v-if="account.status === 'renewal_due' || renewalClass(account.renewalDate)"
                    :to="`/renewals?group=${account.id}`"
                    class="gc-quickview__action-btn gc-quickview__action-btn--renewal"
                    @click.stop
                  >
                    <UIcon name="i-heroicons-arrow-path" style="width: 12px; height: 12px;" /> Start Renewal
                  </NuxtLink>
                  <button type="button" class="gc-quickview__action-btn">Inclusions</button>
                  <button type="button" class="gc-quickview__action-btn">Exclusions</button>
                  <button type="button" class="gc-quickview__action-btn">Claims</button>
                  <button type="button" class="gc-quickview__action-btn">Billing</button>
                  <button type="button" class="gc-quickview__action-btn">Certificates</button>
                  <button type="button" class="gc-quickview__action-btn">Documents</button>
                </div>

                <NuxtLink :to="`/support/collectivos/${account.id}`" class="gc-quickview__open-btn">
                  Open Full Account
                  <UIcon name="i-heroicons-arrow-right" class="gc-quickview__open-icon" />
                </NuxtLink>
              </div>
            </div>
          </div>
        </Transition>
      </div>

      <!-- Empty state -->
      <div v-if="filteredAccounts.length === 0" class="gc-empty">
        <UIcon name="i-heroicons-building-office-2" class="gc-empty__icon" />
        <p class="gc-empty__text">No group accounts match your filters.</p>
      </div>
    </div>

    <!-- Quick Action Tiles -->
    <div class="gc-quick-tiles">
      <h3 class="gc-quick-tiles__title">Quick Actions</h3>
      <div class="gc-quick-tiles__grid">
        <button
          v-for="action in quickActions"
          :key="action.label"
          type="button"
          class="gc-quick-tiles__tile"
        >
          <UIcon :name="action.icon" class="gc-quick-tiles__tile-icon" />
          <span class="gc-quick-tiles__tile-label">{{ action.label }}</span>
          <span
            v-if="quickActionCounts[action.countKey] > 0"
            class="gc-quick-tiles__tile-badge"
          >
            {{ quickActionCounts[action.countKey] }}
          </span>
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped>
/* ── Page ── */
.gc-page {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-bottom: 48px;
}

/* ── Header ── */
.gc-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.gc-header__title {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.gc-header__subtitle {
  margin-top: 4px;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Count badge ── */
.gc-count-badge {
  font-size: 11px;
  font-weight: 700;
  color: #01696f;
  background: rgba(1, 105, 111, 0.08);
  padding: 2px 9px;
  border-radius: 10px;
  letter-spacing: 0.01em;
}

/* ── View toggle ── */
.gc-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.04);
  margin-left: auto;
}
.gc-view-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: #8a8a86;
  cursor: pointer;
  transition: all 0.15s ease;
}
.gc-view-toggle-btn:hover { color: var(--text-primary); }
.gc-view-toggle-btn--active {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ── Card grid ── */
.gc-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 1024px) { .gc-card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .gc-card-grid { grid-template-columns: 1fr; } }

.gc-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  text-decoration: none;
  transition: all 0.15s ease;
  cursor: pointer;
}
.gc-card:hover {
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.07);
  border-color: rgba(1, 105, 111, 0.15);
}
.gc-card__top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.gc-card__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.gc-card__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gc-card__lob {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.gc-card__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
}
.gc-card__field {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.gc-card__field-label {
  font-size: 12px;
  color: #8a8a86;
}
.gc-card__field-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.gc-card__urgent {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #dc2626;
  padding: 4px 8px;
  background: rgba(239, 68, 68, 0.06);
  border-radius: 6px;
  margin-top: 2px;
}
.gc-card__renewal-cta {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.05);
}
.gc-renewal-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #01696f;
  padding: 4px 10px;
  background: rgba(1,105,111,0.06);
  border-radius: 6px;
  text-decoration: none;
  transition: background 150ms ease;
}
.gc-renewal-btn:hover {
  background: rgba(1,105,111,0.12);
}

/* ── Filter Bar ── */
.gc-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.gc-filters__search {
  flex: 1;
  min-width: 200px;
}

.gc-filters__search-input {
  width: 100%;
}

.gc-filters__tabs {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.gc-filters__tab {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.gc-filters__tab:hover {
  color: var(--text-primary);
}

.gc-filters__tab--active {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.gc-filters__lob-select {
  padding: 7px 32px 7px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* ── Group List ── */
.gc-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  overflow: hidden;
}

.gc-list__item {
  background: #fff;
}

.gc-list__item--expanded {
  background: #fafafa;
}

/* ── Row ── */
.gc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.12s ease;
  min-height: 48px;
}

.gc-row:hover {
  background: rgba(1, 105, 111, 0.02);
}

.gc-row__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.gc-dot--onboarding,
.gc-dot--renewal {
  background: #f59e0b;
}

.gc-dot--suspended {
  background: #ef4444;
}

.gc-dot--default {
  background: #a3a3a3;
}

.gc-row__name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 160px;
  text-decoration: none;
  transition: color 0.12s ease;
}

.gc-row__name:hover {
  color: #01696f;
  text-decoration: underline;
}

.gc-row__lob {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.gc-lob--health {
  background: #dbeafe;
  color: #1e40af;
}

.gc-lob--life {
  background: #e0e7ff;
  color: #4338ca;
}

.gc-lob--disability {
  background: #fef3c7;
  color: #92400e;
}

.gc-lob--default {
  background: #f3f4f6;
  color: #6b7280;
}

.gc-row__carrier {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 100px;
}

.gc-row__members {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.gc-row__members-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.gc-row__premium {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 90px;
}

.gc-row__renewal {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 80px;
}

.gc-renewal--urgent {
  color: #dc2626;
  font-weight: 600;
}

.gc-renewal--warning {
  color: #d97706;
  font-weight: 600;
}

.gc-row__urgent-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  animation: gc-pulse 2s ease-in-out infinite;
}

@keyframes gc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.gc-row__agent {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
  min-width: 70px;
}

.gc-row__chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.gc-row__chevron--open {
  transform: rotate(180deg);
}

/* ── Quick-View Panel ── */
.gc-expand-enter-active,
.gc-expand-leave-active {
  transition: all 0.2s ease;
  overflow: hidden;
}

.gc-expand-enter-from,
.gc-expand-leave-to {
  opacity: 0;
  max-height: 0;
}

.gc-expand-enter-to,
.gc-expand-leave-from {
  opacity: 1;
  max-height: 600px;
}

.gc-quickview {
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding: 20px 18px 20px 40px;
  background: #fafafa;
}

.gc-quickview__grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 28px;
}

.gc-quickview__col-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a8a86;
  margin-bottom: 14px;
}

.gc-quickview__field {
  margin-bottom: 10px;
}

.gc-quickview__field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a8a86;
  margin-bottom: 2px;
}

.gc-quickview__field-value {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.gc-quickview__field-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.gc-quickview__enrollment {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gc-quickview__progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.gc-quickview__progress-fill {
  height: 100%;
  background: #01696f;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.gc-quickview__progress-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Activity ── */
.gc-quickview__activity {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.gc-quickview__activity-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.gc-quickview__activity-item:last-child {
  border-bottom: none;
}

.gc-quickview__activity-date {
  font-size: 11px;
  color: #8a8a86;
  font-weight: 500;
}

.gc-quickview__activity-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.gc-quickview__activity-actor {
  font-size: 11px;
  color: var(--text-muted);
}

.gc-quickview__empty {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Quick Action Buttons ── */
.gc-quickview__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.gc-quickview__action-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: #01696f;
  background: rgba(1, 105, 111, 0.06);
  border: 1px solid rgba(1, 105, 111, 0.12);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.gc-quickview__action-btn:hover {
  background: rgba(1, 105, 111, 0.1);
  border-color: rgba(1, 105, 111, 0.2);
}
.gc-quickview__action-btn--renewal {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  font-weight: 600;
  background: rgba(1,105,111,0.10);
  border-color: rgba(1,105,111,0.18);
}

.gc-quickview__open-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #01696f;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.12s ease;
}

.gc-quickview__open-btn:hover {
  background: #015258;
}

.gc-quickview__open-icon {
  width: 14px;
  height: 14px;
}

/* ── Empty State ── */
.gc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 0;
  background: #fff;
}

.gc-empty__icon {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  opacity: 0.4;
}

.gc-empty__text {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Quick Action Tiles ── */
.gc-quick-tiles {
  margin-top: 4px;
}

.gc-quick-tiles__title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a8a86;
  margin-bottom: 12px;
}

.gc-quick-tiles__grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.gc-quick-tiles__tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  cursor: pointer;
  transition: all 0.15s ease;
}

.gc-quick-tiles__tile:hover {
  border-color: rgba(1, 105, 111, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.gc-quick-tiles__tile-icon {
  width: 22px;
  height: 22px;
  color: #01696f;
}

.gc-quick-tiles__tile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
}

.gc-quick-tiles__tile-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #ef4444;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .gc-quickview__grid {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .gc-quick-tiles__grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .gc-row__carrier,
  .gc-row__agent {
    display: none;
  }
}

@media (max-width: 640px) {
  .gc-kpi-strip {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .gc-kpi-strip__divider {
    display: none;
  }

  .gc-kpi-strip__item {
    min-width: 90px;
    padding: 8px 12px;
  }

  .gc-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .gc-filters__tabs {
    overflow-x: auto;
  }

  .gc-quickview__grid {
    grid-template-columns: 1fr;
  }

  .gc-quick-tiles__grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .gc-row__premium,
  .gc-row__renewal {
    display: none;
  }
}
</style>
